/** * * This method returns the ConfigTarget for a HostSystem * * @param computeResMor A MoRef to the ComputeResource used by the HostSystem * * @param hostMor A MoRef to the HostSystem * * @return Instance of ConfigTarget for the supplied * * HostSystem/ComputeResource * * @throws Exception When no ConfigTarget can be found * */ public ConfigTarget getConfigTargetForHost(ManagedObjectReference computeResMor, ManagedObjectReference hostMor) { ManagedObjectReference envBrowseMor = cb.getServiceUtil().GetMoRefProp(computeResMor, "environmentBrowser"); ConfigTarget configTarget = cb.getConnection().Service.QueryConfigTarget(envBrowseMor, hostMor); if (configTarget == null) { throw new Exception("No ConfigTarget found in ComputeResource"); } return(configTarget); }
public ConfigAttribute(ConfigTarget target, string group, string attribute, System.Collections.Generic.Dictionary <string, object> member) { this.target = target; this.group = !System.String.IsNullOrWhiteSpace(group) ? group.Trim() : Bind.CommandGroupDefault; this.attribute = !System.String.IsNullOrWhiteSpace(attribute) ? attribute.Trim() : System.String.Empty; this.member = member; }
/// <summary> /// Игноре лист за избраната задача /// Двойно кликване: Отваря форма за редакция /// </summary> private void dgv_LIgnoreList_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { try { ConfigTarget ct = GetCurrentTarget(); EditIgnoreItem(ct.IgnoreList, GetCurrentLIgnoreItem(ct.IgnoreList), dt_LIgnoreList); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Игноре лист за избраната задача /// Отваря форма за редакция /// </summary> private void tsmi_EditLIgnore_Click(object sender, EventArgs e) { try { ConfigTarget ct = GetCurrentTarget(); EditIgnoreItem(ct.IgnoreList, GetCurrentLIgnoreItem(ct.IgnoreList), dt_LIgnoreList); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void EditTarget(ConfigTarget aTarget) { using (FTarget_NewEdit fTrgt = new FTarget_NewEdit()) { fTrgt.CTarget = aTarget; if (fTrgt.ShowForm()) { SaveConfig(); LoadTableTargets(); } } }
/// <summary> /// Игноре лист за избраната задача /// Изтрива избрания /// </summary> private void tsmi_DeleteLIgnore_Click(object sender, EventArgs e) { try { ConfigTarget ct = GetCurrentTarget(); ct.IgnoreList.Remove(GetCurrentLIgnoreItem(ct.IgnoreList)); SaveConfig(); LoadTableIgnoreList(ct.IgnoreList, dt_LIgnoreList); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Зарежда талицата с цели за синхронизиране /// </summary> private void LoadTableTargets() { dt_Target.Rows.Clear(); for (int i = 0; i < _ConfigFSynchr.Targets.Count; i++) { ConfigTarget ct = _ConfigFSynchr.Targets[i]; DataRow dr = dt_Target.NewRow(); dr["tc_TNo"] = (i + 1).ToString(); dr["tc_TSource"] = ct.Source; dr["tc_TDestination"] = ct.Destination; dr["tc_TName"] = ct.Name; dt_Target.Rows.Add(dr); } }
private String getNetworkName() { String networkName = null; VirtualMachineRuntimeInfo vmRuntimeInfo = (VirtualMachineRuntimeInfo)cb.getServiceUtil().GetDynamicProperty( _virtualMachine, "runtime"); ManagedObjectReference envBrowser = (ManagedObjectReference)cb.getServiceUtil().GetDynamicProperty( _virtualMachine, "environmentBrowser"); ManagedObjectReference hmor = vmRuntimeInfo.host; if (hmor != null) { ConfigTarget configTarget = cb.getConnection()._service.QueryConfigTarget(envBrowser, null); if (configTarget.network != null) { for (int i = 0; i < configTarget.network.Length; i++) { VirtualMachineNetworkInfo netInfo = configTarget.network[i]; NetworkSummary netSummary = netInfo.network; if (netSummary.accessible) { if (netSummary.name.Equals( cb.get_option("value"))) { networkName = netSummary.name; break; } } } if (networkName == null) { Console.WriteLine("Specify the Correct Network Name"); return(null); } } Console.WriteLine("network Name " + networkName); return(networkName); } else { Console.WriteLine("No Host is responsible to run this VM"); return(null); } }
private void dgv_Targets_SelectionChanged(object sender, EventArgs e) { try { ConfigTarget ct = GetCurrentTarget(); if (ct == null) { LoadTableIgnoreList(null, dt_LIgnoreList); } else { LoadTableIgnoreList(ct.IgnoreList, dt_LIgnoreList); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private DatastoreSummary getDataStoreSummary() { DatastoreSummary dsSum = null; VirtualMachineRuntimeInfo vmRuntimeInfo = (VirtualMachineRuntimeInfo)cb.getServiceUtil().GetDynamicProperty( _virtualMachine, "runtime"); ManagedObjectReference envBrowser = (ManagedObjectReference)cb.getServiceUtil().GetDynamicProperty( _virtualMachine, "environmentBrowser"); ManagedObjectReference hmor = vmRuntimeInfo.host; if (hmor != null) { ConfigTarget configTarget = cb.getConnection()._service.QueryConfigTarget(envBrowser, null); if (configTarget.datastore != null) { for (int i = 0; i < configTarget.datastore.Length; i++) { VirtualMachineDatastoreInfo vdsInfo = configTarget.datastore[i]; DatastoreSummary dsSummary = vdsInfo.datastore; if (dsSummary.accessible) { dsSum = dsSummary; break; } } } return(dsSum); } else { Console.WriteLine("No Datastore found"); return(null); } }
public VirtualMachineConfigSpec createVmConfigSpec(String vmName, String datastoreName, int diskSizeMB, ManagedObjectReference computeResMor, ManagedObjectReference hostMor) { ConfigTarget configTarget = getConfigTargetForHost(computeResMor, hostMor); VirtualDevice[] defaultDevices = getDefaultDevices(computeResMor, hostMor); VirtualMachineConfigSpec configSpec = new VirtualMachineConfigSpec(); String networkName = null; if (configTarget.network != null) { for (int i = 0; i < configTarget.network.Length; i++) { VirtualMachineNetworkInfo netInfo = configTarget.network[i]; NetworkSummary netSummary = netInfo.network; if (netSummary.accessible) { networkName = netSummary.name; break; } } } ManagedObjectReference datastoreRef = null; if (datastoreName != null) { Boolean flag = false; for (int i = 0; i < configTarget.datastore.Length; i++) { VirtualMachineDatastoreInfo vdsInfo = configTarget.datastore[i]; DatastoreSummary dsSummary = vdsInfo.datastore; if (dsSummary.name.Equals(datastoreName)) { flag = true; if (dsSummary.accessible) { datastoreName = dsSummary.name; datastoreRef = dsSummary.datastore; } else { throw new Exception("Specified Datastore is not accessible"); } break; } } if (!flag) { throw new Exception("Specified Datastore is not Found"); } } else { Boolean flag = false; for (int i = 0; i < configTarget.datastore.Length; i++) { VirtualMachineDatastoreInfo vdsInfo = configTarget.datastore[i]; DatastoreSummary dsSummary = vdsInfo.datastore; if (dsSummary.accessible) { datastoreName = dsSummary.name; datastoreRef = dsSummary.datastore; flag = true; break; } } if (!flag) { throw new Exception("No Datastore found on host"); } } String datastoreVolume = getVolumeName(datastoreName); VirtualMachineFileInfo vmfi = new VirtualMachineFileInfo(); vmfi.vmPathName = datastoreVolume; configSpec.files = vmfi; // Add a scsi controller int diskCtlrKey = 1; VirtualDeviceConfigSpec scsiCtrlSpec = new VirtualDeviceConfigSpec(); scsiCtrlSpec.operation = VirtualDeviceConfigSpecOperation.add; scsiCtrlSpec.operationSpecified = true; VirtualLsiLogicController scsiCtrl = new VirtualLsiLogicController(); scsiCtrl.busNumber = 0; scsiCtrlSpec.device = scsiCtrl; scsiCtrl.key = diskCtlrKey; scsiCtrl.sharedBus = VirtualSCSISharing.noSharing; String ctlrType = scsiCtrl.GetType().Name; // Find the IDE controller VirtualDevice ideCtlr = null; for (int di = 0; di < defaultDevices.Length; di++) { if (defaultDevices[di].GetType().Name.Equals("VirtualIDEController")) { ideCtlr = defaultDevices[di]; break; } } // Add a floppy VirtualDeviceConfigSpec floppySpec = new VirtualDeviceConfigSpec(); floppySpec.operation = VirtualDeviceConfigSpecOperation.add; floppySpec.operationSpecified = true; VirtualFloppy floppy = new VirtualFloppy(); VirtualFloppyDeviceBackingInfo flpBacking = new VirtualFloppyDeviceBackingInfo(); flpBacking.deviceName = "/dev/fd0"; floppy.backing = flpBacking; floppy.key = 3; floppySpec.device = floppy; // Add a cdrom based on a physical device VirtualDeviceConfigSpec cdSpec = null; if (ideCtlr != null) { cdSpec = new VirtualDeviceConfigSpec(); cdSpec.operation = VirtualDeviceConfigSpecOperation.add; cdSpec.operationSpecified = true; VirtualCdrom cdrom = new VirtualCdrom(); VirtualCdromIsoBackingInfo cdDeviceBacking = new VirtualCdromIsoBackingInfo(); cdDeviceBacking.datastore = datastoreRef; cdDeviceBacking.fileName = datastoreVolume + "testcd.iso"; cdrom.backing = cdDeviceBacking; cdrom.key = 20; cdrom.controllerKey = ideCtlr.key; cdrom.controllerKeySpecified = true; cdrom.unitNumberSpecified = true; cdrom.unitNumber = 0; cdSpec.device = cdrom; } // Create a new disk - file based - for the vm VirtualDeviceConfigSpec diskSpec = null; diskSpec = createVirtualDisk(datastoreName, diskCtlrKey, datastoreRef, diskSizeMB); // Add a NIC. the network Name must be set as the device name to create the NIC. VirtualDeviceConfigSpec nicSpec = new VirtualDeviceConfigSpec(); if (networkName != null) { nicSpec.operation = VirtualDeviceConfigSpecOperation.add; nicSpec.operationSpecified = true; VirtualEthernetCard nic = new VirtualPCNet32(); VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo(); nicBacking.deviceName = networkName; nic.addressType = "generated"; nic.backing = nicBacking; nic.key = 4; nicSpec.device = nic; } var deviceConfigSpec = new List <VirtualDeviceConfigSpec>(); deviceConfigSpec.Add(scsiCtrlSpec); deviceConfigSpec.Add(floppySpec); deviceConfigSpec.Add(diskSpec); deviceConfigSpec.Add(nicSpec); if (ideCtlr != null) { deviceConfigSpec.Add(cdSpec); } configSpec.deviceChange = deviceConfigSpec.ToArray(); return(configSpec); }