/*
* 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 { Disks } 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 {
Disk,
DisksListNextOptionalParams,
DisksListOptionalParams,
DisksListResponse,
DisksGetOptionalParams,
DisksGetResponse,
DisksCreateOrUpdateOptionalParams,
DisksCreateOrUpdateResponse,
DisksDeleteOptionalParams,
DiskFragment,
DisksUpdateOptionalParams,
DisksUpdateResponse,
AttachDiskProperties,
DisksAttachOptionalParams,
DetachDiskProperties,
DisksDetachOptionalParams,
DisksListNextResponse
} from "../models";
///
/** Class containing Disks operations. */
export class DisksImpl implements Disks {
private readonly client: DevTestLabsClient;
/**
* Initialize a new instance of the class Disks class.
* @param client Reference to the service client
*/
constructor(client: DevTestLabsClient) {
this.client = client;
}
/**
* List disks in a given user profile.
* @param resourceGroupName The name of the resource group.
* @param labName The name of the lab.
* @param userName The name of the user profile.
* @param options The options parameters.
*/
public list(
resourceGroupName: string,
labName: string,
userName: string,
options?: DisksListOptionalParams
): PagedAsyncIterableIterator {
const iter = this.listPagingAll(
resourceGroupName,
labName,
userName,
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,
userName,
options,
settings
);
}
};
}
private async *listPagingPage(
resourceGroupName: string,
labName: string,
userName: string,
options?: DisksListOptionalParams,
settings?: PageSettings
): AsyncIterableIterator {
let result: DisksListResponse;
let continuationToken = settings?.continuationToken;
if (!continuationToken) {
result = await this._list(resourceGroupName, labName, userName, options);
let page = result.value || [];
continuationToken = result.nextLink;
setContinuationToken(page, continuationToken);
yield page;
}
while (continuationToken) {
result = await this._listNext(
resourceGroupName,
labName,
userName,
continuationToken,
options
);
continuationToken = result.nextLink;
let page = result.value || [];
setContinuationToken(page, continuationToken);
yield page;
}
}
private async *listPagingAll(
resourceGroupName: string,
labName: string,
userName: string,
options?: DisksListOptionalParams
): AsyncIterableIterator {
for await (const page of this.listPagingPage(
resourceGroupName,
labName,
userName,
options
)) {
yield* page;
}
}
/**
* List disks in a given user profile.
* @param resourceGroupName The name of the resource group.
* @param labName The name of the lab.
* @param userName The name of the user profile.
* @param options The options parameters.
*/
private _list(
resourceGroupName: string,
labName: string,
userName: string,
options?: DisksListOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, labName, userName, options },
listOperationSpec
);
}
/**
* Get disk.
* @param resourceGroupName The name of the resource group.
* @param labName The name of the lab.
* @param userName The name of the user profile.
* @param name The name of the disk.
* @param options The options parameters.
*/
get(
resourceGroupName: string,
labName: string,
userName: string,
name: string,
options?: DisksGetOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, labName, userName, name, options },
getOperationSpec
);
}
/**
* Create or replace an existing disk. This operation can take a while to complete.
* @param resourceGroupName The name of the resource group.
* @param labName The name of the lab.
* @param userName The name of the user profile.
* @param name The name of the disk.
* @param disk A Disk.
* @param options The options parameters.
*/
async beginCreateOrUpdate(
resourceGroupName: string,
labName: string,
userName: string,
name: string,
disk: Disk,
options?: DisksCreateOrUpdateOptionalParams
): Promise<
PollerLike<
PollOperationState,
DisksCreateOrUpdateResponse
>
> {
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, userName, name, disk, options },
createOrUpdateOperationSpec
);
const poller = new LroEngine(lro, {
resumeFrom: options?.resumeFrom,
intervalInMs: options?.updateIntervalInMs
});
await poller.poll();
return poller;
}
/**
* Create or replace an existing disk. This operation can take a while to complete.
* @param resourceGroupName The name of the resource group.
* @param labName The name of the lab.
* @param userName The name of the user profile.
* @param name The name of the disk.
* @param disk A Disk.
* @param options The options parameters.
*/
async beginCreateOrUpdateAndWait(
resourceGroupName: string,
labName: string,
userName: string,
name: string,
disk: Disk,
options?: DisksCreateOrUpdateOptionalParams
): Promise {
const poller = await this.beginCreateOrUpdate(
resourceGroupName,
labName,
userName,
name,
disk,
options
);
return poller.pollUntilDone();
}
/**
* Delete disk. This operation can take a while to complete.
* @param resourceGroupName The name of the resource group.
* @param labName The name of the lab.
* @param userName The name of the user profile.
* @param name The name of the disk.
* @param options The options parameters.
*/
async beginDelete(
resourceGroupName: string,
labName: string,
userName: string,
name: string,
options?: DisksDeleteOptionalParams
): 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, userName, name, options },
deleteOperationSpec
);
const poller = new LroEngine(lro, {
resumeFrom: options?.resumeFrom,
intervalInMs: options?.updateIntervalInMs
});
await poller.poll();
return poller;
}
/**
* Delete disk. This operation can take a while to complete.
* @param resourceGroupName The name of the resource group.
* @param labName The name of the lab.
* @param userName The name of the user profile.
* @param name The name of the disk.
* @param options The options parameters.
*/
async beginDeleteAndWait(
resourceGroupName: string,
labName: string,
userName: string,
name: string,
options?: DisksDeleteOptionalParams
): Promise {
const poller = await this.beginDelete(
resourceGroupName,
labName,
userName,
name,
options
);
return poller.pollUntilDone();
}
/**
* Allows modifying tags of disks. All other properties will be ignored.
* @param resourceGroupName The name of the resource group.
* @param labName The name of the lab.
* @param userName The name of the user profile.
* @param name The name of the disk.
* @param disk A Disk.
* @param options The options parameters.
*/
update(
resourceGroupName: string,
labName: string,
userName: string,
name: string,
disk: DiskFragment,
options?: DisksUpdateOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, labName, userName, name, disk, options },
updateOperationSpec
);
}
/**
* Attach and create the lease of the disk to 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 userName The name of the user profile.
* @param name The name of the disk.
* @param attachDiskProperties Properties of the disk to attach.
* @param options The options parameters.
*/
async beginAttach(
resourceGroupName: string,
labName: string,
userName: string,
name: string,
attachDiskProperties: AttachDiskProperties,
options?: DisksAttachOptionalParams
): 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,
userName,
name,
attachDiskProperties,
options
},
attachOperationSpec
);
const poller = new LroEngine(lro, {
resumeFrom: options?.resumeFrom,
intervalInMs: options?.updateIntervalInMs
});
await poller.poll();
return poller;
}
/**
* Attach and create the lease of the disk to 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 userName The name of the user profile.
* @param name The name of the disk.
* @param attachDiskProperties Properties of the disk to attach.
* @param options The options parameters.
*/
async beginAttachAndWait(
resourceGroupName: string,
labName: string,
userName: string,
name: string,
attachDiskProperties: AttachDiskProperties,
options?: DisksAttachOptionalParams
): Promise {
const poller = await this.beginAttach(
resourceGroupName,
labName,
userName,
name,
attachDiskProperties,
options
);
return poller.pollUntilDone();
}
/**
* Detach and break the lease of the disk attached to 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 userName The name of the user profile.
* @param name The name of the disk.
* @param detachDiskProperties Properties of the disk to detach.
* @param options The options parameters.
*/
async beginDetach(
resourceGroupName: string,
labName: string,
userName: string,
name: string,
detachDiskProperties: DetachDiskProperties,
options?: DisksDetachOptionalParams
): 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,
userName,
name,
detachDiskProperties,
options
},
detachOperationSpec
);
const poller = new LroEngine(lro, {
resumeFrom: options?.resumeFrom,
intervalInMs: options?.updateIntervalInMs
});
await poller.poll();
return poller;
}
/**
* Detach and break the lease of the disk attached to 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 userName The name of the user profile.
* @param name The name of the disk.
* @param detachDiskProperties Properties of the disk to detach.
* @param options The options parameters.
*/
async beginDetachAndWait(
resourceGroupName: string,
labName: string,
userName: string,
name: string,
detachDiskProperties: DetachDiskProperties,
options?: DisksDetachOptionalParams
): Promise {
const poller = await this.beginDetach(
resourceGroupName,
labName,
userName,
name,
detachDiskProperties,
options
);
return poller.pollUntilDone();
}
/**
* ListNext
* @param resourceGroupName The name of the resource group.
* @param labName The name of the lab.
* @param userName The name of the user profile.
* @param nextLink The nextLink from the previous successful call to the List method.
* @param options The options parameters.
*/
private _listNext(
resourceGroupName: string,
labName: string,
userName: string,
nextLink: string,
options?: DisksListNextOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, labName, userName, 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}/users/{userName}/disks",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.DiskList
},
default: {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [
Parameters.apiVersion,
Parameters.expand,
Parameters.filter,
Parameters.top,
Parameters.orderby
],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.labName,
Parameters.userName
],
headerParameters: [Parameters.accept],
serializer
};
const getOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{name}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.Disk
},
default: {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion, Parameters.expand],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.name,
Parameters.labName,
Parameters.userName
],
headerParameters: [Parameters.accept],
serializer
};
const createOrUpdateOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{name}",
httpMethod: "PUT",
responses: {
200: {
bodyMapper: Mappers.Disk
},
201: {
bodyMapper: Mappers.Disk
},
202: {
bodyMapper: Mappers.Disk
},
204: {
bodyMapper: Mappers.Disk
},
default: {
bodyMapper: Mappers.CloudError
}
},
requestBody: Parameters.disk,
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.name,
Parameters.labName,
Parameters.userName
],
headerParameters: [Parameters.accept, Parameters.contentType],
mediaType: "json",
serializer
};
const deleteOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{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,
Parameters.userName
],
headerParameters: [Parameters.accept],
serializer
};
const updateOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{name}",
httpMethod: "PATCH",
responses: {
200: {
bodyMapper: Mappers.Disk
},
default: {
bodyMapper: Mappers.CloudError
}
},
requestBody: Parameters.disk1,
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.name,
Parameters.labName,
Parameters.userName
],
headerParameters: [Parameters.accept, Parameters.contentType],
mediaType: "json",
serializer
};
const attachOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{name}/attach",
httpMethod: "POST",
responses: {
200: {},
201: {},
202: {},
204: {},
default: {
bodyMapper: Mappers.CloudError
}
},
requestBody: Parameters.attachDiskProperties,
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.name,
Parameters.labName,
Parameters.userName
],
headerParameters: [Parameters.accept, Parameters.contentType],
mediaType: "json",
serializer
};
const detachOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{name}/detach",
httpMethod: "POST",
responses: {
200: {},
201: {},
202: {},
204: {},
default: {
bodyMapper: Mappers.CloudError
}
},
requestBody: Parameters.detachDiskProperties,
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.name,
Parameters.labName,
Parameters.userName
],
headerParameters: [Parameters.accept, Parameters.contentType],
mediaType: "json",
serializer
};
const listNextOperationSpec: coreClient.OperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.DiskList
},
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,
Parameters.userName
],
headerParameters: [Parameters.accept],
serializer
};