Search in sources :

Example 6 with KVMStoragePool

use of com.cloud.agent.storage.KVMStoragePool in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method getVolumePath.

private String getVolumePath(Connect conn, VolumeTO volume) throws LibvirtException, URISyntaxException {
    if (volume.getType() == Volume.Type.ISO && volume.getPath() != null) {
        String isoPath = volume.getPath();
        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();
    }
}
Also used : KVMStoragePool(com.cloud.agent.storage.KVMStoragePool) KVMPhysicalDisk(com.cloud.agent.storage.KVMPhysicalDisk)

Example 7 with KVMStoragePool

use of com.cloud.agent.storage.KVMStoragePool in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method execute.

public Answer execute(DestroyCommand cmd) {
    VolumeTO vol = cmd.getVolume();
    try {
        KVMStoragePool pool = _storagePoolMgr.getStoragePool(vol.getPoolUuid());
        pool.deletePhysicalDisk(vol.getPath());
        return new Answer(cmd, true, "Success");
    } catch (CloudRuntimeException e) {
        s_logger.debug("Failed to delete volume: " + e.toString());
        return new Answer(cmd, false, e.toString());
    }
}
Also used : FenceAnswer(com.cloud.agent.api.FenceAnswer) ConsoleProxyLoadAnswer(com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer) DeleteSnapshotBackupAnswer(com.cloud.agent.api.DeleteSnapshotBackupAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) AttachVolumeAnswer(com.cloud.agent.api.AttachVolumeAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) IpAssocAnswer(com.cloud.agent.api.routing.IpAssocAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) SecurityGroupRuleAnswer(com.cloud.agent.api.SecurityGroupRuleAnswer) VolumeTO(com.cloud.agent.api.to.VolumeTO) KVMStoragePool(com.cloud.agent.storage.KVMStoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 8 with KVMStoragePool

use of com.cloud.agent.storage.KVMStoragePool in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method execute.

private CopyVolumeAnswer execute(CopyVolumeCommand cmd) {
    boolean copyToSecondary = cmd.toSecondaryStorage();
    String volumePath = cmd.getVolumePath();
    StorageFilerTO pool = cmd.getPool();
    String secondaryStorageUrl = cmd.getSecondaryStorageURL();
    KVMStoragePool secondaryStoragePool = null;
    try {
        KVMStoragePool primaryPool = _storagePoolMgr.getStoragePool(pool.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);
        }
    } catch (CloudRuntimeException e) {
        return new CopyVolumeAnswer(cmd, false, e.toString(), null, null);
    } finally {
        if (secondaryStoragePool != null) {
            secondaryStoragePool.delete();
        }
    }
}
Also used : KVMStoragePool(com.cloud.agent.storage.KVMStoragePool) KVMPhysicalDisk(com.cloud.agent.storage.KVMPhysicalDisk) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO)

Example 9 with KVMStoragePool

use of com.cloud.agent.storage.KVMStoragePool in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method execute.

protected CreateVolumeFromSnapshotAnswer execute(final CreateVolumeFromSnapshotCommand cmd) {
    try {
        String snapshotPath = cmd.getSnapshotUuid();
        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);
    }
}
Also used : KVMStoragePool(com.cloud.agent.storage.KVMStoragePool) KVMPhysicalDisk(com.cloud.agent.storage.KVMPhysicalDisk) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)

Example 10 with KVMStoragePool

use of com.cloud.agent.storage.KVMStoragePool in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method execute.

protected BackupSnapshotAnswer execute(final BackupSnapshotCommand cmd) {
    Long dcId = cmd.getDataCenterId();
    Long accountId = cmd.getAccountId();
    Long volumeId = cmd.getVolumeId();
    String secondaryStoragePoolUrl = cmd.getSecondaryStorageUrl();
    String snapshotName = cmd.getSnapshotName();
    String snapshotPath = cmd.getVolumePath();
    String snapshotDestPath = null;
    String snapshotRelPath = null;
    String vmName = cmd.getVmName();
    KVMStoragePool secondaryStoragePool = null;
    try {
        Connect conn = LibvirtConnection.getConnection();
        secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(secondaryStoragePoolUrl);
        String ssPmountPath = secondaryStoragePool.getLocalPath();
        snapshotRelPath = File.separator + "snapshots" + File.separator + dcId + File.separator + accountId + File.separator + volumeId;
        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, "Failed to backup snapshot: " + result, null, true);
            }
        }
    } catch (LibvirtException e) {
        return new BackupSnapshotAnswer(cmd, false, e.toString(), null, true);
    } catch (CloudRuntimeException e) {
        return new BackupSnapshotAnswer(cmd, false, e.toString(), null, true);
    } finally {
        if (secondaryStoragePool != null) {
            secondaryStoragePool.delete();
        }
    }
    return new BackupSnapshotAnswer(cmd, true, null, snapshotRelPath + File.separator + snapshotName, true);
}
Also used : Script(com.cloud.utils.script.Script) LibvirtException(org.libvirt.LibvirtException) KVMPhysicalDisk(com.cloud.agent.storage.KVMPhysicalDisk) Connect(org.libvirt.Connect) DomainSnapshot(org.libvirt.DomainSnapshot) KVMStoragePool(com.cloud.agent.storage.KVMStoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) DomainInfo(org.libvirt.DomainInfo) Domain(org.libvirt.Domain)

Aggregations

KVMStoragePool (com.cloud.agent.storage.KVMStoragePool)19 KVMPhysicalDisk (com.cloud.agent.storage.KVMPhysicalDisk)13 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)12 Script (com.cloud.utils.script.Script)7 CreatePrivateTemplateAnswer (com.cloud.agent.api.storage.CreatePrivateTemplateAnswer)6 AttachVolumeAnswer (com.cloud.agent.api.AttachVolumeAnswer)5 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)5 CreateVolumeFromSnapshotAnswer (com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)5 DeleteSnapshotBackupAnswer (com.cloud.agent.api.DeleteSnapshotBackupAnswer)5 ManageSnapshotAnswer (com.cloud.agent.api.ManageSnapshotAnswer)5 PrimaryStorageDownloadAnswer (com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer)5 Answer (com.cloud.agent.api.Answer)4 CheckHealthAnswer (com.cloud.agent.api.CheckHealthAnswer)4 CheckNetworkAnswer (com.cloud.agent.api.CheckNetworkAnswer)4 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)4 FenceAnswer (com.cloud.agent.api.FenceAnswer)4 GetHostStatsAnswer (com.cloud.agent.api.GetHostStatsAnswer)4 GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)4 GetVmStatsAnswer (com.cloud.agent.api.GetVmStatsAnswer)4 GetVncPortAnswer (com.cloud.agent.api.GetVncPortAnswer)4