use of com.cloud.hypervisor.ovm3.objects.Network 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.Network in project cloudstack by apache.
the class Ovm3HypervisorNetwork method isNetworkSetupByName.
/**/
private boolean isNetworkSetupByName(String nameTag) {
if (nameTag != null) {
LOGGER.debug("Looking for network setup by name " + nameTag);
try {
Network net = new Network(c);
net.getInterfaceList();
if (net.getBridgeByName(nameTag) != null) {
LOGGER.debug("Found bridge with name: " + nameTag);
return true;
}
} catch (Ovm3ResourceException e) {
LOGGER.debug("Unxpected error looking for name: " + nameTag, e);
return false;
}
}
LOGGER.debug("No bridge with name: " + nameTag);
return false;
}
use of com.cloud.hypervisor.ovm3.objects.Network in project cloudstack by apache.
the class Ovm3HypervisorNetwork method createVlanBridge.
private String createVlanBridge(String networkName, Integer vlanId) throws Ovm3ResourceException {
if (vlanId < 1 || vlanId > 4094) {
String msg = "Incorrect vlan " + vlanId + ", needs to be between 1 and 4094";
LOGGER.error(msg);
throw new CloudRuntimeException(msg);
}
Network net = new Network(c);
/* figure out if our bridged vlan exists, if not then create */
String brName = networkName + "." + vlanId.toString();
try {
String physInterface = net.getPhysicalByBridgeName(networkName);
if (net.getInterfaceByName(brName) == null) {
net.startOvsVlanBridge(brName, physInterface, vlanId);
} else {
LOGGER.debug("Interface " + brName + " already exists");
}
} catch (Ovm3ResourceException e) {
String msg = "Unable to create vlan " + vlanId.toString() + " bridge for " + networkName;
LOGGER.warn(msg + ": " + e);
throw new CloudRuntimeException(msg + ":" + e.getMessage());
}
return brName;
}
use of com.cloud.hypervisor.ovm3.objects.Network in project cloudstack by apache.
the class Ovm3VmSupport method deleteVif.
private Boolean deleteVif(Xen.Vm vm, NicTO nic) throws Ovm3ResourceException {
/* here we should use the housekeeping of VLANs/Networks etc..
* so we can clean after the last VM is gone
*/
try {
String net = network.getNetwork(nic);
if (net != null) {
LOGGER.debug("Removing vif " + nic.getDeviceId() + " " + " " + nic.getMac() + " " + net + " from " + vm.getVmName());
vm.removeVif(net, nic.getMac());
} else {
LOGGER.debug("Unable to remove vif " + nic.getDeviceId() + " no network for " + vm.getVmName());
return false;
}
} catch (Exception e) {
String msg = "Unable to remove vif " + nic.getType() + " for " + vm.getVmName() + " " + e.getMessage();
LOGGER.debug(msg);
throw new Ovm3ResourceException(msg);
}
return true;
}
use of com.cloud.hypervisor.ovm3.objects.Network in project cloudstack by apache.
the class Ovm3VmSupport method createVif.
/* should add bitrates and latency... */
private Boolean createVif(Xen.Vm vm, NicTO nic) throws Ovm3ResourceException {
try {
String net = network.getNetwork(nic);
if (net != null) {
LOGGER.debug("Adding vif " + nic.getDeviceId() + " " + nic.getMac() + " " + net + " to " + vm.getVmName());
vm.addVif(nic.getDeviceId(), net, nic.getMac());
} else {
LOGGER.debug("Unable to add vif " + nic.getDeviceId() + " no network for " + vm.getVmName());
return false;
}
} catch (Exception e) {
String msg = "Unable to add vif " + nic.getType() + " for " + vm.getVmName() + " " + e.getMessage();
LOGGER.debug(msg);
throw new Ovm3ResourceException(msg);
}
return true;
}
Aggregations