Search in sources :

Example 6 with ImageFormat

use of com.cloud.model.enumeration.ImageFormat in project cosmic by MissionCriticalCloud.

the class KvmStorageProcessor method copyVolumeFromImageCacheToPrimary.

@Override
public Answer copyVolumeFromImageCacheToPrimary(final CopyCommand cmd) {
    final DataTO srcData = cmd.getSrcTO();
    final DataTO destData = cmd.getDestTO();
    final DataStoreTO srcStore = srcData.getDataStore();
    final DataStoreTO destStore = destData.getDataStore();
    final VolumeObjectTO srcVol = (VolumeObjectTO) srcData;
    final ImageFormat srcFormat = srcVol.getFormat();
    final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) destStore;
    if (!(srcStore instanceof NfsTO)) {
        return new CopyCmdAnswer("can only handle nfs storage");
    }
    final NfsTO nfsStore = (NfsTO) srcStore;
    final String srcVolumePath = srcData.getPath();
    final String secondaryStorageUrl = nfsStore.getUrl();
    KvmStoragePool secondaryStoragePool = null;
    KvmStoragePool primaryPool;
    try {
        try {
            primaryPool = this.storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid());
        } catch (final CloudRuntimeException e) {
            if (e.getMessage().contains("not found")) {
                primaryPool = this.storagePoolMgr.createStoragePool(primaryStore.getUuid(), primaryStore.getHost(), primaryStore.getPort(), primaryStore.getPath(), null, primaryStore.getPoolType());
            } else {
                return new CopyCmdAnswer(e.getMessage());
            }
        }
        final String volumeName = UUID.randomUUID().toString();
        final int index = srcVolumePath.lastIndexOf(File.separator);
        final String volumeDir = srcVolumePath.substring(0, index);
        String srcVolumeName = srcVolumePath.substring(index + 1);
        secondaryStoragePool = this.storagePoolMgr.getStoragePoolByUri(secondaryStorageUrl + File.separator + volumeDir);
        if (!srcVolumeName.endsWith(".qcow2") && srcFormat == ImageFormat.QCOW2) {
            srcVolumeName = srcVolumeName + ".qcow2";
        }
        final KvmPhysicalDisk volume = secondaryStoragePool.getPhysicalDisk(srcVolumeName);
        volume.setFormat(PhysicalDiskFormat.valueOf(srcFormat.toString()));
        final KvmPhysicalDisk newDisk = this.storagePoolMgr.copyPhysicalDisk(volume, volumeName, primaryPool, cmd.getWaitInMillSeconds());
        final VolumeObjectTO newVol = new VolumeObjectTO();
        newVol.setFormat(ImageFormat.valueOf(newDisk.getFormat().toString().toUpperCase()));
        newVol.setPath(volumeName);
        return new CopyCmdAnswer(newVol);
    } catch (final CloudRuntimeException e) {
        this.logger.debug("Failed to ccopyVolumeFromImageCacheToPrimary: ", e);
        return new CopyCmdAnswer(e.toString());
    } finally {
        if (secondaryStoragePool != null) {
            this.storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(), secondaryStoragePool.getUuid());
        }
    }
}
Also used : PrimaryDataStoreTO(com.cloud.legacymodel.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) DataTO(com.cloud.legacymodel.to.DataTO) PrimaryDataStoreTO(com.cloud.legacymodel.to.PrimaryDataStoreTO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) NfsTO(com.cloud.legacymodel.to.NfsTO) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer) ImageFormat(com.cloud.model.enumeration.ImageFormat)

Example 7 with ImageFormat

use of com.cloud.model.enumeration.ImageFormat in project cosmic by MissionCriticalCloud.

the class KvmStorageProcessor method copyVolumeFromPrimaryToSecondary.

