Search in sources :

Example 1 with VirtualMachineConfigInfo

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);
}
Also used : OptionValue(com.vmware.vim25.OptionValue) VirtualMachineConfigInfo(com.vmware.vim25.VirtualMachineConfigInfo) Pair(com.cloud.utils.Pair)

Example 2 with VirtualMachineConfigInfo

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);
}
Also used : VirtualDeviceFileBackingInfo(com.vmware.vim25.VirtualDeviceFileBackingInfo) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) ArrayList(java.util.ArrayList) VirtualDevice(com.vmware.vim25.VirtualDevice) VirtualMachineConfigInfo(com.vmware.vim25.VirtualMachineConfigInfo) VirtualDisk(com.vmware.vim25.VirtualDisk) StorageIOAllocationInfo(com.vmware.vim25.StorageIOAllocationInfo) VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 3 with VirtualMachineConfigInfo

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);
}
Also used : SharesInfo(com.vmware.vim25.SharesInfo) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) ArrayList(java.util.ArrayList) VirtualDevice(com.vmware.vim25.VirtualDevice) VMInstanceVO(com.cloud.vm.VMInstanceVO) VirtualMachineConfigInfo(com.vmware.vim25.VirtualMachineConfigInfo) VirtualDisk(com.vmware.vim25.VirtualDisk) StorageIOAllocationInfo(com.vmware.vim25.StorageIOAllocationInfo) VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VolumeVO(com.cloud.storage.VolumeVO) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 4 with VirtualMachineConfigInfo

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);
}
Also used : OptionValue(com.vmware.vim25.OptionValue) VirtualMachineConfigInfo(com.vmware.vim25.VirtualMachineConfigInfo) Pair(com.cloud.utils.Pair)

Example 5 with VirtualMachineConfigInfo

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();
        }
    }
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualDevice(com.vmware.vim25.VirtualDevice) VirtualMachineConfigInfo(com.vmware.vim25.VirtualMachineConfigInfo)

Aggregations

VirtualMachineConfigInfo (com.vmware.vim25.VirtualMachineConfigInfo)7 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)4 OptionValue (com.vmware.vim25.OptionValue)3 VirtualDevice (com.vmware.vim25.VirtualDevice)3 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)3 Pair (com.cloud.utils.Pair)2 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)2 StorageIOAllocationInfo (com.vmware.vim25.StorageIOAllocationInfo)2 VirtualDisk (com.vmware.vim25.VirtualDisk)2 Task (com.vmware.vim25.mo.Task)2 VirtualMachine (com.vmware.vim25.mo.VirtualMachine)2 ArrayList (java.util.ArrayList)2 VSphereException (org.jenkinsci.plugins.vsphere.tools.VSphereException)2 VolumeVO (com.cloud.storage.VolumeVO)1 VMInstanceVO (com.cloud.vm.VMInstanceVO)1 CustomizationSpecItem (com.vmware.vim25.CustomizationSpecItem)1 SharesInfo (com.vmware.vim25.SharesInfo)1 VirtualDeviceFileBackingInfo (com.vmware.vim25.VirtualDeviceFileBackingInfo)1 VirtualMachineCloneSpec (com.vmware.vim25.VirtualMachineCloneSpec)1 VirtualMachineRelocateSpec (com.vmware.vim25.VirtualMachineRelocateSpec)1