/* * 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. */ import { PagedAsyncIterableIterator, PageSettings } from "@azure/core-paging"; import { setContinuationToken } from "../pagingHelper"; import { VirtualMachines } from "../operationsInterfaces"; import * as coreClient from "@azure/core-client"; import * as Mappers from "../models/mappers"; import * as Parameters from "../models/parameters"; import { DevTestLabsClient } from "../devTestLabsClient"; import { PollerLike, PollOperationState, LroEngine } from "@azure/core-lro"; import { LroImpl } from "../lroImpl"; import { LabVirtualMachine, VirtualMachinesListNextOptionalParams, VirtualMachinesListOptionalParams, VirtualMachinesListResponse, VirtualMachinesGetOptionalParams, VirtualMachinesGetResponse, VirtualMachinesCreateOrUpdateOptionalParams, VirtualMachinesCreateOrUpdateResponse, VirtualMachinesDeleteOptionalParams, LabVirtualMachineFragment, VirtualMachinesUpdateOptionalParams, VirtualMachinesUpdateResponse, DataDiskProperties, VirtualMachinesAddDataDiskOptionalParams, ApplyArtifactsRequest, VirtualMachinesApplyArtifactsOptionalParams, VirtualMachinesClaimOptionalParams, DetachDataDiskProperties, VirtualMachinesDetachDataDiskOptionalParams, VirtualMachinesGetRdpFileContentsOptionalParams, VirtualMachinesGetRdpFileContentsResponse, VirtualMachinesListApplicableSchedulesOptionalParams, VirtualMachinesListApplicableSchedulesResponse, VirtualMachinesRedeployOptionalParams, ResizeLabVirtualMachineProperties, VirtualMachinesResizeOptionalParams, VirtualMachinesRestartOptionalParams, VirtualMachinesStartOptionalParams, VirtualMachinesStopOptionalParams, VirtualMachinesTransferDisksOptionalParams, VirtualMachinesUnClaimOptionalParams, VirtualMachinesListNextResponse } from "../models"; /// /** Class containing VirtualMachines operations. */ export class VirtualMachinesImpl implements VirtualMachines { private readonly client: DevTestLabsClient; /** * Initialize a new instance of the class VirtualMachines class. * @param client Reference to the service client */ constructor(client: DevTestLabsClient) { this.client = client; } /** * List virtual machines in a given lab. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param options The options parameters. */ public list( resourceGroupName: string, labName: string, options?: VirtualMachinesListOptionalParams ): PagedAsyncIterableIterator { const iter = this.listPagingAll(resourceGroupName, labName, options); return { next() { return iter.next(); }, [Symbol.asyncIterator]() { return this; }, byPage: (settings?: PageSettings) => { if (settings?.maxPageSize) { throw new Error("maxPageSize is not supported by this operation."); } return this.listPagingPage( resourceGroupName, labName, options, settings ); } }; } private async *listPagingPage( resourceGroupName: string, labName: string, options?: VirtualMachinesListOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: VirtualMachinesListResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._list(resourceGroupName, labName, options); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listNext( resourceGroupName, labName, continuationToken, options ); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listPagingAll( resourceGroupName: string, labName: string, options?: VirtualMachinesListOptionalParams ): AsyncIterableIterator { for await (const page of this.listPagingPage( resourceGroupName, labName, options )) { yield* page; } } /** * List virtual machines in a given lab. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param options The options parameters. */ private _list( resourceGroupName: string, labName: string, options?: VirtualMachinesListOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, labName, options }, listOperationSpec ); } /** * Get virtual machine. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param options The options parameters. */ get( resourceGroupName: string, labName: string, name: string, options?: VirtualMachinesGetOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, labName, name, options }, getOperationSpec ); } /** * Create or replace an existing virtual machine. This operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param labVirtualMachine A virtual machine. * @param options The options parameters. */ async beginCreateOrUpdate( resourceGroupName: string, labName: string, name: string, labVirtualMachine: LabVirtualMachine, options?: VirtualMachinesCreateOrUpdateOptionalParams ): Promise< PollerLike< PollOperationState, VirtualMachinesCreateOrUpdateResponse > > { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ) => { let currentRawResponse: | coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown ) => { 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 = new LroImpl( sendOperation, { resourceGroupName, labName, name, labVirtualMachine, options }, createOrUpdateOperationSpec ); const poller = new LroEngine(lro, { resumeFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Create or replace an existing virtual machine. This operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param labVirtualMachine A virtual machine. * @param options The options parameters. */ async beginCreateOrUpdateAndWait( resourceGroupName: string, labName: string, name: string, labVirtualMachine: LabVirtualMachine, options?: VirtualMachinesCreateOrUpdateOptionalParams ): Promise { const poller = await this.beginCreateOrUpdate( resourceGroupName, labName, name, labVirtualMachine, options ); return poller.pollUntilDone(); } /** * Delete virtual machine. This operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param options The options parameters. */ async beginDelete( resourceGroupName: string, labName: string, name: string, options?: VirtualMachinesDeleteOptionalParams ): Promise, void>> { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ) => { let currentRawResponse: | coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown ) => { 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 = new LroImpl( sendOperation, { resourceGroupName, labName, name, options }, deleteOperationSpec ); const poller = new LroEngine(lro, { resumeFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Delete virtual machine. This operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param options The options parameters. */ async beginDeleteAndWait( resourceGroupName: string, labName: string, name: string, options?: VirtualMachinesDeleteOptionalParams ): Promise { const poller = await this.beginDelete( resourceGroupName, labName, name, options ); return poller.pollUntilDone(); } /** * Allows modifying tags of virtual machines. All other properties will be ignored. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param labVirtualMachine A virtual machine. * @param options The options parameters. */ update( resourceGroupName: string, labName: string, name: string, labVirtualMachine: LabVirtualMachineFragment, options?: VirtualMachinesUpdateOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, labName, name, labVirtualMachine, options }, updateOperationSpec ); } /** * Attach a new or existing data disk to virtual machine. This operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param dataDiskProperties Request body for adding a new or existing data disk to a virtual machine. * @param options The options parameters. */ async beginAddDataDisk( resourceGroupName: string, labName: string, name: string, dataDiskProperties: DataDiskProperties, options?: VirtualMachinesAddDataDiskOptionalParams ): Promise, void>> { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ) => { let currentRawResponse: | coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown ) => { 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 = new LroImpl( sendOperation, { resourceGroupName, labName, name, dataDiskProperties, options }, addDataDiskOperationSpec ); const poller = new LroEngine(lro, { resumeFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Attach a new or existing data disk to virtual machine. This operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param dataDiskProperties Request body for adding a new or existing data disk to a virtual machine. * @param options The options parameters. */ async beginAddDataDiskAndWait( resourceGroupName: string, labName: string, name: string, dataDiskProperties: DataDiskProperties, options?: VirtualMachinesAddDataDiskOptionalParams ): Promise { const poller = await this.beginAddDataDisk( resourceGroupName, labName, name, dataDiskProperties, options ); return poller.pollUntilDone(); } /** * Apply artifacts to virtual machine. This operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param applyArtifactsRequest Request body for applying artifacts to a virtual machine. * @param options The options parameters. */ async beginApplyArtifacts( resourceGroupName: string, labName: string, name: string, applyArtifactsRequest: ApplyArtifactsRequest, options?: VirtualMachinesApplyArtifactsOptionalParams ): Promise, void>> { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ) => { let currentRawResponse: | coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown ) => { 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 = new LroImpl( sendOperation, { resourceGroupName, labName, name, applyArtifactsRequest, options }, applyArtifactsOperationSpec ); const poller = new LroEngine(lro, { resumeFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Apply artifacts to virtual machine. This operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param applyArtifactsRequest Request body for applying artifacts to a virtual machine. * @param options The options parameters. */ async beginApplyArtifactsAndWait( resourceGroupName: string, labName: string, name: string, applyArtifactsRequest: ApplyArtifactsRequest, options?: VirtualMachinesApplyArtifactsOptionalParams ): Promise { const poller = await this.beginApplyArtifacts( resourceGroupName, labName, name, applyArtifactsRequest, options ); return poller.pollUntilDone(); } /** * Take ownership of an existing virtual machine This operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param options The options parameters. */ async beginClaim( resourceGroupName: string, labName: string, name: string, options?: VirtualMachinesClaimOptionalParams ): Promise, void>> { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ) => { let currentRawResponse: | coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown ) => { 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 = new LroImpl( sendOperation, { resourceGroupName, labName, name, options }, claimOperationSpec ); const poller = new LroEngine(lro, { resumeFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Take ownership of an existing virtual machine This operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param options The options parameters. */ async beginClaimAndWait( resourceGroupName: string, labName: string, name: string, options?: VirtualMachinesClaimOptionalParams ): Promise { const poller = await this.beginClaim( resourceGroupName, labName, name, options ); return poller.pollUntilDone(); } /** * Detach the specified disk from the virtual machine. This operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param detachDataDiskProperties Request body for detaching data disk from a virtual machine. * @param options The options parameters. */ async beginDetachDataDisk( resourceGroupName: string, labName: string, name: string, detachDataDiskProperties: DetachDataDiskProperties, options?: VirtualMachinesDetachDataDiskOptionalParams ): Promise, void>> { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ) => { let currentRawResponse: | coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown ) => { 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 = new LroImpl( sendOperation, { resourceGroupName, labName, name, detachDataDiskProperties, options }, detachDataDiskOperationSpec ); const poller = new LroEngine(lro, { resumeFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Detach the specified disk from the virtual machine. This operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param detachDataDiskProperties Request body for detaching data disk from a virtual machine. * @param options The options parameters. */ async beginDetachDataDiskAndWait( resourceGroupName: string, labName: string, name: string, detachDataDiskProperties: DetachDataDiskProperties, options?: VirtualMachinesDetachDataDiskOptionalParams ): Promise { const poller = await this.beginDetachDataDisk( resourceGroupName, labName, name, detachDataDiskProperties, options ); return poller.pollUntilDone(); } /** * Gets a string that represents the contents of the RDP file for the virtual machine * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param options The options parameters. */ getRdpFileContents( resourceGroupName: string, labName: string, name: string, options?: VirtualMachinesGetRdpFileContentsOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, labName, name, options }, getRdpFileContentsOperationSpec ); } /** * Lists the applicable start/stop schedules, if any. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param options The options parameters. */ listApplicableSchedules( resourceGroupName: string, labName: string, name: string, options?: VirtualMachinesListApplicableSchedulesOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, labName, name, options }, listApplicableSchedulesOperationSpec ); } /** * Redeploy a virtual machine This operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param options The options parameters. */ async beginRedeploy( resourceGroupName: string, labName: string, name: string, options?: VirtualMachinesRedeployOptionalParams ): Promise, void>> { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ) => { let currentRawResponse: | coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown ) => { 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 = new LroImpl( sendOperation, { resourceGroupName, labName, name, options }, redeployOperationSpec ); const poller = new LroEngine(lro, { resumeFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Redeploy a virtual machine This operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param options The options parameters. */ async beginRedeployAndWait( resourceGroupName: string, labName: string, name: string, options?: VirtualMachinesRedeployOptionalParams ): Promise { const poller = await this.beginRedeploy( resourceGroupName, labName, name, options ); return poller.pollUntilDone(); } /** * Resize Virtual Machine. This operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param resizeLabVirtualMachineProperties Request body for resizing a virtual machine. * @param options The options parameters. */ async beginResize( resourceGroupName: string, labName: string, name: string, resizeLabVirtualMachineProperties: ResizeLabVirtualMachineProperties, options?: VirtualMachinesResizeOptionalParams ): Promise, void>> { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ) => { let currentRawResponse: | coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown ) => { 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 = new LroImpl( sendOperation, { resourceGroupName, labName, name, resizeLabVirtualMachineProperties, options }, resizeOperationSpec ); const poller = new LroEngine(lro, { resumeFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Resize Virtual Machine. This operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param resizeLabVirtualMachineProperties Request body for resizing a virtual machine. * @param options The options parameters. */ async beginResizeAndWait( resourceGroupName: string, labName: string, name: string, resizeLabVirtualMachineProperties: ResizeLabVirtualMachineProperties, options?: VirtualMachinesResizeOptionalParams ): Promise { const poller = await this.beginResize( resourceGroupName, labName, name, resizeLabVirtualMachineProperties, options ); return poller.pollUntilDone(); } /** * Restart a virtual machine. This operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param options The options parameters. */ async beginRestart( resourceGroupName: string, labName: string, name: string, options?: VirtualMachinesRestartOptionalParams ): Promise, void>> { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ) => { let currentRawResponse: | coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown ) => { 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 = new LroImpl( sendOperation, { resourceGroupName, labName, name, options }, restartOperationSpec ); const poller = new LroEngine(lro, { resumeFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Restart a virtual machine. This operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param options The options parameters. */ async beginRestartAndWait( resourceGroupName: string, labName: string, name: string, options?: VirtualMachinesRestartOptionalParams ): Promise { const poller = await this.beginRestart( resourceGroupName, labName, name, options ); return poller.pollUntilDone(); } /** * Start a virtual machine. This operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param options The options parameters. */ async beginStart( resourceGroupName: string, labName: string, name: string, options?: VirtualMachinesStartOptionalParams ): Promise, void>> { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ) => { let currentRawResponse: | coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown ) => { 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 = new LroImpl( sendOperation, { resourceGroupName, labName, name, options }, startOperationSpec ); const poller = new LroEngine(lro, { resumeFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Start a virtual machine. This operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param options The options parameters. */ async beginStartAndWait( resourceGroupName: string, labName: string, name: string, options?: VirtualMachinesStartOptionalParams ): Promise { const poller = await this.beginStart( resourceGroupName, labName, name, options ); return poller.pollUntilDone(); } /** * Stop a virtual machine This operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param options The options parameters. */ async beginStop( resourceGroupName: string, labName: string, name: string, options?: VirtualMachinesStopOptionalParams ): Promise, void>> { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ) => { let currentRawResponse: | coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown ) => { 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 = new LroImpl( sendOperation, { resourceGroupName, labName, name, options }, stopOperationSpec ); const poller = new LroEngine(lro, { resumeFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Stop a virtual machine This operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param options The options parameters. */ async beginStopAndWait( resourceGroupName: string, labName: string, name: string, options?: VirtualMachinesStopOptionalParams ): Promise { const poller = await this.beginStop( resourceGroupName, labName, name, options ); return poller.pollUntilDone(); } /** * Transfers all data disks attached to the virtual machine to be owned by the current user. This * operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param options The options parameters. */ async beginTransferDisks( resourceGroupName: string, labName: string, name: string, options?: VirtualMachinesTransferDisksOptionalParams ): Promise, void>> { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ) => { let currentRawResponse: | coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown ) => { 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 = new LroImpl( sendOperation, { resourceGroupName, labName, name, options }, transferDisksOperationSpec ); const poller = new LroEngine(lro, { resumeFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Transfers all data disks attached to the virtual machine to be owned by the current user. This * operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param options The options parameters. */ async beginTransferDisksAndWait( resourceGroupName: string, labName: string, name: string, options?: VirtualMachinesTransferDisksOptionalParams ): Promise { const poller = await this.beginTransferDisks( resourceGroupName, labName, name, options ); return poller.pollUntilDone(); } /** * Release ownership of an existing virtual machine This operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param options The options parameters. */ async beginUnClaim( resourceGroupName: string, labName: string, name: string, options?: VirtualMachinesUnClaimOptionalParams ): Promise, void>> { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec ) => { let currentRawResponse: | coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown ) => { 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 = new LroImpl( sendOperation, { resourceGroupName, labName, name, options }, unClaimOperationSpec ); const poller = new LroEngine(lro, { resumeFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Release ownership of an existing virtual machine This operation can take a while to complete. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the virtual machine. * @param options The options parameters. */ async beginUnClaimAndWait( resourceGroupName: string, labName: string, name: string, options?: VirtualMachinesUnClaimOptionalParams ): Promise { const poller = await this.beginUnClaim( resourceGroupName, labName, name, options ); return poller.pollUntilDone(); } /** * ListNext * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param nextLink The nextLink from the previous successful call to the List method. * @param options The options parameters. */ private _listNext( resourceGroupName: string, labName: string, nextLink: string, options?: VirtualMachinesListNextOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, labName, nextLink, options }, listNextOperationSpec ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const listOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.LabVirtualMachineList }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [ Parameters.apiVersion, Parameters.expand, Parameters.filter, Parameters.top, Parameters.orderby ], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.labName ], headerParameters: [Parameters.accept], serializer }; const getOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.LabVirtualMachine }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion, Parameters.expand], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.name, Parameters.labName ], headerParameters: [Parameters.accept], serializer }; const createOrUpdateOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}", httpMethod: "PUT", responses: { 200: { bodyMapper: Mappers.LabVirtualMachine }, 201: { bodyMapper: Mappers.LabVirtualMachine }, 202: { bodyMapper: Mappers.LabVirtualMachine }, 204: { bodyMapper: Mappers.LabVirtualMachine }, default: { bodyMapper: Mappers.CloudError } }, requestBody: Parameters.labVirtualMachine, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.name, Parameters.labName ], headerParameters: [Parameters.accept, Parameters.contentType], mediaType: "json", serializer }; const deleteOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}", httpMethod: "DELETE", responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.name, Parameters.labName ], headerParameters: [Parameters.accept], serializer }; const updateOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}", httpMethod: "PATCH", responses: { 200: { bodyMapper: Mappers.LabVirtualMachine }, default: { bodyMapper: Mappers.CloudError } }, requestBody: Parameters.labVirtualMachine1, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.name, Parameters.labName ], headerParameters: [Parameters.accept, Parameters.contentType], mediaType: "json", serializer }; const addDataDiskOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/addDataDisk", httpMethod: "POST", responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: { bodyMapper: Mappers.CloudError } }, requestBody: Parameters.dataDiskProperties, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.name, Parameters.labName ], headerParameters: [Parameters.accept, Parameters.contentType], mediaType: "json", serializer }; const applyArtifactsOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/applyArtifacts", httpMethod: "POST", responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: { bodyMapper: Mappers.CloudError } }, requestBody: Parameters.applyArtifactsRequest, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.name, Parameters.labName ], headerParameters: [Parameters.accept, Parameters.contentType], mediaType: "json", serializer }; const claimOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/claim", httpMethod: "POST", responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.name, Parameters.labName ], headerParameters: [Parameters.accept], serializer }; const detachDataDiskOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/detachDataDisk", httpMethod: "POST", responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: { bodyMapper: Mappers.CloudError } }, requestBody: Parameters.detachDataDiskProperties, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.name, Parameters.labName ], headerParameters: [Parameters.accept, Parameters.contentType], mediaType: "json", serializer }; const getRdpFileContentsOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/getRdpFileContents", httpMethod: "POST", responses: { 200: { bodyMapper: Mappers.RdpConnection }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.name, Parameters.labName ], headerParameters: [Parameters.accept], serializer }; const listApplicableSchedulesOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/listApplicableSchedules", httpMethod: "POST", responses: { 200: { bodyMapper: Mappers.ApplicableSchedule }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.name, Parameters.labName ], headerParameters: [Parameters.accept], serializer }; const redeployOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/redeploy", httpMethod: "POST", responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.name, Parameters.labName ], headerParameters: [Parameters.accept], serializer }; const resizeOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/resize", httpMethod: "POST", responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: { bodyMapper: Mappers.CloudError } }, requestBody: Parameters.resizeLabVirtualMachineProperties, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.name, Parameters.labName ], headerParameters: [Parameters.accept, Parameters.contentType], mediaType: "json", serializer }; const restartOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/restart", httpMethod: "POST", responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.name, Parameters.labName ], headerParameters: [Parameters.accept], serializer }; const startOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/start", httpMethod: "POST", responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.name, Parameters.labName ], headerParameters: [Parameters.accept], serializer }; const stopOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/stop", httpMethod: "POST", responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.name, Parameters.labName ], headerParameters: [Parameters.accept], serializer }; const transferDisksOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/transferDisks", httpMethod: "POST", responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.name, Parameters.labName ], headerParameters: [Parameters.accept], serializer }; const unClaimOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/unClaim", httpMethod: "POST", responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.name, Parameters.labName ], headerParameters: [Parameters.accept], serializer }; const listNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.LabVirtualMachineList }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [ Parameters.apiVersion, Parameters.expand, Parameters.filter, Parameters.top, Parameters.orderby ], urlParameters: [ Parameters.$host, Parameters.nextLink, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.labName ], headerParameters: [Parameters.accept], serializer };