public static QueryFilter FullQueryFor(String p) { String[] elts = p.Split(new char[] { ' ' }); List <QueryFilter> queries = new List <QueryFilter>(); foreach (String elt in elts) { if (String.IsNullOrEmpty(elt)) { continue; } queries.Add(new StringPropertyQuery(PropertyNames.label, elt, StringPropertyQuery.PropertyQueryType.contains, false)); queries.Add(new StringPropertyQuery(PropertyNames.description, elt, StringPropertyQuery.PropertyQueryType.contains, false)); ComparableAddress address; if (!ComparableAddress.TryParse(elt, true, false, out address)) { continue; } queries.Add(new IPAddressQuery(PropertyNames.ip_address, address)); } if (queries.Count == 0) { queries.Add(new StringPropertyQuery(PropertyNames.label, "", StringPropertyQuery.PropertyQueryType.contains, false)); } return(new GroupQuery(queries.ToArray(), GroupQuery.GroupQueryType.Or)); }
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); } }
private static ComparableList <ComparableAddress> IPAddressProperty(IXenObject o) { var addresses = new ComparableList <ComparableAddress>(); if (o.Connection == null) { return(addresses); } if (o is VM vm) { if (!vm.is_a_real_vm()) { return(addresses); } VM_guest_metrics metrics = vm.Connection.Resolve(vm.guest_metrics); if (metrics == null) { return(null); } List <VIF> vifs = vm.Connection.ResolveAll(vm.VIFs); foreach (VIF vif in vifs) { foreach (var value in Helpers.FindIpAddresses(metrics.networks, vif.device)) { if (ComparableAddress.TryParse(value, false, true, out var ipAddress)) { addresses.Add(ipAddress); } } } addresses = new ComparableList <ComparableAddress>(addresses.Distinct()); } else if (o is Host host) { foreach (PIF pif in host.Connection.ResolveAll(host.PIFs)) { if (ComparableAddress.TryParse(pif.IP, false, true, out var ipAddress)) { addresses.Add(ipAddress); } } } else if (o is SR sr) { string target = sr.Target(); if (!string.IsNullOrEmpty(target)) { if (ComparableAddress.TryParse(target, false, true, out var ipAddress)) { addresses.Add(ipAddress); } } } return(addresses.Count == 0 ? null : addresses); // CA-28300 }