Search in sources :

Example 1 with ChannelDef

use of com.cloud.hypervisor.kvm.resource.LibvirtVMDef.ChannelDef in project cloudstack by apache.

the class LibvirtDomainXMLParserTest method testDomainXMLParser.

public void testDomainXMLParser() {
    int vncPort = 5900;
    DiskDef.DiskBus diskBus = DiskDef.DiskBus.VIRTIO;
    DiskDef.DiskType diskType = DiskDef.DiskType.FILE;
    DiskDef.DeviceType deviceType = DiskDef.DeviceType.DISK;
    DiskDef.DiskFmtType diskFormat = DiskDef.DiskFmtType.QCOW2;
    DiskDef.DiskCacheMode diskCache = DiskDef.DiskCacheMode.NONE;
    InterfaceDef.NicModel ifModel = InterfaceDef.NicModel.VIRTIO;
    InterfaceDef.GuestNetType ifType = InterfaceDef.GuestNetType.BRIDGE;
    ChannelDef.ChannelType channelType = ChannelDef.ChannelType.UNIX;
    ChannelDef.ChannelState channelState = ChannelDef.ChannelState.DISCONNECTED;
    String ssvmAgentPath = "/var/lib/libvirt/qemu/s-2970-VM.agent";
    String ssvmAgentName = "s-2970-VM.vport";
    String guestAgentPath = "/var/lib/libvirt/qemu/guest-agent.org.qemu.guest_agent.0";
    String guestAgentName = "org.qemu.guest_agent.0";
    String diskLabel = "vda";
    String diskPath = "/var/lib/libvirt/images/my-test-image.qcow2";
    String xml = "<domain type='kvm' id='10'>" + "<name>s-2970-VM</name>" + "<uuid>4d2c1526-865d-4fc9-a1ac-dbd1801a22d0</uuid>" + "<description>Debian GNU/Linux 6(64-bit)</description>" + "<memory unit='KiB'>262144</memory>" + "<currentMemory unit='KiB'>262144</currentMemory>" + "<vcpu placement='static'>1</vcpu>" + "<cputune>" + "<shares>250</shares>" + "</cputune>" + "<resource>" + "<partition>/machine</partition>" + "</resource>" + "<os>" + "<type arch='x86_64' machine='pc-i440fx-1.5'>hvm</type>" + "<boot dev='cdrom'/>" + "<boot dev='hd'/>" + "</os>" + "<features>" + "<acpi/>" + "<apic/>" + "<pae/>" + "</features>" + "<clock offset='utc'/>" + "<on_poweroff>destroy</on_poweroff>" + "<on_reboot>restart</on_reboot>" + "<on_crash>destroy</on_crash>" + "<devices>" + "<emulator>/usr/bin/kvm-spice</emulator>" + "<disk type='" + diskType.toString() + "' device='" + deviceType.toString() + "'>" + "<driver name='qemu' type='" + diskFormat.toString() + "' cache='" + diskCache.toString() + "'/>" + "<source file='" + diskPath + "'/>" + "<target dev='" + diskLabel + "' bus='" + diskBus.toString() + "'/>" + "<alias name='virtio-disk0'/>" + "<address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>" + "</disk>" + "<disk type='file' device='cdrom'>" + "<driver name='qemu' type='raw' cache='none'/>" + "<source file='/usr/share/cloudstack-common/vms/systemvm.iso'/>" + "<target dev='hdc' bus='ide'/>" + "<readonly/>" + "<alias name='ide0-1-0'/>" + "<address type='drive' controller='0' bus='1' target='0' unit='0'/>" + "</disk>" + "<controller type='usb' index='0'>" + "<alias name='usb0'/>" + "<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>" + "</controller>" + "<controller type='pci' index='0' model='pci-root'>" + "<alias name='pci0'/>" + "</controller>" + "<controller type='ide' index='0'>" + "<alias name='ide0'/>" + "<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>" + "</controller>" + "<controller type='virtio-serial' index='0'>" + "<alias name='virtio-serial0'/>" + "<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>" + "</controller>" + "<interface type='" + ifType.toString() + "'>" + "<mac address='0e:00:a9:fe:02:00'/>" + "<source bridge='cloud0'/>" + "<target dev='vnet0'/>" + "<model type='" + ifModel.toString() + "'/>" + "<alias name='net0'/>" + "<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>" + "</interface>" + "<interface type='" + ifType.toString() + "'>" + "<mac address='06:c5:94:00:05:65'/>" + "<source bridge='cloudbr1'/>" + "<target dev='vnet1'/>" + "<model type='" + ifModel.toString() + "'/>" + "<alias name='net1'/>" + "<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>" + "</interface>" + "<interface type='" + ifType.toString() + "'>" + "<mac address='06:c9:f4:00:04:40'/>" + "<source bridge='cloudbr0'/>" + "<target dev='vnet2'/>" + "<model type='" + ifModel.toString() + "'/>" + "<alias name='net2'/>" + "<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>" + "</interface>" + "<interface type='" + ifType.toString() + "'>" + "<mac address='06:7e:c6:00:05:68'/>" + "<source bridge='cloudbr1'/>" + "<target dev='vnet3'/>" + "<model type='" + ifModel.toString() + "'/>" + "<alias name='net3'/>" + "<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>" + "</interface>" + "<serial type='pty'>" + "<source path='/dev/pts/3'/>" + "<target port='0'/>" + "<alias name='serial0'/>" + "</serial>" + "<console type='pty' tty='/dev/pts/3'>" + "<source path='/dev/pts/3'/>" + "<target type='serial' port='0'/>" + "<alias name='serial0'/>" + "</console>" + "<channel type='unix'>" + "<source mode='bind' path='/var/lib/libvirt/qemu/s-2970-VM.agent'/>" + "<target type='virtio' name='s-2970-VM.vport' state='disconnected'/>" + "<alias name='channel0'/>" + "<address type='virtio-serial' controller='0' bus='0' port='1'/>" + "</channel>" + "<input type='tablet' bus='usb'>" + "<alias name='input0'/>" + "</input>" + "<input type='mouse' bus='ps2'/>" + "<graphics type='vnc' port='" + vncPort + "' autoport='yes' listen='0.0.0.0'>" + "<listen type='address' address='0.0.0.0'/>" + "</graphics>" + "<video>" + "<model type='cirrus' vram='9216' heads='1'/>" + "<alias name='video0'/>" + "<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>" + "</video>" + "<memballoon model='virtio'>" + "<alias name='balloon0'/>" + "<address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>" + "</memballoon>" + "<rng model='virtio'>" + "<rate period='5000' bytes='4096' />" + "<backend model='random'>/dev/random</backend>" + "</rng>" + "<channel type='unix'>" + "<source mode='bind' path='" + guestAgentPath + "'/>" + "<target type='virtio' name='" + guestAgentName + "'/>" + "<alias name='channel0'/>" + "<address type='virtio-serial' controller='0' bus='0' port='1'/>" + "</channel>" + "</devices>" + "<seclabel type='none'/>" + "</domain>";
    LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser();
    parser.parseDomainXML(xml);
    assertEquals(vncPort - 5900, (int) parser.getVncPort());
    List<DiskDef> disks = parser.getDisks();
    /* Disk 0 is the first disk, the QCOW2 file backed virto disk */
    int diskId = 0;
    assertEquals(diskLabel, disks.get(diskId).getDiskLabel());
    assertEquals(diskPath, disks.get(diskId).getDiskPath());
    assertEquals(diskCache, disks.get(diskId).getCacheMode());
    assertEquals(diskBus, disks.get(diskId).getBusType());
    assertEquals(diskType, disks.get(diskId).getDiskType());
    assertEquals(deviceType, disks.get(diskId).getDeviceType());
    assertEquals(diskFormat, disks.get(diskId).getDiskFormatType());
    List<ChannelDef> channels = parser.getChannels();
    for (int i = 0; i < channels.size(); i++) {
        assertEquals(channelType, channels.get(i).getChannelType());
        assertEquals(channelType, channels.get(i).getChannelType());
    }
    /* SSVM provisioning port/channel */
    assertEquals(channelState, channels.get(0).getChannelState());
    assertEquals(new File(ssvmAgentPath), channels.get(0).getPath());
    assertEquals(ssvmAgentName, channels.get(0).getName());
    /* Qemu Guest Agent port/channel */
    assertEquals(new File(guestAgentPath), channels.get(1).getPath());
    assertEquals(guestAgentName, channels.get(1).getName());
    List<InterfaceDef> ifs = parser.getInterfaces();
    for (int i = 0; i < ifs.size(); i++) {
        assertEquals(ifModel, ifs.get(i).getModel());
        assertEquals(ifType, ifs.get(i).getNetType());
    }
    List<RngDef> rngs = parser.getRngs();
    assertEquals("/dev/random", rngs.get(0).getPath());
    assertEquals(RngDef.RngBackendModel.RANDOM, rngs.get(0).getRngBackendModel());
    assertEquals(4096, rngs.get(0).getRngRateBytes());
    assertEquals(5000, rngs.get(0).getRngRatePeriod());
}
Also used : InterfaceDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef) RngDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.RngDef) DiskDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef) ChannelDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.ChannelDef) File(java.io.File)

