use of com.cloud.agent.api.StartAnswer 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.StartAnswer 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);
}
}
}
}
use of com.cloud.agent.api.StartAnswer 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.StartAnswer in project cloudstack by apache.
the class OvmResourceBase method execute.
@Override
public synchronized StartAnswer execute(StartCommand cmd) {
VirtualMachineTO vmSpec = cmd.getVirtualMachine();
String vmName = vmSpec.getName();
OvmVm.Details vmDetails = null;
try {
vmDetails = new OvmVm.Details();
applySpecToVm(vmDetails, vmSpec);
createVbds(vmDetails, vmSpec);
createVifs(vmDetails, vmSpec);
startVm(vmDetails);
// Add security group rules
NicTO[] nics = vmSpec.getNics();
for (NicTO nic : nics) {
if (nic.isSecurityGroupEnabled()) {
if (vmSpec.getType().equals(VirtualMachine.Type.User)) {
defaultNetworkRulesForUserVm(vmName, vmSpec.getId(), nic);
}
}
}
return new StartAnswer(cmd);
} catch (Exception e) {
s_logger.debug("Start vm " + vmName + " failed", e);
cleanup(vmDetails);
return new StartAnswer(cmd, e.getMessage());
}
}
use of com.cloud.agent.api.StartAnswer in project cloudstack by apache.
the class HypervDirectConnectResourceTest method testStartCommandCorruptDiskImage.
@Test
public final void testStartCommandCorruptDiskImage() {
String sampleStart = "{\"vm\":{\"id\":16,\"name\":\"i-3-17-VM\"," + "\"type\":\"User\",\"cpus\":1,\"speed\":500," + "\"minRam\":536870912,\"maxRam\":536870912," + "\"arch\":\"x86_64\"," + "\"os\":\"CentOS 6.0 (64-bit)\"," + "\"bootArgs\":\"\",\"rebootOnCrash\":false," + "\"enableHA\":false," + "\"limitCpuUse\":false," + "\"vncPassword\":\"31f82f29aff646eb\"," + "\"params\":{}," + "\"uuid\":\"8b030b6a-0243-440a-8cc5-45d08815ca11\"" + ",\"disks\":[" + "{\"id\":18,\"name\":\"" + s_testSampleVolumeCorruptUUID + "\"," + "\"mountPoint\":" + s_testSampleVolumeCorruptURIJSON + "," + "\"path\":" + s_testSampleVolumeCorruptURIJSON + ",\"size\":0," + "\"type\":\"ROOT\"," + "\"storagePoolType\":\"Filesystem\"," + "\"storagePoolUuid\":\"" + s_testLocalStoreUUID + "\"" + ",\"deviceId\":0}," + "{\"id\":16,\"name\":\"Hyper-V Sample2\",\"size\":0," + "\"type\":\"ISO\",\"storagePoolType\":\"ISO\"," + "\"deviceId\":3}]," + "\"nics\":[" + "{\"deviceId\":0,\"networkRateMbps\":100," + "\"defaultNic\":true," + "\"uuid\":\"99cb4813-23af-428c-a87a-2d1899be4f4b\"," + "\"ip\":\"10.1.1.67\",\"netmask\":\"255.255.255.0\"," + "\"gateway\":\"10.1.1.1\"," + "\"mac\":\"02:00:51:2c:00:0e\",\"dns1\":\"4.4.4.4\"," + "\"broadcastType\":\"Vlan\",\"type\":\"Guest\"," + "\"broadcastUri\":\"vlan://261\"," + "\"isolationUri\":\"vlan://261\"," + "\"isSecurityGroupEnabled\":false}" + "]},\"contextMap\":{},\"wait\":0}";
StartCommand cmd = s_gson.fromJson(sampleStart, StartCommand.class);
StartAnswer ans = (StartAnswer) s_hypervresource.executeRequest(cmd);
Assert.assertFalse(ans.getDetails(), ans.getResult());
}
Aggregations