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);
}
}
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);
}
}
Aggregations