Search in sources :

Example 1 with PrepareForMigrationAnswer

use of com.cloud.agent.api.PrepareForMigrationAnswer in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method execute.

private synchronized Answer execute(PrepareForMigrationCommand cmd) {
    VirtualMachineTO vm = cmd.getVirtualMachine();
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Preparing host for migrating " + vm);
    }
    NicTO[] nics = vm.getNics();
    try {
        Connect conn = LibvirtConnection.getConnection();
        for (NicTO nic : nics) {
            String vlanId = null;
            if (nic.getBroadcastType() == BroadcastDomainType.Vlan) {
                URI broadcastUri = nic.getBroadcastUri();
                vlanId = broadcastUri.getHost();
            }
            if (nic.getType() == TrafficType.Guest) {
                if (nic.getBroadcastType() == BroadcastDomainType.Vlan && !vlanId.equalsIgnoreCase("untagged")) {
                    createVlanBr(vlanId, _pifs.first());
                }
            } else if (nic.getType() == TrafficType.Control) {
                /* Make sure the network is still there */
                createControlNetwork(conn);
            } else if (nic.getType() == TrafficType.Public) {
                if (nic.getBroadcastType() == BroadcastDomainType.Vlan && !vlanId.equalsIgnoreCase("untagged")) {
                    createVlanBr(vlanId, _pifs.second());
                }
            }
        }
        /* setup disks, e.g for iso */
        VolumeTO[] volumes = vm.getDisks();
        for (VolumeTO volume : volumes) {
            if (volume.getType() == Volume.Type.ISO) {
                getVolumePath(conn, volume);
            }
        }
        synchronized (_vms) {
            _vms.put(vm.getName(), State.Migrating);
        }
        return new PrepareForMigrationAnswer(cmd);
    } catch (LibvirtException e) {
        return new PrepareForMigrationAnswer(cmd, e.toString());
    } catch (InternalErrorException e) {
        return new PrepareForMigrationAnswer(cmd, e.toString());
    } catch (URISyntaxException e) {
        return new PrepareForMigrationAnswer(cmd, e.toString());
    }
}
Also used : VolumeTO(com.cloud.agent.api.to.VolumeTO) LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) InternalErrorException(com.cloud.exception.InternalErrorException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) NicTO(com.cloud.agent.api.to.NicTO) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer)

Example 2 with PrepareForMigrationAnswer

use of com.cloud.agent.api.PrepareForMigrationAnswer in project cloudstack by apache.

the class OvmResourceBase method execute.

protected PrepareForMigrationAnswer execute(PrepareForMigrationCommand cmd) {
    VirtualMachineTO vm = cmd.getVirtualMachine();
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Preparing host for migrating " + vm);
    }
    NicTO[] nics = vm.getNics();
    try {
        for (NicTO nic : nics) {
            getNetwork(nic);
        }
        return new PrepareForMigrationAnswer(cmd);
    } catch (Exception e) {
        s_logger.warn("Catch Exception " + e.getClass().getName() + " prepare for migration failed due to " + e.toString(), e);
        return new PrepareForMigrationAnswer(cmd, e);
    }
}
Also used : VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(javax.naming.ConfigurationException) NicTO(com.cloud.agent.api.to.NicTO) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer)

Example 3 with PrepareForMigrationAnswer

use of com.cloud.agent.api.PrepareForMigrationAnswer in project cloudstack by apache.

the class CitrixPrepareForMigrationCommandWrapper method execute.

@Override
public Answer execute(final PrepareForMigrationCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    final VirtualMachineTO vm = command.getVirtualMachine();
    List<String[]> vmDataList = vm.getVmData();
    String configDriveLabel = vm.getConfigDriveLabel();
    if (configDriveLabel == null) {
        configDriveLabel = "config";
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Preparing host for migrating " + vm);
    }
    final NicTO[] nics = vm.getNics();
    try {
        citrixResourceBase.prepareISO(conn, vm.getName(), vmDataList, configDriveLabel);
        for (final NicTO nic : nics) {
            citrixResourceBase.getNetwork(conn, nic);
        }
        s_logger.debug("4. The VM " + vm.getName() + " is in Migrating state");
        return new PrepareForMigrationAnswer(command);
    } catch (final Exception e) {
        s_logger.warn("Catch Exception " + e.getClass().getName() + " prepare for migration failed due to " + e.toString(), e);
        return new PrepareForMigrationAnswer(command, e);
    }
}
Also used : Connection(com.xensource.xenapi.Connection) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) NicTO(com.cloud.agent.api.to.NicTO) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer)

Example 4 with PrepareForMigrationAnswer

use of com.cloud.agent.api.PrepareForMigrationAnswer in project cloudstack by apache.

the class Ovm3VmSupport method execute.