Example 2 with ChannelDef

use of com.cloud.hypervisor.kvm.resource.LibvirtVMDef.ChannelDef in project cloudstack by apache.

the class LibvirtVMDefTest method testChannelDef.

public void testChannelDef() {
    ChannelDef.ChannelType type = ChannelDef.ChannelType.UNIX;
    ChannelDef.ChannelState state = ChannelDef.ChannelState.CONNECTED;
    String name = "v-136-VM.vport";
    File path = new File("/var/lib/libvirt/qemu/" + name);
    ChannelDef channelDef = new ChannelDef(name, type, state, path);
    assertEquals(state, channelDef.getChannelState());
    assertEquals(type, channelDef.getChannelType());
    assertEquals(name, channelDef.getName());
    assertEquals(path, channelDef.getPath());
}
Also used : ChannelDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.ChannelDef) File(java.io.File)

Example 3 with ChannelDef

use of com.cloud.hypervisor.kvm.resource.LibvirtVMDef.ChannelDef in project cloudstack by apache.

the class LibvirtDomainXMLParser method parseDomainXML.

public boolean parseDomainXML(String domXML) {
    DocumentBuilder builder;
    try {
        builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        InputSource is = new InputSource();
        is.setCharacterStream(new StringReader(domXML));
        Document doc = builder.parse(is);
        Element rootElement = doc.getDocumentElement();
        desc = getTagValue("description", rootElement);
        Element devices = (Element) rootElement.getElementsByTagName("devices").item(0);
        NodeList disks = devices.getElementsByTagName("disk");
        for (int i = 0; i < disks.getLength(); i++) {
            Element disk = (Element) disks.item(i);
            String type = disk.getAttribute("type");
            DiskDef def = new DiskDef();
            if (type.equalsIgnoreCase("network")) {
                String diskFmtType = getAttrValue("driver", "type", disk);
                String diskCacheMode = getAttrValue("driver", "cache", disk);
                String diskPath = getAttrValue("source", "name", disk);
                String protocol = getAttrValue("source", "protocol", disk);
                String authUserName = getAttrValue("auth", "username", disk);
                String poolUuid = getAttrValue("secret", "uuid", disk);
                String host = getAttrValue("host", "name", disk);
                int port = Integer.parseInt(getAttrValue("host", "port", disk));
                String diskLabel = getAttrValue("target", "dev", disk);
                String bus = getAttrValue("target", "bus", disk);
                DiskDef.DiskFmtType fmt = null;
                if (diskFmtType != null) {
                    fmt = DiskDef.DiskFmtType.valueOf(diskFmtType.toUpperCase());
                }
                def.defNetworkBasedDisk(diskPath, host, port, authUserName, poolUuid, diskLabel, DiskDef.DiskBus.valueOf(bus.toUpperCase()), DiskDef.DiskProtocol.valueOf(protocol.toUpperCase()), fmt);
                def.setCacheMode(DiskDef.DiskCacheMode.valueOf(diskCacheMode.toUpperCase()));
            } else {
                String diskFmtType = getAttrValue("driver", "type", disk);
                String diskCacheMode = getAttrValue("driver", "cache", disk);
                String diskFile = getAttrValue("source", "file", disk);
                String diskDev = getAttrValue("source", "dev", disk);
                String diskLabel = getAttrValue("target", "dev", disk);
                String bus = getAttrValue("target", "bus", disk);
                String device = disk.getAttribute("device");
                if (type.equalsIgnoreCase("file")) {
                    if (device.equalsIgnoreCase("disk")) {
                        DiskDef.DiskFmtType fmt = null;
                        if (diskFmtType != null) {
                            fmt = DiskDef.DiskFmtType.valueOf(diskFmtType.toUpperCase());
                        }
                        def.defFileBasedDisk(diskFile, diskLabel, DiskDef.DiskBus.valueOf(bus.toUpperCase()), fmt);
                    } else if (device.equalsIgnoreCase("cdrom")) {
                        def.defISODisk(diskFile);
                    }
                } else if (type.equalsIgnoreCase("block")) {
                    def.defBlockBasedDisk(diskDev, diskLabel, DiskDef.DiskBus.valueOf(bus.toUpperCase()));
                }
                if (diskCacheMode != null) {
                    def.setCacheMode(DiskDef.DiskCacheMode.valueOf(diskCacheMode.toUpperCase()));
                }
            }
            NodeList iotune = disk.getElementsByTagName("iotune");
            if ((iotune != null) && (iotune.getLength() != 0)) {
                String bytesReadRateStr = getTagValue("read_bytes_sec", (Element) iotune.item(0));
                if (bytesReadRateStr != null) {
                    Long bytesReadRate = Long.parseLong(bytesReadRateStr);
                    def.setBytesReadRate(bytesReadRate);
                }
                String bytesWriteRateStr = getTagValue("write_bytes_sec", (Element) iotune.item(0));
                if (bytesWriteRateStr != null) {
                    Long bytesWriteRate = Long.parseLong(bytesWriteRateStr);
                    def.setBytesWriteRate(bytesWriteRate);
                }
                String iopsReadRateStr = getTagValue("read_iops_sec", (Element) iotune.item(0));
                if (iopsReadRateStr != null) {
                    Long iopsReadRate = Long.parseLong(iopsReadRateStr);
                    def.setIopsReadRate(iopsReadRate);
                }
                String iopsWriteRateStr = getTagValue("write_iops_sec", (Element) iotune.item(0));
                if (iopsWriteRateStr != null) {
                    Long iopsWriteRate = Long.parseLong(iopsWriteRateStr);
                    def.setIopsWriteRate(iopsWriteRate);
                }
            }
            diskDefs.add(def);
        }
        NodeList nics = devices.getElementsByTagName("interface");
        for (int i = 0; i < nics.getLength(); i++) {
            Element nic = (Element) nics.item(i);
            String type = nic.getAttribute("type");
            String mac = getAttrValue("mac", "address", nic);
            String dev = getAttrValue("target", "dev", nic);
            String model = getAttrValue("model", "type", nic);
            InterfaceDef def = new InterfaceDef();
            NodeList bandwidth = nic.getElementsByTagName("bandwidth");
            Integer networkRateKBps = 0;
            if ((bandwidth != null) && (bandwidth.getLength() != 0)) {
                Integer inbound = Integer.valueOf(getAttrValue("inbound", "average", (Element) bandwidth.item(0)));
                Integer outbound = Integer.valueOf(getAttrValue("outbound", "average", (Element) bandwidth.item(0)));
                if (inbound.equals(outbound)) {
                    networkRateKBps = inbound;
                }
            }
            if (type.equalsIgnoreCase("network")) {
                String network = getAttrValue("source", "network", nic);
                def.defPrivateNet(network, dev, mac, NicModel.valueOf(model.toUpperCase()), networkRateKBps);
            } else if (type.equalsIgnoreCase("bridge")) {
                String bridge = getAttrValue("source", "bridge", nic);
                def.defBridgeNet(bridge, dev, mac, NicModel.valueOf(model.toUpperCase()), networkRateKBps);
            } else if (type.equalsIgnoreCase("ethernet")) {
                String scriptPath = getAttrValue("script", "path", nic);
                def.defEthernet(dev, mac, NicModel.valueOf(model.toUpperCase()), scriptPath, networkRateKBps);
            }
            interfaces.add(def);
        }
        NodeList ports = devices.getElementsByTagName("channel");
        for (int i = 0; i < ports.getLength(); i++) {
            Element channel = (Element) ports.item(i);
            String type = channel.getAttribute("type");
            String path = getAttrValue("source", "path", channel);
            String name = getAttrValue("target", "name", channel);
            String state = getAttrValue("target", "state", channel);
            ChannelDef def = null;
            if (!StringUtils.isNotBlank(state)) {
                def = new ChannelDef(name, ChannelDef.ChannelType.valueOf(type.toUpperCase()), new File(path));
            } else {
                def = new ChannelDef(name, ChannelDef.ChannelType.valueOf(type.toUpperCase()), ChannelDef.ChannelState.valueOf(state.toUpperCase()), new File(path));
            }
            channels.add(def);
        }
        Element graphic = (Element) devices.getElementsByTagName("graphics").item(0);
        if (graphic != null) {
            String port = graphic.getAttribute("port");
            if (port != null) {
                try {
                    vncPort = Integer.parseInt(port);
                    if (vncPort != -1) {
                        vncPort = vncPort - 5900;
                    } else {
                        vncPort = null;
                    }
                } catch (NumberFormatException nfe) {
                    vncPort = null;
                }
            }
        }
        NodeList rngs = devices.getElementsByTagName("rng");
        for (int i = 0; i < rngs.getLength(); i++) {
            RngDef def = null;
            Element rng = (Element) rngs.item(i);
            String backendModel = getAttrValue("backend", "model", rng);
            String path = getTagValue("backend", rng);
            String bytes = getAttrValue("rate", "bytes", rng);
            String period = getAttrValue("rate", "period", rng);
            if (Strings.isNullOrEmpty(backendModel)) {
                def = new RngDef(path, Integer.parseInt(bytes), Integer.parseInt(period));
            } else {
                def = new RngDef(path, RngBackendModel.valueOf(backendModel.toUpperCase()), Integer.parseInt(bytes), Integer.parseInt(period));
            }
            rngDefs.add(def);
        }
        return true;
    } catch (ParserConfigurationException e) {
        s_logger.debug(e.toString());
    } catch (SAXException e) {
        s_logger.debug(e.toString());
    } catch (IOException e) {
        s_logger.debug(e.toString());
    }
    return false;
}
Also used : InputSource(org.xml.sax.InputSource) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) InterfaceDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef) RngDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.RngDef) DiskDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) ChannelDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.ChannelDef) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File)

