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); } } }
DisplayPoolResourceAllocationSettingData( ManagementScope scope, ManagementObject pool) { using (ManagementObject rasd = MsvmResourceAllocationSettingData.GetAllocationSettingsForPool( scope, pool.GetPropertyValue("ResourceType").ToString(), pool.GetPropertyValue("ResourceSubType").ToString(), pool.GetPropertyValue("PoolId").ToString())) { DisplayPoolResourceAllocationSettingData(rasd); } }
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); } }
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); } } } }
Main( string[] args) { if (args.Length > 0) { if (string.Equals(args[0], "EnumerateSupportedResources", StringComparison.OrdinalIgnoreCase) && args.Length == 1) { ResourceUtilities.EnumerateSupportedResources(); } else if (string.Equals(args[0], "CreatePool", StringComparison.OrdinalIgnoreCase) && args.Length == 6) { MsvmResourcePoolConfigurationService.CreatePool( args[1], args[2], args[3], args[4], args[5]); } else if (string.Equals(args[0], "DisplayPoolResources", StringComparison.OrdinalIgnoreCase) && args.Length == 3) { MsvmResourceAllocationSettingData.DisplayPoolResourceAllocationSettingData( args[1], args[2]); } else if (string.Equals(args[0], "ModifyPoolResources", StringComparison.OrdinalIgnoreCase) && args.Length == 5) { MsvmResourcePoolConfigurationService.ModifyPoolResources( args[1], args[2], args[3], args[4]); } else if (string.Equals(args[0], "DisplayPoolSettings", StringComparison.OrdinalIgnoreCase) && args.Length == 3) { MsvmResourcePoolSettingData.DisplayPoolResourcePoolSettingData( args[1], args[2]); } else if (string.Equals(args[0], "ModifyPoolSettings", StringComparison.OrdinalIgnoreCase) && args.Length == 5) { MsvmResourcePoolConfigurationService.ModifyPoolSettings( args[1], args[2], args[3], args[4]); } else if (string.Equals(args[0], "DeletePool", StringComparison.OrdinalIgnoreCase) && args.Length == 3) { MsvmResourcePoolConfigurationService.DeletePool( args[1], args[2]); } else if (string.Equals(args[0], "DisplayPool", StringComparison.OrdinalIgnoreCase) && args.Length == 3) { MsvmResourcePool.DisplayPoolVerbose( args[1], args[2]); } else if (string.Equals(args[0], "DisplayChildPools", StringComparison.OrdinalIgnoreCase) && args.Length == 3) { MsvmResourcePool.DisplayChildPools( args[1], args[2]); } else if (string.Equals(args[0], "DisplayParentPools", StringComparison.OrdinalIgnoreCase) && args.Length == 3) { MsvmResourcePool.DisplayParentPools( args[1], args[2]); } else if (string.Equals(args[0], "DisplayAllocationCapabilities", StringComparison.OrdinalIgnoreCase) && args.Length == 3) { MsvmResourceAllocationSettingData.DisplayValidResourceAllocationSettingDataSettings( args[1], args[2]); } else { ShowUsage(); } } else { ShowUsage(); } }