use of com.cloud.agent.api.to.VirtualMachineTO in project CloudStack-archive by CloudStack-extras.
the class AgentRoutingResource method execute.
protected synchronized Answer execute(StartCommand cmd) throws IllegalArgumentException {
VirtualMachineTO vmSpec = cmd.getVirtualMachine();
String vmName = vmSpec.getName();
if (this.totalCpu < (vmSpec.getCpus() * vmSpec.getSpeed() + this.usedCpu) || this.totalMem < (vmSpec.getMaxRam() + this.usedMem)) {
return new StartAnswer(cmd, "No enough resource to start the vm");
}
State state = State.Stopped;
synchronized (_vms) {
_vms.put(vmName, State.Starting);
}
try {
Answer result = _simMgr.simulate(cmd, hostGuid);
if (!result.getResult()) {
return new StartAnswer(cmd, result.getDetails());
}
this.usedCpu += vmSpec.getCpus() * vmSpec.getSpeed();
this.usedMem += vmSpec.getMaxRam();
_runningVms.put(vmName, new Pair<Long, Long>(Long.valueOf(vmSpec.getCpus() * vmSpec.getSpeed()), vmSpec.getMaxRam()));
state = State.Running;
} finally {
synchronized (_vms) {
_vms.put(vmName, state);
}
}
return new StartAnswer(cmd);
}
use of com.cloud.agent.api.to.VirtualMachineTO in project CloudStack-archive by CloudStack-extras.
the class SimulatorGuru method implement.
@Override
public <T extends VirtualMachine> VirtualMachineTO implement(VirtualMachineProfile<T> vm) {
VirtualMachineTO to = toVirtualMachineTO(vm);
// 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-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());
}
}
use of com.cloud.agent.api.to.VirtualMachineTO in project CloudStack-archive by CloudStack-extras.
the class FakeComputingResource method execute.
protected synchronized StartAnswer execute(StartCommand cmd) {
VmMgr vmMgr = getVmManager();
VirtualMachineTO vmSpec = cmd.getVirtualMachine();
String vmName = vmSpec.getName();
State state = State.Stopped;
try {
if (!_vms.containsKey(vmName)) {
synchronized (_vms) {
_vms.put(vmName, State.Starting);
}
MockVm vm = vmMgr.createVmFromSpec(vmSpec);
vmMgr.createVbd(vmSpec, vmName, vm);
vmMgr.createVif(vmSpec, vmName, vm);
state = State.Running;
for (NicTO nic : cmd.getVirtualMachine().getNics()) {
if (nic.getType() == TrafficType.Guest) {
InetAddress addr = _dhcpSnooper.getIPAddr(nic.getMac(), vmName);
nic.setIp(addr.getHostAddress());
}
}
_vmDataServer.handleVmStarted(cmd.getVirtualMachine());
return new StartAnswer(cmd);
} else {
String msg = "There is already a VM having the same name " + vmName;
s_logger.warn(msg);
return new StartAnswer(cmd, msg);
}
} catch (Exception ex) {
} finally {
synchronized (_vms) {
_vms.put(vmName, state);
}
}
return new StartAnswer(cmd);
}
use of com.cloud.agent.api.to.VirtualMachineTO in project CloudStack-archive by CloudStack-extras.
the class LibvirtComputingResource method execute.
protected synchronized StartAnswer execute(StartCommand cmd) {
VirtualMachineTO vmSpec = cmd.getVirtualMachine();
String vmName = vmSpec.getName();
LibvirtVMDef vm = null;
State state = State.Stopped;
Connect conn = null;
try {
conn = LibvirtConnection.getConnection();
synchronized (_vms) {
_vms.put(vmName, State.Starting);
}
vm = createVMFromSpec(vmSpec);
createVbd(conn, vmSpec, vmName, vm);
createVifs(conn, vmSpec, vm);
s_logger.debug("starting " + vmName + ": " + vm.toString());
startDomain(conn, vmName, vm.toString());
Script.runSimpleBashScript("virsh schedinfo " + vmName + " --set cpu_shares=" + vmSpec.getCpus() * vmSpec.getSpeed());
NicTO[] nics = vmSpec.getNics();
for (NicTO nic : nics) {
if (nic.getIsolationUri() != null && nic.getIsolationUri().getScheme().equalsIgnoreCase(IsolationType.Ec2.toString())) {
if (vmSpec.getType() != VirtualMachine.Type.User) {
default_network_rules_for_systemvm(conn, vmName);
break;
} else {
default_network_rules(conn, vmName, nic, vmSpec.getId());
}
}
}
state = State.Running;
return new StartAnswer(cmd);
} catch (Exception e) {
s_logger.warn("Exception ", e);
if (conn != null) {
handleVmStartFailure(conn, vmName, vm);
}
return new StartAnswer(cmd, e.getMessage());
} finally {
synchronized (_vms) {
if (state != State.Stopped) {
_vms.put(vmName, state);
} else {
_vms.remove(vmName);
}
}
}
}
Aggregations