Search in sources :

Example 1 with RngDef

use of com.cloud.agent.resource.kvm.xml.LibvirtVmDef.RngDef in project cosmic by MissionCriticalCloud.

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("This VM is optimised for: " + vmTo.getOptimiseFor().toString());
    vm.setPlatformEmulator(vmTo.getPlatformEmulator());
    final MetadataTO metadataTo = vmTo.getMetadata();
    if (metadataTo != null) {
        final MetadataDef metadata = new MetadataDef();
        metadata.getNodes().put("cosmicDomainUuid", metadataTo.getDomainUuid());
        metadata.getNodes().put("cosmicDomainName", metadataTo.getCosmicDomainName());
        metadata.getNodes().put("cosmicDomainPath", metadataTo.getCosmicDomainPath());
        metadata.getNodes().put("cosmicInternalVmId", metadataTo.getVmId());
        metadata.getNodes().put("cosmicInstanceName", metadataTo.getInstanceName());
        metadata.getNodes().put("cosmicXmlGeneratedInCosmicVersion", LibvirtComputingResource.class.getPackage().getImplementationVersion());
        metadata.getNodes().put("cosmicXmlGeneratedDateTime", getCurrentLocalDateTimeStamp());
        metadata.getNodes().put("cosmicXmlGeneratedEpoch", getCurrentEpoch());
        metadata.getNodes().put("cosmicVmHostname", metadataTo.getHostname());
        metadata.getNodes().put("cosmicOptimiseFor", vmTo.getOptimiseFor().toString());
        final List<String> vpcNameList = metadataTo.getVpcNameList();
        if (vpcNameList != null) {
            for (final String vpcName : vpcNameList) {
                metadata.getNodes().put("cosmicVPC", vpcName);
            }
        }
        final Map<String, String> vmTags = metadataTo.getResourceTags();
        if (vmTags != null) {
            for (Map.Entry<String, String> vmTag : vmTags.entrySet()) {
                metadata.getNodes().put("cosmicTag_" + vmTag.getKey(), vmTag.getValue());
            }
        }
        vm.addComponent(metadata);
    }
    final GuestDef guest = new GuestDef();
    guest.setGuestType(LibvirtVmDef.GuestType.KVM);
    vm.setHvsType(HypervisorType.KVM.toString().toLowerCase());
    vm.setLibvirtVersion(this.hypervisorLibvirtVersion);
    vm.setQemuVersion(this.hypervisorQemuVersion);
    guest.setGuestArch(vmTo.getArch());
    guest.setMachineType("pc");
    guest.setUuid(uuid);
    guest.setManufacturer(vmTo.getManufacturer());
    guest.setBootMenuTimeout(vmTo.getBootMenuTimeout());
    if (vmTo.getBootOrder() != null) {
        for (BootOrder device : vmTo.getBootOrder()) {
            guest.setBootOrder(device);
        }
    } else {
        guest.setBootOrder(BootOrder.CDROM);
        guest.setBootOrder(BootOrder.HARDDISK);
    }
    vm.addComponent(guest);
    final GuestResourceDef grd = new GuestResourceDef();
    if (vmTo.getMinRam() != vmTo.getMaxRam() && !this.libvirtComputingResourceProperties.getVmMemballoonDisable()) {
        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.addComponent(grd);
    final CpuModeDef cmd = new CpuModeDef();
    cmd.setMode(getGuestCpuMode());
    cmd.setModel(getGuestCpuModel());
    cmd.setCpuflags(vmTo.getCpuflags());
    if (vmTo.getType() == VirtualMachineType.User) {
        cmd.setFeatures(getCpuFeatures());
    }
    // But only when maintenance policy is live migrate
    if (OptimiseFor.Windows.equals(vmTo.getOptimiseFor()) && MaintenancePolicy.LiveMigrate.equals(vmTo.getMaintenancePolicy())) {
        String extended_cpu_flags = vmTo.getCpuflags();
        if (extended_cpu_flags == null) {
            extended_cpu_flags = "-hypervisor";
        } else {
            extended_cpu_flags += " -hypervisor";
        }
        cmd.setCpuflags(extended_cpu_flags);
    }
    // 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.addComponent(cmd);
    final CpuTuneDef ctd = new CpuTuneDef();
    if (VirtualMachineType.DomainRouter.equals(vmTo.getType())) {
        ctd.setShares(vmTo.getCpus() * this.libvirtComputingResourceProperties.getGuestCpuSharesRouter());
    } else {
        ctd.setShares(vmTo.getCpus() * this.libvirtComputingResourceProperties.getGuestCpuShares());
    }
    vm.addComponent(ctd);
    final FeaturesDef features = new FeaturesDef();
    features.addFeature("pae");
    features.addFeature("apic");
    features.addFeature("acpi");
    vm.addComponent(features);
    if (vmTo.getOptimiseFor() == OptimiseFor.Windows) {
        final HyperVEnlightenmentFeatureDef hyperVFeatures = new HyperVEnlightenmentFeatureDef();
        hyperVFeatures.addFeature("relaxed", true);
        hyperVFeatures.addFeature("vapic", true);
        hyperVFeatures.addFeature("spinlocks", true);
        hyperVFeatures.setRetries(8191);
        features.addHyperVFeature(hyperVFeatures);
    }
    final TermPolicy term = new TermPolicy();
    if (VirtualMachineType.User.equals(vmTo.getType())) {
        term.setCrashPolicy(getVmTermpolicyCrash());
        term.setPowerOffPolicy(getVmTermpolicyPowerOff());
        term.setRebootPolicy(getVmTermpolicyReboot());
    } else {
        term.setCrashPolicy(getSystemTermpolicyCrash());
        term.setPowerOffPolicy(getSystemTermpolicyPowerOff());
        term.setRebootPolicy(getSystemTermpolicyReboot());
    }
    vm.addComponent(term);
    final ClockDef clock = new ClockDef();
    Boolean kvmClockEnabled = !isKvmClockDisabled();
    Boolean hypervClockEnabled = false;
    Boolean trackGuest = false;
    if (vmTo.getOptimiseFor() == OptimiseFor.Windows) {
        clock.setClockOffset(ClockDef.ClockOffset.LOCALTIME);
        kvmClockEnabled = false;
        hypervClockEnabled = true;
        trackGuest = true;
    }
    clock.addTimer("kvmclock", null, kvmClockEnabled, false);
    clock.addTimer("hypervclock", null, hypervClockEnabled, false);
    // Recommended default clock/timer settings - https://bugzilla.redhat.com/show_bug.cgi?id=1053847
    // Important note for track="guest" in Windows VMs:
    // https://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0
    // .1/html/Virtualization_Deployment_and_Administration_Guide/sect-Virtualization-Tips_and_tricks-Libvirt_Managed_Timers.html
    clock.addTimer("rtc", "catchup", true, trackGuest);
    clock.addTimer("pit", "delay", true, false);
    clock.addTimer("hpet", null, false, false);
    vm.addComponent(clock);
    final DevicesDef devices = new DevicesDef();
    devices.setEmulatorPath(this.hypervisorPath);
    devices.setGuestType(guest.getGuestType());
    final SerialDef serial = new SerialDef("pty", null, (short) 0);
    devices.addDevice(serial);
    final QemuGuestAgentDef guestagent = new QemuGuestAgentDef();
    devices.addDevice(guestagent);
    if (this.libvirtComputingResourceProperties.getVmRngEnable()) {
        final RngDef rngDevice = new RngDef(this.rngPath, this.rngBackendModel);
        devices.addDevice(rngDevice);
    }
    final WatchDogDef watchDog = new WatchDogDef(this.libvirtComputingResourceProperties.getVmWatchdogAction(), this.libvirtComputingResourceProperties.getVmWatchdogModel());
    devices.addDevice(watchDog);
    final VideoDef videoCard = new VideoDef(this.libvirtComputingResourceProperties.getVmVideoHardware(), this.libvirtComputingResourceProperties.getVmVideoRam());
    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, passwd, null);
    devices.addDevice(grap);
    final InputDef input = new InputDef("tablet", "usb");
    devices.addDevice(input);
    // Always add a virtio scsi controller
    vmTo.getName();
    final ScsiDef sd = new ScsiDef((short) 0, 0, 0, 9, 0, vcpus);
    devices.addDevice(sd);
    logger.debug("Adding SCSI definition for " + vmTo.getName() + ":\n" + sd.toString());
    vm.addComponent(devices);
    return vm;
}
Also used : ScsiDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.ScsiDef) MetadataTO(com.cloud.legacymodel.to.MetadataTO) BootOrder(com.cloud.model.enumeration.BootOrder) CpuTuneDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.CpuTuneDef) GraphicDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.GraphicDef) VideoDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.VideoDef) RngDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.RngDef) SerialDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.SerialDef) ConsoleDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.ConsoleDef) InputDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.InputDef) CpuModeDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.CpuModeDef) FeaturesDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.FeaturesDef) LibvirtVmDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef) TermPolicy(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.TermPolicy) DevicesDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.DevicesDef) GuestResourceDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.GuestResourceDef) ClockDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.ClockDef) MetadataDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.MetadataDef) HyperVEnlightenmentFeatureDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.HyperVEnlightenmentFeatureDef) WatchDogDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.WatchDogDef) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) GuestDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.GuestDef) QemuGuestAgentDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.QemuGuestAgentDef)

