use of com.vmware.vim25.VirtualMachineConfigInfo in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method getVncPort.
public Pair<String, Integer> getVncPort(String hostNetworkName) throws Exception {
HostMO hostMo = getRunningHost();
VmwareHypervisorHostNetworkSummary summary = hostMo.getHyperHostNetworkSummary(hostNetworkName);
VirtualMachineConfigInfo configInfo = getConfigInfo();
OptionValue[] values = configInfo.getExtraConfig();
if (values != null) {
for (OptionValue option : values) {
if (option.getKey().equals("RemoteDisplay.vnc.port")) {
String value = (String) option.getValue();
if (value != null) {
return new Pair<String, Integer>(summary.getHostIp(), Integer.parseInt(value));
}
}
}
}
return new Pair<String, Integer>(summary.getHostIp(), 0);
}
use of com.vmware.vim25.VirtualMachineConfigInfo in project cloudstack by apache.
the class ResultWrapper method updateSiocInfoForWorkerVM.
private ResultWrapper updateSiocInfoForWorkerVM(VMwareUtil.VMwareConnection connection, ManagedObjectReference morVm, String datastoreName, int limitIopsPerGB) throws Exception {
int limitIopsTotal = 0;
List<ManagedObjectReference> tasks = new ArrayList<>();
VirtualMachineConfigInfo vmci = (VirtualMachineConfigInfo) VMwareUtil.getEntityProps(connection, morVm, new String[] { "config" }).get("config");
List<VirtualDevice> devices = vmci.getHardware().getDevice();
for (VirtualDevice device : devices) {
if (device instanceof VirtualDisk) {
VirtualDisk disk = (VirtualDisk) device;
if (disk.getBacking() instanceof VirtualDeviceFileBackingInfo) {
VirtualDeviceFileBackingInfo backingInfo = (VirtualDeviceFileBackingInfo) disk.getBacking();
if (backingInfo.getFileName().contains(datastoreName)) {
boolean diskUpdated = false;
StorageIOAllocationInfo sioai = disk.getStorageIOAllocation();
long currentLimitIops = sioai.getLimit() != null ? sioai.getLimit() : Long.MIN_VALUE;
long newLimitIops = getNewLimitIopsBasedOnVolumeSize(disk.getCapacityInBytes(), limitIopsPerGB);
limitIopsTotal += newLimitIops;
if (currentLimitIops != newLimitIops) {
sioai.setLimit(newLimitIops);
diskUpdated = true;
}
if (diskUpdated) {
VirtualDeviceConfigSpec vdcs = new VirtualDeviceConfigSpec();
vdcs.setDevice(disk);
vdcs.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
VirtualMachineConfigSpec vmcs = new VirtualMachineConfigSpec();
vmcs.getDeviceChange().add(vdcs);
try {
ManagedObjectReference task = VMwareUtil.reconfigureVm(connection, morVm, vmcs);
tasks.add(task);
LOGGER.info(getInfoMsgForWorkerVm(newLimitIops));
} catch (Exception ex) {
throw new Exception("Error: " + ex.getMessage());
}
}
}
}
}
}
return new ResultWrapper(limitIopsTotal, tasks);
}
use of com.vmware.vim25.VirtualMachineConfigInfo in project cloudstack by apache.
the class ResultWrapper method updateSiocInfo.
private ResultWrapper updateSiocInfo(VMwareUtil.VMwareConnection connection, Map<String, ManagedObjectReference> nameToVm, Long instanceId, StoragePoolVO storagePool, int sharesPerGB, int limitIopsPerGB) throws Exception {
int limitIopsTotal = 0;
List<ManagedObjectReference> tasks = new ArrayList<>();
VMInstanceVO vmInstance = vmInstanceDao.findById(instanceId);
if (vmInstance == null) {
String errMsg = "Error: The VM with ID " + instanceId + " could not be located.";
throw new Exception(errMsg);
}
String vmName = vmInstance.getInstanceName();
ManagedObjectReference morVm = nameToVm.get(vmName);
if (morVm == null) {
String errMsg = "Error: The VM with ID " + instanceId + " could not be located (ManagedObjectReference).";
throw new Exception(errMsg);
}
VirtualMachineConfigInfo vmci = (VirtualMachineConfigInfo) VMwareUtil.getEntityProps(connection, morVm, new String[] { "config" }).get("config");
List<VirtualDevice> devices = vmci.getHardware().getDevice();
for (VirtualDevice device : devices) {
if (device instanceof VirtualDisk) {
VirtualDisk disk = (VirtualDisk) device;
VolumeVO volumeVO = getVolumeFromVirtualDisk(vmInstance, storagePool.getId(), devices, disk);
if (volumeVO != null) {
boolean diskUpdated = false;
StorageIOAllocationInfo sioai = disk.getStorageIOAllocation();
SharesInfo sharesInfo = sioai.getShares();
int currentShares = sharesInfo.getShares();
int newShares = getNewSharesBasedOnVolumeSize(volumeVO, sharesPerGB);
if (currentShares != newShares) {
sharesInfo.setLevel(SharesLevel.CUSTOM);
sharesInfo.setShares(newShares);
diskUpdated = true;
}
long currentLimitIops = sioai.getLimit() != null ? sioai.getLimit() : Long.MIN_VALUE;
long newLimitIops = getNewLimitIopsBasedOnVolumeSize(volumeVO, limitIopsPerGB);
limitIopsTotal += newLimitIops;
if (currentLimitIops != newLimitIops) {
sioai.setLimit(newLimitIops);
diskUpdated = true;
}
if (diskUpdated) {
VirtualDeviceConfigSpec vdcs = new VirtualDeviceConfigSpec();
vdcs.setDevice(disk);
vdcs.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
VirtualMachineConfigSpec vmcs = new VirtualMachineConfigSpec();
vmcs.getDeviceChange().add(vdcs);
try {
ManagedObjectReference task = VMwareUtil.reconfigureVm(connection, morVm, vmcs);
tasks.add(task);
LOGGER.info(getInfoMsg(volumeVO, newShares, newLimitIops));
} catch (Exception ex) {
throw new Exception("Error: " + ex.getMessage());
}
}
}
}
}
return new ResultWrapper(limitIopsTotal, tasks);
}
use of com.vmware.vim25.VirtualMachineConfigInfo in project cloudstack by apache.
the class VirtualMachineMO method getVncPort.
public Pair<String, Integer> getVncPort(String hostNetworkName) throws Exception {
HostMO hostMo = getRunningHost();
VmwareHypervisorHostNetworkSummary summary = hostMo.getHyperHostNetworkSummary(hostNetworkName);
VirtualMachineConfigInfo configInfo = getConfigInfo();
List<OptionValue> values = configInfo.getExtraConfig();
if (values != null) {
for (OptionValue option : values) {
if (option.getKey().equals("RemoteDisplay.vnc.port")) {
String value = (String) option.getValue();
if (value != null) {
return new Pair<String, Integer>(summary.getHostIp(), Integer.parseInt(value));
}
}
}
}
return new Pair<String, Integer>(summary.getHostIp(), 0);
}
use of com.vmware.vim25.VirtualMachineConfigInfo in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method cloneFromDiskChain.
public void cloneFromDiskChain(String clonedVmName, int cpuSpeedMHz, int memoryMb, String[] disks, ManagedObjectReference morDs) throws Exception {
assert (disks != null);
assert (disks.length >= 1);
HostMO hostMo = getRunningHost();
VirtualMachineConfigInfo vmConfigInfo = getConfigInfo();
if (!hostMo.createBlankVm(clonedVmName, 1, cpuSpeedMHz, 0, false, memoryMb, 0, vmConfigInfo.getGuestId(), morDs, false))
throw new Exception("Unable to create a blank VM");
VirtualMachineMO clonedVmMo = hostMo.findVmOnHyperHost(clonedVmName);
if (clonedVmMo == null)
throw new Exception("Unable to find just-created blank VM");
boolean bSuccess = false;
try {
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
deviceConfigSpecArray[0] = new VirtualDeviceConfigSpec();
VirtualDevice device = VmwareHelper.prepareDiskDevice(clonedVmMo, -1, disks, morDs, -1, 1);
deviceConfigSpecArray[0].setDevice(device);
deviceConfigSpecArray[0].setOperation(VirtualDeviceConfigSpecOperation.add);
vmConfigSpec.setDeviceChange(deviceConfigSpecArray);
clonedVmMo.configureVm(vmConfigSpec);
bSuccess = true;
} finally {
if (!bSuccess) {
clonedVmMo.detachAllDisks();
clonedVmMo.destroy();
}
}
}
Aggregations