public void queryMemoryOverhead() { _service = ecb.getConnection().Service; _sic = ecb.getConnection().ServiceContent; ArrayList supportedVersions = VersionUtil.getSupportedVersions(ecb.get_option("url")); String hostname = ecb.get_option("hostname"); ManagedObjectReference hmor = ecb.getServiceUtil().GetDecendentMoRef(null, "HostSystem", hostname); if (hmor != null) { if (VersionUtil.isApiVersionSupported(supportedVersions, "2.5")) { VirtualMachineConfigInfo vmConfigInfo = new VirtualMachineConfigInfo(); vmConfigInfo.changeVersion = "1"; DateTime dt = ecb.getConnection().Service.CurrentTime(ecb.getConnection().ServiceRef); vmConfigInfo.modified = dt; VirtualMachineDefaultPowerOpInfo defaultInfo = new VirtualMachineDefaultPowerOpInfo(); vmConfigInfo.defaultPowerOps = defaultInfo; VirtualMachineFileInfo fileInfo = new VirtualMachineFileInfo(); vmConfigInfo.files = fileInfo; VirtualMachineFlagInfo flagInfo = new VirtualMachineFlagInfo(); vmConfigInfo.flags = flagInfo; vmConfigInfo.guestFullName = "Full Name"; vmConfigInfo.guestId = "Id"; VirtualHardware vhardware = new VirtualHardware(); vhardware.memoryMB = int.Parse(ecb.get_option("memorysize")); vhardware.numCPU = int.Parse(ecb.get_option("cpucount")); vmConfigInfo.hardware = vhardware; // Not Required For Computing The Overhead vmConfigInfo.name = "OnlyFoeInfo"; vmConfigInfo.uuid = "12345678-abcd-1234-cdef-123456789abc"; vmConfigInfo.version = "First"; vmConfigInfo.template = false; vmConfigInfo.alternateGuestName = "Alternate"; long overhead = ecb._connection._service.QueryMemoryOverheadEx( hmor, vmConfigInfo); Console.WriteLine("Using queryMemoryOverheadEx API using vmReconfigInfo"); Console.WriteLine("Memory overhead necessary to " + "poweron a virtual machine with memory " + ecb.get_option("memorysize") + " MB and cpu count " + ecb.get_option("cpucount") + " -: " + overhead + " bytes"); } else { long overhead = ecb._connection._service.QueryMemoryOverhead(hmor, long.Parse(ecb.get_option("memorysize")), 0, false, int.Parse(ecb.get_option("cpucount")) ); Console.WriteLine("Using queryMemoryOverhead API " + "using CPU count and Memory Size"); Console.WriteLine("Memory overhead necessary to " + "poweron a virtual machine with memory " + ecb.get_option("memorysize") + " MB and cpu count " + ecb.get_option("cpucount") + " -: " + overhead + " bytes"); } } else { Console.WriteLine("Host " + ecb.get_option("hostname") + " not found"); } }
public void queryMemoryOverhead() { _service = ecb.getConnection().Service; _sic = ecb.getConnection().ServiceContent; ArrayList supportedVersions = VersionUtil.getSupportedVersions(ecb.get_option("url")); String hostname = ecb.get_option("hostname"); ManagedObjectReference hmor = ecb.getServiceUtil().GetDecendentMoRef(null, "HostSystem", hostname); if (hmor != null) { if (VersionUtil.isApiVersionSupported(supportedVersions, "2.5")) { VirtualMachineConfigInfo vmConfigInfo = new VirtualMachineConfigInfo(); vmConfigInfo.changeVersion = "1"; DateTime dt = ecb.getConnection().Service.CurrentTime(ecb.getConnection().ServiceRef); vmConfigInfo.modified = dt; VirtualMachineDefaultPowerOpInfo defaultInfo = new VirtualMachineDefaultPowerOpInfo(); vmConfigInfo.defaultPowerOps=defaultInfo; VirtualMachineFileInfo fileInfo = new VirtualMachineFileInfo(); vmConfigInfo.files=fileInfo; VirtualMachineFlagInfo flagInfo = new VirtualMachineFlagInfo(); vmConfigInfo.flags=flagInfo; vmConfigInfo.guestFullName="Full Name"; vmConfigInfo.guestId="Id"; VirtualHardware vhardware = new VirtualHardware(); vhardware.memoryMB=int.Parse(ecb.get_option("memorysize")); vhardware.numCPU=int.Parse(ecb.get_option("cpucount")); vmConfigInfo.hardware=vhardware; // Not Required For Computing The Overhead vmConfigInfo.name="OnlyFoeInfo"; vmConfigInfo.uuid="12345678-abcd-1234-cdef-123456789abc"; vmConfigInfo.version="First"; vmConfigInfo.template=false; vmConfigInfo.alternateGuestName="Alternate"; long overhead = ecb._connection._service.QueryMemoryOverheadEx( hmor,vmConfigInfo); Console.WriteLine("Using queryMemoryOverheadEx API using vmReconfigInfo"); Console.WriteLine("Memory overhead necessary to " + "poweron a virtual machine with memory " + ecb.get_option("memorysize") + " MB and cpu count " + ecb.get_option("cpucount") + " -: " + overhead + " bytes"); } else { long overhead = ecb._connection._service.QueryMemoryOverhead(hmor, long.Parse(ecb.get_option("memorysize")), 0, false, int.Parse(ecb.get_option("cpucount")) ); Console.WriteLine("Using queryMemoryOverhead API " + "using CPU count and Memory Size"); Console.WriteLine("Memory overhead necessary to " + "poweron a virtual machine with memory " + ecb.get_option("memorysize") + " MB and cpu count " + ecb.get_option("cpucount") + " -: " + overhead + " bytes"); } } else { Console.WriteLine("Host " + ecb.get_option("hostname") + " not found"); } }