/// <summary> /// Called when the Host collection of the current VM's Connection changes. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Host_CollectionChanged(object sender, CollectionChangeEventArgs e) { // NB this code is unused at the moment, since the HA is not yet capable of adding/removing hosts once switched on // This may change in the future // ... in which case test this code ;) Host host = (Host)e.Element; if (e.Action == CollectionChangeAction.Add) { // Listen for changes on the host's metrics field host.PropertyChanged += host_PropertyChanged; // Remember the host so we can deregister the listener later hosts.Add(host); // Register on the new host's metrics object - we need to know if the host goes down Host_metrics metrics = vm.Connection.Resolve(host.metrics); if (metrics != null) { metrics.PropertyChanged += metrics_PropertyChanged; // Remember the metrics object so we can deregister the listener later hostMetrics.Add(metrics); } } else if (e.Action == CollectionChangeAction.Remove) { host.PropertyChanged -= host_PropertyChanged; hosts.Remove(host); // Also try deregistering from the host's metrics. Probably not terrible if we cannot. Host_metrics metrics = vm.Connection.Resolve(host.metrics); if (metrics != null) { metrics.PropertyChanged -= metrics_PropertyChanged; hostMetrics.Remove(metrics); } } }
public void SetXenObjects(IXenObject orig, IXenObject clone) { _XenObject = clone; bool isVm = _XenObject is VM; bool isHost = _XenObject is Host; bool isSr = _XenObject is SR; cpuAlert.Show(isVm || isHost); netAlert.Show(isVm || isHost); diskAlert.Show(isVm); memoryAlert.Show(isHost && Helpers.ClearwaterOrGreater(_XenObject.Connection)); srAlert.Show(isSr && Helpers.ClearwaterOrGreater(_XenObject.Connection)); if (isHost) { Host host = (Host)_XenObject; Host_metrics metrics = host.Connection.Resolve(host.metrics); if (metrics != null) { nudMemoryUsage.Maximum = metrics.memory_total / (1024 * 1024); } } Repopulate(); }
public void SetXenObjects(IXenObject orig, IXenObject clone) { _XenObject = clone; bool isVm = _XenObject is VM; bool isHost = _XenObject is Host; bool isSr = _XenObject is SR; cpuAlert.Show(isVm || isHost); netAlert.Show(isVm || isHost); diskAlert.Show(isVm); memoryAlert.Show(isHost); srAlert.Show(isSr); dom0MemoryAlert.Show(isHost && Helpers.CreedenceOrGreater(_XenObject.Connection)); physicalUtilisationAlert.Show(isSr && ((SR)_XenObject).IsThinProvisioned); if (isHost) { Host host = (Host)_XenObject; Host_metrics metrics = host.Connection.Resolve(host.metrics); if (metrics != null) { nudMemoryUsage.Maximum = metrics.memory_total / (1024 * 1024); } } Repopulate(); }
public void SetXenObjects(IXenObject orig, IXenObject clone) { _XenObject = clone; bool isVm = _XenObject is VM; bool isHost = _XenObject is Host; bool isSr = _XenObject is SR; cpuAlert.Show(isVm || isHost); netAlert.Show(isVm || isHost); diskAlert.Show(isVm); memoryAlert.Show(isHost); srAlert.Show(isSr); dom0MemoryAlert.Show(isHost && Helpers.CreedenceOrGreater(_XenObject.Connection)); // Always hidden since thin provisioning was removed, because that was the only case // in which the calculation worked, but retaining it in case we use it again physicalUtilisationAlert.Show(false); if (isHost) { Host host = (Host)_XenObject; Host_metrics metrics = host.Connection.Resolve(host.metrics); if (metrics != null) { nudMemoryUsage.Maximum = metrics.memory_total / (1024 * 1024); } } Repopulate(); }
private TreeNode AddHostNode(TreeNode parent, int index, IXenConnection connection, Host host, out bool expand, out bool live) { Host_metrics host_metrics = host.Connection.Resolve <Host_metrics>(host.metrics); live = (host_metrics != null) && host_metrics.live; return(this.AddNode(parent, index, host.name_label, Images.GetIconFor(host), false, host, out expand)); }
private void populateHosts() { Program.AssertOnEventThread(); ToStringWrapper <Host> previousSelection = NewMasterComboBox.SelectedItem as ToStringWrapper <Host>; NewMasterComboBox.BeginUpdate(); try { NewMasterComboBox.Items.Clear(); foreach (Host host in connection.Cache.Hosts) { Host_metrics metrics = connection.Resolve <Host_metrics>(host.metrics); if (host.opaque_ref == this.host.opaque_ref) { continue; } host.PropertyChanged -= new PropertyChangedEventHandler(host_PropertyChanged); host.PropertyChanged += new PropertyChangedEventHandler(host_PropertyChanged); if (host.enabled && metrics != null && metrics.live) { NewMasterComboBox.Items.Add(new ToStringWrapper <Host>(host, host.Name())); } } SelectProperItemInNewMasterComboBox(previousSelection); } finally { NewMasterComboBox.EndUpdate(); } }
private void UpdateMaintenanceWarning() { Host_metrics metrics = host.Connection.Resolve(host.metrics); bool maintenanceMode = host.MaintenanceMode() || (metrics != null && !metrics.live); tplMaintenanceWarning.Visible = !maintenanceMode; tplRebootWarning.Visible = maintenanceMode; memorySpinner.Enabled = maintenanceMode; }
public void Initialize(Host host, long xen_memory) { this.host = host; this.host_metrics = host.Connection.Resolve(host.metrics); this.xen_memory = xen_memory; vms = host.Connection.ResolveAll(host.resident_VMs); vm_metrics = new Dictionary<VM, VM_metrics>(); foreach (VM vm in vms) vm_metrics[vm] = vm.Connection.Resolve(vm.metrics); }
private void UpdateMaintenanceWarning() { Host_metrics metrics = host.Connection.Resolve(host.metrics); bool maintenanceMode = host.MaintenanceMode || (metrics != null && !metrics.live); maintenanceWarningImage.Visible = maintenanceWarningLabel.Visible = maintenanceModeLinkLabel.Visible = !maintenanceMode; hostRebootWarningImage.Visible = hostRebootWarningLabel.Visible = maintenanceMode; memorySpinner.Enabled = maintenanceMode; }
private void DeregisterHostEvents(Host host) { Host_metrics metrics = host.Connection.Resolve(host.metrics); if (metrics != null) { metrics.PropertyChanged -= hostMetrics_PropertyChanged; } host.PropertyChanged -= host_PropertyChanged; }
public void Initialize(Host host, long xen_memory) { this.host = host; this.host_metrics = host.Connection.Resolve(host.metrics); this.xen_memory = xen_memory; vms = host.Connection.ResolveAll(host.resident_VMs); vm_metrics = new Dictionary <VM, VM_metrics>(); foreach (VM vm in vms) { vm_metrics[vm] = vm.Connection.Resolve(vm.metrics); } }
/// <summary> /// Must be a VM. /// </summary> public void SetXenObjects(IXenObject orig, IXenObject clone) { // This should only ever be set once System.Diagnostics.Trace.Assert(vm == null); vm = (VM)clone; origRestartPriority = vm.HARestartPriority(); SelectedPriority = origRestartPriority; origOrder = vm.order; origStartDelay = vm.start_delay; Repopulate(); haNtolIndicator.Connection = vm.Connection; haNtolIndicator.Settings = Helpers.GetVmHaRestartPriorities(vm.Connection, Properties.Settings.Default.ShowHiddenVMs); haNtolIndicator.UpdateInProgressChanged += new EventHandler(haNtolIndicator_UpdateInProgressChanged); // Put property changed listener on pool, disable edits if HA becomes disabled pool = Helpers.GetPoolOfOne(vm.Connection); if (pool != null) { pool.PropertyChanged += pool_PropertyChanged; } origNtol = pool.ha_host_failures_to_tolerate; // Put property changed listener on all hosts to listen for changes in their Host_metrics foreach (Host host in vm.Connection.Cache.Hosts) { host.PropertyChanged += host_PropertyChanged; // Remember the host so we can deregister the listener later hosts.Add(host); // Also register on the current metrics object - we need to know if a host goes down Host_metrics metrics = vm.Connection.Resolve(host.metrics); if (metrics != null) { metrics.PropertyChanged += metrics_PropertyChanged; // Remember the metrics object so we can deregister the listener later hostMetrics.Add(metrics); } } // Listen for new hosts so that we can add metrics listeners vm.Connection.Cache.RegisterCollectionChanged <Host>(Host_CollectionChangedWithInvoke); // Start thread to determine if VM is agile ToggleScanningVmAgile(true); Thread t = new Thread(UpdateVMAgility); t.Name = "Updater for VM agility for " + Helpers.GetName(vm); t.IsBackground = true; t.Priority = ThreadPriority.Highest; t.Start(); }
public ControlDomainMemoryDialog(Host host) : base(host.Connection) { if (host == null) throw new ArgumentNullException("host"); InitializeComponent(); this.host = host; this.host.PropertyChanged += Server_PropertyChanged; hostMetrics = connection.Resolve(this.host.metrics); if (hostMetrics != null) hostMetrics.PropertyChanged += Server_PropertyChanged; Text = string.Format(Messages.CONTROL_DOMAIN_MEMORY_DIALOG_TITLE, this.host.Name); Populate(); }
private double GetMemoryMax(IXenObject xo) { if (xo is Host) { Host host = (Host)xo; Host_metrics metrics = host.Connection.Resolve(host.metrics); return(metrics != null ? metrics.memory_total : 100); } else if (xo is VM) { VM vm = (VM)xo; VM_metrics metrics = vm.Connection.Resolve(vm.metrics); return(metrics != null ? metrics.memory_actual : vm.memory_dynamic_max); } return(100); }
/// <summary> /// Called when any Host of the current VM's connection has a property changed event. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void host_PropertyChanged(object sender, PropertyChangedEventArgs e) { Host host = (Host)sender; if (e.PropertyName == "metrics") { // Just register on the new metrics object - assume the old one is deleted and will fire no more events Host_metrics metrics = vm.Connection.Resolve(host.metrics); if (metrics != null) { metrics.PropertyChanged += metrics_PropertyChanged; // Remember the metrics object so we can deregister the listener later hostMetrics.Add(metrics); } } }
private double GetMemoryResolution(IXenObject xmo) { if (xmo is Host) { Host host = (Host)xmo; Host_metrics metrics = host.Connection.Resolve(host.metrics); return(metrics != null ? metrics.memory_total / 10 : 10); } else if (xmo is VM) { VM vm = (VM)xmo; VM_metrics metrics = vm.Connection.Resolve(vm.metrics); return((metrics != null ? metrics.memory_actual : (long)vm.memory_dynamic_max) / 10d); } return(10); }
public static List <Host> CheckHostIQNsExist() { List <Host> badHosts = new List <Host>(); foreach (IXenConnection connection in ConnectionsManager.XenConnectionsCopy) { foreach (Host host in connection.Cache.Hosts) { Host_metrics metrics = connection.Resolve <Host_metrics>(host.metrics); if (metrics != null && metrics.live && host.iscsi_iqn == "") { badHosts.Add(host); } } } return(badHosts); }
protected double maxDynMin = -1; // signal value for no constraint protected void CalcMaxDynMin() { maxDynMin = -1; if (vm0.power_state == vm_power_state.Running || vm0.power_state == vm_power_state.Paused) { // Calculate the maximum possible value of dynamic_min, by looking at all the other VMs on this host // and obeying the constraint sum(dynamic_min) + control domain + virtualisation overhead <= total host memory Host host = vm0.Connection.Resolve(vm0.resident_on); if (host != null) { Host_metrics host_metrics = host.Connection.Resolve(host.metrics); if (host_metrics != null) { double sum_dyn_min = host.memory_overhead; foreach (VM vm in host.Connection.ResolveAll(host.resident_VMs)) { sum_dyn_min += vm.memory_overhead; if (vm.is_control_domain) { VM_metrics vmm = vm.Connection.Resolve(vm.metrics); if (vmm != null) { sum_dyn_min += vmm.memory_actual; } } else if (!vms.Contains(vm)) { sum_dyn_min += vm.memory_dynamic_min; } } maxDynMin = host_metrics.memory_total - sum_dyn_min; if (maxDynMin < 0) { maxDynMin = 0; } maxDynMin /= vms.Count; } } } }
public static Icons GetIconFor(Host host) { Host_metrics metrics = host.Connection.Resolve <Host_metrics>(host.metrics); bool host_is_live = metrics != null && metrics.live; if (host_is_live) { if (host.HasCrashDumps) { return(Icons.HostHasCrashDumps); } if (host.current_operations.ContainsValue(host_allowed_operations.evacuate) || !host.enabled) { return(Icons.HostEvacuate); } else if (!XenAPI.Host.IsFullyPatched(host, ConnectionsManager.XenConnectionsCopy)) { return(Icons.HostUnpatched); } else if (Helpers.IsOlderThanMaster(host)) { return(Icons.HostOlderThanMaster); } else { return(Icons.HostConnected); } } else { // XenAdmin.XenSearch.Group puts a fake host in the treeview for disconnected // XenConnections. So here we give the yellow 'connection in progress' icon which formerly // applied only to XenConnections. if (host.Connection.InProgress && !host.Connection.IsConnected) { return(Icons.HostConnecting); } else { return(Icons.HostDisconnected); } } }
public ControlDomainMemoryDialog(Host host) : base(host.Connection) { if (host == null) { throw new ArgumentNullException("host"); } InitializeComponent(); this.host = host; this.host.PropertyChanged += Server_PropertyChanged; hostMetrics = connection.Resolve(this.host.metrics); if (hostMetrics != null) { hostMetrics.PropertyChanged += Server_PropertyChanged; } Text = string.Format(Messages.CONTROL_DOMAIN_MEMORY_DIALOG_TITLE, this.host.Name); Populate(); }
private static Host GetHostLiveness(Mock <IXenConnection> fake, bool hostEnabled, bool hostMaintenanceMode, bool hostLive) { var host = new Host(); var metrics = new XenRef <Host_metrics>("0"); host.metrics = metrics; //Metric live var metric = new Host_metrics { live = hostLive }; host.other_config = new Dictionary <string, string>(); //Maintenance mode host.other_config.Add("MAINTENANCE_MODE", hostMaintenanceMode.ToString().ToLower()); Assert.AreEqual(hostMaintenanceMode, host.MaintenanceMode()); fake.Setup(x => x.Resolve(It.IsAny <XenRef <Host_metrics> >())).Returns(metric); //Host enabled host.enabled = hostEnabled; host.Connection = fake.Object; return(host); }
private void ShowMemError(bool showAlways, bool testValue) { if (vm == null || !ShowMemory) { return; } Host selectedAffinity = vm.Connection.Resolve <Host>(vm.power_state == vm_power_state.Running ? vm.resident_on : vm.affinity); if (selectedAffinity != null) { Host_metrics host_metrics = vm.Connection.Resolve <Host_metrics>(selectedAffinity.metrics); if ((showAlways || (testValue && (host_metrics != null && (double)host_metrics.memory_total < (double)nudMemory.Value * (double)Util.BINARY_MEGA)))) { MemWarningLabel.Visible = true; } else { MemWarningLabel.Visible = false; } } }
private static Host GetHostLiveness(Mock<IXenConnection> fake,bool hostEnabled,bool hostMaintenanceMode,bool hostLive) { var host = new Host(); var metrics = new XenRef<Host_metrics>("0"); host.metrics = metrics; //Metric live var metric = new Host_metrics {live = hostLive}; host.other_config = new Dictionary<string, string>(); //Maintenance mode host.other_config.Add("MAINTENANCE_MODE", hostMaintenanceMode.ToString().ToLower()); Assert.AreEqual(hostMaintenanceMode,host.MaintenanceMode); fake.Setup(x => x.Resolve(It.IsAny<XenRef<Host_metrics>>())).Returns(metric); //Host enabled host.enabled = hostEnabled; host.Connection = fake.Object; return host; }
private void PopulateHosts() { Program.AssertOnEventThread(); if (!tableLayoutPanelNewMaster.Visible) { return; } try { NewMasterComboBox.BeginUpdate(); var hosts = connection.Cache.Hosts.Where(h => h.opaque_ref != _host.opaque_ref).ToList(); hosts.Sort(); foreach (Host host in hosts) { host.PropertyChanged -= host_PropertyChanged; host.PropertyChanged += host_PropertyChanged; Host_metrics metrics = connection.Resolve(host.metrics); if (host.enabled && metrics != null && metrics.live) { var item = new ToStringWrapper <Host>(host, host.Name()); NewMasterComboBox.Items.Add(item); if (hostSelection != null && host.opaque_ref == hostSelection.item.opaque_ref) { NewMasterComboBox.SelectedItem = item; } } } //Update NewMasterComboBox for host power on recommendation foreach (KeyValuePair <XenRef <VM>, string[]> kvp in reasons) { var vm = connection.Resolve(kvp.Key); if (vm != null && vm.is_control_domain) { Host powerOnHost = connection.Cache.Hosts.FirstOrDefault(h => h.uuid == kvp.Value[(int)RecProperties.ToHost]); if (powerOnHost != null) { var hostToAdd = new ToStringWrapper <Host>(powerOnHost, powerOnHost.Name()); if (NewMasterComboBox.Items.Cast <ToStringWrapper <Host> >().FirstOrDefault(i => i.item.opaque_ref == powerOnHost.opaque_ref) == null) { powerOnHost.PropertyChanged -= host_PropertyChanged; powerOnHost.PropertyChanged += host_PropertyChanged; NewMasterComboBox.Items.Add(hostToAdd); } } } } if (NewMasterComboBox.SelectedItem == null && NewMasterComboBox.Items.Count > 0) { NewMasterComboBox.SelectedIndex = 0; } } finally { EnableComboBox(); NewMasterComboBox.EndUpdate(); } }
private void Rebuild() { Program.AssertOnEventThread(); _rebuild_needed = false; if (!this.Visible) { return; } _rebuilding = true; pageContainerPanel.SuspendLayout(); // Store a list of the current controls. We remove them at the end because it makes less flicker that way. // While we're going through them, remember which VMs were on expanded rows. List <Control> oldControls = new List <Control>(pageContainerPanel.Controls.Count); List <VM> expandedVMs = new List <VM>(vms.Count); foreach (Control c in pageContainerPanel.Controls) { oldControls.Add(c); VMMemoryRow vmRow = c as VMMemoryRow; if (vmRow != null && vmRow.Expanded) { expandedVMs.AddRange(vmRow.VMs); } } // Group VMs with the same settings Dictionary <MemSettings, List <VM> > settingsToVMs = new Dictionary <MemSettings, List <VM> >(); // all VMs with a particular setting List <MemSettings> listSettings = new List <MemSettings>(); // also make a list of MemSettings to preserve the order vms.Sort(); foreach (VM vm in vms) { MemSettings settings = vm.has_ballooning() ? new MemSettings(true, vm.power_state, vm.memory_static_min, vm.memory_static_max, vm.memory_dynamic_min, vm.memory_dynamic_max) : new MemSettings(false, vm.power_state, 0, vm.memory_static_max, 0, 0); // don't consider other mem settings if ballooning off if (!settingsToVMs.ContainsKey(settings)) // we've not seen these settings on another VM { settingsToVMs.Add(settings, new List <VM>()); listSettings.Add(settings); } settingsToVMs[settings].Add(vm); } // Add server rows int initScroll = pageContainerPanel.VerticalScroll.Value; int top = pageContainerPanel.Padding.Top - initScroll; hosts.Sort(); foreach (Host host in hosts) { Host_metrics metrics = host.Connection.Resolve(host.metrics); if (metrics == null || !metrics.live) { continue; } AddRowToPanel(new HostMemoryRow(host), ref top); } // Add VM rows. // Sort the rows first by power state then by usual sort order of first VM (because of vms.Sort() above). // Easier to traverse listSettings five times, but more complicated sorts could be achieved by listSettings.Sort(). vm_power_state[] power_state_order = { vm_power_state.Running, vm_power_state.Paused, vm_power_state.Suspended, vm_power_state.Halted, vm_power_state.unknown }; foreach (vm_power_state ps in power_state_order) { foreach (MemSettings settings in listSettings) { if (settings.power_state == ps) { List <VM> rowVMs = settingsToVMs[settings]; bool expand = Helpers.ListsIntersect(expandedVMs, rowVMs); // expand header if any of its VMs were expanded before AddRowToPanel(new VMMemoryRow(rowVMs, expand), ref top); } } } // Remove old controls foreach (Control c in oldControls) { pageContainerPanel.Controls.Remove(c); int scroll = initScroll; if (scroll > pageContainerPanel.VerticalScroll.Maximum) { scroll = pageContainerPanel.VerticalScroll.Maximum; } pageContainerPanel.VerticalScroll.Value = scroll; // Without this, the scroll bar can jump around while the page is being rebuilt c.Dispose(); } _rebuilding = false; pageContainerPanel.ResumeLayout(); ReLayout(); SetupDeprecationBanner(); }
public static DataSet Create(string uuid, IXenObject xo, bool show, string settype) { var dataSet = new DataSet(uuid, xo, show, settype); if (settype.StartsWith("latency") || settype.EndsWith("latency")) { if (settype.StartsWith("latency")) { //if it's storage latency xapi units are in milliseconds dataSet.MultiplyingFactor = 1000000; } else if (settype.StartsWith("vbd")) { //if it's vbd latency xapi units are in microseconds dataSet.MultiplyingFactor = 1000; } else { //otherwise they are in seconds dataSet.MultiplyingFactor = 1000000000; } dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.NanoSeconds, RangeScaleMode.Auto); dataSet.Type = DataType.Latency; } else if (settype.StartsWith("vif") || settype.StartsWith("pif")) { //xapi units are in bytes/sec or errors/sec Unit unit = settype.EndsWith("errors") ? Unit.CountsPerSecond : Unit.BytesPerSecond; dataSet.CustomYRange = new DataRange(1, 0, 1, unit, RangeScaleMode.Auto); dataSet.Type = DataType.Network; } else if (settype.StartsWith("vbd")) { if (settype.Contains("iops")) { dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.CountsPerSecond, RangeScaleMode.Auto); } else if (settype.Contains("io_throughput")) { dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.BytesPerSecond, RangeScaleMode.Auto); dataSet.MultiplyingFactor = (int)Util.BINARY_MEGA; //xapi units are in mebibytes/sec } else if (settype.EndsWith("iowait")) { dataSet.CustomYRange = new DataRange(100, 0, 10, Unit.Percentage, RangeScaleMode.Auto); dataSet.MultiplyingFactor = 100; } else if (settype.EndsWith("inflight") || settype.EndsWith("avgqu_sz")) { dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.None, RangeScaleMode.Auto); } else { dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.BytesPerSecond, RangeScaleMode.Auto); } dataSet.Type = DataType.Disk; } else if ((settype.Contains("memory") || settype.Contains("allocation")) && !settype.Contains("utilisation")) { dataSet.Type = settype.Contains("gpu") ? DataType.Gpu : DataType.Memory; dataSet.MultiplyingFactor = settype.Contains("kib") || settype == "memory_internal_free" ? (int)Util.BINARY_KILO : 1; if (settype == "memory" || settype == "memory_total_kib") { dataSet.NeverShow = true; } else if (settype == "memory_free_kib" && xo is Host) { dataSet.Name = Helpers.GetFriendlyDataSourceName("memory_used_kib", dataSet.XenObject); Host host = (Host)xo; Host_metrics metrics = host.Connection.Resolve(host.metrics); long max = metrics != null ? metrics.memory_total : 100; dataSet.CustomYRange = new DataRange(max, 0, max / 10d, Unit.Bytes, RangeScaleMode.Delegate) { UpdateMax = dataSet.GetMemoryMax, UpdateResolution = dataSet.GetMemoryResolution }; } else if (settype == "memory_internal_free" && xo is VM) { dataSet.Name = Helpers.GetFriendlyDataSourceName("memory_internal_used", dataSet.XenObject); VM vm = (VM)xo; VM_metrics metrics = vm.Connection.Resolve(vm.metrics); long max = metrics != null ? metrics.memory_actual : (long)vm.memory_dynamic_max; dataSet.CustomYRange = new DataRange(max, 0, max / 10d, Unit.Bytes, RangeScaleMode.Delegate) { UpdateMax = dataSet.GetMemoryMax, UpdateResolution = dataSet.GetMemoryResolution }; } else { dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.Bytes, RangeScaleMode.Auto); } } else if (settype.StartsWith("loadavg")) { dataSet.CustomYRange = new DataRange(100, 0, 10, Unit.Percentage, RangeScaleMode.Auto); dataSet.MultiplyingFactor = 100; dataSet.Type = DataType.LoadAverage; } else if (settype.StartsWith("cpu") || settype == "avg_cpu" || settype.StartsWith("runstate")) { dataSet.CustomYRange = new DataRange(100, 0, 10, Unit.Percentage, RangeScaleMode.Fixed); dataSet.MultiplyingFactor = 100; dataSet.Type = DataType.Cpu; } else if (settype.StartsWith("io_throughput")) { dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.BytesPerSecond, RangeScaleMode.Auto); dataSet.MultiplyingFactor = (int)Util.BINARY_MEGA; //xapi units are in mebibytes/sec dataSet.Type = DataType.Storage; } else if (settype.StartsWith("sr")) { dataSet.Type = DataType.Storage; if (settype.EndsWith("cache_size")) { dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.Bytes, RangeScaleMode.Auto); } else if (settype.EndsWith("cache_hits") || settype.EndsWith("cache_misses")) { dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.CountsPerSecond, RangeScaleMode.Auto); } } else if (settype.StartsWith("iops")) { //xapi units are in requests/sec dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.CountsPerSecond, RangeScaleMode.Auto); dataSet.Type = DataType.Storage; } else if (settype.StartsWith("iowait")) { dataSet.CustomYRange = new DataRange(100, 0, 10, Unit.Percentage, RangeScaleMode.Auto); dataSet.MultiplyingFactor = 100; dataSet.Type = DataType.Storage; } else if (settype.StartsWith("inflight") || settype.StartsWith("avgqu_sz")) { //xapi units are in requests dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.None, RangeScaleMode.Auto); dataSet.Type = DataType.Storage; } else if (settype.StartsWith("gpu")) { if (settype.Contains("power_usage")) { //xapi units are in mW dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.MilliWatt, RangeScaleMode.Auto); } else if (settype.Contains("temperature")) { //xapi units are in Centigrade dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.Centigrade, RangeScaleMode.Auto); } else if (settype.Contains("utilisation")) { dataSet.CustomYRange = new DataRange(100, 0, 10, Unit.Percentage, RangeScaleMode.Fixed); dataSet.MultiplyingFactor = 100; } dataSet.Type = DataType.Gpu; } else { dataSet.CustomYRange = new DataRange(1, 0, 1, Unit.None, RangeScaleMode.Auto); dataSet.Type = DataType.Custom; } return(dataSet); }
private void CheckForError() { long max_mem_total = 0; long max_mem_free = 0; long max_vcpus = 0; Host max_mem_total_host = null; Host max_mem_free_host = null; Host max_vcpus_host = null; foreach (Host host in Connection.Cache.Hosts) { long host_cpus = 0; foreach (Host_cpu cpu in Connection.Cache.Host_cpus) { if (cpu.host.opaque_ref.Equals(host.opaque_ref)) { host_cpus++; } } Host_metrics metrics = Connection.Resolve(host.metrics); if (host_cpus > max_vcpus) { max_vcpus = host_cpus; max_vcpus_host = host; } if (metrics != null && metrics.memory_total > max_mem_total) { max_mem_total = metrics.memory_total; max_mem_total_host = host; } // The available memory of a server is taken to be the current memory_free, // plus however much we can squeeze down the existing VMs. This assumes // that the overhead won't increase when we create the new VM, so it // has false negatives. long memory_free = host.memory_available_calc; if (metrics != null && memory_free > max_mem_free) { max_mem_free = memory_free; max_mem_free_host = host; } } if (max_mem_total_host != null && SelectedMemoryDynamicMin > max_mem_total) { ErrorPanel.Visible = true; ErrorLabel.Text = string.Format(Messages.NEWVMWIZARD_CPUMEMPAGE_MEMORYWARN1, Helpers.GetName(max_mem_total_host), Util.MemorySizeString(max_mem_total)); } else if (max_mem_free_host != null && SelectedMemoryDynamicMin > max_mem_free) { ErrorPanel.Visible = true; ErrorLabel.Text = string.Format(Messages.NEWVMWIZARD_CPUMEMPAGE_MEMORYWARN2, Helpers.GetName(max_mem_free_host), Util.MemorySizeString(max_mem_free)); } else if (max_vcpus_host != null && SelectedVcpus > max_vcpus) { ErrorPanel.Visible = true; ErrorLabel.Text = string.Format(Messages.NEWVMWIZARD_CPUMEMPAGE_VCPUSWARN, Helpers.GetName(max_vcpus_host), max_vcpus); } else { ErrorPanel.Visible = false; } }
public object hostcollect(Session session) { ArrayList vmc = new ArrayList(); int ne = 1; string log; string entry; string mydocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); try { //Session session = new Session(server, Convert.ToInt32(port)); //session.login_with_password(username, password); List <XenRef <Host> > hostRefs = Host.get_all(session); List <XenRef <Host_cpu> > hcpuRefs = Host_cpu.get_all(session); foreach (XenRef <Host> hostRef in hostRefs) { Host host = Host.get_record(session, hostRef); XenRef <Host_metrics> gmsref = Host.get_metrics(session, host.opaque_ref); Host_metrics gms = Host_metrics.get_record(session, gmsref); vmc.Add("Xenserver Name:"); try { vmc.Add(Convert.ToString(host.name_label)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("Hostname:"); try { vmc.Add(Convert.ToString(host.hostname)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("Is Host alive:"); try { vmc.Add(Convert.ToString(gms.live)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("IP address:"); try { vmc.Add("Not displayed in demo version"); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("Total Host Memory:"); try { vmc.Add("Not displayed in demo version"); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("Host Memory Free:"); try { vmc.Add("Not displayed in demo version"); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("Number CPU cores:"); try { vmc.Add("Not displayed in demo version"); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } try { foreach (XenRef <Host_cpu> hcpuRef in hcpuRefs) { Host_cpu hcpu = Host_cpu.get_record(session, hcpuRef); if (hcpu.host.ServerOpaqueRef == hostRef) { vmc.Add("CPU Core Number:"); try { vmc.Add(Convert.ToString(hcpu.number)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("CPU Core Vendor:"); try { vmc.Add(Convert.ToString(hcpu.vendor)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("CPU Core Model Name:"); try { vmc.Add(Convert.ToString(hcpu.modelname)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("CPU Core Speed:"); try { vmc.Add("Not displayed in demo version"); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("CPU Core Stepping Revesion:"); try { vmc.Add(hcpu.stepping); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("CPU Core Family:"); try { vmc.Add(Convert.ToString(hcpu.family)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } } } } catch { } vmc.Add("ISCSI IQN Name:"); try { vmc.Add("Not displayed in demo version"); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("Number of Allowed Operations:"); try { vmc.Add(Convert.ToString(host.allowed_operations.Count)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } try { for (int i = 0; i <= host.allowed_operations.Count - 1;) { vmc.Add("Allowed Operation:"); try { vmc.Add(Convert.ToString(host.allowed_operations[i])); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } i = i + 1; } } catch { } vmc.Add("Xenserver version:"); try { vmc.Add(Convert.ToString(host.software_version["product_version"])); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("Build Number:"); try { vmc.Add(Convert.ToString(host.software_version["build_number"])); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("Kernel version:"); try { vmc.Add(Convert.ToString(host.software_version["linux"])); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("API version:"); try { vmc.Add(Convert.ToString(host.API_version_vendor)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("Number of Physical Block Devices (PBD):"); try { vmc.Add(Convert.ToString(host.PBDs.Count)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } try { for (int i = 0; i <= host.PBDs.Count - 1;) { if (host.PBDs[i].ServerOpaqueRef == "OpaqueRef:NULL") { } else { PBD pbd = PBD.get_record(session, host.PBDs[i].ServerOpaqueRef); Dictionary <String, String> dict = null; dict = pbd.device_config; String pdninfo = null; foreach (String keyStr in dict.Keys) { if (keyStr == "location" || keyStr == "device") { pdninfo = (String)(dict[keyStr]); vmc.Add("Physical Block Devices:"); try { vmc.Add(Convert.ToString(pdninfo)); } catch { log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } } } i = i + 1; } } } catch { } vmc.Add("Number of Physical NICs (PIF):"); try { vmc.Add(Convert.ToString(host.PIFs.Count)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } try { for (int i = 0; i <= host.PIFs.Count - 1;) { if (host.PIFs[i].ServerOpaqueRef == "OpaqueRef:NULL") { } else { PIF vbd = PIF.get_record(session, Convert.ToString(host.PIFs[i].ServerOpaqueRef)); PIF_metrics pif = PIF_metrics.get_record(session, vbd.metrics); vmc.Add("PIF IP Address:"); try { vmc.Add("Not displayed in demo version"); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("PIF Netmask:"); try { vmc.Add(Convert.ToString(vbd.netmask)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("PIF DHCP/Static:"); try { vmc.Add(Convert.ToString(vbd.ip_configuration_mode)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("PIF MAC Address:"); try { vmc.Add("Not displayed in demo version"); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("PIF DNS servers:"); try { vmc.Add("Not displayed in demo version"); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("PIF Gateway:"); try { vmc.Add(Convert.ToString(vbd.gateway)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } if (vbd.other_config.Count >= 1) { vmc.Add("PIF Domain:"); try { vmc.Add(Convert.ToString(vbd.other_config["domain"])); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } } vmc.Add("PIF VLAN ID:"); try { vmc.Add(Convert.ToString(vbd.VLAN)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("PIF MTU:"); try { vmc.Add(Convert.ToString(vbd.MTU)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("PIF Device:"); try { vmc.Add(Convert.ToString(vbd.device)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("Is PIF attached:"); try { vmc.Add(Convert.ToString(vbd.currently_attached)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("PIF Device Name:"); try { vmc.Add(Convert.ToString(pif.device_name)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("PIF Device ID:"); try { vmc.Add(Convert.ToString(pif.device_id)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("PIF Vendor Name:"); try { vmc.Add(Convert.ToString(pif.vendor_name)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("PIF Vendor ID:"); try { vmc.Add(Convert.ToString(pif.vendor_id)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("PIF Speed:"); if (Convert.ToString(pif.speed) == "65535") { vmc.Add("PIF not connected"); } else { try { vmc.Add(Convert.ToString(pif.speed)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } } vmc.Add("PIF is set to duplex:"); try { vmc.Add(Convert.ToString(pif.duplex)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("PIF PCI Bus:"); try { vmc.Add(Convert.ToString(pif.pci_bus_path)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++; } vmc.Add("PIF Carrier:"); try { vmc.Add(Convert.ToString(pif.carrier)); } catch { vmc.Add("Data not available"); log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne; writelog.entry(log, entry); ne++;; } i = i + 1; } } } catch { } ne = 1; } log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Finished "; writelog.entry(log, entry); } catch { log = mydocs + "\\Halfmode\\HalfmodeConnection.log"; entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Failed"; writelog.entry(log, entry); } if ((vmc.Count & 2) == 0) { } else { vmc.Add(" "); } return(vmc); }