/*
* 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 { Location } from "../operationsInterfaces";
import * as coreClient from "@azure/core-client";
import * as Mappers from "../models/mappers";
import * as Parameters from "../models/parameters";
import { ContainerInstanceManagementClient } from "../containerInstanceManagementClient";
import {
Usage,
LocationListUsageOptionalParams,
LocationListUsageResponse,
CachedImages,
LocationListCachedImagesNextOptionalParams,
LocationListCachedImagesOptionalParams,
LocationListCachedImagesResponse,
Capabilities,
LocationListCapabilitiesNextOptionalParams,
LocationListCapabilitiesOptionalParams,
LocationListCapabilitiesResponse,
LocationListCachedImagesNextResponse,
LocationListCapabilitiesNextResponse
} from "../models";
///
/** Class containing Location operations. */
export class LocationImpl implements Location {
private readonly client: ContainerInstanceManagementClient;
/**
* Initialize a new instance of the class Location class.
* @param client Reference to the service client
*/
constructor(client: ContainerInstanceManagementClient) {
this.client = client;
}
/**
* Get the usage for a subscription
* @param location The identifier for the physical azure location.
* @param options The options parameters.
*/
public listUsage(
location: string,
options?: LocationListUsageOptionalParams
): PagedAsyncIterableIterator {
const iter = this.listUsagePagingAll(location, 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.listUsagePagingPage(location, options, settings);
}
};
}
private async *listUsagePagingPage(
location: string,
options?: LocationListUsageOptionalParams,
_settings?: PageSettings
): AsyncIterableIterator {
let result: LocationListUsageResponse;
result = await this._listUsage(location, options);
yield result.value || [];
}
private async *listUsagePagingAll(
location: string,
options?: LocationListUsageOptionalParams
): AsyncIterableIterator {
for await (const page of this.listUsagePagingPage(location, options)) {
yield* page;
}
}
/**
* Get the list of cached images on specific OS type for a subscription in a region.
* @param location The identifier for the physical azure location.
* @param options The options parameters.
*/
public listCachedImages(
location: string,
options?: LocationListCachedImagesOptionalParams
): PagedAsyncIterableIterator {
const iter = this.listCachedImagesPagingAll(location, 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.listCachedImagesPagingPage(location, options, settings);
}
};
}
private async *listCachedImagesPagingPage(
location: string,
options?: LocationListCachedImagesOptionalParams,
settings?: PageSettings
): AsyncIterableIterator {
let result: LocationListCachedImagesResponse;
let continuationToken = settings?.continuationToken;
if (!continuationToken) {
result = await this._listCachedImages(location, options);
let page = result.value || [];
continuationToken = result.nextLink;
setContinuationToken(page, continuationToken);
yield page;
}
while (continuationToken) {
result = await this._listCachedImagesNext(
location,
continuationToken,
options
);
continuationToken = result.nextLink;
let page = result.value || [];
setContinuationToken(page, continuationToken);
yield page;
}
}
private async *listCachedImagesPagingAll(
location: string,
options?: LocationListCachedImagesOptionalParams
): AsyncIterableIterator {
for await (const page of this.listCachedImagesPagingPage(
location,
options
)) {
yield* page;
}
}
/**
* Get the list of CPU/memory/GPU capabilities of a region.
* @param location The identifier for the physical azure location.
* @param options The options parameters.
*/
public listCapabilities(
location: string,
options?: LocationListCapabilitiesOptionalParams
): PagedAsyncIterableIterator {
const iter = this.listCapabilitiesPagingAll(location, 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.listCapabilitiesPagingPage(location, options, settings);
}
};
}
private async *listCapabilitiesPagingPage(
location: string,
options?: LocationListCapabilitiesOptionalParams,
settings?: PageSettings
): AsyncIterableIterator {
let result: LocationListCapabilitiesResponse;
let continuationToken = settings?.continuationToken;
if (!continuationToken) {
result = await this._listCapabilities(location, options);
let page = result.value || [];
continuationToken = result.nextLink;
setContinuationToken(page, continuationToken);
yield page;
}
while (continuationToken) {
result = await this._listCapabilitiesNext(
location,
continuationToken,
options
);
continuationToken = result.nextLink;
let page = result.value || [];
setContinuationToken(page, continuationToken);
yield page;
}
}
private async *listCapabilitiesPagingAll(
location: string,
options?: LocationListCapabilitiesOptionalParams
): AsyncIterableIterator {
for await (const page of this.listCapabilitiesPagingPage(
location,
options
)) {
yield* page;
}
}
/**
* Get the usage for a subscription
* @param location The identifier for the physical azure location.
* @param options The options parameters.
*/
private _listUsage(
location: string,
options?: LocationListUsageOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ location, options },
listUsageOperationSpec
);
}
/**
* Get the list of cached images on specific OS type for a subscription in a region.
* @param location The identifier for the physical azure location.
* @param options The options parameters.
*/
private _listCachedImages(
location: string,
options?: LocationListCachedImagesOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ location, options },
listCachedImagesOperationSpec
);
}
/**
* Get the list of CPU/memory/GPU capabilities of a region.
* @param location The identifier for the physical azure location.
* @param options The options parameters.
*/
private _listCapabilities(
location: string,
options?: LocationListCapabilitiesOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ location, options },
listCapabilitiesOperationSpec
);
}
/**
* ListCachedImagesNext
* @param location The identifier for the physical azure location.
* @param nextLink The nextLink from the previous successful call to the ListCachedImages method.
* @param options The options parameters.
*/
private _listCachedImagesNext(
location: string,
nextLink: string,
options?: LocationListCachedImagesNextOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ location, nextLink, options },
listCachedImagesNextOperationSpec
);
}
/**
* ListCapabilitiesNext
* @param location The identifier for the physical azure location.
* @param nextLink The nextLink from the previous successful call to the ListCapabilities method.
* @param options The options parameters.
*/
private _listCapabilitiesNext(
location: string,
nextLink: string,
options?: LocationListCapabilitiesNextOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ location, nextLink, options },
listCapabilitiesNextOperationSpec
);
}
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listUsageOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/providers/Microsoft.ContainerInstance/locations/{location}/usages",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.UsageListResult
},
default: {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.location
],
headerParameters: [Parameters.accept],
serializer
};
const listCachedImagesOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/providers/Microsoft.ContainerInstance/locations/{location}/cachedImages",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.CachedImagesListResult
},
default: {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.location
],
headerParameters: [Parameters.accept],
serializer
};
const listCapabilitiesOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/providers/Microsoft.ContainerInstance/locations/{location}/capabilities",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.CapabilitiesListResult
},
default: {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.location
],
headerParameters: [Parameters.accept],
serializer
};
const listCachedImagesNextOperationSpec: coreClient.OperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.CachedImagesListResult
},
default: {
bodyMapper: Mappers.CloudError
}
},
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.nextLink,
Parameters.location
],
headerParameters: [Parameters.accept],
serializer
};
const listCapabilitiesNextOperationSpec: coreClient.OperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.CapabilitiesListResult
},
default: {
bodyMapper: Mappers.CloudError
}
},
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.nextLink,
Parameters.location
],
headerParameters: [Parameters.accept],
serializer
};