internal List <CDiscoveredConfig> GetHosts(int queryid)
        {
            List <CDiscoveredConfig> HostsFound = new List <CDiscoveredConfig> {
            };
            IList <EntityViewBase> hosts        = null;

            // dont continue if not logged in
            if (HVClient == null)
            {
                return(HostsFound);
            }

            try { Log.Write("[HvApi] Querying hosts associated with: " + Server.Name.ToUpper()); hosts = HVClient.FindEntityViews(typeof(HostSystem)); }
            catch (Exception ex) { Log.Write("Error: Cannot query host information. Details: " + ex.TargetSite + ex.Message); }

            _SiteInfo = Server.Session.Queries[queryid].Sites;

            if (hosts != null)
            {
                Log.Write(CFunctions.StringReplace("Found hosts ({0}) associated with {1}", hosts.Count.ToString(), Server.Name.ToUpper()));
                foreach (HostSystem host in hosts)
                {
                    string cluster = "";
                    if (HVClient.HostType == HvHostType.Cluster)
                    {
                        cluster = HVClient._ClusterName;
                    }

                    CDiscoveredMetrics hostmetrics = new CDiscoveredMetrics();
                    hostmetrics.Set(CMetricType.HostCpu, CMetricSubtype.Sockets, host.Hardware.CpuInfo.NumCpuPackages);
                    hostmetrics.Set(CMetricType.HostCpu, CMetricSubtype.Cores, host.Hardware.CpuInfo.NumCpuCores);
                    hostmetrics.Set(CMetricType.HostMem, CMetricSubtype.Allocated, CFunctions.ConvertDataUnit(host.Hardware.MemorySize, CDataUnitType.Byte, CDataUnitType.MiB));
                    hostmetrics.Set(CMetricType.VmCount, CMetricSubtype.None, host.Vm.Count());
                    hostmetrics.Set(CMetricType.DsCount, CMetricSubtype.None, host.Datastore.Count());

                    CDiscoveredAttributes hostattribs = new CDiscoveredAttributes();
                    hostattribs.Set(CAttributeType.Reference, "HostSystem-" + host.Id.ToLower());
                    hostattribs.Set(CAttributeType.IP, host.IP.ToString());
                    hostattribs.Set(CAttributeType.OS, host.OS);
                    hostattribs.Set(CAttributeType.Cluster, cluster);
                    hostattribs.Set(CAttributeType.HardwareVersion, (host.Hardware.SystemInfo.Vendor + " " + host.Hardware.SystemInfo.Model).Replace(",", String.Empty));
                    hostattribs.Set(CAttributeType.PowerState, "poweredOn"); // silly but we will not get any data from powered off hosts
                    //hostattribs.Merge(GetObjectState(host))

                    CDiscoveredConfig hostinfo = new CDiscoveredConfig()
                    {
                        Type       = new CDiscoveredTypes(CDiscoveredTypes.HVHost),
                        Site       = CSite.Resolve(host.IP, _SiteInfo),
                        Name       = host.Name.ToString(),
                        Metrics    = hostmetrics,
                        Attributes = hostattribs,
                        Owner      = new List <string> {
                            Server.Id
                        }
                    };

                    if ((hosts.Count == 1) && (HVClient.HostType == HvHostType.Standalone))
                    {
                        hostinfo.Id = Server.Id;
                    }
                    StoreObjectUid(hostinfo.Name, hostinfo.Id);

                    Log.Write(hostinfo.ToString(), Log.Verbosity.Debug);

                    HostsFound.Add(hostinfo);
                }
                HostsFound = HostsFound.OrderBy(o => o.Name).ToList();
            }

            return(HostsFound);
        }
        internal List <CDiscoveredConfig> GetVms(int queryid)
        {
            List <CDiscoveredConfig> VMsFound = new List <CDiscoveredConfig> {
            };
            IList <EntityViewBase> vms        = null;

            // dont continue if not logged in
            if (HVClient == null)
            {
                return(VMsFound);
            }

            try { Log.Write("[HvApi] Querying virtual machines associated with: " + Server.Name.ToUpper()); vms = HVClient.FindEntityViews(typeof(VirtualMachine)); }
            catch (Exception ex) { Log.Write("Error: Cannot query virtual machine information. Details: " + ex.TargetSite + ex.Message); }

            _SiteInfo = Server.Session.Queries[queryid].Sites;

            if (vms != null)
            {
                // iterate through vms and get general information
                Log.Write(CFunctions.StringReplace("Found virtual machines ({0}) associated with {1}", vms.Count.ToString(), Server.Name.ToUpper()));
                foreach (EntityViewBase tmp in vms)
                {
                    VirtualMachine vm = (VirtualMachine)tmp;

                    if (vm.Name != null)
                    {
                        long storagealloc = CFunctions.ConvertDataUnit(vm.Storage.Allocated, CDataUnitType.Byte, CDataUnitType.MiB);
                        long storageused  = CFunctions.ConvertDataUnit(vm.Storage.Used, CDataUnitType.Byte, CDataUnitType.MiB);
                        //double storageunshared = CFunctions.ConvertDataUnit(vm.Storage.Unshared, CDataUnitType.Byte, CDataUnitType.MiB);

                        string owner = RetrieveObjectUid(vm.Host);

                        CDiscoveredMetrics guestusage = new CDiscoveredMetrics();
                        guestusage.Set(CMetricType.VmDisk, CMetricSubtype.Allocated, vm.Storage.Allocated);
                        guestusage.Set(CMetricType.VmDisk, CMetricSubtype.Used, vm.Storage.Used);
                        guestusage.Set(CMetricType.VmCpu, CMetricSubtype.Sockets, vm.Hardware.NumCPU);
                        guestusage.Set(CMetricType.VmCpu, CMetricSubtype.Cores, ((int)vm.Hardware.NumCPU * vm.Hardware.NumCoresPerSocket.GetValueOrDefault(1)));
                        guestusage.Set(CMetricType.VmMem, CMetricSubtype.Allocated, vm.Hardware.MemoryMB);
                        guestusage.Set(CMetricType.VmDisk, CMetricSubtype.Allocated, storagealloc);
                        guestusage.Set(CMetricType.VmDisk, CMetricSubtype.Used, storageused);

                        CDiscoveredAttributes guestattribs = new CDiscoveredAttributes();
                        guestattribs.Set(CAttributeType.Reference, "VirtualMachine-" + vm.Id.ToLower());
                        guestattribs.Set(CAttributeType.IP, vm.Guest.IP.ToString());
                        guestattribs.Set(CAttributeType.OS, vm.Guest.OS);
                        guestattribs.Set(CAttributeType.HardwareVersion, vm.Version);
                        guestattribs.Set(CAttributeType.ToolsVersion, vm.Guest.ToolsVersion.ToString());

                        guestattribs.Set(CAttributeType.Cluster, vm.Cluster);

                        //guestattribs.Merge(GetObjectState(vm))
                        string vmPowerState = "poweredOff";
                        if ((VmEnabledState)vm.State == VmEnabledState.Enabled)
                        {
                            vmPowerState = "poweredOn";
                        }
                        else if (((VmEnabledState)vm.State == VmEnabledState.Paused) || ((VmEnabledState)vm.State == VmEnabledState.Pausing) || ((VmEnabledState)vm.State == VmEnabledState.Suspended))
                        {
                            vmPowerState = "suspended";
                        }
                        guestattribs.Set(CAttributeType.PowerState, vmPowerState);
                        CDiscoveredConfig guestinfo = new CDiscoveredConfig
                        {
                            Type       = new CDiscoveredTypes(CDiscoveredTypes.HVVM),
                            Site       = CSite.Resolve(vm.Guest.IP, _SiteInfo),
                            Name       = vm.Name.ToString(),
                            Metrics    = guestusage,
                            Attributes = guestattribs,
                            Owner      = new List <string> {
                                owner
                            }
                        };

                        StoreObjectUid(guestinfo.Attributes.Get(CAttributeType.Reference), guestinfo.Id);
                        guestinfo.ChildObjects = GetVmDisks(queryid, vm);

                        Log.Write(guestinfo.ToString(), Log.Verbosity.Debug);

                        VMsFound.Add(guestinfo);
                    }
                }

                VMsFound = VMsFound.OrderBy(o => o.Name).ToList(); // sort alphabally

                // get additional details for thin vmdk files
                //VMsFound = UpdateVIVMDiskDatastoreInfo(queryid, VMsFound);
            }

            return(VMsFound);
        }