// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A // PARTICULAR PURPOSE. // // Copyright (c) Microsoft. All rights reserved. namespace Microsoft.Samples.HyperV.ResourcePools { using System; using System.Collections; using System.Globalization; using System.Management; using Microsoft.Samples.HyperV.Common; static class MsvmResourcePool { /// /// Returns the reference path for the specified pool ID. /// /// The ManagementScope to use to connect to WMI. /// The resource type to assign. /// The resource subtype to assign. /// The pool ID. /// The reference path for the Msvm_ResourcePool object. internal static string GetResourcePoolPath( ManagementScope scope, string resourceType, string resourceSubType, string poolId) { using (ManagementObject pool = WmiUtilities.GetResourcePool( resourceType, resourceSubType, poolId, scope)) { return pool.Path.Path; } } /// /// Displays information for the specified pool. /// /// Msvm_ResourcePool MOB. internal static void DisplayResourcePool( ManagementObject pool) { Console.WriteLine("Msvm_ResourcePool:"); Console.WriteLine("\tPoolID: {0}", pool.GetPropertyValue("PoolID")); Console.WriteLine("\tInstanceID: {0}", pool.GetPropertyValue("InstanceID")); Console.WriteLine("\tResourceType: {0}", pool.GetPropertyValue("ResourceType")); Console.WriteLine("\tResourceSubtype: {0}", pool.GetPropertyValue("ResourceSubType")); } /// /// Displays the Msvm_ResourcePool, Msvm_ResourcePoolSettingData and /// Msvm_ResourceAllocationSettingsData properties for the specified /// resource pool. /// /// The display name for the resource type. /// The pool ID. internal static void DisplayPoolVerbose( string resourceDisplayName, string poolId) { Console.WriteLine( "Displaying the Msvm_ResourcePool, Msvm_ResourcePoolSettingData and " + "the Msvm_ResourceAllocationSettingsData properties for the following " + "resource pool:\n"); ManagementScope scope = ResourcePoolUtilities.GetManagementScope(); using (ManagementObject pool = WmiUtilities.GetResourcePool( ResourceUtilities.GetResourceType(resourceDisplayName), ResourceUtilities.GetResourceSubType(resourceDisplayName), poolId, scope)) { DisplayResourcePool(pool); MsvmResourceAllocationSettingData.DisplayPoolResourceAllocationSettingData( scope, pool); MsvmResourcePoolSettingData.DisplayPoolResourcePoolSettingData( scope, pool); } } /// /// Displays the pool IDs for the immediate child pools for the /// specified pool. /// /// The display name for the resource type. /// The pool ID. internal static void DisplayChildPools( string resourceDisplayName, string poolId) { Console.WriteLine( "Displaying the Msvm_ResourcePool objects for the child pools of the " + "following resource pool:\n" + "\tPool Id: " + poolId); ResourceUtilities.DisplayResourceInformation( resourceDisplayName); ManagementScope scope = ResourcePoolUtilities.GetManagementScope(); using (ManagementObject pool = WmiUtilities.GetResourcePool( ResourceUtilities.GetResourceType(resourceDisplayName), ResourceUtilities.GetResourceSubType(resourceDisplayName), poolId, scope)) using (ManagementObjectCollection childPoolCollection = pool.GetRelated( "Msvm_ResourcePool", "Msvm_ElementAllocatedFromPool", null, null, "Dependent", "Antecedent", false, null)) { foreach (ManagementObject childPool in childPoolCollection) using (childPool) { DisplayResourcePool(childPool); } } } /// /// Displays the pool IDs for the parent pools for the /// specified pool. /// /// The display name for the resource type. /// The pool ID. internal static void DisplayParentPools( string resourceDisplayName, string poolId) { Console.WriteLine( "Displaying the Msvm_ResourcePool objects for the parent pools of the " + "following resource pool:\n" + "\tPool Id: " + poolId); ResourceUtilities.DisplayResourceInformation( resourceDisplayName); ManagementScope scope = ResourcePoolUtilities.GetManagementScope(); using (ManagementObject pool = WmiUtilities.GetResourcePool( ResourceUtilities.GetResourceType(resourceDisplayName), ResourceUtilities.GetResourceSubType(resourceDisplayName), poolId, scope)) using (ManagementObjectCollection childPoolCollection = pool.GetRelated( "Msvm_ResourcePool", "Msvm_ElementAllocatedFromPool", null, null, "Antecedent", "Dependent", false, null)) { foreach (ManagementObject childPool in childPoolCollection) using (childPool) { DisplayResourcePool(childPool); } } } } }