Example 2 with RngDef

use of com.cloud.agent.resource.kvm.xml.LibvirtVmDef.RngDef in project cosmic by MissionCriticalCloud.

the class LibvirtDomainXmlParser method parseDomainXml.

public boolean parseDomainXml(final String domXml) {
    final DocumentBuilder builder;
    try {
        builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        final InputSource is = new InputSource();
        is.setCharacterStream(new StringReader(domXml));
        final Document doc = builder.parse(is);
        final Element rootElement = doc.getDocumentElement();
        this.desc = getTagValue("description", rootElement);
        final Element devices = (Element) rootElement.getElementsByTagName("devices").item(0);
        final NodeList disks = devices.getElementsByTagName("disk");
        for (int i = 0; i < disks.getLength(); i++) {
            final Element disk = (Element) disks.item(i);
            final String type = disk.getAttribute("type");
            final LibvirtDiskDef def = new LibvirtDiskDef();
            if (type.equalsIgnoreCase("network")) {
                final String diskFormatType = getAttrValue("driver", "type", disk);
                final String diskCacheMode = getAttrValue("driver", "cache", disk);
                final String diskPath = getAttrValue("source", "name", disk);
                final String protocol = getAttrValue("source", "protocol", disk);
                final String authUserName = getAttrValue("auth", "username", disk);
                final String poolUuid = getAttrValue("secret", "uuid", disk);
                final String host = getAttrValue("host", "name", disk);
                final int port = Integer.parseInt(getAttrValue("host", "port", disk));
                final String diskLabel = getAttrValue("target", "dev", disk);
                final String bus = getAttrValue("target", "bus", disk);
                ImageFormat imageFormat = null;
                if (diskFormatType != null) {
                    imageFormat = ImageFormat.valueOf(diskFormatType.toUpperCase());
                }
                def.defNetworkBasedDisk(diskPath, host, port, authUserName, poolUuid, diskLabel, DiskControllerType.valueOf(bus.toUpperCase()), LibvirtDiskDef.DiskProtocol.valueOf(protocol.toUpperCase()), imageFormat);
                def.setCacheMode(LibvirtDiskDef.DiskCacheMode.valueOf(diskCacheMode.toUpperCase()));
            } else {
                final String diskFormatType = getAttrValue("driver", "type", disk);
                final String diskCacheMode = getAttrValue("driver", "cache", disk);
                final String diskFile = getAttrValue("source", "file", disk);
                final String diskDev = getAttrValue("source", "dev", disk);
                final String diskLabel = getAttrValue("target", "dev", disk);
                final String bus = getAttrValue("target", "bus", disk);
                final String device = disk.getAttribute("device");
                if (type.equalsIgnoreCase("file")) {
                    if (device.equalsIgnoreCase("disk")) {
                        ImageFormat imageFormat = null;
                        if (diskFormatType != null) {
                            imageFormat = ImageFormat.valueOf(diskFormatType.toUpperCase());
                        }
                        def.defFileBasedDisk(diskFile, diskLabel, DiskControllerType.valueOf(bus.toUpperCase()), imageFormat);
                    } else if (device.equalsIgnoreCase("cdrom")) {
                        def.defIsoDisk(diskFile);
                    }
                } else if (type.equalsIgnoreCase("block")) {
                    def.defBlockBasedDisk(diskDev, diskLabel, DiskControllerType.valueOf(bus.toUpperCase()));
                }
                if (diskCacheMode != null) {
                    def.setCacheMode(LibvirtDiskDef.DiskCacheMode.valueOf(diskCacheMode.toUpperCase()));
                }
            }
            final NodeList iotune = disk.getElementsByTagName("iotune");
            if (iotune != null && iotune.getLength() != 0) {
                final String bytesReadRateStr = getTagValue("read_bytes_sec", (Element) iotune.item(0));
                if (bytesReadRateStr != null) {
                    final Long bytesReadRate = Long.parseLong(bytesReadRateStr);
                    def.setBytesReadRate(bytesReadRate);
                }
                final String bytesWriteRateStr = getTagValue("write_bytes_sec", (Element) iotune.item(0));
                if (bytesWriteRateStr != null) {
                    final Long bytesWriteRate = Long.parseLong(bytesWriteRateStr);
                    def.setBytesWriteRate(bytesWriteRate);
                }
                final String iopsReadRateStr = getTagValue("read_iops_sec", (Element) iotune.item(0));
                if (iopsReadRateStr != null) {
                    final Long iopsReadRate = Long.parseLong(iopsReadRateStr);
                    def.setIopsReadRate(iopsReadRate);
                }
                final String iopsWriteRateStr = getTagValue("write_iops_sec", (Element) iotune.item(0));
                if (iopsWriteRateStr != null) {
                    final Long iopsWriteRate = Long.parseLong(iopsWriteRateStr);
                    def.setIopsWriteRate(iopsWriteRate);
                }
                final String iopsTotalRateStr = getTagValue("total_iops_sec", (Element) iotune.item(0));
                if (iopsTotalRateStr != null) {
                    final Long iopsTotalRate = Long.parseLong(iopsTotalRateStr);
                    def.setIopsTotalRate(iopsTotalRate);
                }
            }
            this.diskDefs.add(def);
        }
        final NodeList nics = devices.getElementsByTagName("interface");
        for (int i = 0; i < nics.getLength(); i++) {
            final Element nic = (Element) nics.item(i);
            final String type = nic.getAttribute("type");
            final String mac = getAttrValue("mac", "address", nic);
            final String dev = getAttrValue("target", "dev", nic);
            final String model = getAttrValue("model", "type", nic);
            final InterfaceDef def = new InterfaceDef();
            final NodeList bandwidth = nic.getElementsByTagName("bandwidth");
            Integer networkRateKBps = 0;
            if (bandwidth != null && bandwidth.getLength() != 0) {
                final Integer inbound = Integer.valueOf(getAttrValue("inbound", "average", (Element) bandwidth.item(0)));
                final Integer outbound = Integer.valueOf(getAttrValue("outbound", "average", (Element) bandwidth.item(0)));
                if (inbound.equals(outbound)) {
                    networkRateKBps = inbound;
                }
            }
            if (type.equalsIgnoreCase("network")) {
                final String network = getAttrValue("source", "network", nic);
                def.defPrivateNet(network, dev, mac, NicModel.valueOf(model.toUpperCase()), networkRateKBps);
            } else if (type.equalsIgnoreCase("bridge")) {
                final String bridge = getAttrValue("source", "bridge", nic);
                def.defBridgeNet(bridge, dev, mac, NicModel.valueOf(model.toUpperCase()), networkRateKBps);
            } else if (type.equalsIgnoreCase("ethernet")) {
                final String scriptPath = getAttrValue("script", "path", nic);
                def.defEthernet(dev, mac, NicModel.valueOf(model.toUpperCase()), scriptPath, networkRateKBps);
            }
            this.interfaces.add(def);
        }
        final Element graphic = (Element) devices.getElementsByTagName("graphics").item(0);
        if (graphic != null) {
            final String port = graphic.getAttribute("port");
            if (port != null) {
                try {
                    this.vncPort = Integer.parseInt(port);
                    if (this.vncPort != -1) {
                        this.vncPort = this.vncPort - 5900;
                    } else {
                        this.vncPort = null;
                    }
                } catch (final NumberFormatException nfe) {
                    this.vncPort = null;
                }
            }
        }
        final NodeList rngs = devices.getElementsByTagName("rng");
        for (int i = 0; i < rngs.getLength(); i++) {
            RngDef def = null;
            final Element rng = (Element) rngs.item(i);
            final String backendModel = getAttrValue("backend", "model", rng);
            final String path = getTagValue("backend", rng);
            if (Strings.isNullOrEmpty(backendModel)) {
                def = new RngDef(path);
            } else {
                def = new RngDef(path, RngBackendModel.valueOf(backendModel.toUpperCase()));
            }
            this.rngDefs.add(def);
        }
        final NodeList watchDogs = devices.getElementsByTagName("watchdog");
        for (int i = 0; i < watchDogs.getLength(); i++) {
            WatchDogDef def = null;
            final Element watchDog = (Element) watchDogs.item(i);
            final String action = watchDog.getAttribute("action");
            final String model = watchDog.getAttribute("model");
            if (Strings.isNullOrEmpty(action)) {
                def = new WatchDogDef(WatchDogModel.valueOf(model.toUpperCase()));
            } else {
                def = new WatchDogDef(WatchDogAction.valueOf(action.toUpperCase()), WatchDogModel.valueOf(model.toUpperCase()));
            }
            this.watchDogDefs.add(def);
        }
        return true;
    } catch (final ParserConfigurationException e) {
        s_logger.debug(e.toString());
    } catch (final SAXException e) {
        s_logger.debug(e.toString());
    } catch (final 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) ImageFormat(com.cloud.model.enumeration.ImageFormat) SAXException(org.xml.sax.SAXException) InterfaceDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.InterfaceDef) RngDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.RngDef) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) WatchDogDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.WatchDogDef) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 3 with RngDef

