public static ulong GetMaxConsumableResource(IComputerSystem host) { using (IResourcePool resourcePool = ResourcePool.Query(host, "ResourceType = 4").FirstOrDefault <IResourcePool>()) { if (resourcePool == null) { throw new HyperVException("Unable to find the default settings for the Memory resource"); } return(resourcePool.MaxConsumableResource); } }
public static IEthernetPortAllocationSettingData GetDefaultEthernetPortAllocationSettingData(IComputerSystem host) { IResourcePool resourcePool = ResourcePool.Query(host, "ResourceType = 33 and Primordial = True").FirstOrDefault <IResourcePool>(); if (resourcePool == null) { throw new HyperVException("Unable to find the default settings for the resource"); } ManagementObject managementObject = (ManagementObject)null; using (ManagementObjectCollection related = ((IWMICommon)resourcePool).Object.GetRelated("Msvm_AllocationCapabilities", "Msvm_ElementCapabilities", (string)null, (string)null, (string)null, (string)null, false, (EnumerationOptions)null)) { using (ManagementObject firstElement = related.GetFirstElement()) { foreach (ManagementObject relationship in firstElement.GetRelationships("Msvm_SettingsDefineCapabilities")) { if ((int)(ushort)relationship["ValueRole"] == 0) { managementObject = relationship; break; } relationship.Dispose(); } } } if (managementObject == null) { throw new HyperVException("Unable to find the default settings for the resource"); } string path = (string)managementObject["PartComponent"]; managementObject.Dispose(); ManagementObject instance = new ManagementObject(path); instance.Scope = ((IWMICommon)resourcePool).Scope; instance.Get(); return((IEthernetPortAllocationSettingData) new EthernetPortAllocationSettingData(instance)); }