public void RecordSessionOfVM() { try { _service = ecb.getConnection().Service; _sic = ecb.getConnection().ServiceContent; ArrayList supportedVersions = VersionUtil.getSupportedVersions(ecb.get_option("url")); ManagedObjectReference vmmor = ecb.getServiceUtil().GetDecendentMoRef(null, "VirtualMachine", ecb.get_option("vmname")); if (vmmor == null) { Console.WriteLine("Unable to find VirtualMachine named : " + ecb.get_option("vmname") + " in Inventory"); } if (VersionUtil.isApiVersionSupported(supportedVersions, "2.5")) { Boolean flag = VersionUtil.isApiVersionSupported(supportedVersions, "4.0"); if (flag) { if (ecb.get_option("snapshotname") == null || ecb.get_option("description") == null) { Console.WriteLine("snapshotname and description arguments are " + "mandatory for recording session feature"); return; } VirtualMachineFlagInfo flagInfo = new VirtualMachineFlagInfo(); flagInfo.recordReplayEnabled = true; flagInfo.recordReplayEnabledSpecified = true; VirtualMachineConfigSpec configSpec = new VirtualMachineConfigSpec(); configSpec.flags = flagInfo; _service.ReconfigVM_TaskAsync(vmmor, configSpec); _service.StartRecording_TaskAsync(vmmor, ecb.get_option("snapshotname"), ecb.get_option("description")); _service.StopRecording_TaskAsync(vmmor); Console.WriteLine("Session recorded successfully"); } else { VirtualMachineSnapshotTree[] tree = (VirtualMachineSnapshotTree[])getObjectProperty(vmmor, "snapshot.rootSnapshotList"); if (tree != null && tree.Length != 0) { ManagedObjectReference taskMor = _service.RemoveAllSnapshots_Task(vmmor, true, false); object[] result = ecb.getServiceUtil().WaitForValues(taskMor, new string[] { "info.state", "info.result" }, new string[] { "state" }, // info has a property - state for state of the task new object[][] { new object[] { TaskInfoState.success, TaskInfoState.error } } ); if (result[0].Equals(TaskInfoState.success)) { Console.WriteLine("Removed all the snapshot successfully"); } } else { Console.WriteLine("No snapshot found for this virtual machine"); } } } else { VirtualMachineSnapshotTree[] tree = (VirtualMachineSnapshotTree[])getObjectProperty(vmmor, "snapshot.rootSnapshotList"); if (tree != null && tree.Length != 0) { ManagedObjectReference taskMor = _service.RemoveAllSnapshots_Task(vmmor, true, false); object[] result = ecb.getServiceUtil().WaitForValues(taskMor, new string[] { "info.state", "info.result" }, new string[] { "state" }, // info has a property - state for state of the task new object[][] { new object[] { TaskInfoState.success, TaskInfoState.error } } ); if (result[0].Equals(TaskInfoState.success)) { Console.WriteLine("Removed all the snapshot successfully"); } } else { Console.WriteLine("No snapshot found for this virtual machine"); } } } catch (Exception e) { ecb.log.LogLine("RecordSession : Failed Connect"); throw e; } finally { ecb.log.LogLine("Ended RecordSession"); ecb.log.Close(); } }
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"); } }