/* Migration should make sure both HVs are the same ? */
public PrepareForMigrationAnswer execute(PrepareForMigrationCommand cmd) {
    VirtualMachineTO vm = cmd.getVirtualMachine();
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Preparing host for migrating " + vm.getName());
    }
    NicTO[] nics = vm.getNics();
    try {
        for (NicTO nic : nics) {
            network.getNetwork(nic);
        }
        hypervisor.setVmState(vm.getName(), State.Migrating);
        LOGGER.debug("VM " + vm.getName() + " is in Migrating state");
        return new PrepareForMigrationAnswer(cmd);
    } catch (Ovm3ResourceException e) {
        LOGGER.error("Catch Exception " + e.getClass().getName() + " prepare for migration failed due to: " + e.getMessage());
        return new PrepareForMigrationAnswer(cmd, e);
    }
}
Also used : Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) NicTO(com.cloud.agent.api.to.NicTO) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer)

Example 5 with PrepareForMigrationAnswer

use of com.cloud.agent.api.PrepareForMigrationAnswer in project cloudstack by apache.

the class VmwareResource method execute.

protected Answer execute(PrepareForMigrationCommand cmd) {
    if (s_logger.isInfoEnabled()) {
        s_logger.info("Executing resource PrepareForMigrationCommand: " + _gson.toJson(cmd));
    }
    VirtualMachineTO vm = cmd.getVirtualMachine();
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Preparing host for migrating " + vm);
    }
    final String vmName = vm.getName();
    try {
        VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
        VmwareManager mgr = hyperHost.getContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
        // find VM through datacenter (VM is not at the target host yet)
        VirtualMachineMO vmMo = hyperHost.findVmOnPeerHyperHost(vmName);
        if (vmMo == null) {
            s_logger.info("VM " + vmName + " was not found in the cluster of host " + hyperHost.getHyperHostName() + ". Looking for the VM in datacenter.");
            ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter();
            DatacenterMO dcMo = new DatacenterMO(hyperHost.getContext(), dcMor);
            vmMo = dcMo.findVm(vmName);
            if (vmMo == null) {
                String msg = "VM " + vmName + " does not exist in VMware datacenter";
                s_logger.error(msg);
                throw new Exception(msg);
            }
        }
        NicTO[] nics = vm.getNics();
        for (NicTO nic : nics) {
            // prepare network on the host
            prepareNetworkFromNicInfo(new HostMO(getServiceContext(), _morHyperHost), nic, false, cmd.getVirtualMachine().getType());
        }
        Pair<String, Long> secStoreUrlAndId = mgr.getSecondaryStorageStoreUrlAndId(Long.parseLong(_dcId));
        String secStoreUrl = secStoreUrlAndId.first();
        Long secStoreId = secStoreUrlAndId.second();
        if (secStoreUrl == null) {
            String msg = "secondary storage for dc " + _dcId + " is not ready yet?";
            throw new Exception(msg);
        }
        mgr.prepareSecondaryStorageStore(secStoreUrl, secStoreId);
        ManagedObjectReference morSecDs = prepareSecondaryDatastoreOnHost(secStoreUrl);
        if (morSecDs == null) {
            String msg = "Failed to prepare secondary storage on host, secondary store url: " + secStoreUrl;
            throw new Exception(msg);
        }
        return new PrepareForMigrationAnswer(cmd);
    } catch (Throwable e) {
        if (e instanceof RemoteException) {
            s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
            invalidateServiceContext();
        }
        String msg = "Unexcpeted exception " + VmwareHelper.getExceptionMessage(e);
        s_logger.error(msg, e);
        return new PrepareForMigrationAnswer(cmd, msg);
    }
}
Also used : VmwareManager(com.cloud.hypervisor.vmware.manager.VmwareManager) HostMO(com.cloud.hypervisor.vmware.mo.HostMO) VirtualMachineMO(com.cloud.hypervisor.vmware.mo.VirtualMachineMO) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) RemoteException(java.rmi.RemoteException) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) DatacenterMO(com.cloud.hypervisor.vmware.mo.DatacenterMO) NicTO(com.cloud.agent.api.to.NicTO)

Aggregations

PrepareForMigrationAnswer (com.cloud.agent.api.PrepareForMigrationAnswer)8 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)7 NicTO (com.cloud.agent.api.to.NicTO)6 InternalErrorException (com.cloud.exception.InternalErrorException)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 URISyntaxException (java.net.URISyntaxException)3 ConfigurationException (javax.naming.ConfigurationException)3 IOException (java.io.IOException)2 Connect (org.libvirt.Connect)2 LibvirtException (org.libvirt.LibvirtException)2 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)1 CheckVirtualMachineCommand (com.cloud.agent.api.CheckVirtualMachineCommand)1 MigrateWithStorageAnswer (com.cloud.agent.api.MigrateWithStorageAnswer)1 MigrateWithStorageCommand (com.cloud.agent.api.MigrateWithStorageCommand)1 MigrateWithStorageCompleteAnswer (com.cloud.agent.api.MigrateWithStorageCompleteAnswer)1 MigrateWithStorageCompleteCommand (com.cloud.agent.api.MigrateWithStorageCompleteCommand)1 MigrateWithStorageReceiveAnswer (com.cloud.agent.api.MigrateWithStorageReceiveAnswer)1 MigrateWithStorageReceiveCommand (com.cloud.agent.api.MigrateWithStorageReceiveCommand)1 MigrateWithStorageSendAnswer (com.cloud.agent.api.MigrateWithStorageSendAnswer)1 MigrateWithStorageSendCommand (com.cloud.agent.api.MigrateWithStorageSendCommand)1