@Override
public Answer copyVolumeFromPrimaryToSecondary(final CopyCommand cmd) {
    final DataTO srcData = cmd.getSrcTO();
    final DataTO destData = cmd.getDestTO();
    final VolumeObjectTO srcVol = (VolumeObjectTO) srcData;
    final VolumeObjectTO destVol = (VolumeObjectTO) destData;
    final ImageFormat srcFormat = srcVol.getFormat();
    final ImageFormat destFormat = destVol.getFormat();
    final DataStoreTO srcStore = srcData.getDataStore();
    final DataStoreTO destStore = destData.getDataStore();
    final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) srcStore;
    if (!(destStore instanceof NfsTO)) {
        return new CopyCmdAnswer("can only handle nfs storage");
    }
    final NfsTO nfsStore = (NfsTO) destStore;
    final String srcVolumePath = srcData.getPath();
    final String destVolumePath = destData.getPath();
    final String secondaryStorageUrl = nfsStore.getUrl();
    KvmStoragePool secondaryStoragePool = null;
    try {
        final String volumeName = UUID.randomUUID().toString();
        final String destVolumeName = volumeName + "." + destFormat.toString().toLowerCase();
        final KvmPhysicalDisk volume = this.storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), srcVolumePath);
        volume.setFormat(PhysicalDiskFormat.valueOf(srcFormat.toString()));
        secondaryStoragePool = this.storagePoolMgr.getStoragePoolByUri(secondaryStorageUrl);
        secondaryStoragePool.createFolder(destVolumePath);
        this.storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(), secondaryStoragePool.getUuid());
        secondaryStoragePool = this.storagePoolMgr.getStoragePoolByUri(secondaryStorageUrl + File.separator + destVolumePath);
        this.storagePoolMgr.copyPhysicalDisk(volume, destVolumeName, secondaryStoragePool, cmd.getWaitInMillSeconds());
        final VolumeObjectTO newVol = new VolumeObjectTO();
        newVol.setPath(destVolumePath + File.separator + destVolumeName);
        newVol.setFormat(destFormat);
        return new CopyCmdAnswer(newVol);
    } catch (final CloudRuntimeException e) {
        this.logger.debug("Failed to copyVolumeFromPrimaryToSecondary: ", e);
        return new CopyCmdAnswer(e.toString());
    } finally {
        if (secondaryStoragePool != null) {
            this.storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(), secondaryStoragePool.getUuid());
        }
    }
}
Also used : PrimaryDataStoreTO(com.cloud.legacymodel.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) DataTO(com.cloud.legacymodel.to.DataTO) PrimaryDataStoreTO(com.cloud.legacymodel.to.PrimaryDataStoreTO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) NfsTO(com.cloud.legacymodel.to.NfsTO) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer) ImageFormat(com.cloud.model.enumeration.ImageFormat)

Example 8 with ImageFormat

use of com.cloud.model.enumeration.ImageFormat 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 9 with ImageFormat

use of com.cloud.model.enumeration.ImageFormat in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testPrimaryStorageDownloadCommandNOTemplateDisk.

@Test(expected = NullPointerException.class)
public void testPrimaryStorageDownloadCommandNOTemplateDisk() {
    final StoragePool pool = Mockito.mock(StoragePool.class);
    final List<KvmPhysicalDisk> disks = new ArrayList<>();
    final String name = "Test";
    final String url = "http://template/";
    final ImageFormat format = ImageFormat.QCOW2;
    final long accountId = 1l;
    final int wait = 0;
    final PrimaryStorageDownloadCommand command = new PrimaryStorageDownloadCommand(name, url, format, accountId, pool, wait);
    final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
    final KvmStoragePool primaryPool = Mockito.mock(KvmStoragePool.class);
    final KvmStoragePool secondaryPool = Mockito.mock(KvmStoragePool.class);
    final KvmPhysicalDisk tmplVol = Mockito.mock(KvmPhysicalDisk.class);
    final KvmPhysicalDisk primaryVol = Mockito.mock(KvmPhysicalDisk.class);
    final KvmPhysicalDisk disk = new KvmPhysicalDisk("/path", "disk.qcow2", primaryPool);
    disks.add(disk);
    final int index = url.lastIndexOf("/");
    final String mountpoint = url.substring(0, index);
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.getStoragePoolByUri(mountpoint)).thenReturn(secondaryPool);
    when(secondaryPool.listPhysicalDisks()).thenReturn(disks);
    when(storagePoolMgr.getStoragePool(command.getPool().getType(), command.getPoolUuid())).thenReturn(primaryPool);
    when(storagePoolMgr.copyPhysicalDisk(tmplVol, UUID.randomUUID().toString(), primaryPool, 0)).thenReturn(primaryVol);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
}
Also used : NfsStoragePool(com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StoragePool(com.cloud.legacymodel.storage.StoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) PrimaryStorageDownloadCommand(com.cloud.legacymodel.communication.command.PrimaryStorageDownloadCommand) ArrayList(java.util.ArrayList) ImageFormat(com.cloud.model.enumeration.ImageFormat) Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) KvmPhysicalDisk(com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk) Test(org.junit.Test)

Example 10 with ImageFormat

use of com.cloud.model.enumeration.ImageFormat 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

ImageFormat (com.cloud.model.enumeration.ImageFormat)16 Answer (com.cloud.legacymodel.communication.answer.Answer)5 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)5 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)5 NfsStoragePool (com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool)4 KvmPhysicalDisk (com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk)4 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)4 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)4 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)4 DiskControllerType (com.cloud.model.enumeration.DiskControllerType)4 ArrayList (java.util.ArrayList)4 LibvirtDiskDef (com.cloud.agent.resource.kvm.xml.LibvirtDiskDef)3 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)3 PrimaryStorageDownloadCommand (com.cloud.legacymodel.communication.command.PrimaryStorageDownloadCommand)3 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)3 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)3 StoragePool (com.cloud.legacymodel.storage.StoragePool)3 Account (com.cloud.legacymodel.user.Account)3 VMTemplateVO (com.cloud.storage.VMTemplateVO)3 IOException (java.io.IOException)3