UNPKG

@azure/arm-compute

Version:
475 lines 20.6 kB
"use strict"; /* * Copyright (c) Microsoft Corporation. * Licensed under the MIT License. * * Code generated by Microsoft (R) AutoRest Code Generator. * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.CapacityReservationsImpl = void 0; const tslib_1 = require("tslib"); const pagingHelper_js_1 = require("../pagingHelper.js"); const coreClient = tslib_1.__importStar(require("@azure/core-client")); const Mappers = tslib_1.__importStar(require("../models/mappers.js")); const Parameters = tslib_1.__importStar(require("../models/parameters.js")); const core_lro_1 = require("@azure/core-lro"); const lroImpl_js_1 = require("../lroImpl.js"); /// <reference lib="esnext.asynciterable" /> /** Class containing CapacityReservations operations. */ class CapacityReservationsImpl { client; /** * Initialize a new instance of the class CapacityReservations class. * @param client Reference to the service client */ constructor(client) { this.client = client; } /** * Lists all of the capacity reservations in the specified capacity reservation group. Use the nextLink * property in the response to get the next page of capacity reservations. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param capacityReservationGroupName The name of the capacity reservation group. * @param options The options parameters. */ listByCapacityReservationGroup(resourceGroupName, capacityReservationGroupName, options) { const iter = this.listByCapacityReservationGroupPagingAll(resourceGroupName, capacityReservationGroupName, options); return { next() { return iter.next(); }, [Symbol.asyncIterator]() { return this; }, byPage: (settings) => { if (settings?.maxPageSize) { throw new Error("maxPageSize is not supported by this operation."); } return this.listByCapacityReservationGroupPagingPage(resourceGroupName, capacityReservationGroupName, options, settings); }, }; } async *listByCapacityReservationGroupPagingPage(resourceGroupName, capacityReservationGroupName, options, settings) { let result; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._listByCapacityReservationGroup(resourceGroupName, capacityReservationGroupName, options); let page = result.value || []; continuationToken = result.nextLink; (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken); yield page; } while (continuationToken) { result = await this._listByCapacityReservationGroupNext(resourceGroupName, capacityReservationGroupName, continuationToken, options); continuationToken = result.nextLink; let page = result.value || []; (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken); yield page; } } async *listByCapacityReservationGroupPagingAll(resourceGroupName, capacityReservationGroupName, options) { for await (const page of this.listByCapacityReservationGroupPagingPage(resourceGroupName, capacityReservationGroupName, options)) { yield* page; } } /** * Lists all of the capacity reservations in the specified capacity reservation group. Use the nextLink * property in the response to get the next page of capacity reservations. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param capacityReservationGroupName The name of the capacity reservation group. * @param options The options parameters. */ _listByCapacityReservationGroup(resourceGroupName, capacityReservationGroupName, options) { return this.client.sendOperationRequest({ resourceGroupName, capacityReservationGroupName, options }, listByCapacityReservationGroupOperationSpec); } /** * The operation that retrieves information about the capacity reservation. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param capacityReservationGroupName The name of the capacity reservation group. * @param capacityReservationName The name of the capacity reservation. * @param options The options parameters. */ get(resourceGroupName, capacityReservationGroupName, capacityReservationName, options) { return this.client.sendOperationRequest({ resourceGroupName, capacityReservationGroupName, capacityReservationName, options, }, getOperationSpec); } /** * The operation to create or update a capacity reservation. Please note some properties can be set * only during capacity reservation creation. Please refer to https://aka.ms/CapacityReservation for * more details. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param capacityReservationGroupName The name of the capacity reservation group. * @param capacityReservationName The name of the capacity reservation. * @param parameters Parameters supplied to the Create capacity reservation. * @param options The options parameters. */ async beginCreateOrUpdate(resourceGroupName, capacityReservationGroupName, capacityReservationName, parameters, options) { const directSendOperation = async (args, spec) => { return this.client.sendOperationRequest(args, spec); }; const sendOperationFn = async (args, spec) => { let currentRawResponse = undefined; const providedCallback = args.options?.onResponse; const callback = (rawResponse, flatResponse) => { currentRawResponse = rawResponse; providedCallback?.(rawResponse, flatResponse); }; const updatedArgs = { ...args, options: { ...args.options, onResponse: callback, }, }; const flatResponse = await directSendOperation(updatedArgs, spec); return { flatResponse, rawResponse: { statusCode: currentRawResponse.status, body: currentRawResponse.parsedBody, headers: currentRawResponse.headers.toJSON(), }, }; }; const lro = (0, lroImpl_js_1.createLroSpec)({ sendOperationFn, args: { resourceGroupName, capacityReservationGroupName, capacityReservationName, parameters, options, }, spec: createOrUpdateOperationSpec, }); const poller = await (0, core_lro_1.createHttpPoller)(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs, resourceLocationConfig: "location", }); await poller.poll(); return poller; } /** * The operation to create or update a capacity reservation. Please note some properties can be set * only during capacity reservation creation. Please refer to https://aka.ms/CapacityReservation for * more details. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param capacityReservationGroupName The name of the capacity reservation group. * @param capacityReservationName The name of the capacity reservation. * @param parameters Parameters supplied to the Create capacity reservation. * @param options The options parameters. */ async beginCreateOrUpdateAndWait(resourceGroupName, capacityReservationGroupName, capacityReservationName, parameters, options) { const poller = await this.beginCreateOrUpdate(resourceGroupName, capacityReservationGroupName, capacityReservationName, parameters, options); return poller.pollUntilDone(); } /** * The operation to update a capacity reservation. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param capacityReservationGroupName The name of the capacity reservation group. * @param capacityReservationName The name of the capacity reservation. * @param parameters Parameters supplied to the Update capacity reservation operation. * @param options The options parameters. */ async beginUpdate(resourceGroupName, capacityReservationGroupName, capacityReservationName, parameters, options) { const directSendOperation = async (args, spec) => { return this.client.sendOperationRequest(args, spec); }; const sendOperationFn = async (args, spec) => { let currentRawResponse = undefined; const providedCallback = args.options?.onResponse; const callback = (rawResponse, flatResponse) => { currentRawResponse = rawResponse; providedCallback?.(rawResponse, flatResponse); }; const updatedArgs = { ...args, options: { ...args.options, onResponse: callback, }, }; const flatResponse = await directSendOperation(updatedArgs, spec); return { flatResponse, rawResponse: { statusCode: currentRawResponse.status, body: currentRawResponse.parsedBody, headers: currentRawResponse.headers.toJSON(), }, }; }; const lro = (0, lroImpl_js_1.createLroSpec)({ sendOperationFn, args: { resourceGroupName, capacityReservationGroupName, capacityReservationName, parameters, options, }, spec: updateOperationSpec, }); const poller = await (0, core_lro_1.createHttpPoller)(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs, resourceLocationConfig: "location", }); await poller.poll(); return poller; } /** * The operation to update a capacity reservation. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param capacityReservationGroupName The name of the capacity reservation group. * @param capacityReservationName The name of the capacity reservation. * @param parameters Parameters supplied to the Update capacity reservation operation. * @param options The options parameters. */ async beginUpdateAndWait(resourceGroupName, capacityReservationGroupName, capacityReservationName, parameters, options) { const poller = await this.beginUpdate(resourceGroupName, capacityReservationGroupName, capacityReservationName, parameters, options); return poller.pollUntilDone(); } /** * The operation to delete a capacity reservation. This operation is allowed only when all the * associated resources are disassociated from the capacity reservation. Please refer to * https://aka.ms/CapacityReservation for more details. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param capacityReservationGroupName The name of the capacity reservation group. * @param capacityReservationName The name of the capacity reservation. * @param options The options parameters. */ async beginDelete(resourceGroupName, capacityReservationGroupName, capacityReservationName, options) { const directSendOperation = async (args, spec) => { return this.client.sendOperationRequest(args, spec); }; const sendOperationFn = async (args, spec) => { let currentRawResponse = undefined; const providedCallback = args.options?.onResponse; const callback = (rawResponse, flatResponse) => { currentRawResponse = rawResponse; providedCallback?.(rawResponse, flatResponse); }; const updatedArgs = { ...args, options: { ...args.options, onResponse: callback, }, }; const flatResponse = await directSendOperation(updatedArgs, spec); return { flatResponse, rawResponse: { statusCode: currentRawResponse.status, body: currentRawResponse.parsedBody, headers: currentRawResponse.headers.toJSON(), }, }; }; const lro = (0, lroImpl_js_1.createLroSpec)({ sendOperationFn, args: { resourceGroupName, capacityReservationGroupName, capacityReservationName, options, }, spec: deleteOperationSpec, }); const poller = await (0, core_lro_1.createHttpPoller)(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs, resourceLocationConfig: "location", }); await poller.poll(); return poller; } /** * The operation to delete a capacity reservation. This operation is allowed only when all the * associated resources are disassociated from the capacity reservation. Please refer to * https://aka.ms/CapacityReservation for more details. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param capacityReservationGroupName The name of the capacity reservation group. * @param capacityReservationName The name of the capacity reservation. * @param options The options parameters. */ async beginDeleteAndWait(resourceGroupName, capacityReservationGroupName, capacityReservationName, options) { const poller = await this.beginDelete(resourceGroupName, capacityReservationGroupName, capacityReservationName, options); return poller.pollUntilDone(); } /** * ListByCapacityReservationGroupNext * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param capacityReservationGroupName The name of the capacity reservation group. * @param nextLink The nextLink from the previous successful call to the ListByCapacityReservationGroup * method. * @param options The options parameters. */ _listByCapacityReservationGroupNext(resourceGroupName, capacityReservationGroupName, nextLink, options) { return this.client.sendOperationRequest({ resourceGroupName, capacityReservationGroupName, nextLink, options }, listByCapacityReservationGroupNextOperationSpec); } } exports.CapacityReservationsImpl = CapacityReservationsImpl; // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const listByCapacityReservationGroupOperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/capacityReservationGroups/{capacityReservationGroupName}/capacityReservations", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.CapacityReservationListResult, }, default: { bodyMapper: Mappers.CloudError, }, }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.capacityReservationGroupName, ], headerParameters: [Parameters.accept], serializer, }; const getOperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/capacityReservationGroups/{capacityReservationGroupName}/capacityReservations/{capacityReservationName}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.CapacityReservation, }, default: { bodyMapper: Mappers.CloudError, }, }, queryParameters: [Parameters.apiVersion, Parameters.expand9], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.capacityReservationGroupName, Parameters.capacityReservationName, ], headerParameters: [Parameters.accept], serializer, }; const createOrUpdateOperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/capacityReservationGroups/{capacityReservationGroupName}/capacityReservations/{capacityReservationName}", httpMethod: "PUT", responses: { 200: { bodyMapper: Mappers.CapacityReservation, }, 201: { bodyMapper: Mappers.CapacityReservation, }, 202: { bodyMapper: Mappers.CapacityReservation, }, 204: { bodyMapper: Mappers.CapacityReservation, }, default: { bodyMapper: Mappers.CloudError, }, }, requestBody: Parameters.parameters30, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.capacityReservationGroupName, Parameters.capacityReservationName, ], headerParameters: [Parameters.accept, Parameters.contentType], mediaType: "json", serializer, }; const updateOperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/capacityReservationGroups/{capacityReservationGroupName}/capacityReservations/{capacityReservationName}", httpMethod: "PATCH", responses: { 200: { bodyMapper: Mappers.CapacityReservation, }, 201: { bodyMapper: Mappers.CapacityReservation, }, 202: { bodyMapper: Mappers.CapacityReservation, }, 204: { bodyMapper: Mappers.CapacityReservation, }, default: { bodyMapper: Mappers.CloudError, }, }, requestBody: Parameters.parameters31, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.capacityReservationGroupName, Parameters.capacityReservationName, ], headerParameters: [Parameters.accept, Parameters.contentType], mediaType: "json", serializer, }; const deleteOperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/capacityReservationGroups/{capacityReservationGroupName}/capacityReservations/{capacityReservationName}", httpMethod: "DELETE", responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: { bodyMapper: Mappers.CloudError, }, }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.capacityReservationGroupName, Parameters.capacityReservationName, ], headerParameters: [Parameters.accept], serializer, }; const listByCapacityReservationGroupNextOperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.CapacityReservationListResult, }, default: { bodyMapper: Mappers.CloudError, }, }, urlParameters: [ Parameters.$host, Parameters.nextLink, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.capacityReservationGroupName, ], headerParameters: [Parameters.accept], serializer, }; //# sourceMappingURL=capacityReservations.js.map