UNPKG

@azure/arm-compute

Version:
389 lines 16.9 kB
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. import { setContinuationToken } from "../pagingHelper.js"; import * as coreClient from "@azure/core-client"; import * as Mappers from "../models/mappers.js"; import * as Parameters from "../models/parameters.js"; import { createHttpPoller } from "@azure/core-lro"; import { createLroSpec } from "../lroImpl.js"; /// <reference lib="esnext.asynciterable" /> /** Class containing DiskRestorePointOperations operations. */ export class DiskRestorePointOperationsImpl { client; /** * Initialize a new instance of the class DiskRestorePointOperations class. * @param client Reference to the service client */ constructor(client) { this.client = client; } /** * Lists diskRestorePoints under a vmRestorePoint. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param restorePointCollectionName The name of the restore point collection that the disk restore * point belongs. * @param vmRestorePointName The name of the vm restore point that the disk disk restore point belongs. * @param options The options parameters. */ listByRestorePoint(resourceGroupName, restorePointCollectionName, vmRestorePointName, options) { const iter = this.listByRestorePointPagingAll(resourceGroupName, restorePointCollectionName, vmRestorePointName, 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.listByRestorePointPagingPage(resourceGroupName, restorePointCollectionName, vmRestorePointName, options, settings); }, }; } async *listByRestorePointPagingPage(resourceGroupName, restorePointCollectionName, vmRestorePointName, options, settings) { let result; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._listByRestorePoint(resourceGroupName, restorePointCollectionName, vmRestorePointName, options); const page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listByRestorePointNext(resourceGroupName, restorePointCollectionName, vmRestorePointName, continuationToken, options); continuationToken = result.nextLink; const page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } async *listByRestorePointPagingAll(resourceGroupName, restorePointCollectionName, vmRestorePointName, options) { for await (const page of this.listByRestorePointPagingPage(resourceGroupName, restorePointCollectionName, vmRestorePointName, options)) { yield* page; } } /** * Lists diskRestorePoints under a vmRestorePoint. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param restorePointCollectionName The name of the restore point collection that the disk restore * point belongs. * @param vmRestorePointName The name of the vm restore point that the disk disk restore point belongs. * @param options The options parameters. */ _listByRestorePoint(resourceGroupName, restorePointCollectionName, vmRestorePointName, options) { return this.client.sendOperationRequest({ resourceGroupName, restorePointCollectionName, vmRestorePointName, options, }, listByRestorePointOperationSpec); } /** * Get disk restorePoint resource * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param restorePointCollectionName The name of the restore point collection that the disk restore * point belongs. * @param vmRestorePointName The name of the vm restore point that the disk disk restore point belongs. * @param diskRestorePointName The name of the DiskRestorePoint * @param options The options parameters. */ get(resourceGroupName, restorePointCollectionName, vmRestorePointName, diskRestorePointName, options) { return this.client.sendOperationRequest({ resourceGroupName, restorePointCollectionName, vmRestorePointName, diskRestorePointName, options, }, getOperationSpec); } /** * Grants access to a diskRestorePoint. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param restorePointCollectionName The name of the restore point collection that the disk restore * point belongs. * @param vmRestorePointName The name of the vm restore point that the disk disk restore point belongs. * @param diskRestorePointName The name of the DiskRestorePoint * @param grantAccessData Access data object supplied in the body of the get disk access operation. * @param options The options parameters. */ async beginGrantAccess(resourceGroupName, restorePointCollectionName, vmRestorePointName, diskRestorePointName, grantAccessData, 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 = createLroSpec({ sendOperationFn, args: { resourceGroupName, restorePointCollectionName, vmRestorePointName, diskRestorePointName, grantAccessData, options, }, spec: grantAccessOperationSpec, }); const poller = await createHttpPoller(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs, resourceLocationConfig: "location", }); await poller.poll(); return poller; } /** * Grants access to a diskRestorePoint. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param restorePointCollectionName The name of the restore point collection that the disk restore * point belongs. * @param vmRestorePointName The name of the vm restore point that the disk disk restore point belongs. * @param diskRestorePointName The name of the DiskRestorePoint * @param grantAccessData Access data object supplied in the body of the get disk access operation. * @param options The options parameters. */ async beginGrantAccessAndWait(resourceGroupName, restorePointCollectionName, vmRestorePointName, diskRestorePointName, grantAccessData, options) { const poller = await this.beginGrantAccess(resourceGroupName, restorePointCollectionName, vmRestorePointName, diskRestorePointName, grantAccessData, options); return poller.pollUntilDone(); } /** * Revokes access to a diskRestorePoint. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param restorePointCollectionName The name of the restore point collection that the disk restore * point belongs. * @param vmRestorePointName The name of the vm restore point that the disk disk restore point belongs. * @param diskRestorePointName The name of the DiskRestorePoint * @param options The options parameters. */ async beginRevokeAccess(resourceGroupName, restorePointCollectionName, vmRestorePointName, diskRestorePointName, 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 = createLroSpec({ sendOperationFn, args: { resourceGroupName, restorePointCollectionName, vmRestorePointName, diskRestorePointName, options, }, spec: revokeAccessOperationSpec, }); const poller = await createHttpPoller(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs, resourceLocationConfig: "location", }); await poller.poll(); return poller; } /** * Revokes access to a diskRestorePoint. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param restorePointCollectionName The name of the restore point collection that the disk restore * point belongs. * @param vmRestorePointName The name of the vm restore point that the disk disk restore point belongs. * @param diskRestorePointName The name of the DiskRestorePoint * @param options The options parameters. */ async beginRevokeAccessAndWait(resourceGroupName, restorePointCollectionName, vmRestorePointName, diskRestorePointName, options) { const poller = await this.beginRevokeAccess(resourceGroupName, restorePointCollectionName, vmRestorePointName, diskRestorePointName, options); return poller.pollUntilDone(); } /** * ListByRestorePointNext * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param restorePointCollectionName The name of the restore point collection that the disk restore * point belongs. * @param vmRestorePointName The name of the vm restore point that the disk disk restore point belongs. * @param nextLink The nextLink from the previous successful call to the ListByRestorePoint method. * @param options The options parameters. */ _listByRestorePointNext(resourceGroupName, restorePointCollectionName, vmRestorePointName, nextLink, options) { return this.client.sendOperationRequest({ resourceGroupName, restorePointCollectionName, vmRestorePointName, nextLink, options, }, listByRestorePointNextOperationSpec); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const listByRestorePointOperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/restorePointCollections/{restorePointCollectionName}/restorePoints/{vmRestorePointName}/diskRestorePoints", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.DiskRestorePointList, }, default: { bodyMapper: Mappers.CloudError, }, }, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.restorePointCollectionName, Parameters.vmRestorePointName, ], headerParameters: [Parameters.accept], serializer, }; const getOperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/restorePointCollections/{restorePointCollectionName}/restorePoints/{vmRestorePointName}/diskRestorePoints/{diskRestorePointName}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.DiskRestorePoint, }, default: { bodyMapper: Mappers.CloudError, }, }, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.restorePointCollectionName, Parameters.vmRestorePointName, Parameters.diskRestorePointName, ], headerParameters: [Parameters.accept], serializer, }; const grantAccessOperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/restorePointCollections/{restorePointCollectionName}/restorePoints/{vmRestorePointName}/diskRestorePoints/{diskRestorePointName}/beginGetAccess", httpMethod: "POST", responses: { 200: { bodyMapper: Mappers.AccessUri, }, 201: { bodyMapper: Mappers.AccessUri, }, 202: { bodyMapper: Mappers.AccessUri, }, 204: { bodyMapper: Mappers.AccessUri, }, default: { bodyMapper: Mappers.CloudError, }, }, requestBody: Parameters.grantAccessData, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.restorePointCollectionName, Parameters.vmRestorePointName, Parameters.diskRestorePointName, ], headerParameters: [Parameters.accept, Parameters.contentType], mediaType: "json", serializer, }; const revokeAccessOperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/restorePointCollections/{restorePointCollectionName}/restorePoints/{vmRestorePointName}/diskRestorePoints/{diskRestorePointName}/endGetAccess", httpMethod: "POST", responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: { bodyMapper: Mappers.CloudError, }, }, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.restorePointCollectionName, Parameters.vmRestorePointName, Parameters.diskRestorePointName, ], headerParameters: [Parameters.accept], serializer, }; const listByRestorePointNextOperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.DiskRestorePointList, }, default: { bodyMapper: Mappers.CloudError, }, }, urlParameters: [ Parameters.$host, Parameters.nextLink, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.restorePointCollectionName, Parameters.vmRestorePointName, ], headerParameters: [Parameters.accept], serializer, }; //# sourceMappingURL=diskRestorePointOperations.js.map