use of com.cloud.agent.resource.kvm.xml.LibvirtVmDef.RngDef in project cosmic by MissionCriticalCloud.

the class LibvirtDomainXMLParserTest method testDomainXMLParser.

public void testDomainXMLParser() {
    final int vncPort = 5900;
    final DiskControllerType diskBus = DiskControllerType.SCSI;
    final LibvirtDiskDef.DiskType diskType = LibvirtDiskDef.DiskType.FILE;
    final LibvirtDiskDef.DeviceType deviceType = LibvirtDiskDef.DeviceType.DISK;
    final ImageFormat imageFormat = ImageFormat.QCOW2;
    final LibvirtDiskDef.DiskCacheMode diskCache = LibvirtDiskDef.DiskCacheMode.NONE;
    final NicModel ifModel = NicModel.VIRTIO;
    final GuestNetType ifType = GuestNetType.BRIDGE;
    final String diskLabel = "vda";
    final String diskPath = "/var/lib/libvirt/images/my-test-image.qcow2";
    final 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='" + imageFormat.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='/opt/cosmic/agent/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'/>" + "<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'>" + "<backend model='random'>/dev/random</backend>" + "</rng>" + "<watchdog model='i6300esb' action='reset'/>" + "<watchdog model='ib700' action='poweroff'/>" + "</devices>" + "<seclabel type='none'/>" + "</domain>";
    final LibvirtDomainXmlParser parser = new LibvirtDomainXmlParser();
    parser.parseDomainXml(xml);
    assertEquals(vncPort - 5900, (int) parser.getVncPort());
    final List<LibvirtDiskDef> disks = parser.getDisks();
    /* Disk 0 is the first disk, the QCOW2 file backed virto disk */
    final 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(imageFormat, disks.get(diskId).getDiskFormatType());
    final 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());
    }
    final List<RngDef> rngs = parser.getRngs();
    assertEquals("/dev/random", rngs.get(0).getPath());
    assertEquals(RngBackendModel.RANDOM, rngs.get(0).getRngBackendModel());
    final List<WatchDogDef> watchDogs = parser.getWatchDogs();
    assertEquals(WatchDogModel.I6300ESB, watchDogs.get(0).getModel());
    assertEquals(WatchDogAction.RESET, watchDogs.get(0).getAction());
    assertEquals(WatchDogModel.IB700, watchDogs.get(1).getModel());
    assertEquals(WatchDogAction.POWEROFF, watchDogs.get(1).getAction());
}
Also used : LibvirtDomainXmlParser(com.cloud.agent.resource.kvm.xml.LibvirtDomainXmlParser) NicModel(com.cloud.model.enumeration.NicModel) GuestNetType(com.cloud.model.enumeration.GuestNetType) ImageFormat(com.cloud.model.enumeration.ImageFormat) DiskControllerType(com.cloud.model.enumeration.DiskControllerType) InterfaceDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.InterfaceDef) RngDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.RngDef) LibvirtDiskDef(com.cloud.agent.resource.kvm.xml.LibvirtDiskDef) WatchDogDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.WatchDogDef)

Aggregations

RngDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef.RngDef)3 WatchDogDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef.WatchDogDef)3 InterfaceDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef.InterfaceDef)2 ImageFormat (com.cloud.model.enumeration.ImageFormat)2 LibvirtDiskDef (com.cloud.agent.resource.kvm.xml.LibvirtDiskDef)1 LibvirtDomainXmlParser (com.cloud.agent.resource.kvm.xml.LibvirtDomainXmlParser)1 LibvirtVmDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef)1 ClockDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef.ClockDef)1 ConsoleDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef.ConsoleDef)1 CpuModeDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef.CpuModeDef)1 CpuTuneDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef.CpuTuneDef)1 DevicesDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef.DevicesDef)1 FeaturesDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef.FeaturesDef)1 GraphicDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef.GraphicDef)1 GuestDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef.GuestDef)1 GuestResourceDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef.GuestResourceDef)1 HyperVEnlightenmentFeatureDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef.HyperVEnlightenmentFeatureDef)1 InputDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef.InputDef)1 MetadataDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef.MetadataDef)1 QemuGuestAgentDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef.QemuGuestAgentDef)1