Search in sources :

Example 46 with Host

use of com.xensource.xenapi.Host in project cloudstack by apache.

the class XenServer610MigrateWithStorageCompleteCommandWrapper method execute.

@Override
public Answer execute(final MigrateWithStorageCompleteCommand command, final XenServer610Resource xenServer610Resource) {
    final Connection connection = xenServer610Resource.getConnection();
    final VirtualMachineTO vmSpec = command.getVirtualMachine();
    final String name = vmSpec.getName();
    try {
        final XsHost xsHost = xenServer610Resource.getHost();
        final String uuid = xsHost.getUuid();
        final Set<VM> vms = VM.getByNameLabel(connection, name);
        // Check if VMs can be found by label.
        if (vms == null) {
            throw new CloudRuntimeException("Couldn't find VMs by label " + name + " on the destination host.");
        }
        final VM migratedVm = vms.iterator().next();
        // Check the vm is present on the new host.
        if (migratedVm == null) {
            throw new CloudRuntimeException("Couldn't find the migrated vm " + name + " on the destination host.");
        }
        final Host host = Host.getByUuid(connection, uuid);
        migratedVm.setAffinity(connection, host);
        // Volume paths would have changed. Return that information.
        final List<VolumeObjectTO> volumeToSet = xenServer610Resource.getUpdatedVolumePathsOfMigratedVm(connection, migratedVm, vmSpec.getDisks());
        return new MigrateWithStorageCompleteAnswer(command, volumeToSet);
    } catch (final CloudRuntimeException e) {
        s_logger.error("Migration of vm " + name + " with storage failed due to " + e.toString(), e);
        return new MigrateWithStorageCompleteAnswer(command, e);
    } catch (final Exception e) {
        s_logger.error("Migration of vm " + name + " with storage failed due to " + e.toString(), e);
        return new MigrateWithStorageCompleteAnswer(command, e);
    }
}
Also used : XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VM(com.xensource.xenapi.VM) Connection(com.xensource.xenapi.Connection) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) Host(com.xensource.xenapi.Host) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) MigrateWithStorageCompleteAnswer(com.cloud.agent.api.MigrateWithStorageCompleteAnswer) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 47 with Host

use of com.xensource.xenapi.Host in project cloudstack by apache.

the class Xenserver625StorageProcessor method createFileSR.

protected SR createFileSR(final Connection conn, final String path) {
    SR sr = null;
    PBD pbd = null;
    try {
        final String srname = path.trim();
        synchronized (srname.intern()) {
            final Set<SR> srs = SR.getByNameLabel(conn, srname);
            if (srs != null && !srs.isEmpty()) {
                return srs.iterator().next();
            }
            final Map<String, String> smConfig = new HashMap<String, String>();
            final Host host = Host.getByUuid(conn, hypervisorResource.getHost().getUuid());
            final String uuid = UUID.randomUUID().toString();
            sr = SR.introduce(conn, uuid, srname, srname, "file", "file", false, smConfig);
            final PBD.Record record = new PBD.Record();
            record.host = host;
            record.SR = sr;
            smConfig.put("location", path);
            record.deviceConfig = smConfig;
            pbd = PBD.create(conn, record);
            pbd.plug(conn);
            sr.scan(conn);
        }
        return sr;
    } catch (final Exception ex) {
        try {
            if (pbd != null) {
                pbd.destroy(conn);
            }
        } catch (final Exception e1) {
            s_logger.debug("Failed to destroy PBD", ex);
        }
        try {
            if (sr != null) {
                sr.forget(conn);
            }
        } catch (final Exception e2) {
            s_logger.error("Failed to forget SR", ex);
        }
        final String msg = "createFileSR failed! due to the following: " + ex.toString();
        s_logger.warn(msg, ex);
        throw new CloudRuntimeException(msg, ex);
    }
}
Also used : PBD(com.xensource.xenapi.PBD) HashMap(java.util.HashMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Host(com.xensource.xenapi.Host) InternalErrorException(com.cloud.exception.InternalErrorException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) SR(com.xensource.xenapi.SR)

Aggregations

Host (com.xensource.xenapi.Host)47 XenAPIException (com.xensource.xenapi.Types.XenAPIException)35 XmlRpcException (org.apache.xmlrpc.XmlRpcException)33 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)32 HashMap (java.util.HashMap)24 Connection (com.xensource.xenapi.Connection)17 SR (com.xensource.xenapi.SR)17 IOException (java.io.IOException)15 ConfigurationException (javax.naming.ConfigurationException)14 InternalErrorException (com.cloud.exception.InternalErrorException)13 MalformedURLException (java.net.MalformedURLException)13 URISyntaxException (java.net.URISyntaxException)12 TimeoutException (java.util.concurrent.TimeoutException)12 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)12 SAXException (org.xml.sax.SAXException)12 VM (com.xensource.xenapi.VM)11 PBD (com.xensource.xenapi.PBD)10 XsHost (com.cloud.hypervisor.xenserver.resource.XsHost)7 Map (java.util.Map)7 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)6