public ListPools ( Microsoft.Azure.Commands.Batch.Models.ListPoolOptions options ) : IEnumerable |
||
options | Microsoft.Azure.Commands.Batch.Models.ListPoolOptions | The options to use when querying for pools. |
return | IEnumerable |
public IEnumerable<PSCloudPool> ListPools(ListPoolOptions options)
{
if (options == null)
{
throw new ArgumentNullException("options");
}
// Get the single pool matching the specified id
if (!string.IsNullOrWhiteSpace(options.PoolId))
{
WriteVerbose(string.Format(Resources.GetPoolById, options.PoolId));
PoolOperations poolOperations = options.Context.BatchOMClient.PoolOperations;
ODATADetailLevel getDetailLevel = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand);
CloudPool pool = poolOperations.GetPool(options.PoolId, detailLevel: getDetailLevel, additionalBehaviors: options.AdditionalBehaviors);
PSCloudPool psPool = new PSCloudPool(pool);
return new PSCloudPool[] { psPool };
}
// List pools using the specified filter
else
{
string verboseLogString = null;
ODATADetailLevel listDetailLevel = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand);
if (!string.IsNullOrEmpty(options.Filter))
{
verboseLogString = Resources.GetPoolByOData;
listDetailLevel.FilterClause = options.Filter;
}
else
{
verboseLogString = Resources.GetPoolNoFilter;
}
WriteVerbose(verboseLogString);
PoolOperations poolOperations = options.Context.BatchOMClient.PoolOperations;
IPagedEnumerable<CloudPool> pools = poolOperations.ListPools(listDetailLevel, options.AdditionalBehaviors);
Func<CloudPool, PSCloudPool> mappingFunction = p => { return new PSCloudPool(p); };
return PSPagedEnumerable<PSCloudPool, CloudPool>.CreateWithMaxCount(
pools, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount)));
}
}
public static void WaitForSteadyPoolAllocation(BatchController controller, BatchAccountContext context, string poolId) { RequestInterceptor interceptor = CreateHttpRecordingInterceptor(); BatchClientBehavior[] behaviors = new BatchClientBehavior[] { interceptor }; BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient); ListPoolOptions options = new ListPoolOptions(context, behaviors) { PoolId = poolId }; DateTime timeout = DateTime.Now.AddMinutes(2); PSCloudPool pool = client.ListPools(options).First(); while (pool.AllocationState != AllocationState.Steady) { if (DateTime.Now > timeout) { throw new TimeoutException("Timed out waiting for steady allocation state"); } Sleep(5000); pool = client.ListPools(options).First(); } }