use of com.cloud.hypervisor.ovm3.objects.Xen in project cloudstack by apache.
the class Ovm3HypervisorResourceTest method createVm.
public VirtualMachineTO createVm(String vmName) throws Ovm3ResourceException {
con = support.prepConnectionResults();
Xen vdata = new Xen(con);
Xen.Vm vm = vdata.getVmConfig(vmName);
vdata.listVm(xen.getRepoId(), xen.getVmId());
// Ovm3VmGuestTypes types = new Ovm3VmGuestTypes();
Long id = 1L;
String instanceName = vm.getVmName();
VirtualMachine.Type type = Type.User;
// vm.getVmCpus();
int cpus = 1;
Integer speed = 0;
long minRam = vm.getVmMemory();
long maxRam = vm.getVmMemory();
BootloaderType bootloader = BootloaderType.PyGrub;
String os = "Oracle Enterprise Linux 6.0 (64-bit)";
boolean enableHA = true;
boolean limitCpuUse = false;
String vncPassword = "gobbeldygoo";
VirtualMachineTO vmspec = new VirtualMachineTO(id, instanceName, type, cpus, speed, minRam, maxRam, bootloader, os, enableHA, limitCpuUse, vncPassword);
vmspec.setBootArgs("");
addDisksToSpec(vmspec, vm.getVmDisks());
addNicsToSpec(vmspec, vm.getVmVifs());
return vmspec;
}
use of com.cloud.hypervisor.ovm3.objects.Xen in project cloudstack by apache.
the class Ovm3VmSupport method execute.
/* do migrations of VMs in a simple way just inside a cluster for now */
public MigrateAnswer execute(final MigrateCommand cmd) {
final String vmName = cmd.getVmName();
String destUuid = cmd.getHostGuid();
String destIp = cmd.getDestinationIp();
State state = State.Error;
/*
* TODO: figure out non pooled migration, works from CLI but not from
* the agent... perhaps pause the VM and then migrate it ? for now just
* stop the VM.
*/
String msg = "Migrating " + vmName + " to " + destIp;
LOGGER.info(msg);
if (!config.getAgentInOvm3Cluster() && !config.getAgentInOvm3Pool()) {
try {
Xen xen = new Xen(c);
Xen.Vm vm = xen.getRunningVmConfig(vmName);
HostVO destHost = resourceMgr.findHostByGuid(destUuid);
if (destHost == null) {
msg = "Unable to find migration target host in DB " + destUuid + " with ip " + destIp;
LOGGER.info(msg);
return new MigrateAnswer(cmd, false, msg, null);
}
xen.stopVm(ovmObject.deDash(vm.getVmRootDiskPoolId()), vm.getVmUuid());
msg = destHost.toString();
state = State.Stopping;
return new MigrateAnswer(cmd, false, msg, null);
} catch (Ovm3ResourceException e) {
msg = "Unpooled VM Migrate of " + vmName + " to " + destUuid + " failed due to: " + e.getMessage();
LOGGER.debug(msg, e);
return new MigrateAnswer(cmd, false, msg, null);
} finally {
/* shouldn't we just reinitialize completely as a last resort ? */
hypervisor.setVmState(vmName, state);
}
} else {
try {
Xen xen = new Xen(c);
Xen.Vm vm = xen.getRunningVmConfig(vmName);
if (vm == null) {
state = State.Stopped;
msg = vmName + " is no running on " + config.getAgentHostname();
return new MigrateAnswer(cmd, false, msg, null);
}
/* not a storage migration!!! */
xen.migrateVm(ovmObject.deDash(vm.getVmRootDiskPoolId()), vm.getVmUuid(), destIp);
state = State.Stopping;
msg = "Migration of " + vmName + " successfull";
return new MigrateAnswer(cmd, true, msg, null);
} catch (Ovm3ResourceException e) {
msg = "Pooled VM Migrate" + ": Migration of " + vmName + " to " + destIp + " failed due to " + e.getMessage();
LOGGER.debug(msg, e);
return new MigrateAnswer(cmd, false, msg, null);
} finally {
hypervisor.setVmState(vmName, state);
}
}
}
use of com.cloud.hypervisor.ovm3.objects.Xen in project cloudstack by apache.
the class Ovm3HypervisorResource method execute.
@Override
public synchronized StartAnswer execute(StartCommand cmd) {
VirtualMachineTO vmSpec = cmd.getVirtualMachine();
String vmName = vmSpec.getName();
State state = State.Stopped;
Xen xen = new Xen(c);
try {
hypervisorsupport.setVmStateStarting(vmName);
Xen.Vm vm = xen.getVmConfig();
/* max and min ? */
vm.setVmCpus(vmSpec.getCpus());
/* in mb not in bytes */
vm.setVmMemory(vmSpec.getMinRam() / 1024 / 1024);
vm.setVmUuid(UUID.nameUUIDFromBytes(vmSpec.getName().getBytes(Charset.defaultCharset())).toString());
vm.setVmName(vmName);
String domType = guesttypes.getOvm3GuestType(vmSpec.getOs());
if (domType == null || domType.isEmpty()) {
domType = "default";
LOGGER.debug("VM Virt type missing setting to: " + domType);
} else {
LOGGER.debug("VM Virt type set to " + domType + " for " + vmSpec.getOs());
}
vm.setVmDomainType(domType);
if (vmSpec.getBootloader() == BootloaderType.CD) {
LOGGER.warn("CD booting is not supported");
}
/*
* officially CD boot is only supported on HVM, although there is a
* simple way around it..
*/
vmsupport.createVbds(vm, vmSpec);
if (vmSpec.getType() != VirtualMachine.Type.User) {
// double check control network if we run a non user VM
hypervisornetwork.configureNetworking();
vm.setVmExtra(vmSpec.getBootArgs().replace(" ", "%"));
String svmPath = configuration.getAgentOvmRepoPath() + "/" + ovmObject.deDash(vm.getPrimaryPoolUuid()) + "/ISOs";
String svmIso = svmPath + "/" + storagepool.getSystemVMPatchIsoFile().getName();
vm.addIso(svmIso);
}
/* OVS/Network stuff should go here! */
vmsupport.createVifs(vm, vmSpec);
vm.setupVifs();
vm.setVnc("0.0.0.0", vmSpec.getVncPassword());
xen.createVm(ovmObject.deDash(vm.getPrimaryPoolUuid()), vm.getVmUuid());
xen.startVm(ovmObject.deDash(vm.getPrimaryPoolUuid()), vm.getVmUuid());
state = State.Running;
if (vmSpec.getType() != VirtualMachine.Type.User) {
String controlIp = null;
for (NicTO nic : vmSpec.getNics()) {
if (nic.getType() == TrafficType.Control) {
controlIp = nic.getIp();
}
}
/* fix is in cloudstack.py for xend restart timer */
for (int count = 0; count < 60; count++) {
CloudstackPlugin cSp = new CloudstackPlugin(c);
/* skip a beat to make sure we didn't miss start */
if (hypervisorsupport.getVmState(vmName) == null && count > 1) {
String msg = "VM " + vmName + " went missing on " + configuration.getAgentHostname() + ", returning stopped";
LOGGER.debug(msg);
state = State.Stopped;
return new StartAnswer(cmd, msg);
}
/* creative fix? */
try {
Boolean res = cSp.domrCheckSsh(controlIp);
LOGGER.debug("connected to " + controlIp + " on attempt " + count + " result: " + res);
if (res) {
break;
}
} catch (Exception x) {
LOGGER.trace("unable to connect to " + controlIp + " on attempt " + count + " " + x.getMessage(), x);
}
Thread.sleep(5000);
}
}
/*
* Can't remember if HA worked if we were only a pool ?
*/
if (configuration.getAgentInOvm3Pool() && configuration.getAgentInOvm3Cluster()) {
xen.configureVmHa(ovmObject.deDash(vm.getPrimaryPoolUuid()), vm.getVmUuid(), true);
}
/* should be starting no ? */
state = State.Running;
return new StartAnswer(cmd);
} catch (Exception e) {
LOGGER.debug("Start vm " + vmName + " failed", e);
state = State.Stopped;
return new StartAnswer(cmd, e.getMessage());
} finally {
hypervisorsupport.setVmState(vmName, state);
}
}
use of com.cloud.hypervisor.ovm3.objects.Xen in project cloudstack by apache.
the class Ovm3HypervisorResource method execute.
/**
* Removes the vm and its configuration from the hypervisor.
*/
@Override
public StopAnswer execute(StopCommand cmd) {
String vmName = cmd.getVmName();
State state = State.Error;
hypervisorsupport.setVmState(vmName, State.Stopping);
try {
Xen vms = new Xen(c);
Xen.Vm vm = null;
vm = vms.getRunningVmConfig(vmName);
if (vm == null) {
state = State.Stopping;
LOGGER.debug("Unable to get details of vm: " + vmName + ", treating it as Stopping");
return new StopAnswer(cmd, "success", true);
}
String repoId = ovmObject.deDash(vm.getVmRootDiskPoolId());
String vmId = vm.getVmUuid();
/* can we do without the poolId ? */
vms.stopVm(repoId, vmId);
int tries = 30;
while (vms.getRunningVmConfig(vmName) != null && tries > 0) {
String msg = "Waiting for " + vmName + " to stop";
LOGGER.debug(msg);
tries--;
Thread.sleep(10 * 1000);
}
vms.deleteVm(repoId, vmId);
vmsupport.cleanup(vm);
if (vms.getRunningVmConfig(vmName) != null) {
String msg = "Stop " + vmName + " failed ";
LOGGER.debug(msg);
return new StopAnswer(cmd, msg, false);
}
state = State.Stopped;
return new StopAnswer(cmd, "success", true);
} catch (Exception e) {
LOGGER.debug("Stop " + vmName + " failed ", e);
return new StopAnswer(cmd, e.getMessage(), false);
} finally {
if (state != null) {
hypervisorsupport.setVmState(vmName, state);
} else {
hypervisorsupport.revmoveVmState(vmName);
}
}
}
use of com.cloud.hypervisor.ovm3.objects.Xen in project cloudstack by apache.
the class Ovm3VirtualRoutingResource method prepNetBoth.
private ExecutionResult prepNetBoth(String routerName, IpAddressTO[] ips, String type) {
Xen xen = new Xen(c);
try {
Xen.Vm vm = xen.getVmConfig(routerName);
for (IpAddressTO ip : ips) {
Integer devId = vm.getVifIdByMac(ip.getVifMacAddress());
if (devId < 0 && "IpAssocVpcCommand".equals(type)) {
String msg = "No valid Nic devId found for " + vm.getVmName() + " with " + ip.getVifMacAddress();
logger.error(msg);
return new ExecutionResult(false, msg);
} else if (devId < 0 && "IpAssocCommand".equals(type)) {
// vm.get
String msg = "No valid Nic devId found for " + vm.getVmName() + " with " + ip.getVifMacAddress() + " " + " Ignoring for now (routervm)";
logger.debug(msg);
devId = 2;
}
ip.setNicDevId(devId);
}
} catch (Exception e) {
String msg = type + " failure on applying one ip due to exception: " + e;
logger.error(msg);
return new ExecutionResult(false, msg);
}
return new ExecutionResult(true, null);
}
Aggregations