public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                string resourceGroupName;
                string reservationGroupName;
                string name;

                switch (this.ParameterSetName)
                {
                case ResourceIDParameterSet:
                    resourceGroupName    = GetResourceGroupName(this.ResourceId);
                    reservationGroupName = GetResourceName(this.ResourceId, "Microsoft.Compute/capacityReservationGroups", "capacityReservations");
                    name = GetResourceName(this.ResourceId, "capacityReservations");
                    break;

                case InputObjectParameterSet:
                    resourceGroupName    = GetResourceGroupName(this.CapacityReservation.Id);
                    reservationGroupName = GetResourceName(this.CapacityReservation.Id, "Microsoft.Compute/capacityReservationGroups", "capacityReservations");
                    name = this.CapacityReservation.Name;
                    break;

                default:
                    resourceGroupName    = this.ResourceGroupName;
                    reservationGroupName = this.ReservationGroupName;
                    name = this.Name;
                    break;
                }

                CapacityReservationUpdate updateParams = new CapacityReservationUpdate();
                if (this.IsParameterBound(c => c.Tag))
                {
                    updateParams.Tags = this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value);
                }
                if (this.IsParameterBound(c => c.CapacityToReserve))
                {
                    updateParams.Sku          = new Sku();
                    updateParams.Sku.Capacity = this.CapacityToReserve;
                }

                var result   = CapacityReservationClient.Update(resourceGroupName, reservationGroupName, name, updateParams);
                var psObject = new PSCapacityReservation();
                ComputeAutomationAutoMapperProfile.Mapper.Map <CapacityReservation, PSCapacityReservation>(result, psObject);
                WriteObject(psObject);
            });
        }
        public virtual CapacityReservationUpdateOperation Update(bool waitForCompletion, CapacityReservationUpdate parameters, CancellationToken cancellationToken = default)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            using var scope = _clientDiagnostics.CreateScope("CapacityReservation.Update");
            scope.Start();
            try
            {
                var response  = _capacityReservationsRestClient.Update(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, parameters, cancellationToken);
                var operation = new CapacityReservationUpdateOperation(this, _clientDiagnostics, Pipeline, _capacityReservationsRestClient.CreateUpdateRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, parameters).Request, response);
                if (waitForCompletion)
                {
                    operation.WaitForCompletion(cancellationToken);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
        public Response Update(string subscriptionId, string resourceGroupName, string capacityReservationGroupName, string capacityReservationName, CapacityReservationUpdate parameters, CancellationToken cancellationToken = default)
        {
            if (subscriptionId == null)
            {
                throw new ArgumentNullException(nameof(subscriptionId));
            }
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException(nameof(resourceGroupName));
            }
            if (capacityReservationGroupName == null)
            {
                throw new ArgumentNullException(nameof(capacityReservationGroupName));
            }
            if (capacityReservationName == null)
            {
                throw new ArgumentNullException(nameof(capacityReservationName));
            }
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            using var message = CreateUpdateRequest(subscriptionId, resourceGroupName, capacityReservationGroupName, capacityReservationName, parameters);
            _pipeline.Send(message, cancellationToken);
            switch (message.Response.Status)
            {
            case 200:
            case 202:
                return(message.Response);

            default:
                throw _clientDiagnostics.CreateRequestFailedException(message.Response);
            }
        }
        internal HttpMessage CreateUpdateRequest(string subscriptionId, string resourceGroupName, string capacityReservationGroupName, string capacityReservationName, CapacityReservationUpdate parameters)
        {
            var message = _pipeline.CreateMessage();
            var request = message.Request;

            request.Method = RequestMethod.Patch;
            var uri = new RawRequestUriBuilder();

            uri.Reset(endpoint);
            uri.AppendPath("/subscriptions/", false);
            uri.AppendPath(subscriptionId, true);
            uri.AppendPath("/resourceGroups/", false);
            uri.AppendPath(resourceGroupName, true);
            uri.AppendPath("/providers/Microsoft.Compute/capacityReservationGroups/", false);
            uri.AppendPath(capacityReservationGroupName, true);
            uri.AppendPath("/capacityReservations/", false);
            uri.AppendPath(capacityReservationName, true);
            uri.AppendQuery("api-version", apiVersion, true);
            request.Uri = uri;
            request.Headers.Add("Accept", "application/json");
            request.Headers.Add("Content-Type", "application/json");
            var content = new Utf8JsonRequestContent();

            content.JsonWriter.WriteObjectValue(parameters);
            request.Content = content;
            message.SetProperty("UserAgentOverride", _userAgent);
            return(message);
        }
 /// <summary>
 /// The operation to update a capacity reservation.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='capacityReservationGroupName'>
 /// The name of the capacity reservation group.
 /// </param>
 /// <param name='capacityReservationName'>
 /// The name of the capacity reservation.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the Update capacity reservation operation.
 /// </param>
 public static CapacityReservation Update(this ICapacityReservationsOperations operations, string resourceGroupName, string capacityReservationGroupName, string capacityReservationName, CapacityReservationUpdate parameters)
 {
     return(operations.UpdateAsync(resourceGroupName, capacityReservationGroupName, capacityReservationName, parameters).GetAwaiter().GetResult());
 }
 /// <summary>
 /// The operation to update a capacity reservation.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='capacityReservationGroupName'>
 /// The name of the capacity reservation group.
 /// </param>
 /// <param name='capacityReservationName'>
 /// The name of the capacity reservation.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the Update capacity reservation operation.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <CapacityReservation> BeginUpdateAsync(this ICapacityReservationsOperations operations, string resourceGroupName, string capacityReservationGroupName, string capacityReservationName, CapacityReservationUpdate parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginUpdateWithHttpMessagesAsync(resourceGroupName, capacityReservationGroupName, capacityReservationName, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
示例#7
0
        public async virtual Task <ArmOperation <CapacityReservation> > UpdateAsync(bool waitForCompletion, CapacityReservationUpdate parameters, CancellationToken cancellationToken = default)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            using var scope = _capacityReservationClientDiagnostics.CreateScope("CapacityReservation.Update");
            scope.Start();
            try
            {
                var response = await _capacityReservationRestClient.UpdateAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, parameters, cancellationToken).ConfigureAwait(false);

                var operation = new ComputeArmOperation <CapacityReservation>(new CapacityReservationOperationSource(Client), _capacityReservationClientDiagnostics, Pipeline, _capacityReservationRestClient.CreateUpdateRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, parameters).Request, response, OperationFinalStateVia.Location);
                if (waitForCompletion)
                {
                    await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }