Examples of KVMPhysicalDisk


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

                    .getUuid());
            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);
                secondaryStoragePool.delete();
                secondaryStoragePool = _storagePoolMgr
                        .getStoragePoolByURI(secondaryStorageUrl
                                + volumeDestPath);
                _storagePoolMgr.copyPhysicalDisk(volume, destVolumeName,
                        secondaryStoragePool);
                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);
                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.getUuid());
            disksize = dskch.getSize();

            if (cmd.getTemplateUrl() != null) {

                BaseVol = primaryPool.getPhysicalDisk(cmd.getTemplateUrl());
                vol = _storagePoolMgr.createDiskFromTemplate(BaseVol, UUID
                        .randomUUID().toString(), primaryPool);

                if (vol == null) {
                    return new Answer(cmd, false,
                            " Can't create storage volume on storage pool");
                }
            } else {
                vol = primaryPool.createPhysicalDisk(UUID.randomUUID()
                        .toString(), dskch.getSize());
            }
            VolumeTO volume = new VolumeTO(cmd.getVolumeId(), dskch.getType(),
                    pool.getType(), pool.getUuid(), pool.getPath(),
                    vol.getName(), vol.getName(), disksize, null);
            return new CreateAnswer(cmd, volume);
        } catch (CloudRuntimeException e) {
            s_logger.debug("Failed to create volume: " + e.toString());
            return new CreateAnswer(cmd, e);
        }
View Full Code Here

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

                s_logger.debug("Snapshots are not supported on RBD volumes");
                return new ManageSnapshotAnswer(cmd, false,
                    "Snapshots are not supported on RBD volumes");
            }

            KVMPhysicalDisk disk = primaryPool.getPhysicalDisk(cmd
                    .getVolumePath());
            if (state == DomainInfo.DomainState.VIR_DOMAIN_RUNNING
                    && !primaryPool.isExternalSnapshot()) {
                String vmUuid = vm.getUUIDString();
                Object[] args = new Object[] { snapshotName, vmUuid };
                String snapshot = SnapshotXML.format(args);
                s_logger.debug(snapshot);
                if (cmd.getCommandSwitch().equalsIgnoreCase(
                        ManageSnapshotCommand.CREATE_SNAPSHOT)) {
                    vm.snapshotCreateXML(snapshot);
                } else {
                    DomainSnapshot snap = vm.snapshotLookupByName(snapshotName);
                    snap.delete(0);
                }

                /*
                 * libvirt on RHEL6 doesn't handle resume event emitted from
                 * qemu
                 */
                vm = getDomain(conn, cmd.getVmName());
                state = vm.getInfo().state;
                if (state == DomainInfo.DomainState.VIR_DOMAIN_PAUSED) {
                    vm.resume();
                }
            } else {

                /* VM is not running, create a snapshot by ourself */
                final Script command = new Script(_manageSnapshotPath,
                        _cmdsTimeout, s_logger);
                if (cmd.getCommandSwitch().equalsIgnoreCase(
                        ManageSnapshotCommand.CREATE_SNAPSHOT)) {
                    command.add("-c", disk.getPath());
                } else {
                    command.add("-d", snapshotPath);
                }

                command.add("-n", snapshotName);
                String result = command.execute();
                if (result != null) {
                    s_logger.debug("Failed to manage snapshot: " + result);
                    return new ManageSnapshotAnswer(cmd, false,
                            "Failed to manage snapshot: " + result);
                }
            }
            return new ManageSnapshotAnswer(cmd, cmd.getSnapshotId(),
                    disk.getPath() + File.separator + snapshotName, true, null);
        } catch (LibvirtException e) {
            s_logger.debug("Failed to manage snapshot: " + e.toString());
            return new ManageSnapshotAnswer(cmd, false,
                    "Failed to manage snapshot: " + e.toString());
        }
