Search in sources :

Example 16 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)

Example 17 with KVMStoragePool

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

the class LibvirtComputingResource method execute.

protected DeleteSnapshotBackupAnswer execute(final DeleteSnapshotBackupCommand cmd) {
    Long dcId = cmd.getDataCenterId();
    Long accountId = cmd.getAccountId();
    Long volumeId = cmd.getVolumeId();
    KVMStoragePool secondaryStoragePool = null;
    try {
        secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(cmd.getSecondaryStorageUrl());
        String ssPmountPath = secondaryStoragePool.getLocalPath();
        String snapshotDestPath = ssPmountPath + File.separator + "snapshots" + File.separator + dcId + File.separator + accountId + File.separator + volumeId;
        final Script command = new Script(_manageSnapshotPath, _cmdsTimeout, s_logger);
        command.add("-d", snapshotDestPath);
        command.add("-n", cmd.getSnapshotName());
        command.execute();
    } catch (CloudRuntimeException e) {
        return new DeleteSnapshotBackupAnswer(cmd, false, e.toString());
    } finally {
        if (secondaryStoragePool != null) {
            secondaryStoragePool.delete();
        }
    }
    return new DeleteSnapshotBackupAnswer(cmd, true, null);
}
Also used : Script(com.cloud.utils.script.Script) KVMStoragePool(com.cloud.agent.storage.KVMStoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DeleteSnapshotBackupAnswer(com.cloud.agent.api.DeleteSnapshotBackupAnswer)

Example 18 with KVMStoragePool

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

the class LibvirtComputingResource method initialize.

@Override
public StartupCommand[] initialize() {
    Map<String, State> changes = null;
    synchronized (_vms) {
        _vms.clear();
        changes = sync();
    }
    final List<Object> info = getHostInfo();
    final StartupRoutingCommand cmd = new StartupRoutingCommand((Integer) info.get(0), (Long) info.get(1), (Long) info.get(2), (Long) info.get(4), (String) info.get(3), HypervisorType.KVM, RouterPrivateIpStrategy.HostLocal);
    cmd.setStateChanges(changes);
    fillNetworkInformation(cmd);
    _privateIp = cmd.getPrivateIpAddress();
    cmd.getHostDetails().putAll(getVersionStrings());
    cmd.setPool(_pool);
    cmd.setCluster(_clusterId);
    cmd.setGatewayIpAddress(_localGateway);
    StartupStorageCommand sscmd = null;
    try {
        KVMStoragePool localStoragePool = _storagePoolMgr.createStoragePool(_localStorageUUID, "localhost", _localStoragePath, StoragePoolType.Filesystem);
        com.cloud.agent.api.StoragePoolInfo pi = new com.cloud.agent.api.StoragePoolInfo(localStoragePool.getUuid(), cmd.getPrivateIpAddress(), _localStoragePath, _localStoragePath, StoragePoolType.Filesystem, localStoragePool.getCapacity(), localStoragePool.getUsed());
        sscmd = new StartupStorageCommand();
        sscmd.setPoolInfo(pi);
        sscmd.setGuid(pi.getUuid());
        sscmd.setDataCenter(_dcId);
        sscmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
    } catch (CloudRuntimeException e) {
    }
    if (sscmd != null) {
        return new StartupCommand[] { cmd, sscmd };
    } else {
        return new StartupCommand[] { cmd };
    }
}
Also used : StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) StartupCommand(com.cloud.agent.api.StartupCommand) KVMStoragePool(com.cloud.agent.storage.KVMStoragePool) State(com.cloud.vm.VirtualMachine.State) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand)

Example 19 with KVMStoragePool

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

the class LibvirtComputingResource method createPatchVbd.

private void createPatchVbd(Connect conn, String vmName, LibvirtVMDef vm, VirtualMachineTO vmSpec) throws LibvirtException, InternalErrorException {
    List<DiskDef> disks = vm.getDevices().getDisks();
    DiskDef rootDisk = disks.get(0);
    VolumeTO rootVol = getVolume(vmSpec, Volume.Type.ROOT);
    KVMStoragePool pool = _storagePoolMgr.getStoragePool(rootVol.getPoolUuid());
    KVMPhysicalDisk disk = pool.createPhysicalDisk(UUID.randomUUID().toString(), KVMPhysicalDisk.PhysicalDiskFormat.RAW, 10L * 1024 * 1024);
    /* Format/create fs on this disk */
    final Script command = new Script(_createvmPath, _timeout, s_logger);
    command.add("-f", disk.getPath());
    String result = command.execute();
    if (result != null) {
        s_logger.debug("Failed to create data disk: " + result);
        throw new InternalErrorException("Failed to create data disk: " + result);
    }
    String datadiskPath = disk.getPath();
    /* add patch disk */
    DiskDef patchDisk = new DiskDef();
    patchDisk.defFileBasedDisk(datadiskPath, 1, rootDisk.getBusType(), DiskDef.diskFmtType.RAW);
    disks.add(patchDisk);
    String bootArgs = vmSpec.getBootArgs();
    patchSystemVm(bootArgs, datadiskPath, vmName);
}
Also used : Script(com.cloud.utils.script.Script) DiskDef(com.cloud.agent.resource.computing.LibvirtVMDef.DiskDef) VolumeTO(com.cloud.agent.api.to.VolumeTO) KVMStoragePool(com.cloud.agent.storage.KVMStoragePool) KVMPhysicalDisk(com.cloud.agent.storage.KVMPhysicalDisk) InternalErrorException(com.cloud.exception.InternalErrorException)

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