Search in sources :

Example 61 with KvmStoragePoolManager

use of com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager in project cosmic by MissionCriticalCloud.

the class LibvirtPrepareForMigrationCommandWrapper method execute.

@Override
public Answer execute(final PrepareForMigrationCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final VirtualMachineTO vm = command.getVirtualMachine();
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Preparing host for migrating " + vm);
    }
    final NicTO[] nics = vm.getNics();
    boolean skipDisconnect = false;
    final KvmStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
    try {
        final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
        final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(vm.getName());
        for (final NicTO nic : nics) {
            libvirtComputingResource.getVifDriver(nic.getType()).plug(nic, null, "");
        }
        /* setup disks, e.g for iso */
        final DiskTO[] volumes = vm.getDisks();
        for (final DiskTO volume : volumes) {
            if (volume.getType() == VolumeType.ISO) {
                libvirtComputingResource.getVolumePath(conn, volume);
            }
        }
        skipDisconnect = true;
        if (!storagePoolMgr.connectPhysicalDisksViaVmSpec(vm)) {
            return new PrepareForMigrationAnswer(command, "failed to connect physical disks to host");
        }
        return new PrepareForMigrationAnswer(command);
    } catch (final LibvirtException e) {
        return new PrepareForMigrationAnswer(command, e.toString());
    } catch (final InternalErrorException e) {
        return new PrepareForMigrationAnswer(command, e.toString());
    } catch (final URISyntaxException e) {
        return new PrepareForMigrationAnswer(command, e.toString());
    } finally {
        if (!skipDisconnect) {
            storagePoolMgr.disconnectPhysicalDisksViaVmSpec(vm);
        }
    }
}
Also used : LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) URISyntaxException(java.net.URISyntaxException) VirtualMachineTO(com.cloud.legacymodel.to.VirtualMachineTO) PrepareForMigrationAnswer(com.cloud.legacymodel.communication.answer.PrepareForMigrationAnswer) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) NicTO(com.cloud.legacymodel.to.NicTO) DiskTO(com.cloud.legacymodel.to.DiskTO)

Aggregations

KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)61 Answer (com.cloud.legacymodel.communication.answer.Answer)48 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)45 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)44 Test (org.junit.Test)44 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)43 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)43 KvmPhysicalDisk (com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk)31 NfsStoragePool (com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool)24 LibvirtUtilitiesHelper (com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper)24 StoragePool (com.cloud.legacymodel.storage.StoragePool)24 StorageFilerTO (com.cloud.legacymodel.to.StorageFilerTO)21 LibvirtException (org.libvirt.LibvirtException)21 Connect (org.libvirt.Connect)18 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)14 InternalErrorException (com.cloud.legacymodel.exceptions.InternalErrorException)14 NicTO (com.cloud.legacymodel.to.NicTO)14 VirtualMachineTO (com.cloud.legacymodel.to.VirtualMachineTO)14 URISyntaxException (java.net.URISyntaxException)10 LibvirtVmDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef)8