View Full Code Here

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

            snapshotDestPath = ssPmountPath + File.separator + "snapshots"
                    + File.separator + dcId + File.separator + accountId
                    + File.separator + volumeId;
            KVMStoragePool primaryPool = _storagePoolMgr.getStoragePool(cmd
                    .getPrimaryStoragePoolNameLabel());
            KVMPhysicalDisk snapshotDisk = primaryPool.getPhysicalDisk(cmd
                    .getVolumePath());
            Script command = new Script(_manageSnapshotPath, _cmdsTimeout,
                    s_logger);
            command.add("-b", snapshotDisk.getPath());
            command.add("-n", snapshotName);
            command.add("-p", snapshotDestPath);
            command.add("-t", snapshotName);
            String result = command.execute();
            if (result != null) {
                s_logger.debug("Failed to backup snaptshot: " + result);
                return new BackupSnapshotAnswer(cmd, false, result, null, true);
            }
            /* Delete the snapshot on primary */

            DomainInfo.DomainState state = null;
            Domain vm = null;
            if (vmName != null) {
                try {
                    vm = getDomain(conn, cmd.getVmName());
                    state = vm.getInfo().state;
                } catch (LibvirtException e) {

                }
            }

            KVMStoragePool primaryStorage = _storagePoolMgr.getStoragePool(cmd
                    .getPool().getUuid());
            if (state == DomainInfo.DomainState.VIR_DOMAIN_RUNNING
                    && !primaryStorage.isExternalSnapshot()) {
                String vmUuid = vm.getUUIDString();
                Object[] args = new Object[] { snapshotName, vmUuid };
                String snapshot = SnapshotXML.format(args);
                s_logger.debug(snapshot);
                DomainSnapshot snap = vm.snapshotLookupByName(snapshotName);
                snap.delete(0);

                /*
                 * libvirt on RHEL6 doesn't handle resume event emitted from
                 * qemu
                 */
                vm = getDomain(conn, cmd.getVmName());
                state = vm.getInfo().state;
                if (state == DomainInfo.DomainState.VIR_DOMAIN_PAUSED) {
                    vm.resume();
                }
            } else {
                command = new Script(_manageSnapshotPath, _cmdsTimeout,
                        s_logger);
                command.add("-d", snapshotDisk.getPath());
                command.add("-n", snapshotName);
                result = command.execute();
                if (result != null) {
                    s_logger.debug("Failed to backup snapshot: " + result);
                    return new BackupSnapshotAnswer(cmd, false,
View Full Code Here

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

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

            String primaryUuid = cmd.getPrimaryStoragePoolNameLabel();
            KVMStoragePool primaryPool = _storagePoolMgr
                    .getStoragePool(primaryUuid);
            String volUuid = UUID.randomUUID().toString();
            KVMPhysicalDisk disk = _storagePoolMgr.copyPhysicalDisk(snapshot,
                    volUuid, primaryPool);
            return new CreateVolumeFromSnapshotAnswer(cmd, true, "",
                    disk.getName());
        } catch (CloudRuntimeException e) {
            return new CreateVolumeFromSnapshotAnswer(cmd, false, e.toString(),
                    null);
        }
    }
View Full Code Here

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

            secondaryStorage = _storagePoolMgr
                    .getStoragePoolByURI(secondaryStorageURL);

            KVMStoragePool primary = _storagePoolMgr.getStoragePool(cmd
                    .getPrimaryStoragePoolNameLabel());
            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());
                Script.runSimpleBashScript("qemu-img convert"
                                + " -f raw -O qcow2 "
                                + KVMPhysicalDisk.RBDStringBuilder(primary.getSourceHost(),
                                                primary.getSourcePort(),
                                                primary.getAuthUserName(),
                                                primary.getAuthSecret(),
                                                disk.getPath())
                                + " " + tmpltPath + "/" + cmd.getUniqueName() + ".qcow2");
                File templateProp = new File(tmpltPath + "/template.properties");
                if (!templateProp.exists()) {
                    templateProp.createNewFile();
                }
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
                    .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) {
                secondaryPool.delete();
View Full Code Here

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

    private AttachVolumeAnswer execute(AttachVolumeCommand cmd) {
        try {
            Connect conn = LibvirtConnection.getConnection();
            KVMStoragePool primary = _storagePoolMgr.getStoragePool(cmd
                    .getPoolUuid());
            KVMPhysicalDisk disk = primary.getPhysicalDisk(cmd.getVolumePath());
            attachOrDetachDisk(conn, cmd.getAttach(), cmd.getVmName(), disk,
                    cmd.getDeviceId().intValue());
        } 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 volume.getPath();
        }
    }
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.