Examples of KVMPhysicalDisk


Examples of com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk

            String snapshotPath = cmd.getSnapshotUuid();
            int index = snapshotPath.lastIndexOf("/");
            snapshotPath = snapshotPath.substring(0, index);
            snapshotPool = _storagePoolMgr.getStoragePoolByURI(cmd
                    .getSecondaryStorageUrl() + snapshotPath);
            KVMPhysicalDisk snapshot = snapshotPool.getPhysicalDisk(cmd
                    .getSnapshotName());

            secondaryPool = _storagePoolMgr.getStoragePoolByURI(
                    cmd.getSecondaryStorageUrl());

            String templatePath = secondaryPool.getLocalPath() + File.separator
                    + templateInstallFolder;

            _storage.mkdirs(templatePath);

            String tmplPath = templateInstallFolder + File.separator
                    + tmplFileName;
            Script command = new Script(_createTmplPath, _cmdsTimeout, s_logger);
            command.add("-t", templatePath);
            command.add("-n", tmplFileName);
            command.add("-f", snapshot.getPath());
            command.execute();

            Map<String, Object> params = new HashMap<String, Object>();
            params.put(StorageLayer.InstanceConfigKey, _storage);
            Processor qcow2Processor = new QCOW2Processor();
View Full Code Here

Examples of com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk

                } else {
                    return new CreatePrivateTemplateAnswer(cmd, false, e.getMessage());
                }
            }

            KVMPhysicalDisk disk = primary.getPhysicalDisk(cmd.getVolumePath());
            String tmpltPath = secondaryStorage.getLocalPath() + File.separator
                    + templateInstallFolder;
            _storage.mkdirs(tmpltPath);

            if (primary.getType() != StoragePoolType.RBD) {
                Script command = new Script(_createTmplPath, _cmdsTimeout, s_logger);
                command.add("-f", disk.getPath());
                command.add("-t", tmpltPath);
                command.add("-n", cmd.getUniqueName() + ".qcow2");

                String result = command.execute();

                if (result != null) {
                    s_logger.debug("failed to create template: " + result);
                    return new CreatePrivateTemplateAnswer(cmd, false, result);
                }
            } else {
                s_logger.debug("Converting RBD disk " + disk.getPath() + " into template " + cmd.getUniqueName());

                QemuImgFile srcFile = new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(primary.getSourceHost(),
                                primary.getSourcePort(),
                                primary.getAuthUserName(),
                                primary.getAuthSecret(),
                                disk.getPath()));
                srcFile.setFormat(PhysicalDiskFormat.RAW);

                QemuImgFile destFile = new QemuImgFile(tmpltPath + "/" + cmd.getUniqueName() + ".qcow2");
                destFile.setFormat(PhysicalDiskFormat.QCOW2);
View Full Code Here

Examples of com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk

        String tmpltname = null;
        if (index < tmplturl.length() - 1) {
            tmpltname = tmplturl.substring(index + 1);
        }

        KVMPhysicalDisk tmplVol = null;
        KVMStoragePool secondaryPool = null;
        try {
            secondaryPool = _storagePoolMgr.getStoragePoolByURI(mountpoint);

            /* Get template vol */
            if (tmpltname == null) {
                secondaryPool.refresh();
                List<KVMPhysicalDisk> disks = secondaryPool.listPhysicalDisks();
                if (disks == null || disks.isEmpty()) {
                    return new PrimaryStorageDownloadAnswer(
                            "Failed to get volumes from pool: "
                                    + secondaryPool.getUuid());
                }
                for (KVMPhysicalDisk disk : disks) {
                    if (disk.getName().endsWith("qcow2")) {
                        tmplVol = disk;
                        break;
                    }
                }
                if (tmplVol == null) {
                    return new PrimaryStorageDownloadAnswer(
                            "Failed to get template from pool: "
                                    + secondaryPool.getUuid());
                }
            } else {
                tmplVol = secondaryPool.getPhysicalDisk(tmpltname);
            }

            /* Copy volume to primary storage */
            KVMStoragePool primaryPool = _storagePoolMgr.getStoragePool(
                    cmd.getPool().getType(),
                    cmd.getPoolUuid());

            KVMPhysicalDisk primaryVol = _storagePoolMgr.copyPhysicalDisk(
                    tmplVol, UUID.randomUUID().toString(), primaryPool);

            return new PrimaryStorageDownloadAnswer(primaryVol.getName(),
                    primaryVol.getSize());
        } catch (CloudRuntimeException e) {
            return new PrimaryStorageDownloadAnswer(e.toString());
        } finally {
            if (secondaryPool != null) {
                _storagePoolMgr.deleteStoragePool(secondaryPool.getType(),secondaryPool.getUuid());
View Full Code Here

Examples of com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk

        try {
            Connect conn = LibvirtConnection.getConnectionByVmName(cmd.getVmName());
            KVMStoragePool primary = _storagePoolMgr.getStoragePool(
                    cmd.getPooltype(),
                    cmd.getPoolUuid());
            KVMPhysicalDisk disk = primary.getPhysicalDisk(cmd.getVolumePath());
            attachOrDetachDisk(conn, cmd.getAttach(), cmd.getVmName(), disk,
                    cmd.getDeviceId().intValue(), cmd.getBytesReadRate(), cmd.getBytesWriteRate(), cmd.getIopsReadRate(), cmd.getIopsWriteRate());
        } catch (LibvirtException e) {
            return new AttachVolumeAnswer(cmd, e.toString());
        } catch (InternalErrorException e) {
View Full Code Here

Examples of com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk

            int index = isoPath.lastIndexOf("/");
            String path = isoPath.substring(0, index);
            String name = isoPath.substring(index + 1);
            KVMStoragePool secondaryPool = _storagePoolMgr.getStoragePoolByURI(
                    path);
            KVMPhysicalDisk isoVol = secondaryPool.getPhysicalDisk(name);
            return isoVol.getPath();
        } else {
            return data.getPath();
        }
    }
View Full Code Here

Examples of com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk

                return arg0.getDiskSeq() > arg1.getDiskSeq() ? 1 : -1;
            }
        });

        for (DiskTO volume : disks) {
            KVMPhysicalDisk physicalDisk = null;
            KVMStoragePool pool = null;
            DataTO data = volume.getData();
            if (volume.getType() == Volume.Type.ISO && data.getPath() != null) {
                NfsTO nfsStore = (NfsTO)data.getDataStore();
                String volPath = nfsStore.getUrl() + File.separator + data.getPath();
                int index = volPath.lastIndexOf("/");
                String volDir = volPath.substring(0, index);
                String volName = volPath.substring(index + 1);
                KVMStoragePool secondaryStorage = _storagePoolMgr.
                        getStoragePoolByURI(volDir);
                physicalDisk = secondaryStorage.getPhysicalDisk(volName);
            } else if (volume.getType() != Volume.Type.ISO) {
                PrimaryDataStoreTO store = (PrimaryDataStoreTO)data.getDataStore();
                physicalDisk = _storagePoolMgr.getPhysicalDiskstore.getPoolType(),
                        store.getUuid(),
                        data.getPath());
                pool = physicalDisk.getPool();
            }

            String volPath = null;
            if (physicalDisk != null) {
                volPath = physicalDisk.getPath();
            }

            DiskDef.diskBus diskBusType = getGuestDiskModel(vmSpec.getOs());
            DiskDef disk = new DiskDef();
            if (volume.getType() == Volume.Type.ISO) {
                if (volPath == null) {
                    /* Add iso as placeholder */
                    disk.defISODisk(null);
                } else {
                    disk.defISODisk(volPath);
                }
            } else {
                int devId = volume.getDiskSeq().intValue();

                if (pool.getType() == StoragePoolType.RBD) {
                    /*
                            For RBD pools we use the secret mechanism in libvirt.
                            We store the secret under the UUID of the pool, that's why
                            we pass the pool's UUID as the authSecret
                     */
                    disk.defNetworkBasedDisk(physicalDisk.getPath().replace("rbd:", ""), pool.getSourceHost(), pool.getSourcePort(),
                            pool.getAuthUserName(), pool.getUuid(),
                            devId, diskBusType, diskProtocol.RBD);
                } else if (pool.getType() == StoragePoolType.CLVM) {
                    disk.defBlockBasedDisk(physicalDisk.getPath(), devId,
                            diskBusType);
                } else {
                    if (volume.getType() == Volume.Type.DATADISK) {
                        disk.defFileBasedDisk(physicalDisk.getPath(), devId,
                                DiskDef.diskBus.VIRTIO,
                                DiskDef.diskFmtType.QCOW2);
                    } else {
                        disk.defFileBasedDisk(physicalDisk.getPath(), devId, diskBusType, DiskDef.diskFmtType.QCOW2);
                    }

                }

            }

            if (data instanceof VolumeObjectTO) {
                VolumeObjectTO volumeObjectTO = (VolumeObjectTO)data;
                if ((volumeObjectTO.getBytesReadRate() != null) && (volumeObjectTO.getBytesReadRate()  > 0))
                    disk.setBytesReadRate(volumeObjectTO.getBytesReadRate());
                if ((volumeObjectTO.getBytesWriteRate() != null) && (volumeObjectTO.getBytesWriteRate() > 0))
                    disk.setBytesWriteRate(volumeObjectTO.getBytesWriteRate());
                if ((volumeObjectTO.getIopsReadRate() != null) && (volumeObjectTO.getIopsReadRate() > 0))
                    disk.setIopsReadRate(volumeObjectTO.getIopsReadRate());
                if ((volumeObjectTO.getIopsWriteRate() != null) && (volumeObjectTO.getIopsWriteRate() > 0))
                    disk.setIopsWriteRate(volumeObjectTO.getIopsWriteRate());
            }
            vm.getDevices().addDevice(disk);
        }

        if (vmSpec.getType() != VirtualMachine.Type.User) {
            if (_sysvmISOPath != null) {
                DiskDef iso = new DiskDef();
                iso.defISODisk(_sysvmISOPath);
                vm.getDevices().addDevice(iso);
            }
        }

        // For LXC, find and add the root filesystem
        if (HypervisorType.LXC.toString().toLowerCase().equals(vm.getHvsType())) {
            for (DiskTO volume : disks) {
                if (volume.getType() == Volume.Type.ROOT) {
                    DataTO data = volume.getData();
                    PrimaryDataStoreTO store = (PrimaryDataStoreTO)data.getDataStore();
                    KVMPhysicalDisk physicalDisk = _storagePoolMgr.getPhysicalDisk( store.getPoolType(),
                            store.getUuid(),
                            data.getPath());
                    FilesystemDef rootFs = new FilesystemDef(physicalDisk.getPath(), "/");
                    vm.getDevices().addDevice(rootFs);
                    break;
                }
            }
        }
View Full Code Here

Examples of com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk

            int index = isoPath.lastIndexOf("/");
            String path = isoPath.substring(0, index);
            String name = isoPath.substring(index + 1);
            KVMStoragePool secondaryPool = _storagePoolMgr.getStoragePoolByURI(
                    path);
            KVMPhysicalDisk isoVol = secondaryPool.getPhysicalDisk(name);
            isoPath = isoVol.getPath();

            DiskDef iso = new DiskDef();
            iso.defISODisk(isoPath);
            isoXml = iso.toString();
        } else {
View Full Code Here

Examples of com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk

            String volumeName = UUID.randomUUID().toString();

            if (copyToSecondary) {
                String destVolumeName = volumeName + ".qcow2";
                KVMPhysicalDisk volume = primaryPool.getPhysicalDisk(cmd
                        .getVolumePath());
                String volumeDestPath = "/volumes/" + cmd.getVolumeId()
                        + File.separator;
                secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(
                        secondaryStorageUrl);
                secondaryStoragePool.createFolder(volumeDestPath);
                _storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(),secondaryStoragePool.getUuid());
                secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(
                        secondaryStorageUrl
                        + volumeDestPath);
                _storagePoolMgr.copyPhysicalDisk(volume,
                        destVolumeName,secondaryStoragePool, 0);
                return new CopyVolumeAnswer(cmd, true, null, null, volumeName);
            } else {
                volumePath = "/volumes/" + cmd.getVolumeId() + File.separator;
                secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(
                        secondaryStorageUrl
                        + volumePath);
                KVMPhysicalDisk volume = secondaryStoragePool
                        .getPhysicalDisk(cmd.getVolumePath() + ".qcow2");
                _storagePoolMgr.copyPhysicalDisk(volume, volumeName,
                        primaryPool, 0);
                return new CopyVolumeAnswer(cmd, true, null, null, volumeName);
            }
View Full Code Here

Examples of com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk

    }

    protected Answer execute(CreateCommand cmd) {
        StorageFilerTO pool = cmd.getPool();
        DiskProfile dskch = cmd.getDiskCharacteristics();
        KVMPhysicalDisk BaseVol = null;
        KVMStoragePool primaryPool = null;
        KVMPhysicalDisk vol = null;
        long disksize;
        try {
            primaryPool = _storagePoolMgr.getStoragePool(pool.getType(),
                    pool.getUuid());
            disksize = dskch.getSize();

            if (cmd.getTemplateUrl() != null) {
                if(primaryPool.getType() == StoragePoolType.CLVM) {
                    vol = templateToPrimaryDownload(cmd.getTemplateUrl(),primaryPool, dskch.getPath());
                } else {
                    BaseVol = primaryPool.getPhysicalDisk(cmd.getTemplateUrl());
                    vol = _storagePoolMgr.createDiskFromTemplate(BaseVol,
                            dskch.getPath(), primaryPool, 0);
                }
                if (vol == null) {
                    return new Answer(cmd, false,
                            " Can't create storage volume on storage pool");
                }
            } else {
                vol = primaryPool.createPhysicalDisk(dskch.getPath(), dskch.getSize());
            }
            VolumeTO volume = new VolumeTO(cmd.getVolumeId(), dskch.getType(),
                    pool.getType(), pool.getUuid(), pool.getPath(),
                    vol.getName(), vol.getName(), disksize, null);
            volume.setBytesReadRate(dskch.getBytesReadRate());
            volume.setBytesWriteRate(dskch.getBytesWriteRate());
            volume.setIopsReadRate(dskch.getIopsReadRate());
            volume.setIopsWriteRate(dskch.getIopsWriteRate());
            return new CreateAnswer(cmd, volume);
View Full Code Here

Examples of com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk

        String templateName = null;
        if (index < templateUrl.length() - 1) {
            templateName = templateUrl.substring(index + 1);
        }

        KVMPhysicalDisk templateVol = null;
        KVMStoragePool secondaryPool = null;
        try {
            secondaryPool = _storagePoolMgr.getStoragePoolByURI(mountpoint);
            /* Get template vol */
            if (templateName == null) {
                secondaryPool.refresh();
                List<KVMPhysicalDisk> disks = secondaryPool.listPhysicalDisks();
                if (disks == null || disks.isEmpty()) {
                    s_logger.error("Failed to get volumes from pool: " + secondaryPool.getUuid());
                    return null;
                }
                for (KVMPhysicalDisk disk : disks) {
                    if (disk.getName().endsWith("qcow2")) {
                        templateVol = disk;
                        break;
                    }
                }
                if (templateVol == null) {
                    s_logger.error("Failed to get template from pool: " + secondaryPool.getUuid());
                    return null;
                }
            } else {
                templateVol = secondaryPool.getPhysicalDisk(templateName);
            }

            /* Copy volume to primary storage */

            KVMPhysicalDisk primaryVol = _storagePoolMgr.copyPhysicalDisk(templateVol, volUuid, primaryPool, 0);
            return primaryVol;
        } catch (CloudRuntimeException e) {
            s_logger.error("Failed to download template to primary storage",e);
            return null;
        } finally {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.