/// <summary> /// Executes the API call(s) against Azure Resource Management API(s). /// </summary> protected override void ExecuteCore() { if (this.MyInvocation.InvocationName.Equals("New-AzureRmPlan", StringComparison.OrdinalIgnoreCase)) { this.WriteWarning("Alias New-AzureRmPlan will be deprecated in a future release. Please use the cmdlet name New-AzsPlan instead"); } if (ShouldProcess(this.Name, VerbsCommon.New)) { this.WriteVerbose(Resources.CreatingNewPlan.FormatArgs(this.Name, this.ResourceGroupName)); using (var client = this.GetAzureStackClient()) { // Ensure the resource group is created client.ResourceGroups.CreateOrUpdate(new ResourceGroupCreateOrUpdateParameters() { ResourceGroup = new ResourceGroupDefinition() { Location = this.ArmLocation, Name = this.ResourceGroupName, } }); // TODO - determine what properties are needed var parameters = new ManagedPlanCreateOrUpdateParameters() { Plan = new AdminPlanModel() { Name = this.Name, Location = this.ArmLocation, Properties = new AdminPlanPropertiesDefinition() { Name = this.Name, DisplayName = this.DisplayName, QuotaIds = (this.QuotaIds != null ? this.QuotaIds.ToList() : null), SkuIds = (this.SkuIds != null ? this.SkuIds.ToList() : null) } } }; if (QuotaIds == null && SkuIds == null) { throw new PSInvalidOperationException(Resources.QuotaIdOrSkuIdRequired); } if (client.ManagedPlans.List(this.ResourceGroupName, includeDetails: false).Plans .Any( p => string.Equals(p.Properties.Name, parameters.Plan.Properties.Name, StringComparison.OrdinalIgnoreCase))) { throw new PSInvalidOperationException( Resources.PlanAlreadyExists.FormatArgs(parameters.Plan.Properties.Name, this.ResourceGroupName)); } var result = client.ManagedPlans.CreateOrUpdate(this.ResourceGroupName, parameters).Plan; WriteObject(result); } } }
/// <summary> /// Executes the API call(s) against Azure Resource Management API(s). /// </summary> protected override object ExecuteCore() { using (var client = this.GetAzureStackClient(this.SubscriptionId)) { this.WriteVerbose(Resources.UpdatingPlan.FormatArgs(this.Plan.Name, this.ResourceGroup)); var parameters = new ManagedPlanCreateOrUpdateParameters(this.Plan); return(client.ManagedPlans.CreateOrUpdate(this.ResourceGroup, parameters).Plan); } }
/// <summary> /// Executes the API call(s) against Azure Resource Management API(s). /// </summary> protected override void ExecuteCore() { if (this.MyInvocation.InvocationName.Equals("Set-AzureRmPlan", StringComparison.OrdinalIgnoreCase)) { this.WriteWarning("Alias Set-AzureRmPlan will be deprecated in a future release. Please use the cmdlet name Set-AzsPlan instead"); } if (ShouldProcess(this.Plan.Name, VerbsCommon.Set)) { using (var client = this.GetAzureStackClient()) { this.WriteVerbose(Resources.UpdatingPlan.FormatArgs(this.Plan.Name, this.ResourceGroupName)); var parameters = new ManagedPlanCreateOrUpdateParameters(this.Plan); var result = client.ManagedPlans.CreateOrUpdate(this.ResourceGroupName, parameters).Plan; WriteObject(result); } } }
/// <summary> /// Executes the API call(s) against Azure Resource Management API(s). /// </summary> protected override object ExecuteCore() { this.WriteVerbose(Resources.CreatingNewPlan.FormatArgs(this.Name, this.ResourceGroup)); using (var client = this.GetAzureStackClient(this.SubscriptionId)) { // Ensure the resource group is created client.ResourceGroups.CreateOrUpdate(new ResourceGroupCreateOrUpdateParameters() { ResourceGroup = new ResourceGroupDefinition() { Location = this.ArmLocation, Name = this.ResourceGroup, } }); // TODO - determine what properties are needed var parameters = new ManagedPlanCreateOrUpdateParameters() { Plan = new AdminPlanModel() { Name = this.Name, Location = this.ArmLocation, Properties = new AdminPlanDefinition() { Name = this.Name, DisplayName = this.DisplayName, State = this.State, ServiceQuotas = new ServiceQuotaDefinition[0], } } }; if (client.ManagedPlans.List(this.ResourceGroup, includeDetails: false).Plans .Any(p => string.Equals(p.Properties.Name, parameters.Plan.Properties.Name, StringComparison.OrdinalIgnoreCase))) { throw new PSInvalidOperationException(Resources.ManagedPlanAlreadyExists.FormatArgs(parameters.Plan.Properties.Name, this.ResourceGroup)); } return(client.ManagedPlans.CreateOrUpdate(this.ResourceGroup, parameters).Plan); } }
/// <summary> /// Creates or updates the plan /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.AzureStack.Management.IManagedPlanOperations. /// </param> /// <param name='resourceGroupName'> /// Required. Resource group name /// </param> /// <param name='parameters'> /// Required. Plan properties /// </param> /// <returns> /// Result for the create or update operation of the plan /// </returns> public static Task <ManagedPlanCreateOrUpdateResult> CreateOrUpdateAsync(this IManagedPlanOperations operations, string resourceGroupName, ManagedPlanCreateOrUpdateParameters parameters) { return(operations.CreateOrUpdateAsync(resourceGroupName, parameters, CancellationToken.None)); }
/// <summary> /// Creates or updates the plan /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.AzureStack.Management.IManagedPlanOperations. /// </param> /// <param name='resourceGroupName'> /// Required. Resource group name /// </param> /// <param name='parameters'> /// Required. Plan properties /// </param> /// <returns> /// Result for the create or update operation of the plan /// </returns> public static ManagedPlanCreateOrUpdateResult CreateOrUpdate(this IManagedPlanOperations operations, string resourceGroupName, ManagedPlanCreateOrUpdateParameters parameters) { return(Task.Factory.StartNew((object s) => { return ((IManagedPlanOperations)s).CreateOrUpdateAsync(resourceGroupName, parameters); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }