diff --git a/profiles/preview/preview/reservations/mgmt/reservations/models.go b/profiles/preview/preview/reservations/mgmt/reservations/models.go index 9a83e0e8aad5..af54cdd1ddbe 100644 --- a/profiles/preview/preview/reservations/mgmt/reservations/models.go +++ b/profiles/preview/preview/reservations/mgmt/reservations/models.go @@ -22,7 +22,7 @@ package reservations import ( "context" - original "github.com/Azure/azure-sdk-for-go/services/preview/reservations/mgmt/2018-06-01/reservations" + original "github.com/Azure/azure-sdk-for-go/services/preview/reservations/mgmt/2019-04-01/reservations" ) const ( @@ -99,9 +99,8 @@ const ( type InstanceFlexibility = original.InstanceFlexibility const ( - NotSupported InstanceFlexibility = original.NotSupported - Off InstanceFlexibility = original.Off - On InstanceFlexibility = original.On + Off InstanceFlexibility = original.Off + On InstanceFlexibility = original.On ) type ReservationTerm = original.ReservationTerm @@ -115,7 +114,6 @@ type ReservedResourceType = original.ReservedResourceType const ( CosmosDb ReservedResourceType = original.CosmosDb - RedHat ReservedResourceType = original.RedHat SQLDatabases ReservedResourceType = original.SQLDatabases SuseLinux ReservedResourceType = original.SuseLinux VirtualMachines ReservedResourceType = original.VirtualMachines @@ -139,6 +137,10 @@ type AppliedReservationList = original.AppliedReservationList type AppliedReservations = original.AppliedReservations type AppliedReservationsProperties = original.AppliedReservationsProperties type BaseClient = original.BaseClient +type CalculatePriceResponse = original.CalculatePriceResponse +type CalculatePriceResponseProperties = original.CalculatePriceResponseProperties +type CalculatePriceResponsePropertiesBillingCurrencyTotal = original.CalculatePriceResponsePropertiesBillingCurrencyTotal +type CalculatePriceResponsePropertiesPricingCurrencyTotal = original.CalculatePriceResponsePropertiesPricingCurrencyTotal type Catalog = original.Catalog type Client = original.Client type Error = original.Error @@ -163,10 +165,14 @@ type OrderList = original.OrderList type OrderListIterator = original.OrderListIterator type OrderListPage = original.OrderListPage type OrderProperties = original.OrderProperties +type OrderPurchaseFuture = original.OrderPurchaseFuture type OrderResponse = original.OrderResponse type Patch = original.Patch type PatchProperties = original.PatchProperties type Properties = original.Properties +type PurchaseRequest = original.PurchaseRequest +type PurchaseRequestProperties = original.PurchaseRequestProperties +type PurchaseRequestPropertiesReservedResourceProperties = original.PurchaseRequestPropertiesReservedResourceProperties type ReservationMergeFuture = original.ReservationMergeFuture type ReservationUpdateFuture = original.ReservationUpdateFuture type Response = original.Response diff --git a/profiles/preview/preview/reservations/mgmt/reservations/reservationsapi/models.go b/profiles/preview/preview/reservations/mgmt/reservations/reservationsapi/models.go index 56b20725c5a1..2d7aae84ae6d 100644 --- a/profiles/preview/preview/reservations/mgmt/reservations/reservationsapi/models.go +++ b/profiles/preview/preview/reservations/mgmt/reservations/reservationsapi/models.go @@ -19,7 +19,7 @@ package reservationsapi -import original "github.com/Azure/azure-sdk-for-go/services/preview/reservations/mgmt/2018-06-01/reservations/reservationsapi" +import original "github.com/Azure/azure-sdk-for-go/services/preview/reservations/mgmt/2019-04-01/reservations/reservationsapi" type BaseClientAPI = original.BaseClientAPI type ClientAPI = original.ClientAPI diff --git a/services/preview/reservations/mgmt/2019-04-01/reservations/client.go b/services/preview/reservations/mgmt/2019-04-01/reservations/client.go new file mode 100644 index 000000000000..99ecebb16705 --- /dev/null +++ b/services/preview/reservations/mgmt/2019-04-01/reservations/client.go @@ -0,0 +1,208 @@ +// Package reservations implements the Azure ARM Reservations service API version 2019-04-01. +// +// This API describe Azure Reservation +package reservations + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +const ( + // DefaultBaseURI is the default URI used for the service Reservations + DefaultBaseURI = "https://management.azure.com" +) + +// BaseClient is the base client for Reservations. +type BaseClient struct { + autorest.Client + BaseURI string +} + +// New creates an instance of the BaseClient client. +func New() BaseClient { + return NewWithBaseURI(DefaultBaseURI) +} + +// NewWithBaseURI creates an instance of the BaseClient client. +func NewWithBaseURI(baseURI string) BaseClient { + return BaseClient{ + Client: autorest.NewClientWithUserAgent(UserAgent()), + BaseURI: baseURI, + } +} + +// GetAppliedReservationList get applicable `Reservation`s that are applied to this subscription. +// Parameters: +// subscriptionID - id of the subscription +func (client BaseClient) GetAppliedReservationList(ctx context.Context, subscriptionID string) (result AppliedReservations, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GetAppliedReservationList") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetAppliedReservationListPreparer(ctx, subscriptionID) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.BaseClient", "GetAppliedReservationList", nil, "Failure preparing request") + return + } + + resp, err := client.GetAppliedReservationListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "reservations.BaseClient", "GetAppliedReservationList", resp, "Failure sending request") + return + } + + result, err = client.GetAppliedReservationListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.BaseClient", "GetAppliedReservationList", resp, "Failure responding to request") + } + + return +} + +// GetAppliedReservationListPreparer prepares the GetAppliedReservationList request. +func (client BaseClient) GetAppliedReservationListPreparer(ctx context.Context, subscriptionID string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Capacity/appliedReservations", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetAppliedReservationListSender sends the GetAppliedReservationList request. The method will close the +// http.Response Body if it receives an error. +func (client BaseClient) GetAppliedReservationListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// GetAppliedReservationListResponder handles the response to the GetAppliedReservationList request. The method always +// closes the http.Response Body. +func (client BaseClient) GetAppliedReservationListResponder(resp *http.Response) (result AppliedReservations, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetCatalog sends the get catalog request. +// Parameters: +// subscriptionID - id of the subscription +// reservedResourceType - the type of the resource for which the skus should be provided. +// location - filters the skus based on the location specified in this parameter. This can be an azure region +// or global +func (client BaseClient) GetCatalog(ctx context.Context, subscriptionID string, reservedResourceType string, location string) (result ListCatalog, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GetCatalog") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetCatalogPreparer(ctx, subscriptionID, reservedResourceType, location) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.BaseClient", "GetCatalog", nil, "Failure preparing request") + return + } + + resp, err := client.GetCatalogSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "reservations.BaseClient", "GetCatalog", resp, "Failure sending request") + return + } + + result, err = client.GetCatalogResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.BaseClient", "GetCatalog", resp, "Failure responding to request") + } + + return +} + +// GetCatalogPreparer prepares the GetCatalog request. +func (client BaseClient) GetCatalogPreparer(ctx context.Context, subscriptionID string, reservedResourceType string, location string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + "reservedResourceType": autorest.Encode("query", reservedResourceType), + } + if len(location) > 0 { + queryParameters["location"] = autorest.Encode("query", location) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Capacity/catalogs", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetCatalogSender sends the GetCatalog request. The method will close the +// http.Response Body if it receives an error. +func (client BaseClient) GetCatalogSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// GetCatalogResponder handles the response to the GetCatalog request. The method always +// closes the http.Response Body. +func (client BaseClient) GetCatalogResponder(resp *http.Response) (result ListCatalog, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Value), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/services/preview/reservations/mgmt/2019-04-01/reservations/models.go b/services/preview/reservations/mgmt/2019-04-01/reservations/models.go new file mode 100644 index 000000000000..e474ab0b2f08 --- /dev/null +++ b/services/preview/reservations/mgmt/2019-04-01/reservations/models.go @@ -0,0 +1,1407 @@ +package reservations + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "encoding/json" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/date" + "github.com/Azure/go-autorest/autorest/to" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// The package's fully qualified name. +const fqdn = "github.com/Azure/azure-sdk-for-go/services/preview/reservations/mgmt/2019-04-01/reservations" + +// AppliedScopeType enumerates the values for applied scope type. +type AppliedScopeType string + +const ( + // Shared ... + Shared AppliedScopeType = "Shared" + // Single ... + Single AppliedScopeType = "Single" +) + +// PossibleAppliedScopeTypeValues returns an array of possible values for the AppliedScopeType const type. +func PossibleAppliedScopeTypeValues() []AppliedScopeType { + return []AppliedScopeType{Shared, Single} +} + +// ErrorResponseCode enumerates the values for error response code. +type ErrorResponseCode string + +const ( + // ActivateQuoteFailed ... + ActivateQuoteFailed ErrorResponseCode = "ActivateQuoteFailed" + // AppliedScopesNotAssociatedWithCommerceAccount ... + AppliedScopesNotAssociatedWithCommerceAccount ErrorResponseCode = "AppliedScopesNotAssociatedWithCommerceAccount" + // AuthorizationFailed ... + AuthorizationFailed ErrorResponseCode = "AuthorizationFailed" + // BadRequest ... + BadRequest ErrorResponseCode = "BadRequest" + // BillingCustomerInputError ... + BillingCustomerInputError ErrorResponseCode = "BillingCustomerInputError" + // BillingError ... + BillingError ErrorResponseCode = "BillingError" + // BillingPaymentInstrumentHardError ... + BillingPaymentInstrumentHardError ErrorResponseCode = "BillingPaymentInstrumentHardError" + // BillingPaymentInstrumentSoftError ... + BillingPaymentInstrumentSoftError ErrorResponseCode = "BillingPaymentInstrumentSoftError" + // BillingScopeIDCannotBeChanged ... + BillingScopeIDCannotBeChanged ErrorResponseCode = "BillingScopeIdCannotBeChanged" + // BillingTransientError ... + BillingTransientError ErrorResponseCode = "BillingTransientError" + // CalculatePriceFailed ... + CalculatePriceFailed ErrorResponseCode = "CalculatePriceFailed" + // CapacityUpdateScopesFailed ... + CapacityUpdateScopesFailed ErrorResponseCode = "CapacityUpdateScopesFailed" + // ClientCertificateThumbprintNotSet ... + ClientCertificateThumbprintNotSet ErrorResponseCode = "ClientCertificateThumbprintNotSet" + // CreateQuoteFailed ... + CreateQuoteFailed ErrorResponseCode = "CreateQuoteFailed" + // Forbidden ... + Forbidden ErrorResponseCode = "Forbidden" + // FulfillmentConfigurationError ... + FulfillmentConfigurationError ErrorResponseCode = "FulfillmentConfigurationError" + // FulfillmentError ... + FulfillmentError ErrorResponseCode = "FulfillmentError" + // FulfillmentOutOfStockError ... + FulfillmentOutOfStockError ErrorResponseCode = "FulfillmentOutOfStockError" + // FulfillmentTransientError ... + FulfillmentTransientError ErrorResponseCode = "FulfillmentTransientError" + // HTTPMethodNotSupported ... + HTTPMethodNotSupported ErrorResponseCode = "HttpMethodNotSupported" + // InternalServerError ... + InternalServerError ErrorResponseCode = "InternalServerError" + // InvalidAccessToken ... + InvalidAccessToken ErrorResponseCode = "InvalidAccessToken" + // InvalidFulfillmentRequestParameters ... + InvalidFulfillmentRequestParameters ErrorResponseCode = "InvalidFulfillmentRequestParameters" + // InvalidHealthCheckType ... + InvalidHealthCheckType ErrorResponseCode = "InvalidHealthCheckType" + // InvalidLocationID ... + InvalidLocationID ErrorResponseCode = "InvalidLocationId" + // InvalidRefundQuantity ... + InvalidRefundQuantity ErrorResponseCode = "InvalidRefundQuantity" + // InvalidRequestContent ... + InvalidRequestContent ErrorResponseCode = "InvalidRequestContent" + // InvalidRequestURI ... + InvalidRequestURI ErrorResponseCode = "InvalidRequestUri" + // InvalidReservationID ... + InvalidReservationID ErrorResponseCode = "InvalidReservationId" + // InvalidReservationOrderID ... + InvalidReservationOrderID ErrorResponseCode = "InvalidReservationOrderId" + // InvalidSingleAppliedScopesCount ... + InvalidSingleAppliedScopesCount ErrorResponseCode = "InvalidSingleAppliedScopesCount" + // InvalidSubscriptionID ... + InvalidSubscriptionID ErrorResponseCode = "InvalidSubscriptionId" + // InvalidTenantID ... + InvalidTenantID ErrorResponseCode = "InvalidTenantId" + // MissingAppliedScopesForSingle ... + MissingAppliedScopesForSingle ErrorResponseCode = "MissingAppliedScopesForSingle" + // MissingTenantID ... + MissingTenantID ErrorResponseCode = "MissingTenantId" + // NonsupportedAccountID ... + NonsupportedAccountID ErrorResponseCode = "NonsupportedAccountId" + // NotSpecified ... + NotSpecified ErrorResponseCode = "NotSpecified" + // NotSupportedCountry ... + NotSupportedCountry ErrorResponseCode = "NotSupportedCountry" + // NoValidReservationsToReRate ... + NoValidReservationsToReRate ErrorResponseCode = "NoValidReservationsToReRate" + // OperationCannotBePerformedInCurrentState ... + OperationCannotBePerformedInCurrentState ErrorResponseCode = "OperationCannotBePerformedInCurrentState" + // OperationFailed ... + OperationFailed ErrorResponseCode = "OperationFailed" + // PatchValuesSameAsExisting ... + PatchValuesSameAsExisting ErrorResponseCode = "PatchValuesSameAsExisting" + // PaymentInstrumentNotFound ... + PaymentInstrumentNotFound ErrorResponseCode = "PaymentInstrumentNotFound" + // PurchaseError ... + PurchaseError ErrorResponseCode = "PurchaseError" + // ReRateOnlyAllowedForEA ... + ReRateOnlyAllowedForEA ErrorResponseCode = "ReRateOnlyAllowedForEA" + // ReservationIDNotInReservationOrder ... + ReservationIDNotInReservationOrder ErrorResponseCode = "ReservationIdNotInReservationOrder" + // ReservationOrderCreationFailed ... + ReservationOrderCreationFailed ErrorResponseCode = "ReservationOrderCreationFailed" + // ReservationOrderIDAlreadyExists ... + ReservationOrderIDAlreadyExists ErrorResponseCode = "ReservationOrderIdAlreadyExists" + // ReservationOrderNotEnabled ... + ReservationOrderNotEnabled ErrorResponseCode = "ReservationOrderNotEnabled" + // ReservationOrderNotFound ... + ReservationOrderNotFound ErrorResponseCode = "ReservationOrderNotFound" + // RiskCheckFailed ... + RiskCheckFailed ErrorResponseCode = "RiskCheckFailed" + // RoleAssignmentCreationFailed ... + RoleAssignmentCreationFailed ErrorResponseCode = "RoleAssignmentCreationFailed" + // ServerTimeout ... + ServerTimeout ErrorResponseCode = "ServerTimeout" + // UnauthenticatedRequestsThrottled ... + UnauthenticatedRequestsThrottled ErrorResponseCode = "UnauthenticatedRequestsThrottled" + // UnsupportedReservationTerm ... + UnsupportedReservationTerm ErrorResponseCode = "UnsupportedReservationTerm" +) + +// PossibleErrorResponseCodeValues returns an array of possible values for the ErrorResponseCode const type. +func PossibleErrorResponseCodeValues() []ErrorResponseCode { + return []ErrorResponseCode{ActivateQuoteFailed, AppliedScopesNotAssociatedWithCommerceAccount, AuthorizationFailed, BadRequest, BillingCustomerInputError, BillingError, BillingPaymentInstrumentHardError, BillingPaymentInstrumentSoftError, BillingScopeIDCannotBeChanged, BillingTransientError, CalculatePriceFailed, CapacityUpdateScopesFailed, ClientCertificateThumbprintNotSet, CreateQuoteFailed, Forbidden, FulfillmentConfigurationError, FulfillmentError, FulfillmentOutOfStockError, FulfillmentTransientError, HTTPMethodNotSupported, InternalServerError, InvalidAccessToken, InvalidFulfillmentRequestParameters, InvalidHealthCheckType, InvalidLocationID, InvalidRefundQuantity, InvalidRequestContent, InvalidRequestURI, InvalidReservationID, InvalidReservationOrderID, InvalidSingleAppliedScopesCount, InvalidSubscriptionID, InvalidTenantID, MissingAppliedScopesForSingle, MissingTenantID, NonsupportedAccountID, NotSpecified, NotSupportedCountry, NoValidReservationsToReRate, OperationCannotBePerformedInCurrentState, OperationFailed, PatchValuesSameAsExisting, PaymentInstrumentNotFound, PurchaseError, ReRateOnlyAllowedForEA, ReservationIDNotInReservationOrder, ReservationOrderCreationFailed, ReservationOrderIDAlreadyExists, ReservationOrderNotEnabled, ReservationOrderNotFound, RiskCheckFailed, RoleAssignmentCreationFailed, ServerTimeout, UnauthenticatedRequestsThrottled, UnsupportedReservationTerm} +} + +// InstanceFlexibility enumerates the values for instance flexibility. +type InstanceFlexibility string + +const ( + // Off ... + Off InstanceFlexibility = "Off" + // On ... + On InstanceFlexibility = "On" +) + +// PossibleInstanceFlexibilityValues returns an array of possible values for the InstanceFlexibility const type. +func PossibleInstanceFlexibilityValues() []InstanceFlexibility { + return []InstanceFlexibility{Off, On} +} + +// ReservationTerm enumerates the values for reservation term. +type ReservationTerm string + +const ( + // P1Y ... + P1Y ReservationTerm = "P1Y" + // P3Y ... + P3Y ReservationTerm = "P3Y" +) + +// PossibleReservationTermValues returns an array of possible values for the ReservationTerm const type. +func PossibleReservationTermValues() []ReservationTerm { + return []ReservationTerm{P1Y, P3Y} +} + +// ReservedResourceType enumerates the values for reserved resource type. +type ReservedResourceType string + +const ( + // CosmosDb ... + CosmosDb ReservedResourceType = "CosmosDb" + // SQLDatabases ... + SQLDatabases ReservedResourceType = "SqlDatabases" + // SuseLinux ... + SuseLinux ReservedResourceType = "SuseLinux" + // VirtualMachines ... + VirtualMachines ReservedResourceType = "VirtualMachines" +) + +// PossibleReservedResourceTypeValues returns an array of possible values for the ReservedResourceType const type. +func PossibleReservedResourceTypeValues() []ReservedResourceType { + return []ReservedResourceType{CosmosDb, SQLDatabases, SuseLinux, VirtualMachines} +} + +// StatusCode enumerates the values for status code. +type StatusCode string + +const ( + // StatusCodeActive ... + StatusCodeActive StatusCode = "Active" + // StatusCodeExpired ... + StatusCodeExpired StatusCode = "Expired" + // StatusCodeMerged ... + StatusCodeMerged StatusCode = "Merged" + // StatusCodeNone ... + StatusCodeNone StatusCode = "None" + // StatusCodePaymentInstrumentError ... + StatusCodePaymentInstrumentError StatusCode = "PaymentInstrumentError" + // StatusCodePending ... + StatusCodePending StatusCode = "Pending" + // StatusCodePurchaseError ... + StatusCodePurchaseError StatusCode = "PurchaseError" + // StatusCodeSplit ... + StatusCodeSplit StatusCode = "Split" + // StatusCodeSucceeded ... + StatusCodeSucceeded StatusCode = "Succeeded" +) + +// PossibleStatusCodeValues returns an array of possible values for the StatusCode const type. +func PossibleStatusCodeValues() []StatusCode { + return []StatusCode{StatusCodeActive, StatusCodeExpired, StatusCodeMerged, StatusCodeNone, StatusCodePaymentInstrumentError, StatusCodePending, StatusCodePurchaseError, StatusCodeSplit, StatusCodeSucceeded} +} + +// AppliedReservationList ... +type AppliedReservationList struct { + Value *[]string `json:"value,omitempty"` + // NextLink - Url to get the next page of reservations + NextLink *string `json:"nextLink,omitempty"` +} + +// AppliedReservations ... +type AppliedReservations struct { + autorest.Response `json:"-"` + // ID - Identifier of the applied reservations + ID *string `json:"id,omitempty"` + // Name - Name of resource + Name *string `json:"name,omitempty"` + // Type - Type of resource. "Microsoft.Capacity/AppliedReservations" + Type *string `json:"type,omitempty"` + *AppliedReservationsProperties `json:"properties,omitempty"` +} + +// MarshalJSON is the custom marshaler for AppliedReservations. +func (ar AppliedReservations) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if ar.ID != nil { + objectMap["id"] = ar.ID + } + if ar.Name != nil { + objectMap["name"] = ar.Name + } + if ar.Type != nil { + objectMap["type"] = ar.Type + } + if ar.AppliedReservationsProperties != nil { + objectMap["properties"] = ar.AppliedReservationsProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for AppliedReservations struct. +func (ar *AppliedReservations) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + ar.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + ar.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + ar.Type = &typeVar + } + case "properties": + if v != nil { + var appliedReservationsProperties AppliedReservationsProperties + err = json.Unmarshal(*v, &appliedReservationsProperties) + if err != nil { + return err + } + ar.AppliedReservationsProperties = &appliedReservationsProperties + } + } + } + + return nil +} + +// AppliedReservationsProperties ... +type AppliedReservationsProperties struct { + ReservationOrderIds *AppliedReservationList `json:"reservationOrderIds,omitempty"` +} + +// CalculatePriceResponse ... +type CalculatePriceResponse struct { + autorest.Response `json:"-"` + Properties *CalculatePriceResponseProperties `json:"properties,omitempty"` +} + +// CalculatePriceResponseProperties ... +type CalculatePriceResponseProperties struct { + // BillingCurrencyTotal - Currency and amount that customer will be charged in customer's local currency. Tax is not included. + BillingCurrencyTotal *CalculatePriceResponsePropertiesBillingCurrencyTotal `json:"billingCurrencyTotal,omitempty"` + // IsBillingPartnerManaged - True if billing is managed by Microsoft Partner. Used only for CSP accounts. + IsBillingPartnerManaged *bool `json:"isBillingPartnerManaged,omitempty"` + // ReservationOrderID - GUID that represents reservation order that can be placed after calculating price. + ReservationOrderID *string `json:"reservationOrderId,omitempty"` + // SkuTitle - Title of SKU that is being purchased. + SkuTitle *string `json:"skuTitle,omitempty"` + // SkuDescription - Description of SKU that is being purchased. + SkuDescription *string `json:"skuDescription,omitempty"` + // PricingCurrencyTotal - Amount that Microsoft uses for record. Used during refund for calculating refund limit. Tax is not included. + PricingCurrencyTotal *CalculatePriceResponsePropertiesPricingCurrencyTotal `json:"pricingCurrencyTotal,omitempty"` +} + +// CalculatePriceResponsePropertiesBillingCurrencyTotal currency and amount that customer will be charged +// in customer's local currency. Tax is not included. +type CalculatePriceResponsePropertiesBillingCurrencyTotal struct { + CurrencyCode *string `json:"currencyCode,omitempty"` + Amount *float64 `json:"amount,omitempty"` +} + +// CalculatePriceResponsePropertiesPricingCurrencyTotal amount that Microsoft uses for record. Used during +// refund for calculating refund limit. Tax is not included. +type CalculatePriceResponsePropertiesPricingCurrencyTotal struct { + CurrencyCode *string `json:"currencyCode,omitempty"` + Amount *float64 `json:"amount,omitempty"` +} + +// Catalog ... +type Catalog struct { + // ResourceType - The type of resource the SKU applies to. + ResourceType *string `json:"resourceType,omitempty"` + // Name - The name of SKU + Name *string `json:"name,omitempty"` + // Terms - Available reservation terms for this resource + Terms *[]ReservationTerm `json:"terms,omitempty"` + Locations *[]string `json:"locations,omitempty"` + SkuProperties *[]SkuProperty `json:"skuProperties,omitempty"` + Restrictions *[]SkuRestriction `json:"restrictions,omitempty"` +} + +// Error ... +type Error struct { + Error *ExtendedErrorInfo `json:"error,omitempty"` +} + +// ExtendedErrorInfo ... +type ExtendedErrorInfo struct { + // Code - Possible values include: 'NotSpecified', 'InternalServerError', 'ServerTimeout', 'AuthorizationFailed', 'BadRequest', 'ClientCertificateThumbprintNotSet', 'InvalidRequestContent', 'OperationFailed', 'HTTPMethodNotSupported', 'InvalidRequestURI', 'MissingTenantID', 'InvalidTenantID', 'InvalidReservationOrderID', 'InvalidReservationID', 'ReservationIDNotInReservationOrder', 'ReservationOrderNotFound', 'InvalidSubscriptionID', 'InvalidAccessToken', 'InvalidLocationID', 'UnauthenticatedRequestsThrottled', 'InvalidHealthCheckType', 'Forbidden', 'BillingScopeIDCannotBeChanged', 'AppliedScopesNotAssociatedWithCommerceAccount', 'PatchValuesSameAsExisting', 'RoleAssignmentCreationFailed', 'ReservationOrderCreationFailed', 'ReservationOrderNotEnabled', 'CapacityUpdateScopesFailed', 'UnsupportedReservationTerm', 'ReservationOrderIDAlreadyExists', 'RiskCheckFailed', 'CreateQuoteFailed', 'ActivateQuoteFailed', 'NonsupportedAccountID', 'PaymentInstrumentNotFound', 'MissingAppliedScopesForSingle', 'NoValidReservationsToReRate', 'ReRateOnlyAllowedForEA', 'OperationCannotBePerformedInCurrentState', 'InvalidSingleAppliedScopesCount', 'InvalidFulfillmentRequestParameters', 'NotSupportedCountry', 'InvalidRefundQuantity', 'PurchaseError', 'BillingCustomerInputError', 'BillingPaymentInstrumentSoftError', 'BillingPaymentInstrumentHardError', 'BillingTransientError', 'BillingError', 'FulfillmentConfigurationError', 'FulfillmentOutOfStockError', 'FulfillmentTransientError', 'FulfillmentError', 'CalculatePriceFailed' + Code ErrorResponseCode `json:"code,omitempty"` + Message *string `json:"message,omitempty"` +} + +// ExtendedStatusInfo ... +type ExtendedStatusInfo struct { + // StatusCode - Possible values include: 'StatusCodeNone', 'StatusCodePending', 'StatusCodeActive', 'StatusCodePurchaseError', 'StatusCodePaymentInstrumentError', 'StatusCodeSplit', 'StatusCodeMerged', 'StatusCodeExpired', 'StatusCodeSucceeded' + StatusCode StatusCode `json:"statusCode,omitempty"` + // Message - The message giving detailed information about the status code. + Message *string `json:"message,omitempty"` +} + +// List ... +type List struct { + autorest.Response `json:"-"` + Value *[]Response `json:"value,omitempty"` + // NextLink - Url to get the next page of reservations. + NextLink *string `json:"nextLink,omitempty"` +} + +// ListCatalog ... +type ListCatalog struct { + autorest.Response `json:"-"` + Value *[]Catalog `json:"value,omitempty"` +} + +// ListIterator provides access to a complete listing of Response values. +type ListIterator struct { + i int + page ListPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *ListIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ListIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *ListIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter ListIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter ListIterator) Response() List { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter ListIterator) Value() Response { + if !iter.page.NotDone() { + return Response{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the ListIterator type. +func NewListIterator(page ListPage) ListIterator { + return ListIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (l List) IsEmpty() bool { + return l.Value == nil || len(*l.Value) == 0 +} + +// listPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (l List) listPreparer(ctx context.Context) (*http.Request, error) { + if l.NextLink == nil || len(to.String(l.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(l.NextLink))) +} + +// ListPage contains a page of Response values. +type ListPage struct { + fn func(context.Context, List) (List, error) + l List +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *ListPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ListPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + next, err := page.fn(ctx, page.l) + if err != nil { + return err + } + page.l = next + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *ListPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page ListPage) NotDone() bool { + return !page.l.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page ListPage) Response() List { + return page.l +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page ListPage) Values() []Response { + if page.l.IsEmpty() { + return nil + } + return *page.l.Value +} + +// Creates a new instance of the ListPage type. +func NewListPage(getNextPage func(context.Context, List) (List, error)) ListPage { + return ListPage{fn: getNextPage} +} + +// ListResponse ... +type ListResponse struct { + autorest.Response `json:"-"` + Value *[]Response `json:"value,omitempty"` +} + +// MergeProperties ... +type MergeProperties struct { + // Sources - Format of the resource id should be /providers/Microsoft.Capacity/reservationOrders/{reservationOrderId}/reservations/{reservationId} + Sources *[]string `json:"sources,omitempty"` +} + +// MergePropertiesType ... +type MergePropertiesType struct { + // MergeDestination - Reservation Resource Id Created due to the merge. Format of the resource Id is /providers/Microsoft.Capacity/reservationOrders/{reservationOrderId}/reservations/{reservationId} + MergeDestination *string `json:"mergeDestination,omitempty"` + // MergeSources - Resource Ids of the Source Reservation's merged to form this Reservation. Format of the resource Id is /providers/Microsoft.Capacity/reservationOrders/{reservationOrderId}/reservations/{reservationId} + MergeSources *[]string `json:"mergeSources,omitempty"` +} + +// MergeRequest ... +type MergeRequest struct { + *MergeProperties `json:"properties,omitempty"` +} + +// MarshalJSON is the custom marshaler for MergeRequest. +func (mr MergeRequest) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if mr.MergeProperties != nil { + objectMap["properties"] = mr.MergeProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for MergeRequest struct. +func (mr *MergeRequest) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var mergeProperties MergeProperties + err = json.Unmarshal(*v, &mergeProperties) + if err != nil { + return err + } + mr.MergeProperties = &mergeProperties + } + } + } + + return nil +} + +// OperationDisplay ... +type OperationDisplay struct { + Provider *string `json:"provider,omitempty"` + Resource *string `json:"resource,omitempty"` + Operation *string `json:"operation,omitempty"` + Description *string `json:"description,omitempty"` +} + +// OperationList ... +type OperationList struct { + autorest.Response `json:"-"` + Value *[]OperationResponse `json:"value,omitempty"` + // NextLink - Url to get the next page of items. + NextLink *string `json:"nextLink,omitempty"` +} + +// OperationListIterator provides access to a complete listing of OperationResponse values. +type OperationListIterator struct { + i int + page OperationListPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *OperationListIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OperationListIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *OperationListIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter OperationListIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter OperationListIterator) Response() OperationList { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter OperationListIterator) Value() OperationResponse { + if !iter.page.NotDone() { + return OperationResponse{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the OperationListIterator type. +func NewOperationListIterator(page OperationListPage) OperationListIterator { + return OperationListIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (ol OperationList) IsEmpty() bool { + return ol.Value == nil || len(*ol.Value) == 0 +} + +// operationListPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (ol OperationList) operationListPreparer(ctx context.Context) (*http.Request, error) { + if ol.NextLink == nil || len(to.String(ol.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(ol.NextLink))) +} + +// OperationListPage contains a page of OperationResponse values. +type OperationListPage struct { + fn func(context.Context, OperationList) (OperationList, error) + ol OperationList +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *OperationListPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OperationListPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + next, err := page.fn(ctx, page.ol) + if err != nil { + return err + } + page.ol = next + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *OperationListPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page OperationListPage) NotDone() bool { + return !page.ol.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page OperationListPage) Response() OperationList { + return page.ol +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page OperationListPage) Values() []OperationResponse { + if page.ol.IsEmpty() { + return nil + } + return *page.ol.Value +} + +// Creates a new instance of the OperationListPage type. +func NewOperationListPage(getNextPage func(context.Context, OperationList) (OperationList, error)) OperationListPage { + return OperationListPage{fn: getNextPage} +} + +// OperationResponse ... +type OperationResponse struct { + Name *string `json:"name,omitempty"` + Display *OperationDisplay `json:"display,omitempty"` + Origin *string `json:"origin,omitempty"` +} + +// OrderList ... +type OrderList struct { + autorest.Response `json:"-"` + Value *[]OrderResponse `json:"value,omitempty"` + // NextLink - Url to get the next page of reservationOrders. + NextLink *string `json:"nextLink,omitempty"` +} + +// OrderListIterator provides access to a complete listing of OrderResponse values. +type OrderListIterator struct { + i int + page OrderListPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *OrderListIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OrderListIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *OrderListIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter OrderListIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter OrderListIterator) Response() OrderList { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter OrderListIterator) Value() OrderResponse { + if !iter.page.NotDone() { + return OrderResponse{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the OrderListIterator type. +func NewOrderListIterator(page OrderListPage) OrderListIterator { + return OrderListIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (ol OrderList) IsEmpty() bool { + return ol.Value == nil || len(*ol.Value) == 0 +} + +// orderListPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (ol OrderList) orderListPreparer(ctx context.Context) (*http.Request, error) { + if ol.NextLink == nil || len(to.String(ol.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(ol.NextLink))) +} + +// OrderListPage contains a page of OrderResponse values. +type OrderListPage struct { + fn func(context.Context, OrderList) (OrderList, error) + ol OrderList +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *OrderListPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OrderListPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + next, err := page.fn(ctx, page.ol) + if err != nil { + return err + } + page.ol = next + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *OrderListPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page OrderListPage) NotDone() bool { + return !page.ol.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page OrderListPage) Response() OrderList { + return page.ol +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page OrderListPage) Values() []OrderResponse { + if page.ol.IsEmpty() { + return nil + } + return *page.ol.Value +} + +// Creates a new instance of the OrderListPage type. +func NewOrderListPage(getNextPage func(context.Context, OrderList) (OrderList, error)) OrderListPage { + return OrderListPage{fn: getNextPage} +} + +// OrderProperties ... +type OrderProperties struct { + // DisplayName - Friendly name for user to easily identified the reservation. + DisplayName *string `json:"displayName,omitempty"` + // RequestDateTime - This is the DateTime when the reservation was initially requested for purchase. + RequestDateTime *date.Time `json:"requestDateTime,omitempty"` + // CreatedDateTime - This is the DateTime when the reservation was created. + CreatedDateTime *date.Time `json:"createdDateTime,omitempty"` + // ExpiryDate - This is the date when the Reservation will expire. + ExpiryDate *date.Date `json:"expiryDate,omitempty"` + OriginalQuantity *int32 `json:"originalQuantity,omitempty"` + // Term - Possible values include: 'P1Y', 'P3Y' + Term ReservationTerm `json:"term,omitempty"` + // ProvisioningState - Current state of the reservation. + ProvisioningState *string `json:"provisioningState,omitempty"` + ReservationsProperty *[]Response `json:"reservations,omitempty"` +} + +// OrderPurchaseFuture an abstraction for monitoring and retrieving the results of a long-running +// operation. +type OrderPurchaseFuture struct { + azure.Future +} + +// Result returns the result of the asynchronous operation. +// If the operation has not completed it will return an error. +func (future *OrderPurchaseFuture) Result(client OrderClient) (or OrderResponse, err error) { + var done bool + done, err = future.Done(client) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.OrderPurchaseFuture", "Result", future.Response(), "Polling failure") + return + } + if !done { + err = azure.NewAsyncOpIncompleteError("reservations.OrderPurchaseFuture") + return + } + sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + if or.Response.Response, err = future.GetResult(sender); err == nil && or.Response.Response.StatusCode != http.StatusNoContent { + or, err = client.PurchaseResponder(or.Response.Response) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.OrderPurchaseFuture", "Result", or.Response.Response, "Failure responding to request") + } + } + return +} + +// OrderResponse ... +type OrderResponse struct { + autorest.Response `json:"-"` + Etag *int32 `json:"etag,omitempty"` + // ID - Identifier of the reservation + ID *string `json:"id,omitempty"` + // Name - Name of the reservation + Name *string `json:"name,omitempty"` + *OrderProperties `json:"properties,omitempty"` + // Type - Type of resource. "Microsoft.Capacity/reservations" + Type *string `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for OrderResponse. +func (or OrderResponse) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if or.Etag != nil { + objectMap["etag"] = or.Etag + } + if or.ID != nil { + objectMap["id"] = or.ID + } + if or.Name != nil { + objectMap["name"] = or.Name + } + if or.OrderProperties != nil { + objectMap["properties"] = or.OrderProperties + } + if or.Type != nil { + objectMap["type"] = or.Type + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for OrderResponse struct. +func (or *OrderResponse) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "etag": + if v != nil { + var etag int32 + err = json.Unmarshal(*v, &etag) + if err != nil { + return err + } + or.Etag = &etag + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + or.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + or.Name = &name + } + case "properties": + if v != nil { + var orderProperties OrderProperties + err = json.Unmarshal(*v, &orderProperties) + if err != nil { + return err + } + or.OrderProperties = &orderProperties + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + or.Type = &typeVar + } + } + } + + return nil +} + +// Patch ... +type Patch struct { + *PatchProperties `json:"properties,omitempty"` +} + +// MarshalJSON is the custom marshaler for Patch. +func (p Patch) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if p.PatchProperties != nil { + objectMap["properties"] = p.PatchProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for Patch struct. +func (p *Patch) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var patchProperties PatchProperties + err = json.Unmarshal(*v, &patchProperties) + if err != nil { + return err + } + p.PatchProperties = &patchProperties + } + } + } + + return nil +} + +// PatchProperties ... +type PatchProperties struct { + // AppliedScopeType - Possible values include: 'Single', 'Shared' + AppliedScopeType AppliedScopeType `json:"appliedScopeType,omitempty"` + AppliedScopes *[]string `json:"appliedScopes,omitempty"` + // InstanceFlexibility - Possible values include: 'On', 'Off' + InstanceFlexibility InstanceFlexibility `json:"instanceFlexibility,omitempty"` + // Name - Name of the Reservation + Name *string `json:"name,omitempty"` +} + +// Properties ... +type Properties struct { + // ReservedResourceType - Possible values include: 'VirtualMachines', 'SQLDatabases', 'SuseLinux', 'CosmosDb' + ReservedResourceType ReservedResourceType `json:"reservedResourceType,omitempty"` + // InstanceFlexibility - Possible values include: 'On', 'Off' + InstanceFlexibility InstanceFlexibility `json:"instanceFlexibility,omitempty"` + // DisplayName - Friendly name for user to easily identify the reservation + DisplayName *string `json:"displayName,omitempty"` + AppliedScopes *[]string `json:"appliedScopes,omitempty"` + // AppliedScopeType - Possible values include: 'Single', 'Shared' + AppliedScopeType AppliedScopeType `json:"appliedScopeType,omitempty"` + Quantity *int32 `json:"quantity,omitempty"` + // ProvisioningState - Current state of the reservation. + ProvisioningState *string `json:"provisioningState,omitempty"` + // EffectiveDateTime - DateTime of the Reservation starting when this version is effective from. + EffectiveDateTime *date.Time `json:"effectiveDateTime,omitempty"` + // LastUpdatedDateTime - DateTime of the last time the Reservation was updated. + LastUpdatedDateTime *date.Time `json:"lastUpdatedDateTime,omitempty"` + // ExpiryDate - This is the date when the Reservation will expire. + ExpiryDate *date.Date `json:"expiryDate,omitempty"` + // SkuDescription - Description of the SKU in english. + SkuDescription *string `json:"skuDescription,omitempty"` + ExtendedStatusInfo *ExtendedStatusInfo `json:"extendedStatusInfo,omitempty"` + SplitProperties *SplitPropertiesType `json:"splitProperties,omitempty"` + MergeProperties *MergePropertiesType `json:"mergeProperties,omitempty"` +} + +// PurchaseRequest ... +type PurchaseRequest struct { + Sku *SkuName `json:"sku,omitempty"` + // Location - The Azure Region where the reserved resource lives. + Location *string `json:"location,omitempty"` + *PurchaseRequestProperties `json:"properties,omitempty"` +} + +// MarshalJSON is the custom marshaler for PurchaseRequest. +func (pr PurchaseRequest) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if pr.Sku != nil { + objectMap["sku"] = pr.Sku + } + if pr.Location != nil { + objectMap["location"] = pr.Location + } + if pr.PurchaseRequestProperties != nil { + objectMap["properties"] = pr.PurchaseRequestProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for PurchaseRequest struct. +func (pr *PurchaseRequest) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "sku": + if v != nil { + var sku SkuName + err = json.Unmarshal(*v, &sku) + if err != nil { + return err + } + pr.Sku = &sku + } + case "location": + if v != nil { + var location string + err = json.Unmarshal(*v, &location) + if err != nil { + return err + } + pr.Location = &location + } + case "properties": + if v != nil { + var purchaseRequestProperties PurchaseRequestProperties + err = json.Unmarshal(*v, &purchaseRequestProperties) + if err != nil { + return err + } + pr.PurchaseRequestProperties = &purchaseRequestProperties + } + } + } + + return nil +} + +// PurchaseRequestProperties ... +type PurchaseRequestProperties struct { + // ReservedResourceType - Possible values include: 'VirtualMachines', 'SQLDatabases', 'SuseLinux', 'CosmosDb' + ReservedResourceType ReservedResourceType `json:"reservedResourceType,omitempty"` + BillingScopeID *string `json:"billingScopeId,omitempty"` + // Term - Possible values include: 'P1Y', 'P3Y' + Term ReservationTerm `json:"term,omitempty"` + Quantity *int32 `json:"quantity,omitempty"` + // DisplayName - Friendly name of the Reservation + DisplayName *string `json:"displayName,omitempty"` + // AppliedScopeType - Possible values include: 'Single', 'Shared' + AppliedScopeType AppliedScopeType `json:"appliedScopeType,omitempty"` + AppliedScopes *[]string `json:"appliedScopes,omitempty"` + // ReservedResourceProperties - Properties specific to each reserved resource type. Not required if not applicable. + ReservedResourceProperties *PurchaseRequestPropertiesReservedResourceProperties `json:"reservedResourceProperties,omitempty"` +} + +// PurchaseRequestPropertiesReservedResourceProperties properties specific to each reserved resource type. +// Not required if not applicable. +type PurchaseRequestPropertiesReservedResourceProperties struct { + // InstanceFlexibility - Possible values include: 'On', 'Off' + InstanceFlexibility InstanceFlexibility `json:"instanceFlexibility,omitempty"` +} + +// ReservationMergeFuture an abstraction for monitoring and retrieving the results of a long-running +// operation. +type ReservationMergeFuture struct { + azure.Future +} + +// Result returns the result of the asynchronous operation. +// If the operation has not completed it will return an error. +func (future *ReservationMergeFuture) Result(client Client) (lr ListResponse, err error) { + var done bool + done, err = future.Done(client) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.ReservationMergeFuture", "Result", future.Response(), "Polling failure") + return + } + if !done { + err = azure.NewAsyncOpIncompleteError("reservations.ReservationMergeFuture") + return + } + sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + if lr.Response.Response, err = future.GetResult(sender); err == nil && lr.Response.Response.StatusCode != http.StatusNoContent { + lr, err = client.MergeResponder(lr.Response.Response) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.ReservationMergeFuture", "Result", lr.Response.Response, "Failure responding to request") + } + } + return +} + +// ReservationUpdateFuture an abstraction for monitoring and retrieving the results of a long-running +// operation. +type ReservationUpdateFuture struct { + azure.Future +} + +// Result returns the result of the asynchronous operation. +// If the operation has not completed it will return an error. +func (future *ReservationUpdateFuture) Result(client Client) (r Response, err error) { + var done bool + done, err = future.Done(client) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.ReservationUpdateFuture", "Result", future.Response(), "Polling failure") + return + } + if !done { + err = azure.NewAsyncOpIncompleteError("reservations.ReservationUpdateFuture") + return + } + sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + if r.Response.Response, err = future.GetResult(sender); err == nil && r.Response.Response.StatusCode != http.StatusNoContent { + r, err = client.UpdateResponder(r.Response.Response) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.ReservationUpdateFuture", "Result", r.Response.Response, "Failure responding to request") + } + } + return +} + +// Response ... +type Response struct { + autorest.Response `json:"-"` + // Location - The Azure Region where the reserved resource lives. + Location *string `json:"location,omitempty"` + Etag *int32 `json:"etag,omitempty"` + // ID - Identifier of the reservation + ID *string `json:"id,omitempty"` + // Name - Name of the reservation + Name *string `json:"name,omitempty"` + Sku *SkuName `json:"sku,omitempty"` + Properties *Properties `json:"properties,omitempty"` + // Type - Type of resource. "Microsoft.Capacity/reservationOrders/reservations" + Type *string `json:"type,omitempty"` +} + +// SkuName ... +type SkuName struct { + Name *string `json:"name,omitempty"` +} + +// SkuProperty ... +type SkuProperty struct { + // Name - An invariant to describe the feature. + Name *string `json:"name,omitempty"` + // Value - An invariant if the feature is measured by quantity. + Value *string `json:"value,omitempty"` +} + +// SkuRestriction ... +type SkuRestriction struct { + // Type - The type of restrictions. + Type *string `json:"type,omitempty"` + // Values - The value of restrictions. If the restriction type is set to location. This would be different locations where the SKU is restricted. + Values *[]string `json:"values,omitempty"` + // ReasonCode - The reason for restriction. + ReasonCode *string `json:"reasonCode,omitempty"` +} + +// SplitFuture an abstraction for monitoring and retrieving the results of a long-running operation. +type SplitFuture struct { + azure.Future +} + +// Result returns the result of the asynchronous operation. +// If the operation has not completed it will return an error. +func (future *SplitFuture) Result(client Client) (lr ListResponse, err error) { + var done bool + done, err = future.Done(client) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.SplitFuture", "Result", future.Response(), "Polling failure") + return + } + if !done { + err = azure.NewAsyncOpIncompleteError("reservations.SplitFuture") + return + } + sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + if lr.Response.Response, err = future.GetResult(sender); err == nil && lr.Response.Response.StatusCode != http.StatusNoContent { + lr, err = client.SplitResponder(lr.Response.Response) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.SplitFuture", "Result", lr.Response.Response, "Failure responding to request") + } + } + return +} + +// SplitProperties ... +type SplitProperties struct { + // Quantities - List of the quantities in the new reservations to create. + Quantities *[]int32 `json:"quantities,omitempty"` + // ReservationID - Resource id of the reservation to be split. Format of the resource id should be /providers/Microsoft.Capacity/reservationOrders/{reservationOrderId}/reservations/{reservationId} + ReservationID *string `json:"reservationId,omitempty"` +} + +// SplitPropertiesType ... +type SplitPropertiesType struct { + // SplitDestinations - List of destination Resource Id that are created due to split. Format of the resource Id is /providers/Microsoft.Capacity/reservationOrders/{reservationOrderId}/reservations/{reservationId} + SplitDestinations *[]string `json:"splitDestinations,omitempty"` + // SplitSource - Resource Id of the Reservation from which this is split. Format of the resource Id is /providers/Microsoft.Capacity/reservationOrders/{reservationOrderId}/reservations/{reservationId} + SplitSource *string `json:"splitSource,omitempty"` +} + +// SplitRequest ... +type SplitRequest struct { + *SplitProperties `json:"properties,omitempty"` +} + +// MarshalJSON is the custom marshaler for SplitRequest. +func (sr SplitRequest) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if sr.SplitProperties != nil { + objectMap["properties"] = sr.SplitProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for SplitRequest struct. +func (sr *SplitRequest) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var splitProperties SplitProperties + err = json.Unmarshal(*v, &splitProperties) + if err != nil { + return err + } + sr.SplitProperties = &splitProperties + } + } + } + + return nil +} diff --git a/services/preview/reservations/mgmt/2019-04-01/reservations/operation.go b/services/preview/reservations/mgmt/2019-04-01/reservations/operation.go new file mode 100644 index 000000000000..ce6d56887749 --- /dev/null +++ b/services/preview/reservations/mgmt/2019-04-01/reservations/operation.go @@ -0,0 +1,147 @@ +package reservations + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// OperationClient is the this API describe Azure Reservation +type OperationClient struct { + BaseClient +} + +// NewOperationClient creates an instance of the OperationClient client. +func NewOperationClient() OperationClient { + return NewOperationClientWithBaseURI(DefaultBaseURI) +} + +// NewOperationClientWithBaseURI creates an instance of the OperationClient client. +func NewOperationClientWithBaseURI(baseURI string) OperationClient { + return OperationClient{NewWithBaseURI(baseURI)} +} + +// List list all the operations. +func (client OperationClient) List(ctx context.Context) (result OperationListPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OperationClient.List") + defer func() { + sc := -1 + if result.ol.Response.Response != nil { + sc = result.ol.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.OperationClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.ol.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "reservations.OperationClient", "List", resp, "Failure sending request") + return + } + + result.ol, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.OperationClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client OperationClient) ListPreparer(ctx context.Context) (*http.Request, error) { + const APIVersion = "2019-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPath("/providers/Microsoft.Capacity/operations"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client OperationClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client OperationClient) ListResponder(resp *http.Response) (result OperationList, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client OperationClient) listNextResults(ctx context.Context, lastResults OperationList) (result OperationList, err error) { + req, err := lastResults.operationListPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "reservations.OperationClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "reservations.OperationClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.OperationClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client OperationClient) ListComplete(ctx context.Context) (result OperationListIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OperationClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx) + return +} diff --git a/services/preview/reservations/mgmt/2019-04-01/reservations/order.go b/services/preview/reservations/mgmt/2019-04-01/reservations/order.go new file mode 100644 index 000000000000..52411bf7b3a9 --- /dev/null +++ b/services/preview/reservations/mgmt/2019-04-01/reservations/order.go @@ -0,0 +1,370 @@ +package reservations + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// OrderClient is the this API describe Azure Reservation +type OrderClient struct { + BaseClient +} + +// NewOrderClient creates an instance of the OrderClient client. +func NewOrderClient() OrderClient { + return NewOrderClientWithBaseURI(DefaultBaseURI) +} + +// NewOrderClientWithBaseURI creates an instance of the OrderClient client. +func NewOrderClientWithBaseURI(baseURI string) OrderClient { + return OrderClient{NewWithBaseURI(baseURI)} +} + +// Calculate calculate price for placing a `ReservationOrder`. +// Parameters: +// body - information needed for calculate or purchase reservation +func (client OrderClient) Calculate(ctx context.Context, body PurchaseRequest) (result CalculatePriceResponse, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OrderClient.Calculate") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.CalculatePreparer(ctx, body) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.OrderClient", "Calculate", nil, "Failure preparing request") + return + } + + resp, err := client.CalculateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "reservations.OrderClient", "Calculate", resp, "Failure sending request") + return + } + + result, err = client.CalculateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.OrderClient", "Calculate", resp, "Failure responding to request") + } + + return +} + +// CalculatePreparer prepares the Calculate request. +func (client OrderClient) CalculatePreparer(ctx context.Context, body PurchaseRequest) (*http.Request, error) { + const APIVersion = "2019-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPath("/providers/Microsoft.Capacity/calculatePrice"), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CalculateSender sends the Calculate request. The method will close the +// http.Response Body if it receives an error. +func (client OrderClient) CalculateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CalculateResponder handles the response to the Calculate request. The method always +// closes the http.Response Body. +func (client OrderClient) CalculateResponder(resp *http.Response) (result CalculatePriceResponse, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Get get the details of the `ReservationOrder`. +// Parameters: +// reservationOrderID - order Id of the reservation +func (client OrderClient) Get(ctx context.Context, reservationOrderID string) (result OrderResponse, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OrderClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetPreparer(ctx, reservationOrderID) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.OrderClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "reservations.OrderClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.OrderClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client OrderClient) GetPreparer(ctx context.Context, reservationOrderID string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "reservationOrderId": autorest.Encode("path", reservationOrderID), + } + + const APIVersion = "2019-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Capacity/reservationOrders/{reservationOrderId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client OrderClient) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client OrderClient) GetResponder(resp *http.Response) (result OrderResponse, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List list of all the `ReservationOrder`s that the user has access to in the current tenant. +func (client OrderClient) List(ctx context.Context) (result OrderListPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OrderClient.List") + defer func() { + sc := -1 + if result.ol.Response.Response != nil { + sc = result.ol.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.OrderClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.ol.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "reservations.OrderClient", "List", resp, "Failure sending request") + return + } + + result.ol, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.OrderClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client OrderClient) ListPreparer(ctx context.Context) (*http.Request, error) { + const APIVersion = "2019-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPath("/providers/Microsoft.Capacity/reservationOrders"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client OrderClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client OrderClient) ListResponder(resp *http.Response) (result OrderList, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client OrderClient) listNextResults(ctx context.Context, lastResults OrderList) (result OrderList, err error) { + req, err := lastResults.orderListPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "reservations.OrderClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "reservations.OrderClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.OrderClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client OrderClient) ListComplete(ctx context.Context) (result OrderListIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OrderClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx) + return +} + +// Purchase purchase `ReservationOrder` and create resource under the specified URI. +// Parameters: +// reservationOrderID - order Id of the reservation +// body - information needed for calculate or purchase reservation +func (client OrderClient) Purchase(ctx context.Context, reservationOrderID string, body PurchaseRequest) (result OrderPurchaseFuture, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OrderClient.Purchase") + defer func() { + sc := -1 + if result.Response() != nil { + sc = result.Response().StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.PurchasePreparer(ctx, reservationOrderID, body) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.OrderClient", "Purchase", nil, "Failure preparing request") + return + } + + result, err = client.PurchaseSender(req) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.OrderClient", "Purchase", result.Response(), "Failure sending request") + return + } + + return +} + +// PurchasePreparer prepares the Purchase request. +func (client OrderClient) PurchasePreparer(ctx context.Context, reservationOrderID string, body PurchaseRequest) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "reservationOrderId": autorest.Encode("path", reservationOrderID), + } + + const APIVersion = "2019-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Capacity/reservationOrders/{reservationOrderId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// PurchaseSender sends the Purchase request. The method will close the +// http.Response Body if it receives an error. +func (client OrderClient) PurchaseSender(req *http.Request) (future OrderPurchaseFuture, err error) { + var resp *http.Response + resp, err = autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + if err != nil { + return + } + future.Future, err = azure.NewFutureFromResponse(resp) + return +} + +// PurchaseResponder handles the response to the Purchase request. The method always +// closes the http.Response Body. +func (client OrderClient) PurchaseResponder(resp *http.Response) (result OrderResponse, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/services/preview/reservations/mgmt/2019-04-01/reservations/reservation.go b/services/preview/reservations/mgmt/2019-04-01/reservations/reservation.go new file mode 100644 index 000000000000..7ea4c3a4afef --- /dev/null +++ b/services/preview/reservations/mgmt/2019-04-01/reservations/reservation.go @@ -0,0 +1,577 @@ +package reservations + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// Client is the this API describe Azure Reservation +type Client struct { + BaseClient +} + +// NewClient creates an instance of the Client client. +func NewClient() Client { + return NewClientWithBaseURI(DefaultBaseURI) +} + +// NewClientWithBaseURI creates an instance of the Client client. +func NewClientWithBaseURI(baseURI string) Client { + return Client{NewWithBaseURI(baseURI)} +} + +// Get get specific `Reservation` details. +// Parameters: +// reservationID - id of the Reservation Item +// reservationOrderID - order Id of the reservation +func (client Client) Get(ctx context.Context, reservationID string, reservationOrderID string) (result Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/Client.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetPreparer(ctx, reservationID, reservationOrderID) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.Client", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "reservations.Client", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.Client", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client Client) GetPreparer(ctx context.Context, reservationID string, reservationOrderID string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "reservationId": autorest.Encode("path", reservationID), + "reservationOrderId": autorest.Encode("path", reservationOrderID), + } + + const APIVersion = "2019-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Capacity/reservationOrders/{reservationOrderId}/reservations/{reservationId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client Client) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client Client) GetResponder(resp *http.Response) (result Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List list `Reservation`s within a single `ReservationOrder`. +// Parameters: +// reservationOrderID - order Id of the reservation +func (client Client) List(ctx context.Context, reservationOrderID string) (result ListPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/Client.List") + defer func() { + sc := -1 + if result.l.Response.Response != nil { + sc = result.l.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, reservationOrderID) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.Client", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.l.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "reservations.Client", "List", resp, "Failure sending request") + return + } + + result.l, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.Client", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client Client) ListPreparer(ctx context.Context, reservationOrderID string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "reservationOrderId": autorest.Encode("path", reservationOrderID), + } + + const APIVersion = "2019-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Capacity/reservationOrders/{reservationOrderId}/reservations", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client Client) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client Client) ListResponder(resp *http.Response) (result List, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client Client) listNextResults(ctx context.Context, lastResults List) (result List, err error) { + req, err := lastResults.listPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "reservations.Client", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "reservations.Client", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.Client", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client Client) ListComplete(ctx context.Context, reservationOrderID string) (result ListIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/Client.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx, reservationOrderID) + return +} + +// ListRevisions list of all the revisions for the `Reservation`. +// Parameters: +// reservationID - id of the Reservation Item +// reservationOrderID - order Id of the reservation +func (client Client) ListRevisions(ctx context.Context, reservationID string, reservationOrderID string) (result ListPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/Client.ListRevisions") + defer func() { + sc := -1 + if result.l.Response.Response != nil { + sc = result.l.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listRevisionsNextResults + req, err := client.ListRevisionsPreparer(ctx, reservationID, reservationOrderID) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.Client", "ListRevisions", nil, "Failure preparing request") + return + } + + resp, err := client.ListRevisionsSender(req) + if err != nil { + result.l.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "reservations.Client", "ListRevisions", resp, "Failure sending request") + return + } + + result.l, err = client.ListRevisionsResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.Client", "ListRevisions", resp, "Failure responding to request") + } + + return +} + +// ListRevisionsPreparer prepares the ListRevisions request. +func (client Client) ListRevisionsPreparer(ctx context.Context, reservationID string, reservationOrderID string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "reservationId": autorest.Encode("path", reservationID), + "reservationOrderId": autorest.Encode("path", reservationOrderID), + } + + const APIVersion = "2019-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Capacity/reservationOrders/{reservationOrderId}/reservations/{reservationId}/revisions", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListRevisionsSender sends the ListRevisions request. The method will close the +// http.Response Body if it receives an error. +func (client Client) ListRevisionsSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListRevisionsResponder handles the response to the ListRevisions request. The method always +// closes the http.Response Body. +func (client Client) ListRevisionsResponder(resp *http.Response) (result List, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listRevisionsNextResults retrieves the next set of results, if any. +func (client Client) listRevisionsNextResults(ctx context.Context, lastResults List) (result List, err error) { + req, err := lastResults.listPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "reservations.Client", "listRevisionsNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListRevisionsSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "reservations.Client", "listRevisionsNextResults", resp, "Failure sending next results request") + } + result, err = client.ListRevisionsResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.Client", "listRevisionsNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListRevisionsComplete enumerates all values, automatically crossing page boundaries as required. +func (client Client) ListRevisionsComplete(ctx context.Context, reservationID string, reservationOrderID string) (result ListIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/Client.ListRevisions") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListRevisions(ctx, reservationID, reservationOrderID) + return +} + +// Merge merge the specified `Reservation`s into a new `Reservation`. The two `Reservation`s being merged must have +// same properties. +// Parameters: +// reservationOrderID - order Id of the reservation +// body - information needed for commercial request for a reservation +func (client Client) Merge(ctx context.Context, reservationOrderID string, body MergeRequest) (result ReservationMergeFuture, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/Client.Merge") + defer func() { + sc := -1 + if result.Response() != nil { + sc = result.Response().StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.MergePreparer(ctx, reservationOrderID, body) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.Client", "Merge", nil, "Failure preparing request") + return + } + + result, err = client.MergeSender(req) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.Client", "Merge", result.Response(), "Failure sending request") + return + } + + return +} + +// MergePreparer prepares the Merge request. +func (client Client) MergePreparer(ctx context.Context, reservationOrderID string, body MergeRequest) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "reservationOrderId": autorest.Encode("path", reservationOrderID), + } + + const APIVersion = "2019-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Capacity/reservationOrders/{reservationOrderId}/merge", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// MergeSender sends the Merge request. The method will close the +// http.Response Body if it receives an error. +func (client Client) MergeSender(req *http.Request) (future ReservationMergeFuture, err error) { + var resp *http.Response + resp, err = autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + if err != nil { + return + } + future.Future, err = azure.NewFutureFromResponse(resp) + return +} + +// MergeResponder handles the response to the Merge request. The method always +// closes the http.Response Body. +func (client Client) MergeResponder(resp *http.Response) (result ListResponse, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Split split a `Reservation` into two `Reservation`s with specified quantity distribution. +// Parameters: +// reservationOrderID - order Id of the reservation +// body - information needed to Split a reservation item +func (client Client) Split(ctx context.Context, reservationOrderID string, body SplitRequest) (result SplitFuture, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/Client.Split") + defer func() { + sc := -1 + if result.Response() != nil { + sc = result.Response().StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.SplitPreparer(ctx, reservationOrderID, body) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.Client", "Split", nil, "Failure preparing request") + return + } + + result, err = client.SplitSender(req) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.Client", "Split", result.Response(), "Failure sending request") + return + } + + return +} + +// SplitPreparer prepares the Split request. +func (client Client) SplitPreparer(ctx context.Context, reservationOrderID string, body SplitRequest) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "reservationOrderId": autorest.Encode("path", reservationOrderID), + } + + const APIVersion = "2019-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Capacity/reservationOrders/{reservationOrderId}/split", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// SplitSender sends the Split request. The method will close the +// http.Response Body if it receives an error. +func (client Client) SplitSender(req *http.Request) (future SplitFuture, err error) { + var resp *http.Response + resp, err = autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + if err != nil { + return + } + future.Future, err = azure.NewFutureFromResponse(resp) + return +} + +// SplitResponder handles the response to the Split request. The method always +// closes the http.Response Body. +func (client Client) SplitResponder(resp *http.Response) (result ListResponse, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Update updates the applied scopes of the `Reservation`. +// Parameters: +// reservationOrderID - order Id of the reservation +// reservationID - id of the Reservation Item +// parameters - information needed to patch a reservation item +func (client Client) Update(ctx context.Context, reservationOrderID string, reservationID string, parameters Patch) (result ReservationUpdateFuture, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/Client.Update") + defer func() { + sc := -1 + if result.Response() != nil { + sc = result.Response().StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.UpdatePreparer(ctx, reservationOrderID, reservationID, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.Client", "Update", nil, "Failure preparing request") + return + } + + result, err = client.UpdateSender(req) + if err != nil { + err = autorest.NewErrorWithError(err, "reservations.Client", "Update", result.Response(), "Failure sending request") + return + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client Client) UpdatePreparer(ctx context.Context, reservationOrderID string, reservationID string, parameters Patch) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "reservationId": autorest.Encode("path", reservationID), + "reservationOrderId": autorest.Encode("path", reservationOrderID), + } + + const APIVersion = "2019-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Capacity/reservationOrders/{reservationOrderId}/reservations/{reservationId}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client Client) UpdateSender(req *http.Request) (future ReservationUpdateFuture, err error) { + var resp *http.Response + resp, err = autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + if err != nil { + return + } + future.Future, err = azure.NewFutureFromResponse(resp) + return +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client Client) UpdateResponder(resp *http.Response) (result Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/services/preview/reservations/mgmt/2019-04-01/reservations/reservationsapi/interfaces.go b/services/preview/reservations/mgmt/2019-04-01/reservations/reservationsapi/interfaces.go new file mode 100644 index 000000000000..fb7faec0646d --- /dev/null +++ b/services/preview/reservations/mgmt/2019-04-01/reservations/reservationsapi/interfaces.go @@ -0,0 +1,60 @@ +package reservationsapi + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/azure-sdk-for-go/services/preview/reservations/mgmt/2019-04-01/reservations" +) + +// BaseClientAPI contains the set of methods on the BaseClient type. +type BaseClientAPI interface { + GetAppliedReservationList(ctx context.Context, subscriptionID string) (result reservations.AppliedReservations, err error) + GetCatalog(ctx context.Context, subscriptionID string, reservedResourceType string, location string) (result reservations.ListCatalog, err error) +} + +var _ BaseClientAPI = (*reservations.BaseClient)(nil) + +// OrderClientAPI contains the set of methods on the OrderClient type. +type OrderClientAPI interface { + Calculate(ctx context.Context, body reservations.PurchaseRequest) (result reservations.CalculatePriceResponse, err error) + Get(ctx context.Context, reservationOrderID string) (result reservations.OrderResponse, err error) + List(ctx context.Context) (result reservations.OrderListPage, err error) + Purchase(ctx context.Context, reservationOrderID string, body reservations.PurchaseRequest) (result reservations.OrderPurchaseFuture, err error) +} + +var _ OrderClientAPI = (*reservations.OrderClient)(nil) + +// ClientAPI contains the set of methods on the Client type. +type ClientAPI interface { + Get(ctx context.Context, reservationID string, reservationOrderID string) (result reservations.Response, err error) + List(ctx context.Context, reservationOrderID string) (result reservations.ListPage, err error) + ListRevisions(ctx context.Context, reservationID string, reservationOrderID string) (result reservations.ListPage, err error) + Merge(ctx context.Context, reservationOrderID string, body reservations.MergeRequest) (result reservations.ReservationMergeFuture, err error) + Split(ctx context.Context, reservationOrderID string, body reservations.SplitRequest) (result reservations.SplitFuture, err error) + Update(ctx context.Context, reservationOrderID string, reservationID string, parameters reservations.Patch) (result reservations.ReservationUpdateFuture, err error) +} + +var _ ClientAPI = (*reservations.Client)(nil) + +// OperationClientAPI contains the set of methods on the OperationClient type. +type OperationClientAPI interface { + List(ctx context.Context) (result reservations.OperationListPage, err error) +} + +var _ OperationClientAPI = (*reservations.OperationClient)(nil) diff --git a/services/preview/reservations/mgmt/2019-04-01/reservations/version.go b/services/preview/reservations/mgmt/2019-04-01/reservations/version.go new file mode 100644 index 000000000000..dcf01044ad00 --- /dev/null +++ b/services/preview/reservations/mgmt/2019-04-01/reservations/version.go @@ -0,0 +1,30 @@ +package reservations + +import "github.com/Azure/azure-sdk-for-go/version" + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +// UserAgent returns the UserAgent string to use when sending http.Requests. +func UserAgent() string { + return "Azure-SDK-For-Go/" + version.Number + " reservations/2019-04-01" +} + +// Version returns the semantic version (see http://semver.org) of the client. +func Version() string { + return version.Number +}