public override void ExecuteCmdlet() { ListPoolOptions options = new ListPoolOptions(this.BatchContext, this.AdditionalBehaviors) { PoolId = this.Id, Filter = this.Filter, MaxCount = this.MaxCount }; // The enumerator will internally query the service in chunks. Using WriteObject with the enumerate flag will enumerate // the entire collection first and then write the items out one by one in a single group. Using foreach, we can take // advantage of the enumerator's behavior and write output to the pipeline in bursts. foreach (PSCloudPool pool in BatchClient.ListPools(options)) { WriteObject(pool); } }
/// <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)))); } } }
/// <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))); } } }
/// <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 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)))); } }
/// <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 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))); } }
/// <summary> /// Gets the number of pools under the specified account /// </summary> public static int GetPoolCount(BatchController controller, BatchAccountContext context) { RequestInterceptor interceptor = CreateHttpRecordingInterceptor(); BatchClientBehavior[] behaviors = new BatchClientBehavior[] { interceptor }; BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient); ListPoolOptions options = new ListPoolOptions(context, behaviors); return client.ListPools(options).Count(); }
/// <summary> /// Gets the CurrentDedicated count from a pool /// </summary> public static int GetPoolCurrentDedicated(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 }; PSCloudPool pool = client.ListPools(options).First(); return pool.CurrentDedicated.Value; }
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(); } }
public static string WaitForOSVersionChange(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.CurrentOSVersion != pool.TargetOSVersion) { if (DateTime.Now > timeout) { throw new TimeoutException("Timed out waiting for active state pool"); } Sleep(5000); pool = client.ListPools(options).First(); } return pool.TargetOSVersion; }
/// <summary> /// Gets the number of pools under the specified account /// </summary> public static int GetPoolCount(BatchController controller, BatchAccountContext context) { BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient); ListPoolOptions options = new ListPoolOptions(context); return client.ListPools(options).Count(); }
/// <summary> /// Gets the CurrentDedicated count from a pool /// </summary> public static int GetPoolCurrentDedicated(BatchController controller, BatchAccountContext context, string poolId) { BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient); ListPoolOptions options = new ListPoolOptions(context) { PoolId = poolId }; PSCloudPool pool = client.ListPools(options).First(); return pool.CurrentDedicated.Value; }
/// <summary> /// Creates an MPI pool. /// </summary> public static void CreateMpiPoolIfNotExists(BatchController controller, BatchAccountContext context, int targetDedicated = 3) { BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient); ListPoolOptions listOptions = new ListPoolOptions(context) { PoolId = MpiPoolId }; try { client.ListPools(listOptions); return; // The call returned without throwing an exception, so the pool exists } catch (AggregateException aex) { BatchException innerException = aex.InnerException as BatchException; if (innerException == null || innerException.RequestInformation == null || innerException.RequestInformation.AzureError == null || innerException.RequestInformation.AzureError.Code != BatchErrorCodeStrings.PoolNotFound) { throw; } // We got the pool not found error, so continue and create the pool } string blobUrl = UploadBlobAndGetUrl(MpiSetupFileContainer, MpiSetupFileName, MpiSetupFileLocalPath); StartTask startTask = new StartTask(); startTask.CommandLine = string.Format("cmd /c set & {0} -unattend -force", MpiSetupFileName); startTask.ResourceFiles = new List<ResourceFile>(); startTask.ResourceFiles.Add(new ResourceFile(blobUrl, MpiSetupFileName)); startTask.RunElevated = true; startTask.WaitForSuccess = true; CreateTestPool(controller, context, MpiPoolId, targetDedicated, startTask: startTask); }
public static string WaitForOSVersionChange(BatchController controller, BatchAccountContext context, string poolId) { BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient); ListPoolOptions options = new ListPoolOptions(context) { PoolId = poolId }; DateTime timeout = DateTime.Now.AddMinutes(5); PSCloudPool pool = client.ListPools(options).First(); while (pool.CloudServiceConfiguration.CurrentOSVersion != pool.CloudServiceConfiguration.TargetOSVersion) { if (DateTime.Now > timeout) { throw new TimeoutException("Timed out waiting for active state pool"); } Sleep(5000); pool = client.ListPools(options).First(); } return pool.CloudServiceConfiguration.TargetOSVersion; }
/// <summary> /// Creates an MPI pool. /// </summary> public static void CreateMpiPoolIfNotExists(BatchController controller, BatchAccountContext context, int targetDedicated = 3) { BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient); ListPoolOptions listOptions = new ListPoolOptions(context) { PoolId = MpiPoolId }; try { client.ListPools(listOptions); return; // The call returned without throwing an exception, so the pool exists } catch (BatchException ex) { if (ex.RequestInformation == null || ex.RequestInformation.BatchError == null || ex.RequestInformation.BatchError.Code != BatchErrorCodeStrings.PoolNotFound) { throw; } // We got the pool not found error, so continue and create the pool } CreateTestPool(controller, context, MpiPoolId, targetDedicated); }