Example 4 with ChannelDef

use of com.cloud.hypervisor.kvm.resource.LibvirtVMDef.ChannelDef in project cloudstack by apache.

the class LibvirtComputingResource method createVMFromSpec.

public LibvirtVMDef createVMFromSpec(final VirtualMachineTO vmTO) {
    final LibvirtVMDef vm = new LibvirtVMDef();
    vm.setDomainName(vmTO.getName());
    String uuid = vmTO.getUuid();
    uuid = getUuid(uuid);
    vm.setDomUUID(uuid);
    vm.setDomDescription(vmTO.getOs());
    vm.setPlatformEmulator(vmTO.getPlatformEmulator());
    final GuestDef guest = new GuestDef();
    if (HypervisorType.LXC == _hypervisorType && VirtualMachine.Type.User == vmTO.getType()) {
        // LXC domain is only valid for user VMs. Use KVM for system VMs.
        guest.setGuestType(GuestDef.GuestType.LXC);
        vm.setHvsType(HypervisorType.LXC.toString().toLowerCase());
    } else {
        guest.setGuestType(GuestDef.GuestType.KVM);
        vm.setHvsType(HypervisorType.KVM.toString().toLowerCase());
        vm.setLibvirtVersion(_hypervisorLibvirtVersion);
        vm.setQemuVersion(_hypervisorQemuVersion);
    }
    guest.setGuestArch(vmTO.getArch());
    guest.setMachineType("pc");
    guest.setUuid(uuid);
    guest.setBootOrder(GuestDef.BootOrder.CDROM);
    guest.setBootOrder(GuestDef.BootOrder.HARDISK);
    vm.addComp(guest);
    final GuestResourceDef grd = new GuestResourceDef();
    if (vmTO.getMinRam() != vmTO.getMaxRam() && !_noMemBalloon) {
        grd.setMemBalloning(true);
        grd.setCurrentMem(vmTO.getMinRam() / 1024);
        grd.setMemorySize(vmTO.getMaxRam() / 1024);
    } else {
        grd.setMemorySize(vmTO.getMaxRam() / 1024);
    }
    final int vcpus = vmTO.getCpus();
    grd.setVcpuNum(vcpus);
    vm.addComp(grd);
    final CpuModeDef cmd = new CpuModeDef();
    cmd.setMode(_guestCpuMode);
    cmd.setModel(_guestCpuModel);
    if (vmTO.getType() == VirtualMachine.Type.User) {
        cmd.setFeatures(_cpuFeatures);
    }
    // multi cores per socket, for larger core configs
    if (vcpus % 6 == 0) {
        final int sockets = vcpus / 6;
        cmd.setTopology(6, sockets);
    } else if (vcpus % 4 == 0) {
        final int sockets = vcpus / 4;
        cmd.setTopology(4, sockets);
    }
    vm.addComp(cmd);
    if (_hypervisorLibvirtVersion >= 9000) {
        final CpuTuneDef ctd = new CpuTuneDef();
        /**
             A 4.0.X/4.1.X management server doesn't send the correct JSON
             command for getMinSpeed, it only sends a 'speed' field.

             So if getMinSpeed() returns null we fall back to getSpeed().

             This way a >4.1 agent can work communicate a <=4.1 management server

             This change is due to the overcommit feature in 4.2
             */
        if (vmTO.getMinSpeed() != null) {
            ctd.setShares(vmTO.getCpus() * vmTO.getMinSpeed());
        } else {
            ctd.setShares(vmTO.getCpus() * vmTO.getSpeed());
        }
        vm.addComp(ctd);
    }
    final FeaturesDef features = new FeaturesDef();
    features.addFeatures("pae");
    features.addFeatures("apic");
    features.addFeatures("acpi");
    //for rhel 6.5 and above, hyperv enlightment feature is added
    /*
         * if (vmTO.getOs().contains("Windows Server 2008") && hostOsVersion != null && ((hostOsVersion.first() == 6 && hostOsVersion.second() >= 5) || (hostOsVersion.first() >= 7))) {
         *    LibvirtVMDef.HyperVEnlightenmentFeatureDef hyv = new LibvirtVMDef.HyperVEnlightenmentFeatureDef();
         *    hyv.setRelaxed(true);
         *    features.addHyperVFeature(hyv);
         * }
         */
    vm.addComp(features);
    final TermPolicy term = new TermPolicy();
    term.setCrashPolicy("destroy");
    term.setPowerOffPolicy("destroy");
    term.setRebootPolicy("restart");
    vm.addComp(term);
    final ClockDef clock = new ClockDef();
    if (vmTO.getOs().startsWith("Windows")) {
        clock.setClockOffset(ClockDef.ClockOffset.LOCALTIME);
        clock.setTimer("rtc", "catchup", null);
    } else if (vmTO.getType() != VirtualMachine.Type.User || isGuestPVEnabled(vmTO.getOs())) {
        if (_hypervisorLibvirtVersion >= 9 * 1000 + 10) {
            clock.setTimer("kvmclock", null, null, _noKvmClock);
        }
    }
    vm.addComp(clock);
    final DevicesDef devices = new DevicesDef();
    devices.setEmulatorPath(_hypervisorPath);
    devices.setGuestType(guest.getGuestType());
    final SerialDef serial = new SerialDef("pty", null, (short) 0);
    devices.addDevice(serial);
    /* Add a VirtIO channel for SystemVMs for communication and provisioning */
    if (vmTO.getType() != VirtualMachine.Type.User) {
        devices.addDevice(new ChannelDef(vmTO.getName() + ".vport", ChannelDef.ChannelType.UNIX, new File(_qemuSocketsPath + "/" + vmTO.getName() + ".agent")));
    }
    if (_rngEnable) {
        final RngDef rngDevice = new RngDef(_rngPath, _rngBackendModel, _rngRateBytes, _rngRatePeriod);
        devices.addDevice(rngDevice);
    }
    /* Add a VirtIO channel for the Qemu Guest Agent tools */
    devices.addDevice(new ChannelDef(_qemuGuestAgentSocketName, ChannelDef.ChannelType.UNIX, new File(_qemuSocketsPath + "/" + vmTO.getName() + "." + _qemuGuestAgentSocketName)));
    final VideoDef videoCard = new VideoDef(_videoHw, _videoRam);
    devices.addDevice(videoCard);
    final ConsoleDef console = new ConsoleDef("pty", null, null, (short) 0);
    devices.addDevice(console);
    //add the VNC port passwd here, get the passwd from the vmInstance.
    final String passwd = vmTO.getVncPassword();
    final GraphicDef grap = new GraphicDef("vnc", (short) 0, true, vmTO.getVncAddr(), passwd, null);
    devices.addDevice(grap);
    final InputDef input = new InputDef("tablet", "usb");
    devices.addDevice(input);
    DiskDef.DiskBus busT = getDiskModelFromVMDetail(vmTO);
    if (busT == null) {
        busT = getGuestDiskModel(vmTO.getPlatformEmulator());
    }
    // If we're using virtio scsi, then we need to add a virtual scsi controller
    if (busT == DiskDef.DiskBus.SCSI) {
        final SCSIDef sd = new SCSIDef((short) 0, 0, 0, 9, 0);
        devices.addDevice(sd);
    }
    vm.addComp(devices);
    return vm;
}
Also used : TermPolicy(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.TermPolicy) CpuTuneDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.CpuTuneDef) DevicesDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DevicesDef) GuestResourceDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.GuestResourceDef) ClockDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.ClockDef) GraphicDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.GraphicDef) VideoDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.VideoDef) RngDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.RngDef) DiskDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef) SCSIDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.SCSIDef) SerialDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.SerialDef) ConsoleDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.ConsoleDef) InputDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InputDef) CpuModeDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.CpuModeDef) FeaturesDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.FeaturesDef) ChannelDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.ChannelDef) GuestDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.GuestDef) File(java.io.File)

Aggregations

ChannelDef (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.ChannelDef)4 File (java.io.File)4 DiskDef (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef)3 RngDef (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.RngDef)3 InterfaceDef (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef)2 ClockDef (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.ClockDef)1 ConsoleDef (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.ConsoleDef)1 CpuModeDef (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.CpuModeDef)1 CpuTuneDef (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.CpuTuneDef)1 DevicesDef (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DevicesDef)1 FeaturesDef (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.FeaturesDef)1 GraphicDef (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.GraphicDef)1 GuestDef (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.GuestDef)1 GuestResourceDef (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.GuestResourceDef)1 InputDef (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InputDef)1 SCSIDef (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.SCSIDef)1 SerialDef (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.SerialDef)1 TermPolicy (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.TermPolicy)1 VideoDef (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.VideoDef)1 IOException (java.io.IOException)1