use of com.cloud.agent.api.to.VirtualMachineTO in project CloudStack-archive by CloudStack-extras.
the class MockVmManagerImpl method startVM.
@Override
public Answer startVM(StartCommand cmd, SimulatorInfo info) {
VirtualMachineTO vm = cmd.getVirtualMachine();
String result = startVM(vm.getName(), vm.getNics(), vm.getCpus() * vm.getSpeed(), vm.getMaxRam(), vm.getBootArgs(), info.getHostUuid());
if (result != null) {
return new StartAnswer(cmd, result);
} else {
return new StartAnswer(cmd);
}
}
use of com.cloud.agent.api.to.VirtualMachineTO in project cloudstack by apache.
the class BareMetalGuru method implement.
@Override
public VirtualMachineTO implement(VirtualMachineProfile vm) {
VirtualMachineTO to = toVirtualMachineTO(vm);
VMInstanceVO vo = _vmDao.findById(vm.getId());
if (vo.getLastHostId() == null) {
to.setBootArgs(BaremetalManager.DO_PXE);
}
Map<String, String> details = new HashMap<String, String>();
details.put("template", vm.getTemplate().getUrl());
to.setDetails(details);
// Determine the VM's OS description
GuestOSVO guestOS = _guestOsDao.findById(vm.getVirtualMachine().getGuestOSId());
to.setOs(guestOS.getDisplayName());
return to;
}
use of com.cloud.agent.api.to.VirtualMachineTO in project cloudstack by apache.
the class Ovm3HypervisorResourceTest method createOtherVmTest.
@Test
public void createOtherVmTest() throws ConfigurationException, Ovm3ResourceException {
VirtualMachineTO vmspec = createVm(vmName);
vmspec.setOs("bogus");
hypervisor = vmActionPreparation();
StartCommand cmd = new StartCommand(vmspec, getHost(hypervisor.getName()), true);
Answer ra = hypervisor.executeRequest(cmd);
results.basicBooleanTest(ra.getResult());
}
use of com.cloud.agent.api.to.VirtualMachineTO in project cloudstack by apache.
the class Ovm3HypervisorResourceTest method createVmTest.
@Test
public void createVmTest() throws ConfigurationException, Ovm3ResourceException {
VirtualMachineTO vmspec = createVm(vmName);
hypervisor = vmActionPreparation();
StartCommand cmd = new StartCommand(vmspec, getHost(hypervisor.getName()), true);
Answer ra = hypervisor.executeRequest(cmd);
results.basicBooleanTest(ra.getResult());
}
use of com.cloud.agent.api.to.VirtualMachineTO in project cloudstack by apache.
the class XenServer610MigrateWithStorageSendCommandWrapper method execute.
@Override
public Answer execute(final MigrateWithStorageSendCommand command, final XenServer610Resource xenServer610Resource) {
final Connection connection = xenServer610Resource.getConnection();
final VirtualMachineTO vmSpec = command.getVirtualMachine();
final List<Pair<VolumeTO, Object>> volumeToSr = command.getVolumeToSr();
final List<Pair<NicTO, Object>> nicToNetwork = command.getNicToNetwork();
final Map<String, String> token = command.getToken();
final String vmName = vmSpec.getName();
Task task = null;
try {
// In a cluster management server setup, the migrate with storage receive and send
// commands and answers may have to be forwarded to another management server. This
// happens when the host/resource on which the command has to be executed is owned
// by the second management server. The serialization/deserialization of the command
// and answers fails as the xapi SR and Network class type isn't understand by the
// agent attache. Seriliaze the SR and Network objects here to a string and pass in
// the answer object. It'll be deserialzed and object created in migrate with
// storage send command execution.
Gson gson = new Gson();
final Map<String, String> other = new HashMap<String, String>();
other.put("live", "true");
// Create the vdi map which tells what volumes of the vm need to go
// on which sr on the destination.
final Map<VDI, SR> vdiMap = new HashMap<VDI, SR>();
for (final Pair<VolumeTO, Object> entry : volumeToSr) {
if (entry.second() instanceof SR) {
final SR sr = (SR) entry.second();
final VDI vdi = xenServer610Resource.getVDIbyUuid(connection, entry.first().getPath());
vdiMap.put(vdi, sr);
} else {
throw new CloudRuntimeException("The object " + entry.second() + " passed is not of type SR.");
}
}
final Set<VM> vms = VM.getByNameLabel(connection, vmSpec.getName());
VM vmToMigrate = null;
if (vms != null) {
vmToMigrate = vms.iterator().next();
}
// Create the vif map.
final Map<VIF, Network> vifMap = new HashMap<VIF, Network>();
for (final Pair<NicTO, Object> entry : nicToNetwork) {
if (entry.second() instanceof Network) {
final Network network = (Network) entry.second();
final VIF vif = xenServer610Resource.getVifByMac(connection, vmToMigrate, entry.first().getMac());
vifMap.put(vif, network);
} else {
throw new CloudRuntimeException("The object " + entry.second() + " passed is not of type Network.");
}
}
// Check migration with storage is possible.
task = vmToMigrate.assertCanMigrateAsync(connection, token, true, vdiMap, vifMap, other);
try {
// poll every 1 seconds.
final long timeout = xenServer610Resource.getMigrateWait() * 1000L;
xenServer610Resource.waitForTask(connection, task, 1000, timeout);
xenServer610Resource.checkForSuccess(connection, task);
} catch (final Types.HandleInvalid e) {
s_logger.error("Error while checking if vm " + vmName + " can be migrated.", e);
throw new CloudRuntimeException("Error while checking if vm " + vmName + " can be migrated.", e);
}
// Migrate now.
task = vmToMigrate.migrateSendAsync(connection, token, true, vdiMap, vifMap, other);
try {
// poll every 1 seconds.
final long timeout = xenServer610Resource.getMigrateWait() * 1000L;
xenServer610Resource.waitForTask(connection, task, 1000, timeout);
xenServer610Resource.checkForSuccess(connection, task);
} catch (final Types.HandleInvalid e) {
s_logger.error("Error while migrating vm " + vmName, e);
throw new CloudRuntimeException("Error while migrating vm " + vmName, e);
}
final Set<VolumeTO> volumeToSet = null;
return new MigrateWithStorageSendAnswer(command, volumeToSet);
} catch (final CloudRuntimeException e) {
s_logger.error("Migration of vm " + vmName + " with storage failed due to " + e.toString(), e);
return new MigrateWithStorageSendAnswer(command, e);
} catch (final Exception e) {
s_logger.error("Migration of vm " + vmName + " with storage failed due to " + e.toString(), e);
return new MigrateWithStorageSendAnswer(command, e);
} finally {
if (task != null) {
try {
task.destroy(connection);
} catch (final Exception e) {
s_logger.debug("Unable to destroy task " + task.toString() + " on host " + xenServer610Resource.getHost().getUuid() + " due to " + e.toString());
}
}
}
}
Aggregations