use of com.vmware.vim25.VmConfigSpec in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method configureVm.
public boolean configureVm(VirtualMachineConfigSpec vmConfigSpec) throws Exception {
ManagedObjectReference morTask = _context.getService().reconfigVM_Task(_mor, vmConfigSpec);
String result = _context.getServiceUtil().waitForTask(morTask);
if (result.equals("sucess")) {
_context.waitForTaskProgressDone(morTask);
return true;
} else {
s_logger.error("VMware reconfigVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
return false;
}
use of com.vmware.vim25.VmConfigSpec in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method tearDownDevice.
public void tearDownDevice(VirtualDevice device) throws Exception {
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
deviceConfigSpecArray[0] = new VirtualDeviceConfigSpec();
deviceConfigSpecArray[0].setDevice(device);
deviceConfigSpecArray[0].setOperation(VirtualDeviceConfigSpecOperation.remove);
vmConfigSpec.setDeviceChange(deviceConfigSpecArray);
if (!configureVm(vmConfigSpec)) {
throw new Exception("Failed to detach devices");
}
}
use of com.vmware.vim25.VmConfigSpec in project cloudstack by apache.
the class VmwareResource method plugPublicNic.
private void plugPublicNic(VirtualMachineMO vmMo, final String vlanId, final String vifMacAddress) throws Exception {
// TODO : probably need to set traffic shaping
Pair<ManagedObjectReference, String> networkInfo = null;
VirtualSwitchType vSwitchType = VirtualSwitchType.StandardVirtualSwitch;
if (_publicTrafficInfo != null) {
vSwitchType = _publicTrafficInfo.getVirtualSwitchType();
}
/** FIXME We have no clue which network this nic is on and that means that we can't figure out the BroadcastDomainType
* so we assume that it's VLAN for now
*/
if (VirtualSwitchType.StandardVirtualSwitch == vSwitchType) {
networkInfo = HypervisorHostHelper.prepareNetwork(_publicTrafficInfo.getVirtualSwitchName(), "cloud.public", vmMo.getRunningHost(), vlanId, null, null, _opsTimeout, true, BroadcastDomainType.Vlan, null);
} else {
networkInfo = HypervisorHostHelper.prepareNetwork(_publicTrafficInfo.getVirtualSwitchName(), "cloud.public", vmMo.getRunningHost(), vlanId, null, null, null, _opsTimeout, vSwitchType, _portsPerDvPortGroup, null, false, BroadcastDomainType.Vlan, _vsmCredentials);
}
int nicIndex = allocPublicNicIndex(vmMo);
try {
VirtualDevice[] nicDevices = vmMo.getNicDevices();
VirtualEthernetCard device = (VirtualEthernetCard) nicDevices[nicIndex];
if (VirtualSwitchType.StandardVirtualSwitch == vSwitchType) {
VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo();
nicBacking.setDeviceName(networkInfo.second());
nicBacking.setNetwork(networkInfo.first());
device.setBacking(nicBacking);
} else {
HostMO hostMo = vmMo.getRunningHost();
DatacenterMO dataCenterMo = new DatacenterMO(hostMo.getContext(), hostMo.getHyperHostDatacenter());
device.setBacking(dataCenterMo.getDvPortBackingInfo(networkInfo));
}
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
//VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
deviceConfigSpec.setDevice(device);
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
vmConfigSpec.getDeviceChange().add(deviceConfigSpec);
if (!vmMo.configureVm(vmConfigSpec)) {
throw new Exception("Failed to configure devices when plugPublicNic");
}
} catch (Exception e) {
// restore allocation mask in case of exceptions
String nicMasksStr = vmMo.getCustomFieldValue(CustomFieldConstants.CLOUD_NIC_MASK);
int nicMasks = Integer.parseInt(nicMasksStr);
nicMasks &= ~(1 << nicIndex);
vmMo.setCustomFieldValue(CustomFieldConstants.CLOUD_NIC_MASK, String.valueOf(nicMasks));
throw e;
}
}
use of com.vmware.vim25.VmConfigSpec in project cloudstack by apache.
the class VmwareResource method configNestedHVSupport.
protected void configNestedHVSupport(VirtualMachineMO vmMo, VirtualMachineTO vmSpec, VirtualMachineConfigSpec vmConfigSpec) throws Exception {
VmwareContext context = vmMo.getContext();
if ("true".equals(vmSpec.getDetails().get(VmDetailConstants.NESTED_VIRTUALIZATION_FLAG))) {
if (s_logger.isDebugEnabled())
s_logger.debug("Nested Virtualization enabled in configuration, checking hypervisor capability");
ManagedObjectReference hostMor = vmMo.getRunningHost().getMor();
ManagedObjectReference computeMor = context.getVimClient().getMoRefProp(hostMor, "parent");
ManagedObjectReference environmentBrowser = context.getVimClient().getMoRefProp(computeMor, "environmentBrowser");
HostCapability hostCapability = context.getService().queryTargetCapabilities(environmentBrowser, hostMor);
Boolean nestedHvSupported = hostCapability.isNestedHVSupported();
if (nestedHvSupported == null) {
// nestedHvEnabled property is supported only since VMware 5.1. It's not defined for earlier versions.
s_logger.warn("Hypervisor doesn't support nested virtualization, unable to set config for VM " + vmSpec.getName());
} else if (nestedHvSupported.booleanValue()) {
s_logger.debug("Hypervisor supports nested virtualization, enabling for VM " + vmSpec.getName());
vmConfigSpec.setNestedHVEnabled(true);
} else {
s_logger.warn("Hypervisor doesn't support nested virtualization, unable to set config for VM " + vmSpec.getName());
vmConfigSpec.setNestedHVEnabled(false);
}
}
}
use of com.vmware.vim25.VmConfigSpec in project cloudstack by apache.
the class VmwareResourceTest method testConfigureSpecVideoCardNewVRamSize.
@Test
public void testConfigureSpecVideoCardNewVRamSize() {
when(vmConfigSpec.getDeviceChange()).thenReturn(new ArrayList<VirtualDeviceConfigSpec>());
_resource.configureSpecVideoCardNewVRamSize(videoCard, VRAM_MEMORY_SIZE, vmConfigSpec);
InOrder inOrder = Mockito.inOrder(videoCard, vmConfigSpec);
inOrder.verify(videoCard).setVideoRamSizeInKB(VRAM_MEMORY_SIZE);
inOrder.verify(videoCard).setUseAutoDetect(false);
inOrder.verify(vmConfigSpec).getDeviceChange();
}
Aggregations