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);
            }
        }
Exemplo n.º 3
0
        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);
                }
            }
        }