private void ComposeGPUData()
        {
            m_PGPUs = new List <PGPUInfo>();

            var PGPUs = new List <XenAPI.PGPU>(Connection.Cache.PGPUs);

            PGPUs.Sort();

            foreach (XenAPI.PGPU pGpu in PGPUs)
            {
                Host host = Connection.Resolve(pGpu.host);
                if (host == null)
                {
                    continue;
                }
                PCI pci = Connection.Resolve(pGpu.PCI);

                string   temperature = PropertyAccessorHelper.PGPUTemperatureString(pGpu, MetricUpdater);
                string   powerStatus = PropertyAccessorHelper.PGPUPowerUsageString(pGpu, MetricUpdater);
                string   utilisation = PropertyAccessorHelper.PGPUUtilisationString(pGpu, MetricUpdater);
                string   memInfo     = PropertyAccessorHelper.PGPUMemoryUsageString(pGpu, MetricUpdater);
                PGPUInfo buf         = new PGPUInfo(pGpu.Name(), pGpu.uuid, host.Name(), pci.pci_id, utilisation,
                                                    memInfo, temperature, powerStatus);

                m_PGPUs.Add(buf);
            }
        }
        private void ComposeHostData()
        {
            m_Hosts = new List <HostInfo>();
            var hosts = new List <XenAPI.Host>(Connection.Cache.Hosts);

            hosts.Sort();

            foreach (XenAPI.Host host in hosts)
            {
                if (Cancelling)
                {
                    throw new CancelledException();
                }
                string srSizeString = "";
                var    PBDs         = host.Connection.ResolveAll(host.PBDs);
                foreach (XenAPI.PBD pbd in PBDs)
                {
                    SR sr = pbd.Connection.Resolve(pbd.SR);
                    if (sr.IsLocalSR() && sr.type.ToLower() == "lvm")
                    {
                        srSizeString += SRSizeString(sr) + ";";
                    }
                }
                if (srSizeString.Length == 0)
                {
                    srSizeString = Messages.HYPHEN;
                }
                string cpu_usage     = PropertyAccessorHelper.hostCpuUsageStringByMetric(host, MetricUpdater);
                string usage         = PropertyAccessorHelper.hostMemoryUsagePercentageStringByMetric(host, MetricUpdater);
                string network_usage = PropertyAccessorHelper.hostNetworkUsageStringByMetric(host, MetricUpdater);


                HostInfo buf = new HostInfo(host.name_label, host.address, host.uuid, cpu_usage,
                                            host.IsMaster() ? Messages.YES : Messages.NO, network_usage, usage,
                                            Convert.ToString(host.Uptime()), srSizeString, host.Description());
                m_Hosts.Add(buf);
                PercentComplete = Convert.ToInt32((++itemIndex) * baseIndex / itemCount);
            }
        }
        private void ComposeVMData()
        {
            m_VMs = new List <VMInfo>();
            var VMs = new List <XenAPI.VM>(Connection.Cache.VMs);

            VMs.Sort();
            foreach (XenAPI.VM vm in VMs)
            {
                string OSinfo     = vm.GetOSName();
                string srInfo     = "";
                string MacInfo    = "";
                string running_on = Messages.HYPHEN;

                if (Cancelling)
                {
                    throw new CancelledException();
                }

                if (!vm.is_a_real_vm())
                {
                    PercentComplete = Convert.ToInt32((++itemIndex) * baseIndex / itemCount);
                    continue;
                }

                ComparableList <ComparableAddress> addresses = new ComparableList <ComparableAddress>();
                if (vm.guest_metrics != null && !string.IsNullOrEmpty(vm.guest_metrics.opaque_ref) && !(vm.guest_metrics.opaque_ref.ToLower().Contains("null")))
                {
                    VM_guest_metrics metrics = vm.Connection.Resolve(vm.guest_metrics);

                    List <VIF> vifs = vm.Connection.ResolveAll(vm.VIFs);
                    foreach (VIF vif in vifs)
                    {
                        MacInfo += vif.MAC + " ";
                        foreach (var network in metrics.networks.Where(n => n.Key.StartsWith(String.Format("{0}/ip", vif.device))))
                        {
                            ComparableAddress ipAddress;
                            if (!ComparableAddress.TryParse(network.Value, false, true, out ipAddress))
                            {
                                continue;
                            }

                            addresses.Add(ipAddress);
                        }
                    }
                }
                addresses = new ComparableList <ComparableAddress>(addresses.Distinct());
                if (MacInfo.Length == 0)
                {
                    MacInfo = Messages.HYPHEN;
                }

                foreach (XenRef <VBD> vbdRef in vm.VBDs)
                {
                    var vbd = vm.Connection.Resolve(vbdRef);
                    if (vbd != null && !vbd.IsCDROM() && !vbd.IsFloppyDrive() && vbd.bootable)
                    {
                        VDI vdi = vm.Connection.Resolve(vbd.VDI);
                        srInfo += vdi.name_label + ":" + vdi.SizeText() + ";";
                    }
                }
                if (srInfo.Length == 0)
                {
                    srInfo = Messages.HYPHEN;
                }

                if (vm.resident_on != null && !string.IsNullOrEmpty(vm.resident_on.opaque_ref) && !(vm.resident_on.opaque_ref.ToLower().Contains("null")))
                {
                    running_on = vm.Connection.Resolve(vm.resident_on).Name();
                }

                string default_template_name = Messages.HYPHEN;
                if (vm.other_config.ContainsKey("base_template_name"))
                {
                    default_template_name = vm.other_config["base_template_name"];
                }

                VMInfo buf = new VMInfo(vm.Name(), vm.uuid, PropertyAccessorHelper.vmCpuUsageStringByMetric(vm, MetricUpdater),
                                        PropertyAccessorHelper.vmMemoryUsagePercentageStringByMetric(vm, MetricUpdater), srInfo, Convert.ToString(vm.VIFs.Count),
                                        Convert.ToString(addresses), MacInfo, OSinfo, Convert.ToString(vm.power_state),
                                        Convert.ToString(vm.RunningTime()), running_on, default_template_name, vm.Description());

                m_VMs.Add(buf);

                PercentComplete = Convert.ToInt32((++itemIndex) * baseIndex / itemCount);
            }
        }