コード例 #1
0
 /// <summary>
 /// Returns a list of pools
 /// </summary>
 /// <returns></returns>
 public IEnumerable <ICloudPool> ListPools(DetailLevel detailLevel = null)
 {
     using (IPoolManager poolManager = this.Client.OpenPoolManager())
     {
         return(poolManager.ListPools(detailLevel));
     }
 }
コード例 #2
0
 private static void ListPools(IBatchClient client)
 {
     using (IPoolManager pm = client.OpenPoolManager())
     {
         Console.WriteLine("Listing Pools\n=============");
         // Using optional select clause to return only the name and state.
         IEnumerable <ICloudPool> pools = pm.ListPools(new ODATADetailLevel(selectClause: "name,state"));
         foreach (var p in pools)
         {
             Console.WriteLine("pool " + p.Name + " is " + p.State);
         }
         Console.WriteLine();
     }
 }
コード例 #3
0
        /// <summary>
        /// Lists the pools matching the specified filter options
        /// </summary>
        /// <param name="options">The options to use when querying for pools</param>
        /// <returns>The pools matching the specified filter options</returns>
        public IEnumerable <PSCloudPool> ListPools(ListPoolOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            // Get the single pool matching the specified name
            if (!string.IsNullOrWhiteSpace(options.PoolName))
            {
                WriteVerbose(string.Format(Resources.GBP_GetByName, options.PoolName));
                using (IPoolManager poolManager = options.Context.BatchOMClient.OpenPoolManager())
                {
                    ICloudPool  pool   = poolManager.GetPool(options.PoolName, additionalBehaviors: options.AdditionalBehaviors);
                    PSCloudPool psPool = new PSCloudPool(pool);
                    return(new PSCloudPool[] { psPool });
                }
            }
            // List pools using the specified filter
            else
            {
                ODATADetailLevel odata            = null;
                string           verboseLogString = null;
                if (!string.IsNullOrEmpty(options.Filter))
                {
                    verboseLogString = Resources.GBP_GetByOData;
                    odata            = new ODATADetailLevel(filterClause: options.Filter);
                }
                else
                {
                    verboseLogString = Resources.GBP_NoFilter;
                }
                WriteVerbose(verboseLogString);

                using (IPoolManager poolManager = options.Context.BatchOMClient.OpenPoolManager())
                {
                    IEnumerableAsyncExtended <ICloudPool> pools           = poolManager.ListPools(odata, options.AdditionalBehaviors);
                    Func <ICloudPool, PSCloudPool>        mappingFunction = p => { return(new PSCloudPool(p)); };
                    return(PSAsyncEnumerable <PSCloudPool, ICloudPool> .CreateWithMaxCount(
                               pools, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount))));
                }
            }
        }
コード例 #4
0
        private static void CreatePoolIfNotExist(IBatchClient client, string poolName)
        {
            // All Pool and VM operation starts from PoolManager
            using (IPoolManager pm = client.OpenPoolManager())
            {
                // go through all the pools and see if it already exists
                bool found = false;
                foreach (ICloudPool p in pm.ListPools())
                {
                    // pools are uniquely identified by their name
                    if (string.Equals(p.Name, poolName))
                    {
                        Console.WriteLine("Using existing pool {0}", poolName);
                        found = true;

                        if (!p.ListVMs().Any <IVM>())
                        {
                            Console.WriteLine("There are no VMs in this pool. No tasks will be run until at least one VM has been added via resizing.");
                            Console.WriteLine("Resizing pool to add 3 VMs. This might take a while...");
                            p.Resize(3);
                        }

                        break;
                    }
                }

                if (!found)
                {
                    Console.WriteLine("Creating pool: {0}", poolName);
                    // if pool not found, call CreatePool
                    //You can learn more about os families and versions at:
                    //http://msdn.microsoft.com/en-us/library/azure/ee924680.aspx
                    ICloudPool pool = pm.CreatePool(poolName, targetDedicated: 3, vmSize: "small", osFamily: "3");
                    pool.Commit();
                }
            }
        }