private static void OtherConfigWatcher_OtherConfigChanged(object sender, EventArgs e) { List <CustomFieldDefinition> customFieldDefinitions = CustomFieldsManager.GetCustomFields(); // Add new custom fields foreach (CustomFieldDefinition definition in customFieldDefinitions) { if (!customFields.Exists(delegate(CustomFieldGroupingType customFieldGroupingType) { return(customFieldGroupingType.definition.Equals(definition)); })) { customFields.Add(new CustomFieldGroupingType(ObjectTypes.AllExcFolders, definition)); } } // Remove old ones foreach (CustomFieldGroupingType customFieldGroupingType in customFields.ToArray()) { if (!customFieldDefinitions.Exists(delegate(CustomFieldDefinition definition) { return(customFieldGroupingType.definition.Equals(definition)); })) { customFields.Remove(customFieldGroupingType); OnCustomFieldRemoved(customFieldGroupingType); } } }
private void btnDelete_Click(object sender, EventArgs e) { CustomFieldDefinition customFieldDefinition = lbCustomFields.SelectedItem as CustomFieldDefinition; if (customFieldDefinition == null) { return; } string name = customFieldDefinition.Name.Ellipsise(50); if (!MainWindow.Confirm(connection, Program.MainWindow, Messages.MESSAGEBOX_CONFIRM, Messages.MESSAGEBOX_DELETE_CUSTOM_FIELD, name)) { return; } int selIdx = lbCustomFields.SelectedIndex; lbCustomFields.Items.RemoveAt(selIdx); DelegatedAsyncAction action = new DelegatedAsyncAction(connection, String.Format(Messages.DELETE_CUSTOM_FIELD, name), String.Format(Messages.DELETING_CUSTOM_FIELD, name), String.Format(Messages.DELETED_CUSTOM_FIELD, name), delegate(Session session) { CustomFieldsManager.RemoveCustomField(session, connection, customFieldDefinition); }); action.RunAsync(); }
internal override Grouping GetSubgrouping(object val) { CustomFieldDefinition defn = CustomFieldsManager.GetCustomFieldDefinition(val.ToString()); return(defn == null ? null : new CustomFieldGrouping(defn, null)); }
public override bool?Match(IXenObject o) { object value = CustomFieldsManager.GetCustomFieldValue(o, definition); if (!(value is DateTime)) { return(false); } return(DatePropertyQuery.MatchDate((DateTime)value, query, type, DateTime.Now)); }
private bool IsDuplicate() { foreach (CustomFieldDefinition customFieldDefinition in CustomFieldsManager.GetCustomFields(connection)) { if (customFieldDefinition.Name.Trim() == Definition.Name.Trim()) { return(true); } } return(false); }
/// <summary> /// Format the value of a custom field for a XenObject for display to the user (localised if necessary). /// </summary> public override string ToString() { // Must be run on the event thread, otherwise dates won't be formatted correctly (CA-46983). Program.AssertOnEventThread(); object value = CustomFieldsManager.GetCustomFieldValue(o, customFieldDefinition); return((value == null) ? "" : (customFieldDefinition.Type == CustomFieldDefinition.Types.Date) ? HelpersGUI.DateTimeToString((DateTime)value, Messages.DATEFORMAT_DMY_HM, true) : value.ToString()); }
public override bool?Match(IXenObject o) { String value = CustomFieldsManager.GetCustomFieldValue(o, definition) as String; if (value == null) { return(false); } if (query == null) { return(true); } return(StringPropertyQuery.MatchString(value, query.ToLower(), type, false)); }
public void TestSearcherUpdatesWhenCustomFieldsChange() { // create a new custom field string newCustomField = Guid.NewGuid().ToString(); VM vm = GetAnyVM(); CustomFieldsManager.AddCustomField(vm.Connection.Session, vm.Connection, new CustomFieldDefinition(newCustomField, CustomFieldDefinition.Types.String)); // now see if this new custom field has been added to the searcher. MWWaitFor(delegate { // need to click for repopulate. Searcher.QueryElement.QueryTypeComboButton.Item.PerformClick(); return(null != Searcher.QueryElement.QueryTypeComboButton.Items.Find(ts => ts.Text == newCustomField)); }, "New custom field not added to the Searcher."); }
private void Build() { lbCustomFields.BeginUpdate(); try { lbCustomFields.Items.Clear(); lbCustomFields.Items.AddRange(CustomFieldsManager.GetCustomFields(connection).ToArray()); btnDelete.Enabled = false; } finally { lbCustomFields.EndUpdate(); } }
private void btnDelete_Click(object sender, EventArgs e) { CustomFieldDefinition customFieldDefinition = lbCustomFields.SelectedItem as CustomFieldDefinition; if (customFieldDefinition == null) { return; } string name = customFieldDefinition.Name.Ellipsise(50); if (!Program.RunInAutomatedTestMode) { using (var dialog = new WarningDialog(string.Format(Messages.MESSAGEBOX_DELETE_CUSTOM_FIELD, name), ThreeButtonDialog.ButtonYes, ThreeButtonDialog.ButtonNo) { WindowTitle = Messages.MESSAGEBOX_CONFIRM }) { if (dialog.ShowDialog(Program.MainWindow) != DialogResult.Yes) { return; } } } if (connection != null && !connection.IsConnected) { MainWindow.ShowDisconnectedMessage(Program.MainWindow); return; } int selIdx = lbCustomFields.SelectedIndex; lbCustomFields.Items.RemoveAt(selIdx); DelegatedAsyncAction action = new DelegatedAsyncAction(connection, String.Format(Messages.DELETE_CUSTOM_FIELD, name), String.Format(Messages.DELETING_CUSTOM_FIELD, name), String.Format(Messages.DELETED_CUSTOM_FIELD, name), delegate(Session session) { CustomFieldsManager.RemoveCustomField(session, connection, customFieldDefinition); }); action.RunAsync(); }
protected override void Run() { foreach (CustomField customField in customFields) { string key = CustomFieldsManager.GetCustomFieldKey(customField.Definition); string value = customField.ValueAsInvariantString; if (String.IsNullOrEmpty(value)) { Helpers.RemoveFromOtherConfig(Session, xenObject, key); } else { Helpers.SetOtherConfig(Session, xenObject, key, value); } } }
private static void AddCustomFieldsToRow(IXenObject o, GridRow row) { foreach (CustomFieldDefinition customFieldDefinition in CustomFieldsManager.GetCustomFields()) { GridStringItem customFieldItem = new GridStringItem( new CustomFieldWrapper(o, customFieldDefinition), HorizontalAlignment.Center, VerticalAlignment.Middle, false, false, TextBrush, Program.DefaultFont, new EventHandler(delegate { PropertiesDialog dialog = new PropertiesDialog(o); dialog.SelectPage(dialog.CustomFieldsEditPage); dialog.ShowDialog(); })); row.AddItem(CustomFieldsManager.CUSTOM_FIELD + customFieldDefinition.Name, customFieldItem); } }
public AsyncAction SaveSettings() { List <CustomField> customFields = new List <CustomField>(); foreach (KeyValuePair <CustomFieldDefinition, KeyValuePair <Label, Control> > kvp in controls) { object currentValue = CustomFieldsManager.GetCustomFieldValue(xenObject, kvp.Key); object newValue = GetValue(kvp.Key, kvp.Value.Value); if (currentValue == null && newValue == null) { continue; } customFields.Add(new CustomField(kvp.Key, newValue)); } return(new SaveCustomFieldsAction(xenObject, customFields, true)); }
private PropertyAccessor CalcProperty() { if (column.StartsWith(CustomFieldsManager.CUSTOM_FIELD)) { string fieldName = column.Substring(CustomFieldsManager.CUSTOM_FIELD.Length); CustomFieldDefinition customFieldDefinition = CustomFieldsManager.GetCustomFieldDefinition(fieldName); if (customFieldDefinition == null) // a custom field that existed at the time the search was created but no longer exists { return(o => null); } if (customFieldDefinition.Type == CustomFieldDefinition.Types.Date) { return(delegate(IXenObject o) { object val = CustomFieldsManager.GetCustomFieldValue(o, customFieldDefinition); return (DateTime?)(val is DateTime ? val : null); }); } else { return(delegate(IXenObject o) { object val = CustomFieldsManager.GetCustomFieldValue(o, customFieldDefinition); return val == null ? null : val.ToString(); }); } } ColumnNames c; try { c = (ColumnNames)Enum.Parse(typeof(ColumnNames), column); } catch (ArgumentException) { return(null); } PropertyNames propertyName = PropertyAccessors.GetSortPropertyName(c); return(PropertyAccessors.Get(propertyName)); }
/// <summary> /// Add and/or remove custom columns to the grid. /// </summary> private void SetupCustomColumns() { List <CustomFieldDefinition> customFieldDefinitions = CustomFieldsManager.GetCustomFields(); // Did the user remove a custom field? String[] columns = new String[Columns.Keys.Count]; Columns.Keys.CopyTo(columns, 0); foreach (String column in columns) { // Skip default columns if (IsDefaultColumn(column)) { continue; } // Does the custom column in table exist in the custom fields // collection? If not remove. if (!customFieldDefinitions.Exists(delegate(CustomFieldDefinition definition) { return(definition.Name == column); })) { RemoveColumn(column); } } // Add any new columns foreach (CustomFieldDefinition customFieldDefinition in customFieldDefinitions) { if (Columns.ContainsKey(customFieldDefinition.Name)) { continue; } ShowColumn(CustomFieldsManager.CUSTOM_FIELD + customFieldDefinition.Name); } BuildList(); }
internal override QueryFilter GetSubquery(object parent, object val) { System.Diagnostics.Trace.Assert(val != null); CustomFieldDefinition defn = CustomFieldsManager.GetCustomFieldDefinition(definition.Name); System.Diagnostics.Trace.Assert(defn != null); if (defn.Type == CustomFieldDefinition.Types.String) { return(new CustomFieldQuery(defn, (string)val, StringPropertyQuery.PropertyQueryType.exactmatch)); } else if (defn.Type == CustomFieldDefinition.Types.Date) { return(new CustomFieldDateQuery(defn, (DateTime)val, DatePropertyQuery.PropertyQueryType.exact)); } else { return(base.GetSubquery(parent, val)); } }
private void btnAdd_Click(object sender, EventArgs e) { NewCustomFieldDialog dialog = new NewCustomFieldDialog(connection); if (dialog.ShowDialog() != DialogResult.OK) { return; } CustomFieldDefinition definition = dialog.Definition; DelegatedAsyncAction action = new DelegatedAsyncAction(connection, String.Format(Messages.ADD_CUSTOM_FIELD, definition.Name), String.Format(Messages.ADDING_CUSTOM_FIELD, definition.Name), String.Format(Messages.ADDED_CUSTOM_FIELD, definition.Name), delegate(Session session) { CustomFieldsManager.AddCustomField(session, connection, definition); }); action.RunAsync(); }
internal override QueryFilter GetSubquery(object parent, object val) { System.Diagnostics.Trace.Assert(val != null); // Clicked on a key in the tree (which is now in val). if (parent == null) { CustomFieldDefinition defn = CustomFieldsManager.GetCustomFieldDefinition(val.ToString()); System.Diagnostics.Trace.Assert(defn != null); if (defn.Type == CustomFieldDefinition.Types.String) { return(new CustomFieldQuery(defn, String.Empty, StringPropertyQuery.PropertyQueryType.exactmatch)); } else { return(new CustomFieldDateQuery(defn, DateTime.Now, DatePropertyQuery.PropertyQueryType.exact)); } } // Clicked on a value in the tree (key is in parent, value is in val). else { CustomFieldDefinition defn = CustomFieldsManager.GetCustomFieldDefinition(parent.ToString()); System.Diagnostics.Trace.Assert(defn != null); if (defn.Type == CustomFieldDefinition.Types.String) { return(new CustomFieldQuery(defn, val.ToString(), StringPropertyQuery.PropertyQueryType.exactmatch)); } else { return(new CustomFieldDateQuery(defn, (DateTime)val, DatePropertyQuery.PropertyQueryType.exact)); } } }
protected void cmdProvision_Click(object sender, EventArgs e) { // // Ready to provision // // // Need a random number to pick a random virtual host to place the new vm on // Random rand = new Random(); // // Validate user entries // // // Do we have a value for the target vm? // if (txtTargetVm.Text == null || txtTargetVm.Text == "") { txtErrors.Text = "Please enter a name for the virtual machine."; Error_Panel.Visible = true; return; } // // Has a valid IP address been entered? // IPAddress theIp; bool ipResult = IPAddress.TryParse(txtIpAddress.Text, out theIp); if (ipResult != true) { txtErrors.Text = "Please enter a valid IP Address."; Error_Panel.Visible = true; return; } // // This does some basic checking on a subnet // IPAddress theMask; bool mskResult = IPAddress.TryParse(txtSubnet.Text, out theMask); if (mskResult != true) { txtErrors.Text = "Please enter a valid Subnet Mask."; Error_Panel.Visible = true; return; } // // Has a valid IP been entered for the gateway? // IPAddress theGateway; bool gwResult = IPAddress.TryParse(txtGateway.Text, out theGateway); if (gwResult != true) { txtErrors.Text = "Please entera valid IP Address for the default gateway."; Error_Panel.Visible = true; return; } // // Does a vm by this name already exist? // VimClient vimClient = ConnectServer(Globals.sViServer, Globals.sUsername, Globals.sPassword); List<VirtualMachine> chkVirtualMachines = GetVirtualMachines(vimClient, null, txtTargetVm.Text); if (chkVirtualMachines != null) { vimClient.Disconnect(); txtErrors.Text = "virtual machine " + txtTargetVm.Text + " already exists"; Error_Panel.Visible = true; return; } // // Need to parse the value of the dropdown // char[] splitChar = { '.' }; string[] specType = cboCustomizations.SelectedValue.Split(splitChar); // // Connect to selected datacenter // List<ClusterComputeResource> lstClusters = GetClusters(vimClient, cboClusters.SelectedItem.Text); List<Datacenter> lstDatacenters = GetDcFromCluster(vimClient, lstClusters[0].Parent.Value); Datacenter itmDatacenter = lstDatacenters[0]; // // Get a list of hosts in the selected cluster // List<HostSystem> lstHosts = GetHosts(vimClient, cboClusters.SelectedValue); // // Randomly pick host // HostSystem selectedHost = lstHosts[rand.Next(0, lstHosts.Count)]; txtResults.Text = "Host : " + selectedHost.Name + "\r\n"; // // Connect to selected vm to clone // List<VirtualMachine> lstVirtualMachines = GetVirtualMachines(vimClient, null, cboSourceVms.SelectedItem.Text); VirtualMachine itmVirtualMachine = lstVirtualMachines[0]; // // Make sure the spec file type matches the guest os // // // The commented code could be used to poweron a vm, check it's guestfamily and then turn it off. // //string GuestFamily = null; //if (itmVirtualMachine.Runtime.PowerState == VirtualMachinePowerState.poweredOff) //{ // // // // We can power on the vm to get the guestfamily property // // // itmVirtualMachine.PowerOnVM(null); // // // // Set the GuestFamily var // // // while (itmVirtualMachine.Guest.GuestFamily == null) // { // // // // Need to grab the current guest status from the vm // // // itmVirtualMachine.Reload(); // GuestFamily = itmVirtualMachine.Guest.GuestFamily; // } // // // // Turn the VM back off // // // itmVirtualMachine.PowerOffVM(); //} // // Added this test to accomodate cloning templates to vm's, per Ryan Lawrence. // if (!(chkTemplate.Checked)) { if (itmVirtualMachine.Guest.GuestFamily != null) { if ((itmVirtualMachine.Guest.GuestFamily).Contains(specType[specType.GetUpperBound(0)]) == false) { vimClient.Disconnect(); txtErrors.Text = "You specified a " + specType[specType.GetUpperBound(0)] + " spec file to clone a " + itmVirtualMachine.Guest.GuestFamily + " virtual machine."; Error_Panel.Visible = true; return; } } else { // // Sometimes the GuestFamily property isn't populated // vimClient.Disconnect(); txtErrors.Text = "The virtual machine " + itmVirtualMachine.Name.ToString() + " has no GuestFamily property populated, please power on this VM and verify that it's a supported Guest Os."; Error_Panel.Visible = true; return; } } txtResults.Text += "Source : " + itmVirtualMachine.Name + "\r\n"; // // Connect to the selected datastore // List<Datastore> lstDatastores = GetDataStore(vimClient, null, cboDatastores.SelectedItem.Text); Datastore itmDatastore = lstDatastores[0]; txtResults.Text += "Datastore : " + itmDatastore.Name + "\r\n"; // // Connect to portgroup // List<DistributedVirtualPortgroup> lstDvPortGroups = GetDVPortGroups(vimClient, itmDatacenter, cboPortGroups.SelectedItem.Text); DistributedVirtualPortgroup itmDvPortGroup = lstDvPortGroups[0]; txtResults.Text += "Portgroup : " + itmDvPortGroup.Name + "\r\n"; // // Connect to the customizationspec // CustomizationSpecItem itmSpecItem = GetCustomizationSpecItem(vimClient, cboCustomizations.SelectedItem.Text); txtResults.Text += "Spec : " + cboCustomizations.SelectedItem.Text + "\r\n"; // // Create a new VirtualMachineCloneSpec // VirtualMachineCloneSpec mySpec = new VirtualMachineCloneSpec(); mySpec.Location = new VirtualMachineRelocateSpec(); mySpec.Location.Datastore = itmDatastore.MoRef; mySpec.Location.Host = selectedHost.MoRef; // // Get resource pool for selected cluster // List<ResourcePool> lstResPools = GetResPools(vimClient, cboClusters.SelectedValue); ResourcePool itmResPool = lstResPools[0]; // // Assign resource pool to specitem // mySpec.Location.Pool = itmResPool.MoRef; // // Add selected CloneSpec customizations to this CloneSpec // mySpec.Customization = itmSpecItem.Spec; // // Handle hostname for either windows or linux // if (specType[specType.GetUpperBound(0)] == "Windows") { // // Create a windows sysprep object // CustomizationSysprep winIdent = (CustomizationSysprep)itmSpecItem.Spec.Identity; CustomizationFixedName hostname = new CustomizationFixedName(); hostname.Name = txtTargetVm.Text; winIdent.UserData.ComputerName = hostname; // // Store identity in this CloneSpec // mySpec.Customization.Identity = winIdent; } if (specType[specType.GetUpperBound(0)] == "Linux") { // // Create a Linux "sysprep" object // CustomizationLinuxPrep linIdent = (CustomizationLinuxPrep)itmSpecItem.Spec.Identity; CustomizationFixedName hostname = new CustomizationFixedName(); hostname.Name = txtTargetVm.Text; linIdent.HostName = hostname; // // Uncomment the line below to add a suffix to linux vm's // // linIdent.Domain = WebConfigurationManager.AppSettings["dnsSuffix"].ToString(); // // Store identity in this CloneSpec // mySpec.Customization.Identity = linIdent; } // // Create a new ConfigSpec // mySpec.Config = new VirtualMachineConfigSpec(); // // Set number of CPU's // int numCpus = new int(); numCpus = Convert.ToInt16(cboCpus.SelectedValue); mySpec.Config.NumCPUs = numCpus; txtResults.Text += "CPU : " + numCpus + "\r\n"; // // Set amount of RAM // long memoryMb = new long(); memoryMb = (long)(Convert.ToInt16(cboRam.SelectedValue) * 1024); mySpec.Config.MemoryMB = memoryMb; txtResults.Text += "Ram : " + memoryMb + "\r\n"; // // Only handle the first network card // mySpec.Customization.NicSettingMap = new CustomizationAdapterMapping[1]; mySpec.Customization.NicSettingMap[0] = new CustomizationAdapterMapping(); // // Read in the DNS from web.config and assign // string[] ipDns = new string[1]; ipDns[0] = txtDnsServer.Text; mySpec.Customization.GlobalIPSettings = new CustomizationGlobalIPSettings(); mySpec.Customization.GlobalIPSettings.DnsServerList = ipDns; txtResults.Text += "DNS : " + ipDns[0] + "\r\n"; // // Create a new networkDevice // VirtualDevice networkDevice = new VirtualDevice(); foreach (VirtualDevice vDevice in itmVirtualMachine.Config.Hardware.Device) { // // get nic on vm // if (vDevice.DeviceInfo.Label.Contains("Network")) { networkDevice = vDevice; } } // // Create a DeviceSpec // VirtualDeviceConfigSpec[] devSpec = new VirtualDeviceConfigSpec[0]; mySpec.Config.DeviceChange = new VirtualDeviceConfigSpec[1]; mySpec.Config.DeviceChange[0] = new VirtualDeviceConfigSpec(); mySpec.Config.DeviceChange[0].Operation = VirtualDeviceConfigSpecOperation.edit; mySpec.Config.DeviceChange[0].Device = networkDevice; // // Define network settings for the new vm // // // Assign IP Address // CustomizationFixedIp ipAddress = new CustomizationFixedIp(); ipAddress.IpAddress = txtIpAddress.Text; mySpec.Customization.NicSettingMap[0].Adapter = new CustomizationIPSettings(); txtResults.Text += "IP : " + txtIpAddress.Text + "\r\n"; // // Assign subnet mask // mySpec.Customization.NicSettingMap[0].Adapter.Ip = ipAddress; mySpec.Customization.NicSettingMap[0].Adapter.SubnetMask = txtSubnet.Text; txtResults.Text += "Subnet : " + txtSubnet.Text + "\r\n"; // // Assign default gateway // string[] ipGateway = new string[1]; ipGateway[0] = txtGateway.Text; mySpec.Customization.NicSettingMap[0].Adapter.Gateway = ipGateway; txtResults.Text += "Gateway : " + txtGateway.Text + "\r\n"; // // Create network backing information // VirtualEthernetCardDistributedVirtualPortBackingInfo nicBack = new VirtualEthernetCardDistributedVirtualPortBackingInfo(); nicBack.Port = new DistributedVirtualSwitchPortConnection(); // // Connect to the virtual switch // VmwareDistributedVirtualSwitch dvSwitch = GetDvSwitch(vimClient, itmDvPortGroup.Config.DistributedVirtualSwitch); // // Assign the proper switch port // nicBack.Port.SwitchUuid = dvSwitch.Uuid; // // Connect the network card to proper port group // nicBack.Port.PortgroupKey = itmDvPortGroup.MoRef.Value; mySpec.Config.DeviceChange[0].Device.Backing = nicBack; // // Enable the network card at bootup // mySpec.Config.DeviceChange[0].Device.Connectable = new VirtualDeviceConnectInfo(); mySpec.Config.DeviceChange[0].Device.Connectable.StartConnected = true; mySpec.Config.DeviceChange[0].Device.Connectable.AllowGuestControl = true; mySpec.Config.DeviceChange[0].Device.Connectable.Connected = true; // // Get the vmfolder from the datacenter // // // Perform the clone // ManagedObjectReference taskMoRef = itmVirtualMachine.CloneVM_Task(itmDatacenter.VmFolder, txtTargetVm.Text, mySpec); Task cloneVmTask = new Task(vimClient, taskMoRef); // // The following will make the browser appear to hang, I need to hide this panel, and show a working panel // ManagedObjectReference clonedMorRef = (ManagedObjectReference)vimClient.WaitForTask(cloneVmTask.MoRef); // // Connect to the VM in order to set the custom fields // List<VirtualMachine> clonedVMs = GetVirtualMachines(vimClient, null, txtTargetVm.Text); VirtualMachine clonedVM = clonedVMs[0]; NameValueCollection vmFilter = new NameValueCollection(); vmFilter.Add("name",txtTargetVm.Text); EntityViewBase vmViewBase = vimClient.FindEntityView(typeof(VirtualMachine),null,vmFilter,null); ManagedEntity vmEntity = new ManagedEntity(vimClient, clonedVM.MoRef); CustomFieldsManager fieldManager = new CustomFieldsManager(vimClient, clonedVM.MoRef); // // One or more custom field names could be stored in the web.config and processed in some fashion // foreach (CustomFieldDef thisField in clonedVM.AvailableField) { if (thisField.Name.Equals("CreatedBy")) { fieldManager.SetField(clonedVM.MoRef, 1, txtUsername.Text); } } vimClient.Disconnect(); // // Hide the vm controls and show the result box // Vm_Panel.Visible = false; Results_Panel.Visible = true; }
public override object GetGroup(IXenObject o) { return(CustomFieldsManager.GetCustomFieldValue(o, definition)); }
public override object GetGroup(IXenObject o) { return(CustomFieldsManager.CustomFieldArrays(o)); }
static PropertyAccessors() { foreach (vm_power_state p in Enum.GetValues(typeof(vm_power_state))) { VM_power_state_i18n[FriendlyNameManager.GetFriendlyName(string.Format("Label-VM.power_state-{0}", p.ToString()))] = p; } foreach (SR.SRTypes type in Enum.GetValues(typeof(SR.SRTypes))) { SRType_i18n[SR.getFriendlyTypeName(type)] = type; } VirtualisationStatus_i18n[Messages.VIRTUALIZATION_STATE_VM_NOT_OPTIMIZED] = VM.VirtualisationStatus.NOT_INSTALLED; VirtualisationStatus_i18n[Messages.OUT_OF_DATE] = VM.VirtualisationStatus.PV_DRIVERS_OUT_OF_DATE; VirtualisationStatus_i18n[Messages.UNKNOWN] = VM.VirtualisationStatus.UNKNOWN; VirtualisationStatus_i18n[Messages.VIRTUALIZATION_STATE_VM_IO_OPTIMIZED_ONLY] = VM.VirtualisationStatus.IO_DRIVERS_INSTALLED; VirtualisationStatus_i18n[Messages.VIRTUALIZATION_STATE_VM_MANAGEMENT_AGENT_INSTALLED_ONLY] = VM.VirtualisationStatus.MANAGEMENT_INSTALLED; VirtualisationStatus_i18n[Messages.VIRTUALIZATION_STATE_VM_OPTIMIZED] = VM.VirtualisationStatus.IO_DRIVERS_INSTALLED | VM.VirtualisationStatus.MANAGEMENT_INSTALLED; ObjectTypes_i18n[Messages.VMS] = ObjectTypes.VM; ObjectTypes_i18n[Messages.XENSERVER_TEMPLATES] = ObjectTypes.DefaultTemplate; ObjectTypes_i18n[Messages.CUSTOM_TEMPLATES] = ObjectTypes.UserTemplate; ObjectTypes_i18n[Messages.POOLS] = ObjectTypes.Pool; ObjectTypes_i18n[Messages.SERVERS] = ObjectTypes.Server; ObjectTypes_i18n[Messages.DISCONNECTED_SERVERS] = ObjectTypes.DisconnectedServer; ObjectTypes_i18n[Messages.LOCAL_SRS] = ObjectTypes.LocalSR; ObjectTypes_i18n[Messages.REMOTE_SRS] = ObjectTypes.RemoteSR; ObjectTypes_i18n[Messages.NETWORKS] = ObjectTypes.Network; ObjectTypes_i18n[Messages.SNAPSHOTS] = ObjectTypes.Snapshot; ObjectTypes_i18n[Messages.VIRTUAL_DISKS] = ObjectTypes.VDI; ObjectTypes_i18n[Messages.FOLDERS] = ObjectTypes.Folder; ObjectTypes_i18n[Messages.VM_APPLIANCE] = ObjectTypes.Appliance; foreach (VM.HA_Restart_Priority p in VM.GetAvailableRestartPriorities(null)) //CA-57600 - From Boston onwards, the HA restart priorities list contains Restart instead of AlwaysRestartHighPriority and AlwaysRestart { HARestartPriority_i18n[Helpers.RestartPriorityI18n(p)] = p; } // This one is used for grouping and filtering i18n PropertyNames_i18n[PropertyNames.description] = Messages.DESCRIPTION; PropertyNames_i18n[PropertyNames.host] = Messages.SERVER; PropertyNames_i18n[PropertyNames.label] = Messages.NAME; PropertyNames_i18n[PropertyNames.uuid] = Messages.UUID; PropertyNames_i18n[PropertyNames.networks] = Messages.NETWORK; PropertyNames_i18n[PropertyNames.os_name] = Messages.OPERATING_SYSTEM; PropertyNames_i18n[PropertyNames.pool] = Messages.POOL; PropertyNames_i18n[PropertyNames.power_state] = Messages.POWER_STATE; PropertyNames_i18n[PropertyNames.start_time] = Messages.START_TIME; PropertyNames_i18n[PropertyNames.storage] = Messages.SR; PropertyNames_i18n[PropertyNames.disks] = Messages.VIRTUAL_DISK; PropertyNames_i18n[PropertyNames.type] = Messages.TYPE; PropertyNames_i18n[PropertyNames.virtualisation_status] = Messages.TOOLS_STATUS; PropertyNames_i18n[PropertyNames.ha_restart_priority] = Messages.HA_RESTART_PRIORITY; PropertyNames_i18n[PropertyNames.appliance] = Messages.VM_APPLIANCE; PropertyNames_i18n[PropertyNames.tags] = Messages.TAGS; PropertyNames_i18n[PropertyNames.shared] = Messages.SHARED; PropertyNames_i18n[PropertyNames.ha_enabled] = Messages.HA; PropertyNames_i18n[PropertyNames.isNotFullyUpgraded] = Messages.POOL_VERSIONS_LINK_TEXT_SHORT; PropertyNames_i18n[PropertyNames.ip_address] = Messages.ADDRESS; PropertyNames_i18n[PropertyNames.vm] = Messages.VM; PropertyNames_i18n[PropertyNames.dockervm] = "Docker VM"; PropertyNames_i18n[PropertyNames.read_caching_enabled] = Messages.VM_READ_CACHING_ENABLED_SEARCH; PropertyNames_i18n_false[PropertyNames.read_caching_enabled] = Messages.VM_READ_CACHING_DISABLED_SEARCH; PropertyNames_i18n[PropertyNames.memory] = Messages.MEMORY; PropertyNames_i18n[PropertyNames.sr_type] = Messages.STORAGE_TYPE; PropertyNames_i18n[PropertyNames.folder] = Messages.PARENT_FOLDER; PropertyNames_i18n[PropertyNames.folders] = Messages.ANCESTOR_FOLDERS; PropertyNames_i18n[PropertyNames.has_custom_fields] = Messages.HAS_CUSTOM_FIELDS; PropertyNames_i18n[PropertyNames.in_any_appliance] = Messages.IN_ANY_APPLIANCE; PropertyNames_i18n[PropertyNames.vendor_device_state] = Messages.WINDOWS_UPDATE_CAPABLE; PropertyNames_i18n_false[PropertyNames.vendor_device_state] = Messages.WINDOWS_UPDATE_CAPABLE_NOT; VM_power_state_images[vm_power_state.Halted] = Icons.PowerStateHalted; VM_power_state_images[vm_power_state.Paused] = Icons.PowerStateSuspended; VM_power_state_images[vm_power_state.Running] = Icons.PowerStateRunning; VM_power_state_images[vm_power_state.Suspended] = Icons.PowerStateSuspended; VM_power_state_images[vm_power_state.unknown] = Icons.PowerStateUnknown; ObjectTypes_images[ObjectTypes.DefaultTemplate] = Icons.Template; ObjectTypes_images[ObjectTypes.UserTemplate] = Icons.TemplateUser; ObjectTypes_images[ObjectTypes.Pool] = Icons.Pool; ObjectTypes_images[ObjectTypes.Server] = Icons.Host; ObjectTypes_images[ObjectTypes.DisconnectedServer] = Icons.HostDisconnected; ObjectTypes_images[ObjectTypes.LocalSR] = Icons.Storage; ObjectTypes_images[ObjectTypes.RemoteSR] = Icons.Storage; ObjectTypes_images[ObjectTypes.LocalSR | ObjectTypes.RemoteSR] = Icons.Storage; ObjectTypes_images[ObjectTypes.VM] = Icons.VM; ObjectTypes_images[ObjectTypes.Network] = Icons.Network; ObjectTypes_images[ObjectTypes.Snapshot] = Icons.Snapshot; ObjectTypes_images[ObjectTypes.VDI] = Icons.VDI; ObjectTypes_images[ObjectTypes.Folder] = Icons.Folder; ObjectTypes_images[ObjectTypes.Appliance] = Icons.VmAppliance; property_types.Add(PropertyNames.pool, typeof(Pool)); property_types.Add(PropertyNames.host, typeof(Host)); property_types.Add(PropertyNames.os_name, typeof(string)); property_types.Add(PropertyNames.power_state, typeof(vm_power_state)); property_types.Add(PropertyNames.virtualisation_status, typeof(VM.VirtualisationStatus)); property_types.Add(PropertyNames.type, typeof(ObjectTypes)); property_types.Add(PropertyNames.networks, typeof(XenAPI.Network)); property_types.Add(PropertyNames.storage, typeof(SR)); property_types.Add(PropertyNames.ha_restart_priority, typeof(VM.HA_Restart_Priority)); property_types.Add(PropertyNames.read_caching_enabled, typeof(bool)); property_types.Add(PropertyNames.appliance, typeof(VM_appliance)); property_types.Add(PropertyNames.tags, typeof(string)); property_types.Add(PropertyNames.has_custom_fields, typeof(bool)); property_types.Add(PropertyNames.ip_address, typeof(ComparableAddress)); property_types.Add(PropertyNames.vm, typeof(VM)); property_types.Add(PropertyNames.sr_type, typeof(SR.SRTypes)); property_types.Add(PropertyNames.folder, typeof(Folder)); property_types.Add(PropertyNames.folders, typeof(Folder)); property_types.Add(PropertyNames.in_any_appliance, typeof(bool)); property_types.Add(PropertyNames.disks, typeof(VDI)); properties[PropertyNames.os_name] = o => o is VM vm && vm.is_a_real_vm() ? vm.GetOSName() : null; properties[PropertyNames.power_state] = o => o is VM vm && vm.is_a_real_vm() ? (IComparable)vm.power_state : null; properties[PropertyNames.vendor_device_state] = o => o is VM vm && vm.is_a_real_vm() ? (bool?)vm.WindowsUpdateCapable() : null; properties[PropertyNames.virtualisation_status] = o => o is VM vm && vm.is_a_real_vm() ? (IComparable)vm.GetVirtualisationStatus(out _) : null; properties[PropertyNames.start_time] = o => o is VM vm && vm.is_a_real_vm() ? (DateTime?)vm.GetStartTime() : null; properties[PropertyNames.read_caching_enabled] = o => o is VM vm && vm.is_a_real_vm() ? (bool?)vm.ReadCachingEnabled() : null; properties[PropertyNames.label] = Helpers.GetName; properties[PropertyNames.pool] = o => o == null ? null : Helpers.GetPool(o.Connection); properties[PropertyNames.host] = HostProperty; properties[PropertyNames.vm] = VMProperty; properties[PropertyNames.dockervm] = o => o is DockerContainer dc ? new ComparableList <VM> { dc.Parent } : new ComparableList <VM>(); properties[PropertyNames.networks] = NetworksProperty; properties[PropertyNames.storage] = StorageProperty; properties[PropertyNames.disks] = DisksProperty; properties[PropertyNames.has_custom_fields] = delegate(IXenObject o) { // this needs to be tidied up so that CustomFields calls don't require the event thread. bool ret = false; InvokeHelper.Invoke(delegate { ret = CustomFieldsManager.HasCustomFields(o); }); return(ret); }; properties[PropertyNames.memory] = o => { if (o is VM vm && vm.is_a_real_vm() && vm.Connection != null) { var metrics = vm.Connection.Resolve(vm.metrics); if (metrics != null) { return(metrics.memory_actual); } } return(null); }; properties[PropertyNames.ha_restart_priority] = delegate(IXenObject o) { if (o is VM vm && vm.is_a_real_vm()) { Pool pool = Helpers.GetPool(vm.Connection); if (pool != null && pool.ha_enabled) { return(vm.HaPriorityIsRestart() ? VM.HA_Restart_Priority.Restart : vm.HARestartPriority()); } // CA-57600 - From Boston onwards, the HA_restart_priority enum contains Restart instead of // AlwaysRestartHighPriority and AlwaysRestart. When searching in a pre-Boston pool for VMs // with HA_restart_priority.Restart, the search will return VMs with HA_restart_priority // AlwaysRestartHighPriority or AlwaysRestart } return(null); }; properties[PropertyNames.appliance] = delegate(IXenObject o) { if (o is VM_appliance app) { return(app); } if (o is VM vm && vm.is_a_real_vm() && vm.Connection != null) { return(vm.Connection.Resolve(vm.appliance)); } return(null); }; properties[PropertyNames.in_any_appliance] = delegate(IXenObject o) { if (o is VM_appliance) { return(true); } if (o is VM vm && vm.is_a_real_vm() && vm.Connection != null) { return(vm.Connection.Resolve(vm.appliance) != null); } return(null); }; properties[PropertyNames.connection_hostname] = ConnectionHostnameProperty; properties[PropertyNames.cpuText] = CPUTextProperty; properties[PropertyNames.cpuValue] = CPUValueProperty; properties[PropertyNames.description] = DescriptionProperty; properties[PropertyNames.diskText] = DiskTextProperty; properties[PropertyNames.folder] = Folders.GetFolder; properties[PropertyNames.folders] = Folders.GetAncestorFolders; properties[PropertyNames.haText] = HATextProperty; properties[PropertyNames.ha_enabled] = o => o is Pool pool ? (IComparable)pool.ha_enabled : null; properties[PropertyNames.isNotFullyUpgraded] = o => o is Pool pool ? (IComparable) !pool.IsPoolFullyUpgraded() : null; properties[PropertyNames.ip_address] = IPAddressProperty; properties[PropertyNames.license] = LicenseProperty; properties[PropertyNames.memoryText] = MemoryTextProperty; properties[PropertyNames.memoryValue] = MemoryValueProperty; properties[PropertyNames.memoryRank] = MemoryRankProperty; properties[PropertyNames.networkText] = NetworkTextProperty; properties[PropertyNames.shared] = SharedProperty; properties[PropertyNames.size] = o => o is VDI vdi ? (IComparable)vdi.virtual_size : null; properties[PropertyNames.sr_type] = o => o is SR sr ? (IComparable)sr.GetSRType(false) : null; properties[PropertyNames.tags] = Tags.GetTagList; properties[PropertyNames.type] = TypeProperty; properties[PropertyNames.uptime] = UptimeProperty; properties[PropertyNames.uuid] = UUIDProperty; column_sort_by[ColumnNames.name] = PropertyNames.label; column_sort_by[ColumnNames.cpu] = PropertyNames.cpuValue; column_sort_by[ColumnNames.memory] = PropertyNames.memoryValue; column_sort_by[ColumnNames.disks] = PropertyNames.diskText; column_sort_by[ColumnNames.network] = PropertyNames.networkText; column_sort_by[ColumnNames.ha] = PropertyNames.haText; column_sort_by[ColumnNames.ip] = PropertyNames.ip_address; column_sort_by[ColumnNames.uptime] = PropertyNames.uptime; }
private void ShowColumns(List <KeyValuePair <String, int> > columns) { List <String> columnKeys = new List <String>(Columns.Keys); if (columns == null) { // Show all columns foreach (String column in columnKeys) { ShowColumn(column); } foreach (CustomFieldDefinition definition in CustomFieldsManager.GetCustomFields()) { ShowColumn(CustomFieldsManager.CUSTOM_FIELD + definition.Name); } return; } // Hide all columns which are currently visible but not in columns // (do not hide default columns) foreach (String column in columnKeys) { if (!IsMovableColumn(column)) { continue; } if (columns.Exists(delegate(KeyValuePair <String, int> kvp) { return(kvp.Key == column); })) { continue; } HideColumn(column); } ShowColumn("ha"); // force decision to show ha // Show appropriate columns int i = 0; foreach (GridHeaderItem item in HeaderRow.Items.Values) { if (!item.Immovable) { break; } i++; } foreach (KeyValuePair <String, int> column in columns) { if (!IsMovableColumn(column.Key)) { continue; } String key = (column.Key.StartsWith(CustomFieldsManager.CUSTOM_FIELD) || IsDefaultColumn(column.Key)) ? column.Key : CustomFieldsManager.CUSTOM_FIELD + column.Key; ShowColumn(key); if (!HeaderRow.Items.ContainsKey(key)) { continue; } GridHeaderItem item = HeaderRow.Items[key] as GridHeaderItem; if (item == null) { continue; } // Make the column the correct width; item.Width = column.Value; // Move the column to the correct place; GridHeaderRow.Columns.Remove(column.Key); GridHeaderRow.Columns.Insert(i, column.Key); i++; } }
private void Rebuild(bool revertValues) { CustomFieldDefinition[] customFieldDefinitions = CustomFieldsManager.GetCustomFields(xenObject.Connection).ToArray(); tableLayoutPanel.SuspendLayout(); // Add new custom fields foreach (CustomFieldDefinition customFieldDefinition in customFieldDefinitions) { Object value = CustomFieldsManager.GetCustomFieldValue(xenObject, customFieldDefinition); if (!controls.ContainsKey(customFieldDefinition)) { // Create the display label Label lblKey = new Label(); lblKey.Text = customFieldDefinition.Name.EscapeAmpersands(); lblKey.Margin = new Padding(3, 7, 3, 3); lblKey.Font = Program.DefaultFont; lblKey.Width = (int)tableLayoutPanel.ColumnStyles[0].Width; lblKey.AutoEllipsis = true; lblKey.AutoSize = false; tableLayoutPanel.Controls.Add(lblKey); // Create value field Control control; switch (customFieldDefinition.Type) { case CustomFieldDefinition.Types.String: TextBox textBox = new TextBox(); textBox.Text = (String)value; tableLayoutPanel.Controls.Add(textBox); tableLayoutPanel.SetColumnSpan(textBox, 2); textBox.Dock = DockStyle.Fill; control = textBox; break; case CustomFieldDefinition.Types.Date: DateTimePicker date = new DateTimePicker(); date.MinDate = DateTime.MinValue; date.MaxDate = DateTime.MaxValue; date.Dock = DockStyle.Fill; date.MinimumSize = new Size(0, 24); date.ShowCheckBox = true; date.Format = DateTimePickerFormat.Long; if (value != null) { date.Value = (DateTime)value; date.Checked = true; } else { date.Checked = false; } tableLayoutPanel.Controls.Add(date); DateTimePicker time = new DateTimePicker(); time.MinDate = DateTime.MinValue; time.MaxDate = DateTime.MaxValue; time.Dock = DockStyle.Fill; time.MinimumSize = new Size(0, 24); time.Format = DateTimePickerFormat.Time; time.ShowUpDown = true; if (value != null) { time.Value = (DateTime)value; time.Enabled = true; } else { time.Enabled = false; } tableLayoutPanel.Controls.Add(time); // Tag so we can remove this control later date.Tag = time; date.ValueChanged += delegate(Object sender, EventArgs e) { time.Enabled = date.Checked; }; control = date; break; default: throw new InvalidEnumArgumentException(); } controls[customFieldDefinition] = new KeyValuePair <Label, Control>(lblKey, control); } else if (revertValues) { KeyValuePair <Label, Control> kvp = controls[customFieldDefinition]; SetValue(customFieldDefinition, kvp.Value, value); } } // Remove old ones CustomFieldDefinition[] definitions = new CustomFieldDefinition[controls.Keys.Count]; controls.Keys.CopyTo(definitions, 0); foreach (CustomFieldDefinition definition in definitions) { if (Array.IndexOf <CustomFieldDefinition>(customFieldDefinitions, definition) > -1) { continue; } KeyValuePair <Label, Control> kvp = controls[definition]; tableLayoutPanel.Controls.Remove(kvp.Value); tableLayoutPanel.Controls.Remove(kvp.Key); DateTimePicker timeControl = kvp.Value.Tag as DateTimePicker; if (timeControl != null) { tableLayoutPanel.Controls.Remove(timeControl); } controls.Remove(definition); kvp.Key.Dispose(); kvp.Value.Dispose(); } tableLayoutPanel.ResumeLayout(); }