Ejemplo n.º 1
0
        private object CellValue(int col)
        {
            switch (col)
            {
            case 0:
                return(VBD.userdevice);

            case 1:
                return(VDI.Name());

            case 2:
                return(VDI.Description());

            case 3:
                return(SR.Name());

            case 4:
                string name;
                return(VDI.sm_config.TryGetValue("displayname", out name) ? name : "");

            case 5:
                return(VDI.SizeText());

            case 6:
                return(VBD.IsReadOnly() ? Messages.YES : Messages.NO);

            case 7:
                return(GetPriorityString(VBD.GetIoNice()));

            case 8:
                return(VBD.currently_attached ? Messages.YES : Messages.NO);

            case 9:
                return(VBD.device == "" ? Messages.STORAGE_PANEL_UNKNOWN : string.Format("/dev/{0}", VBD.device));

            default:
                throw new ArgumentException(String.Format("Invalid column number {0} in VBDRenderer.CellValue()", col));
            }
        }
        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);
            }
        }