DisplayPoolResourcePoolSettingData( string resourceDisplayName, string poolId) { Console.WriteLine( "Displaying the Msvm_ResourcePoolSettingData properties for the following " + "resource pool:\n" + "\tPool Id: " + poolId); ResourceUtilities.DisplayResourceInformation(resourceDisplayName); ManagementScope scope = ResourcePoolUtilities.GetManagementScope(); using (ManagementObject rpsd = MsvmResourcePoolSettingData.GetPoolResourcePoolSettingData( scope, ResourceUtilities.GetResourceType(resourceDisplayName), ResourceUtilities.GetResourceSubType(resourceDisplayName), poolId)) { Console.WriteLine("Msvm_ResourcePoolSettingData:"); Console.WriteLine("\tElementName: " + rpsd.GetPropertyValue("ElementName").ToString()); } }
DeletePool( string resourceDisplayName, string poolId) { Console.WriteLine( "Deleting a resource pool:\n" + "\tPool Id: " + poolId); ResourceUtilities.DisplayResourceInformation( resourceDisplayName); ManagementScope scope = ResourcePoolUtilities.GetManagementScope(); using (ManagementObject rPConfigurationService = MsvmResourcePoolConfigurationService.GetResourcePoolConfigurationService( scope)) { DeletePoolHelper( scope, rPConfigurationService, ResourceUtilities.GetResourceType(resourceDisplayName), ResourceUtilities.GetResourceSubType(resourceDisplayName), poolId); } }
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); } }
ModifyPoolResourcesByPath( ManagementScope scope, ManagementObject rPConfigurationService, string resourceType, string resourceSubType, string poolPath, string[] parentPoolIdArray, string[][] parentHostResourcesArray) { if (parentPoolIdArray.Length == 0) { throw new ManagementException(string.Format( CultureInfo.CurrentCulture, @"At least one parent pool must be specified when modifying a resource pool's host resources (poolPath ""{0}"")", poolPath)); } if (parentPoolIdArray.Length != parentHostResourcesArray.Length) { throw new ManagementException(string.Format( CultureInfo.CurrentCulture, @"When modifying a child resource pool's host resources, a host resource must be specified for each parent pool. Shared allocations are not supported (poolPath ""{0}"")", poolPath)); } string[] parentPoolPathArray = ResourcePoolUtilities.GetParentPoolArrayFromPoolIds( scope, resourceType, resourceSubType, parentPoolIdArray); string[] resourceAllocationSettingDataArray = MsvmResourceAllocationSettingData.GetNewPoolAllocationSettingsArray( scope, resourceType, resourceSubType, parentPoolIdArray, parentHostResourcesArray); using (ManagementBaseObject inParams = rPConfigurationService.GetMethodParameters( "ModifyPoolResources")) { inParams["ChildPool"] = poolPath; inParams["ParentPools"] = parentPoolPathArray; inParams["AllocationSettings"] = resourceAllocationSettingDataArray; using (ManagementBaseObject outParams = rPConfigurationService.InvokeMethod( "ModifyPoolResources", inParams, null)) { WmiUtilities.ValidateOutput(outParams, scope, true, true); } } }
CreatePool( string resourceDisplayName, string childPoolId, string childPoolName, string parentPoolIdsString, string parentHostResourcesString) { Console.WriteLine( "Creating a resource pool:\n" + "\tPool Id: " + childPoolId + "\n\tPool Name: " + childPoolName); ResourceUtilities.DisplayResourceInformation( resourceDisplayName); ResourcePoolUtilities.DisplayPoolIdAndHostResources( parentPoolIdsString, parentHostResourcesString); string[] poolDelimter = { "[p]" }; // // Pool IDs are delimted by "[p], e.g. // "[p]Child Pool A[p][p]Child Pool B[p]" // string[] parentPoolIdArray = ResourcePoolUtilities.GetOneDimensionalArray( parentPoolIdsString, poolDelimter); string[] hostResourceDelimter = { "[h]" }; // // Parent pool host resources are specified by a 2-D array. Each pool is delimited // by a "[p]"; Each host resource is delimited by a "[h]". For example, // "[p][h]Child A, Resource 1[h][h]Child A, Resource 2[h][p][p][h]Child B, Resource 1[h][p]" // string[][] parentHostResourcesArray = ResourcePoolUtilities.GetTwoDimensionalArray( parentHostResourcesString, poolDelimter, hostResourceDelimter); ManagementScope scope = ResourcePoolUtilities.GetManagementScope(); using (ManagementObject rPConfigurationService = MsvmResourcePoolConfigurationService.GetResourcePoolConfigurationService( scope)) { CreatePoolHelper( scope, rPConfigurationService, ResourceUtilities.GetResourceType(resourceDisplayName), ResourceUtilities.GetResourceSubType(resourceDisplayName), childPoolId, childPoolName, parentPoolIdArray, parentHostResourcesArray); } }
ModifyPoolResources( string resourceDisplayName, string poolId, string parentPoolIdsString, string parentHostResourcesString) { Console.WriteLine( "Modifying a resource pool's host resources:\n" + "\tPool ID: " + poolId); ResourceUtilities.DisplayResourceInformation( resourceDisplayName); ResourcePoolUtilities.DisplayPoolIdAndHostResources( parentPoolIdsString, parentHostResourcesString); string[] poolDelimiter = { "[p]" }; string[] hostResourceDelimter = { "[h]" }; string[] parentPoolIdArray = ResourcePoolUtilities.GetOneDimensionalArray( parentPoolIdsString, poolDelimiter); string[][] parentHostResourcesArray = ResourcePoolUtilities.GetTwoDimensionalArray( parentHostResourcesString, poolDelimiter, hostResourceDelimter); ManagementScope scope = ResourcePoolUtilities.GetManagementScope(); using (ManagementObject rPConfigurationService = MsvmResourcePoolConfigurationService.GetResourcePoolConfigurationService( scope)) { ModifyPoolResourcesHelper( scope, rPConfigurationService, ResourceUtilities.GetResourceType(resourceDisplayName), ResourceUtilities.GetResourceSubType(resourceDisplayName), poolId, parentPoolIdArray, parentHostResourcesArray); } }
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); } } } }
DisplayPoolResourceAllocationSettingData( string resourceDisplayName, string poolId) { Console.WriteLine( "Displaying the Msvm_ResourceAllocationSettingData properties for the following " + "resource pool:\n" + "\tPool Id: " + poolId); ResourceUtilities.DisplayResourceInformation(resourceDisplayName); ManagementScope scope = ResourcePoolUtilities.GetManagementScope(); using (ManagementObject rasd = MsvmResourceAllocationSettingData.GetAllocationSettingsForPool( scope, ResourceUtilities.GetResourceType(resourceDisplayName), ResourceUtilities.GetResourceSubType(resourceDisplayName), poolId)) { DisplayPoolResourceAllocationSettingData(rasd); } }
DisplayValidResourceAllocationSettingDataSettings( string resourceDisplayName, string poolId) { ManagementScope scope = ResourcePoolUtilities.GetManagementScope(); using (ManagementObject pool = WmiUtilities.GetResourcePool( ResourceUtilities.GetResourceType(resourceDisplayName), ResourceUtilities.GetResourceSubType(resourceDisplayName), poolId, scope)) using (ManagementObject defaultRasd = GetDefaultAllocationSettings( scope, pool)) using (ManagementObject minimumRasd = GetMinimumAllocationSettings( scope, pool)) using (ManagementObject maximumRasd = GetMaximumAllocationSettings( scope, pool)) using (ManagementObject incrementalRasd = GetIncrementalAllocationSettings( scope, pool)) { Console.WriteLine("(default)"); DisplayPoolResourceAllocationSettingData(defaultRasd); Console.WriteLine("(minimum)"); DisplayPoolResourceAllocationSettingData(minimumRasd); Console.WriteLine("(maximum)"); DisplayPoolResourceAllocationSettingData(maximumRasd); Console.WriteLine("(incremental)"); DisplayPoolResourceAllocationSettingData(incrementalRasd); } }
ModifyPoolSettings( string resourceDisplayName, string poolId, string newPoolId, string newPoolName) { Console.WriteLine( "Modifying a resource pool's settings:\n" + "\tPool ID: " + poolId + " (change to " + newPoolId + ")\n" + "\tPool Name: (change to " + newPoolName + ")"); ResourceUtilities.DisplayResourceInformation( resourceDisplayName); ManagementScope scope = ResourcePoolUtilities.GetManagementScope(); using (ManagementObject rPConfigurationService = MsvmResourcePoolConfigurationService.GetResourcePoolConfigurationService( scope)) { string resourcePoolSettingData = MsvmResourcePoolSettingData.GetSettingsForPool( scope, ResourceUtilities.GetResourceType(resourceDisplayName), ResourceUtilities.GetResourceSubType(resourceDisplayName), newPoolId, newPoolName); ModifyPoolSettingsHelper( scope, rPConfigurationService, ResourceUtilities.GetResourceType(resourceDisplayName), ResourceUtilities.GetResourceSubType(resourceDisplayName), poolId, resourcePoolSettingData); } }
DisplayPoolIdAndHostResources( string poolIdString, string hostResourcesString) { string[] poolDelimiter = { "[p]" }; string[] hostResourceDelimiter = { "[p]" }; string[] poolIdArray = ResourcePoolUtilities.GetOneDimensionalArray( poolIdString, poolDelimiter); string[][] hostResourcesArray = ResourcePoolUtilities.GetTwoDimensionalArray( hostResourcesString, poolDelimiter, hostResourceDelimiter); if (poolIdArray.Length != hostResourcesArray.Length) { throw new ManagementException("Number of pool Ids (" + poolIdArray.Length + ") specified does not equal the number of host resources (" + hostResourcesArray.Length + ")."); } for (int index = 0; index < poolIdArray.Length; ++index) { string poolId = poolIdArray[index]; string[] hostResources = hostResourcesArray[index]; Console.WriteLine("\tParent pool Id " + poolId + ":"); foreach (string resource in hostResources) { Console.WriteLine("\t\tResource: " + resource); } } }
CreatePoolHelper( ManagementScope scope, ManagementObject rPConfigurationService, string resourceType, string resourceSubType, string childPoolId, string childPoolName, string[] parentPoolIdArray, string[][] parentHostResourcesArray) { if (parentPoolIdArray.Length == 0) { throw new ManagementException(string.Format( CultureInfo.CurrentCulture, @"At least one parent pool must be specified when creating a child resource pool (PoolId ""{0}"")", childPoolId)); } if (parentPoolIdArray.Length != parentHostResourcesArray.Length) { throw new ManagementException(string.Format( CultureInfo.CurrentCulture, @"When creating a child resource pool, a host resource must be specified for each parent pool. Shared allocations are not supported (PoolId ""{0}"")", childPoolId)); } string resourcePoolSettingData = MsvmResourcePoolSettingData.GetSettingsForPool( scope, resourceType, resourceSubType, childPoolId, childPoolName); string[] parentPoolPathArray = ResourcePoolUtilities.GetParentPoolArrayFromPoolIds( scope, resourceType, resourceSubType, parentPoolIdArray); string[] resourceAllocationSettingDataArray = MsvmResourceAllocationSettingData.GetNewPoolAllocationSettingsArray( scope, resourceType, resourceSubType, parentPoolIdArray, parentHostResourcesArray); using (ManagementBaseObject inParams = rPConfigurationService.GetMethodParameters( "CreatePool")) { inParams["PoolSettings"] = resourcePoolSettingData; inParams["ParentPools"] = parentPoolPathArray; inParams["AllocationSettings"] = resourceAllocationSettingDataArray; using (ManagementBaseObject outParams = rPConfigurationService.InvokeMethod( "CreatePool", inParams, null)) { if (WmiUtilities.ValidateOutput(outParams, scope, true, true)) { string poolPath = outParams["Pool"].ToString(); return(new ManagementObject( scope, new ManagementPath(poolPath), null)); } else { return(null); } } } }