internal ReservationToPurchaseExchange(string reservationOrderId, string reservationId, PurchaseRequestContent properties, PurchasePrice billingCurrencyTotal, OperationStatus?status) { ReservationOrderId = reservationOrderId; ReservationId = reservationId; Properties = properties; BillingCurrencyTotal = billingCurrencyTotal; Status = status; }
public virtual Response <CalculatePriceResponse> CalculateReservationOrder(PurchaseRequestContent content, CancellationToken cancellationToken = default) { using var scope = ReservationOrderResponseReservationOrderClientDiagnostics.CreateScope("TenantResourceExtensionClient.CalculateReservationOrder"); scope.Start(); try { var response = ReservationOrderResponseReservationOrderRestClient.Calculate(content, cancellationToken); return(response); } catch (Exception e) { scope.Failed(e); throw; } }
public async Task <Response <CalculatePriceResponse> > CalculateAsync(PurchaseRequestContent content, CancellationToken cancellationToken = default) { Argument.AssertNotNull(content, nameof(content)); using var message = CreateCalculateRequest(content); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: { CalculatePriceResponse value = default; using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); value = CalculatePriceResponse.DeserializeCalculatePriceResponse(document.RootElement); return(Response.FromValue(value, message.Response)); }
internal HttpMessage CreateCalculateRequest(PurchaseRequestContent content) { var message = _pipeline.CreateMessage(); var request = message.Request; request.Method = RequestMethod.Post; var uri = new RawRequestUriBuilder(); uri.Reset(_endpoint); uri.AppendPath("/providers/Microsoft.Capacity/calculatePrice", false); uri.AppendQuery("api-version", _apiVersion, true); request.Uri = uri; request.Headers.Add("Accept", "application/json"); request.Headers.Add("Content-Type", "application/json"); var content0 = new Utf8JsonRequestContent(); content0.JsonWriter.WriteObjectValue(content); request.Content = content0; _userAgent.Apply(message); return(message); }
private PurchaseRequestContent CreatePurchaseRequestContent(string scope, string billingPlan) { var request = new PurchaseRequestContent { Sku = new ReservationsSkuName("Standard_B1ls"), Location = new Core.AzureLocation("westus"), ReservedResourceType = new ReservedResourceType("VirtualMachines"), BillingScopeId = "/subscriptions/6d5e2387-bdf5-4ca1-83db-795fd2398b93", Term = new ReservationTerm("P1Y"), BillingPlan = new ReservationBillingPlan(billingPlan), Quantity = 1, DisplayName = "testVM", AppliedScopeType = new AppliedScopeType(scope), Renew = false, ReservedResourceProperties = new PurchaseRequestPropertiesReservedResourceProperties(new InstanceFlexibility("On")), }; if (scope.Equals("Single")) { request.AppliedScopes.Add("/subscriptions/6d5e2387-bdf5-4ca1-83db-795fd2398b93"); } return(request); }
public virtual async Task <ArmOperation <ReservationOrderResponseResource> > CreateOrUpdateAsync(WaitUntil waitUntil, string reservationOrderId, PurchaseRequestContent content, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(reservationOrderId, nameof(reservationOrderId)); Argument.AssertNotNull(content, nameof(content)); using var scope = _reservationOrderResponseReservationOrderClientDiagnostics.CreateScope("ReservationOrderResponseCollection.CreateOrUpdate"); scope.Start(); try { var response = await _reservationOrderResponseReservationOrderRestClient.PurchaseAsync(reservationOrderId, content, cancellationToken).ConfigureAwait(false); var operation = new ReservationsArmOperation <ReservationOrderResponseResource>(new ReservationOrderResponseOperationSource(Client), _reservationOrderResponseReservationOrderClientDiagnostics, Pipeline, _reservationOrderResponseReservationOrderRestClient.CreatePurchaseRequest(reservationOrderId, content).Request, response, OperationFinalStateVia.Location); if (waitUntil == WaitUntil.Completed) { await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public static Response <CalculatePriceResponse> CalculateReservationOrder(this TenantResource tenantResource, PurchaseRequestContent content, CancellationToken cancellationToken = default) { Argument.AssertNotNull(content, nameof(content)); return(GetExtensionClient(tenantResource).CalculateReservationOrder(content, cancellationToken)); }
public static async Task <Response <CalculatePriceResponse> > CalculateReservationOrderAsync(this TenantResource tenantResource, PurchaseRequestContent content, CancellationToken cancellationToken = default) { Argument.AssertNotNull(content, nameof(content)); return(await GetExtensionClient(tenantResource).CalculateReservationOrderAsync(content, cancellationToken).ConfigureAwait(false)); }
private void TestCreatePurchaseResponse(ArmOperation <ReservationOrderResponseResource> purchaseResponse, PurchaseRequestContent purchaseRequest, string reservationOrderId) { Assert.IsTrue(purchaseResponse.HasCompleted); Assert.IsTrue(purchaseResponse.HasValue); Assert.AreEqual(purchaseRequest.BillingPlan.ToString(), purchaseResponse.Value.Data.BillingPlan.ToString()); Assert.AreEqual(string.Format("/providers/microsoft.capacity/reservationOrders/{0}", reservationOrderId), purchaseResponse.Value.Data.Id.ToString()); Assert.AreEqual("Microsoft.Capacity", purchaseResponse.Value.Data.ResourceType.Namespace); Assert.AreEqual("reservationOrders", purchaseResponse.Value.Data.ResourceType.Type); Assert.AreEqual(purchaseRequest.DisplayName, purchaseResponse.Value.Data.DisplayName); Assert.AreEqual(reservationOrderId, purchaseResponse.Value.Data.Name); Assert.AreEqual(1, purchaseResponse.Value.Data.OriginalQuantity); Assert.AreEqual(purchaseRequest.Term.ToString(), purchaseResponse.Value.Data.Term.ToString()); Assert.IsNotNull(purchaseResponse.Value.Data.Reservations); Assert.AreEqual(1, purchaseResponse.Value.Data.Reservations.Count); }
internal RenewPropertiesResponse(PurchaseRequestContent purchaseProperties, RenewPropertiesResponsePricingCurrencyTotal pricingCurrencyTotal, RenewPropertiesResponseBillingCurrencyTotal billingCurrencyTotal) { PurchaseProperties = purchaseProperties; PricingCurrencyTotal = pricingCurrencyTotal; BillingCurrencyTotal = billingCurrencyTotal; }
internal ReservationToPurchaseCalculateExchange(PurchaseRequestContent properties, PurchasePrice billingCurrencyTotal) { Properties = properties; BillingCurrencyTotal = billingCurrencyTotal; }
public virtual ArmOperation <ReservationOrderResponseResource> Update(WaitUntil waitUntil, PurchaseRequestContent content, CancellationToken cancellationToken = default) { Argument.AssertNotNull(content, nameof(content)); using var scope = _reservationOrderResponseReservationOrderClientDiagnostics.CreateScope("ReservationOrderResponseResource.Update"); scope.Start(); try { var response = _reservationOrderResponseReservationOrderRestClient.Purchase(Id.Name, content, cancellationToken); var operation = new ReservationsArmOperation <ReservationOrderResponseResource>(new ReservationOrderResponseOperationSource(Client), _reservationOrderResponseReservationOrderClientDiagnostics, Pipeline, _reservationOrderResponseReservationOrderRestClient.CreatePurchaseRequest(Id.Name, content).Request, response, OperationFinalStateVia.Location); if (waitUntil == WaitUntil.Completed) { operation.WaitForCompletion(cancellationToken); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }