azure-cli
Version:
Microsoft Azure Cross Platform Command Line tool
1,219 lines (1,179 loc) • 59.7 kB
JavaScript
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is
* regenerated.
*/
'use strict';
const msRest = require('ms-rest');
const msRestAzure = require('ms-rest-azure');
const WebResource = msRest.WebResource;
/**
* The operation to create or update the extension.
*
* @param {string} resourceGroupName The name of the resource group.
*
* @param {string} vmName The name of the virtual machine where the extension
* should be create or updated.
*
* @param {string} vmExtensionName The name of the virtual machine extension.
*
* @param {object} extensionParameters Parameters supplied to the Create
* Virtual Machine Extension operation.
*
* @param {string} [extensionParameters.forceUpdateTag] How the extension
* handler should be forced to update even if the extension configuration has
* not changed.
*
* @param {string} [extensionParameters.publisher] The name of the extension
* handler publisher.
*
* @param {string} [extensionParameters.virtualMachineExtensionType] Specifies
* the type of the extension; an example is "CustomScriptExtension".
*
* @param {string} [extensionParameters.typeHandlerVersion] Specifies the
* version of the script handler.
*
* @param {boolean} [extensionParameters.autoUpgradeMinorVersion] Indicates
* whether the extension should use a newer minor version if one is available
* at deployment time. Once deployed, however, the extension will not upgrade
* minor versions unless redeployed, even with this property set to true.
*
* @param {object} [extensionParameters.settings] Json formatted public
* settings for the extension.
*
* @param {object} [extensionParameters.protectedSettings] The extension can
* contain either protectedSettings or protectedSettingsFromKeyVault or no
* protected settings at all.
*
* @param {object} [extensionParameters.instanceView] The virtual machine
* extension instance view.
*
* @param {string} [extensionParameters.instanceView.name] The virtual machine
* extension name.
*
* @param {string} [extensionParameters.instanceView.type] Specifies the type
* of the extension; an example is "CustomScriptExtension".
*
* @param {string} [extensionParameters.instanceView.typeHandlerVersion]
* Specifies the version of the script handler.
*
* @param {array} [extensionParameters.instanceView.substatuses] The resource
* status information.
*
* @param {array} [extensionParameters.instanceView.statuses] The resource
* status information.
*
* @param {string} extensionParameters.location Resource location
*
* @param {object} [extensionParameters.tags] Resource tags
*
* @param {object} [options] Optional Parameters.
*
* @param {object} [options.customHeaders] Headers that will be added to the
* request
*
* @param {function} callback - The callback.
*
* @returns {function} callback(err, result, request, response)
*
* {Error} err - The Error object if an error occurred, null otherwise.
*
* {object} [result] - The deserialized result object if an error did not occur.
* See {@link VirtualMachineExtension} for more
* information.
*
* {object} [request] - The HTTP Request object if an error did not occur.
*
* {stream} [response] - The HTTP Response stream if an error did not occur.
*/
function _createOrUpdate(resourceGroupName, vmName, vmExtensionName, extensionParameters, options, callback) {
/* jshint validthis: true */
let client = this.client;
if(!callback && typeof options === 'function') {
callback = options;
options = null;
}
if (!callback) {
throw new Error('callback cannot be null.');
}
// Send request
this.beginCreateOrUpdate(resourceGroupName, vmName, vmExtensionName, extensionParameters, options, (err, parsedResult, httpRequest, response) => {
if (err) return callback(err);
let initialResult = new msRest.HttpOperationResponse();
initialResult.request = httpRequest;
initialResult.response = response;
initialResult.body = response.body;
client.getLongRunningOperationResult(initialResult, options, (err, pollingResult) => {
if (err) return callback(err);
// Create Result
let result = null;
httpRequest = pollingResult.request;
response = pollingResult.response;
let responseBody = pollingResult.body;
if (responseBody === '') responseBody = null;
// Deserialize Response
let parsedResponse = null;
try {
parsedResponse = JSON.parse(responseBody);
result = JSON.parse(responseBody);
if (parsedResponse !== null && parsedResponse !== undefined) {
let resultMapper = new client.models['VirtualMachineExtension']().mapper();
result = client.deserialize(resultMapper, parsedResponse, 'result');
}
} catch (error) {
let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
deserializationError.request = msRest.stripRequest(httpRequest);
deserializationError.response = msRest.stripResponse(response);
return callback(deserializationError);
}
return callback(null, result, httpRequest, response);
});
});
}
/**
* The operation to delete the extension.
*
* @param {string} resourceGroupName The name of the resource group.
*
* @param {string} vmName The name of the virtual machine where the extension
* should be deleted.
*
* @param {string} vmExtensionName The name of the virtual machine extension.
*
* @param {object} [options] Optional Parameters.
*
* @param {object} [options.customHeaders] Headers that will be added to the
* request
*
* @param {function} callback - The callback.
*
* @returns {function} callback(err, result, request, response)
*
* {Error} err - The Error object if an error occurred, null otherwise.
*
* {object} [result] - The deserialized result object if an error did not occur.
* See {@link OperationStatusResponse} for more
* information.
*
* {object} [request] - The HTTP Request object if an error did not occur.
*
* {stream} [response] - The HTTP Response stream if an error did not occur.
*/
function _deleteMethod(resourceGroupName, vmName, vmExtensionName, options, callback) {
/* jshint validthis: true */
let client = this.client;
if(!callback && typeof options === 'function') {
callback = options;
options = null;
}
if (!callback) {
throw new Error('callback cannot be null.');
}
// Send request
this.beginDeleteMethod(resourceGroupName, vmName, vmExtensionName, options, (err, parsedResult, httpRequest, response) => {
if (err) return callback(err);
let initialResult = new msRest.HttpOperationResponse();
initialResult.request = httpRequest;
initialResult.response = response;
initialResult.body = response.body;
client.getLongRunningOperationResult(initialResult, options, (err, pollingResult) => {
if (err) return callback(err);
// Create Result
let result = null;
httpRequest = pollingResult.request;
response = pollingResult.response;
let responseBody = pollingResult.body;
if (responseBody === '') responseBody = null;
// Deserialize Response
let parsedResponse = null;
try {
parsedResponse = JSON.parse(responseBody);
result = JSON.parse(responseBody);
if (parsedResponse !== null && parsedResponse !== undefined) {
let resultMapper = new client.models['OperationStatusResponse']().mapper();
result = client.deserialize(resultMapper, parsedResponse, 'result');
}
} catch (error) {
let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
deserializationError.request = msRest.stripRequest(httpRequest);
deserializationError.response = msRest.stripResponse(response);
return callback(deserializationError);
}
return callback(null, result, httpRequest, response);
});
});
}
/**
* The operation to get the extension.
*
* @param {string} resourceGroupName The name of the resource group.
*
* @param {string} vmName The name of the virtual machine containing the
* extension.
*
* @param {string} vmExtensionName The name of the virtual machine extension.
*
* @param {object} [options] Optional Parameters.
*
* @param {string} [options.expand] The expand expression to apply on the
* operation.
*
* @param {object} [options.customHeaders] Headers that will be added to the
* request
*
* @param {function} callback - The callback.
*
* @returns {function} callback(err, result, request, response)
*
* {Error} err - The Error object if an error occurred, null otherwise.
*
* {object} [result] - The deserialized result object if an error did not occur.
* See {@link VirtualMachineExtension} for more
* information.
*
* {object} [request] - The HTTP Request object if an error did not occur.
*
* {stream} [response] - The HTTP Response stream if an error did not occur.
*/
function _get(resourceGroupName, vmName, vmExtensionName, options, callback) {
/* jshint validthis: true */
let client = this.client;
if(!callback && typeof options === 'function') {
callback = options;
options = null;
}
if (!callback) {
throw new Error('callback cannot be null.');
}
let expand = (options && options.expand !== undefined) ? options.expand : undefined;
let apiVersion = '2017-03-30';
// Validate
try {
if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
}
if (vmName === null || vmName === undefined || typeof vmName.valueOf() !== 'string') {
throw new Error('vmName cannot be null or undefined and it must be of type string.');
}
if (vmExtensionName === null || vmExtensionName === undefined || typeof vmExtensionName.valueOf() !== 'string') {
throw new Error('vmExtensionName cannot be null or undefined and it must be of type string.');
}
if (expand !== null && expand !== undefined && typeof expand.valueOf() !== 'string') {
throw new Error('expand must be of type string.');
}
if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
}
if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
throw new Error('this.client.acceptLanguage must be of type string.');
}
} catch (error) {
return callback(error);
}
// Construct URL
let baseUrl = this.client.baseUri;
let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/extensions/{vmExtensionName}';
requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
requestUrl = requestUrl.replace('{vmName}', encodeURIComponent(vmName));
requestUrl = requestUrl.replace('{vmExtensionName}', encodeURIComponent(vmExtensionName));
requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
let queryParameters = [];
if (expand !== null && expand !== undefined) {
queryParameters.push('$expand=' + encodeURIComponent(expand));
}
queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
if (queryParameters.length > 0) {
requestUrl += '?' + queryParameters.join('&');
}
// Create HTTP transport objects
let httpRequest = new WebResource();
httpRequest.method = 'GET';
httpRequest.url = requestUrl;
httpRequest.headers = {};
// Set Headers
httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
if (this.client.generateClientRequestId) {
httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
}
if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
httpRequest.headers['accept-language'] = this.client.acceptLanguage;
}
if(options) {
for(let headerName in options['customHeaders']) {
if (options['customHeaders'].hasOwnProperty(headerName)) {
httpRequest.headers[headerName] = options['customHeaders'][headerName];
}
}
}
httpRequest.body = null;
// Send Request
return client.pipeline(httpRequest, (err, response, responseBody) => {
if (err) {
return callback(err);
}
let statusCode = response.statusCode;
if (statusCode !== 200) {
let error = new Error(responseBody);
error.statusCode = response.statusCode;
error.request = msRest.stripRequest(httpRequest);
error.response = msRest.stripResponse(response);
if (responseBody === '') responseBody = null;
let parsedErrorResponse;
try {
parsedErrorResponse = JSON.parse(responseBody);
if (parsedErrorResponse) {
if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
}
if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
let resultMapper = new client.models['CloudError']().mapper();
error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
}
} catch (defaultError) {
error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
`- "${responseBody}" for the default response.`;
return callback(error);
}
return callback(error);
}
// Create Result
let result = null;
if (responseBody === '') responseBody = null;
// Deserialize Response
if (statusCode === 200) {
let parsedResponse = null;
try {
parsedResponse = JSON.parse(responseBody);
result = JSON.parse(responseBody);
if (parsedResponse !== null && parsedResponse !== undefined) {
let resultMapper = new client.models['VirtualMachineExtension']().mapper();
result = client.deserialize(resultMapper, parsedResponse, 'result');
}
} catch (error) {
let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
deserializationError.request = msRest.stripRequest(httpRequest);
deserializationError.response = msRest.stripResponse(response);
return callback(deserializationError);
}
}
return callback(null, result, httpRequest, response);
});
}
/**
* The operation to create or update the extension.
*
* @param {string} resourceGroupName The name of the resource group.
*
* @param {string} vmName The name of the virtual machine where the extension
* should be create or updated.
*
* @param {string} vmExtensionName The name of the virtual machine extension.
*
* @param {object} extensionParameters Parameters supplied to the Create
* Virtual Machine Extension operation.
*
* @param {string} [extensionParameters.forceUpdateTag] How the extension
* handler should be forced to update even if the extension configuration has
* not changed.
*
* @param {string} [extensionParameters.publisher] The name of the extension
* handler publisher.
*
* @param {string} [extensionParameters.virtualMachineExtensionType] Specifies
* the type of the extension; an example is "CustomScriptExtension".
*
* @param {string} [extensionParameters.typeHandlerVersion] Specifies the
* version of the script handler.
*
* @param {boolean} [extensionParameters.autoUpgradeMinorVersion] Indicates
* whether the extension should use a newer minor version if one is available
* at deployment time. Once deployed, however, the extension will not upgrade
* minor versions unless redeployed, even with this property set to true.
*
* @param {object} [extensionParameters.settings] Json formatted public
* settings for the extension.
*
* @param {object} [extensionParameters.protectedSettings] The extension can
* contain either protectedSettings or protectedSettingsFromKeyVault or no
* protected settings at all.
*
* @param {object} [extensionParameters.instanceView] The virtual machine
* extension instance view.
*
* @param {string} [extensionParameters.instanceView.name] The virtual machine
* extension name.
*
* @param {string} [extensionParameters.instanceView.type] Specifies the type
* of the extension; an example is "CustomScriptExtension".
*
* @param {string} [extensionParameters.instanceView.typeHandlerVersion]
* Specifies the version of the script handler.
*
* @param {array} [extensionParameters.instanceView.substatuses] The resource
* status information.
*
* @param {array} [extensionParameters.instanceView.statuses] The resource
* status information.
*
* @param {string} extensionParameters.location Resource location
*
* @param {object} [extensionParameters.tags] Resource tags
*
* @param {object} [options] Optional Parameters.
*
* @param {object} [options.customHeaders] Headers that will be added to the
* request
*
* @param {function} callback - The callback.
*
* @returns {function} callback(err, result, request, response)
*
* {Error} err - The Error object if an error occurred, null otherwise.
*
* {object} [result] - The deserialized result object if an error did not occur.
* See {@link VirtualMachineExtension} for more
* information.
*
* {object} [request] - The HTTP Request object if an error did not occur.
*
* {stream} [response] - The HTTP Response stream if an error did not occur.
*/
function _beginCreateOrUpdate(resourceGroupName, vmName, vmExtensionName, extensionParameters, options, callback) {
/* jshint validthis: true */
let client = this.client;
if(!callback && typeof options === 'function') {
callback = options;
options = null;
}
if (!callback) {
throw new Error('callback cannot be null.');
}
let apiVersion = '2017-03-30';
// Validate
try {
if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
}
if (vmName === null || vmName === undefined || typeof vmName.valueOf() !== 'string') {
throw new Error('vmName cannot be null or undefined and it must be of type string.');
}
if (vmExtensionName === null || vmExtensionName === undefined || typeof vmExtensionName.valueOf() !== 'string') {
throw new Error('vmExtensionName cannot be null or undefined and it must be of type string.');
}
if (extensionParameters === null || extensionParameters === undefined) {
throw new Error('extensionParameters cannot be null or undefined.');
}
if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
}
if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
throw new Error('this.client.acceptLanguage must be of type string.');
}
} catch (error) {
return callback(error);
}
// Construct URL
let baseUrl = this.client.baseUri;
let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/extensions/{vmExtensionName}';
requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
requestUrl = requestUrl.replace('{vmName}', encodeURIComponent(vmName));
requestUrl = requestUrl.replace('{vmExtensionName}', encodeURIComponent(vmExtensionName));
requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
let queryParameters = [];
queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
if (queryParameters.length > 0) {
requestUrl += '?' + queryParameters.join('&');
}
// Create HTTP transport objects
let httpRequest = new WebResource();
httpRequest.method = 'PUT';
httpRequest.url = requestUrl;
httpRequest.headers = {};
// Set Headers
httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
if (this.client.generateClientRequestId) {
httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
}
if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
httpRequest.headers['accept-language'] = this.client.acceptLanguage;
}
if(options) {
for(let headerName in options['customHeaders']) {
if (options['customHeaders'].hasOwnProperty(headerName)) {
httpRequest.headers[headerName] = options['customHeaders'][headerName];
}
}
}
// Serialize Request
let requestContent = null;
let requestModel = null;
try {
if (extensionParameters !== null && extensionParameters !== undefined) {
let requestModelMapper = new client.models['VirtualMachineExtension']().mapper();
requestModel = client.serialize(requestModelMapper, extensionParameters, 'extensionParameters');
requestContent = JSON.stringify(requestModel);
}
} catch (error) {
let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
`payload - ${JSON.stringify(extensionParameters, null, 2)}.`);
return callback(serializationError);
}
httpRequest.body = requestContent;
// Send Request
return client.pipeline(httpRequest, (err, response, responseBody) => {
if (err) {
return callback(err);
}
let statusCode = response.statusCode;
if (statusCode !== 200 && statusCode !== 201) {
let error = new Error(responseBody);
error.statusCode = response.statusCode;
error.request = msRest.stripRequest(httpRequest);
error.response = msRest.stripResponse(response);
if (responseBody === '') responseBody = null;
let parsedErrorResponse;
try {
parsedErrorResponse = JSON.parse(responseBody);
if (parsedErrorResponse) {
if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
}
if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
let resultMapper = new client.models['CloudError']().mapper();
error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
}
} catch (defaultError) {
error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
`- "${responseBody}" for the default response.`;
return callback(error);
}
return callback(error);
}
// Create Result
let result = null;
if (responseBody === '') responseBody = null;
// Deserialize Response
if (statusCode === 200) {
let parsedResponse = null;
try {
parsedResponse = JSON.parse(responseBody);
result = JSON.parse(responseBody);
if (parsedResponse !== null && parsedResponse !== undefined) {
let resultMapper = new client.models['VirtualMachineExtension']().mapper();
result = client.deserialize(resultMapper, parsedResponse, 'result');
}
} catch (error) {
let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
deserializationError.request = msRest.stripRequest(httpRequest);
deserializationError.response = msRest.stripResponse(response);
return callback(deserializationError);
}
}
// Deserialize Response
if (statusCode === 201) {
let parsedResponse = null;
try {
parsedResponse = JSON.parse(responseBody);
result = JSON.parse(responseBody);
if (parsedResponse !== null && parsedResponse !== undefined) {
let resultMapper = new client.models['VirtualMachineExtension']().mapper();
result = client.deserialize(resultMapper, parsedResponse, 'result');
}
} catch (error) {
let deserializationError1 = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
deserializationError1.request = msRest.stripRequest(httpRequest);
deserializationError1.response = msRest.stripResponse(response);
return callback(deserializationError1);
}
}
return callback(null, result, httpRequest, response);
});
}
/**
* The operation to delete the extension.
*
* @param {string} resourceGroupName The name of the resource group.
*
* @param {string} vmName The name of the virtual machine where the extension
* should be deleted.
*
* @param {string} vmExtensionName The name of the virtual machine extension.
*
* @param {object} [options] Optional Parameters.
*
* @param {object} [options.customHeaders] Headers that will be added to the
* request
*
* @param {function} callback - The callback.
*
* @returns {function} callback(err, result, request, response)
*
* {Error} err - The Error object if an error occurred, null otherwise.
*
* {object} [result] - The deserialized result object if an error did not occur.
* See {@link OperationStatusResponse} for more
* information.
*
* {object} [request] - The HTTP Request object if an error did not occur.
*
* {stream} [response] - The HTTP Response stream if an error did not occur.
*/
function _beginDeleteMethod(resourceGroupName, vmName, vmExtensionName, options, callback) {
/* jshint validthis: true */
let client = this.client;
if(!callback && typeof options === 'function') {
callback = options;
options = null;
}
if (!callback) {
throw new Error('callback cannot be null.');
}
let apiVersion = '2017-03-30';
// Validate
try {
if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
}
if (vmName === null || vmName === undefined || typeof vmName.valueOf() !== 'string') {
throw new Error('vmName cannot be null or undefined and it must be of type string.');
}
if (vmExtensionName === null || vmExtensionName === undefined || typeof vmExtensionName.valueOf() !== 'string') {
throw new Error('vmExtensionName cannot be null or undefined and it must be of type string.');
}
if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
}
if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
throw new Error('this.client.acceptLanguage must be of type string.');
}
} catch (error) {
return callback(error);
}
// Construct URL
let baseUrl = this.client.baseUri;
let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/extensions/{vmExtensionName}';
requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
requestUrl = requestUrl.replace('{vmName}', encodeURIComponent(vmName));
requestUrl = requestUrl.replace('{vmExtensionName}', encodeURIComponent(vmExtensionName));
requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
let queryParameters = [];
queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
if (queryParameters.length > 0) {
requestUrl += '?' + queryParameters.join('&');
}
// Create HTTP transport objects
let httpRequest = new WebResource();
httpRequest.method = 'DELETE';
httpRequest.url = requestUrl;
httpRequest.headers = {};
// Set Headers
httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
if (this.client.generateClientRequestId) {
httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
}
if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
httpRequest.headers['accept-language'] = this.client.acceptLanguage;
}
if(options) {
for(let headerName in options['customHeaders']) {
if (options['customHeaders'].hasOwnProperty(headerName)) {
httpRequest.headers[headerName] = options['customHeaders'][headerName];
}
}
}
httpRequest.body = null;
// Send Request
return client.pipeline(httpRequest, (err, response, responseBody) => {
if (err) {
return callback(err);
}
let statusCode = response.statusCode;
if (statusCode !== 200 && statusCode !== 202 && statusCode !== 204) {
let error = new Error(responseBody);
error.statusCode = response.statusCode;
error.request = msRest.stripRequest(httpRequest);
error.response = msRest.stripResponse(response);
if (responseBody === '') responseBody = null;
let parsedErrorResponse;
try {
parsedErrorResponse = JSON.parse(responseBody);
if (parsedErrorResponse) {
if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
}
if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
let resultMapper = new client.models['CloudError']().mapper();
error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
}
} catch (defaultError) {
error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
`- "${responseBody}" for the default response.`;
return callback(error);
}
return callback(error);
}
// Create Result
let result = null;
if (responseBody === '') responseBody = null;
// Deserialize Response
if (statusCode === 200) {
let parsedResponse = null;
try {
parsedResponse = JSON.parse(responseBody);
result = JSON.parse(responseBody);
if (parsedResponse !== null && parsedResponse !== undefined) {
let resultMapper = new client.models['OperationStatusResponse']().mapper();
result = client.deserialize(resultMapper, parsedResponse, 'result');
}
} catch (error) {
let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
deserializationError.request = msRest.stripRequest(httpRequest);
deserializationError.response = msRest.stripResponse(response);
return callback(deserializationError);
}
}
return callback(null, result, httpRequest, response);
});
}
/** Class representing a VirtualMachineExtensions. */
class VirtualMachineExtensions {
/**
* Create a VirtualMachineExtensions.
* @param {ComputeManagementClient} client Reference to the service client.
*/
constructor(client) {
this.client = client;
this._createOrUpdate = _createOrUpdate;
this._deleteMethod = _deleteMethod;
this._get = _get;
this._beginCreateOrUpdate = _beginCreateOrUpdate;
this._beginDeleteMethod = _beginDeleteMethod;
}
/**
* The operation to create or update the extension.
*
* @param {string} resourceGroupName The name of the resource group.
*
* @param {string} vmName The name of the virtual machine where the extension
* should be create or updated.
*
* @param {string} vmExtensionName The name of the virtual machine extension.
*
* @param {object} extensionParameters Parameters supplied to the Create
* Virtual Machine Extension operation.
*
* @param {string} [extensionParameters.forceUpdateTag] How the extension
* handler should be forced to update even if the extension configuration has
* not changed.
*
* @param {string} [extensionParameters.publisher] The name of the extension
* handler publisher.
*
* @param {string} [extensionParameters.virtualMachineExtensionType] Specifies
* the type of the extension; an example is "CustomScriptExtension".
*
* @param {string} [extensionParameters.typeHandlerVersion] Specifies the
* version of the script handler.
*
* @param {boolean} [extensionParameters.autoUpgradeMinorVersion] Indicates
* whether the extension should use a newer minor version if one is available
* at deployment time. Once deployed, however, the extension will not upgrade
* minor versions unless redeployed, even with this property set to true.
*
* @param {object} [extensionParameters.settings] Json formatted public
* settings for the extension.
*
* @param {object} [extensionParameters.protectedSettings] The extension can
* contain either protectedSettings or protectedSettingsFromKeyVault or no
* protected settings at all.
*
* @param {object} [extensionParameters.instanceView] The virtual machine
* extension instance view.
*
* @param {string} [extensionParameters.instanceView.name] The virtual machine
* extension name.
*
* @param {string} [extensionParameters.instanceView.type] Specifies the type
* of the extension; an example is "CustomScriptExtension".
*
* @param {string} [extensionParameters.instanceView.typeHandlerVersion]
* Specifies the version of the script handler.
*
* @param {array} [extensionParameters.instanceView.substatuses] The resource
* status information.
*
* @param {array} [extensionParameters.instanceView.statuses] The resource
* status information.
*
* @param {string} extensionParameters.location Resource location
*
* @param {object} [extensionParameters.tags] Resource tags
*
* @param {object} [options] Optional Parameters.
*
* @param {object} [options.customHeaders] Headers that will be added to the
* request
*
* @returns {Promise} A promise is returned
*
* @resolve {HttpOperationResponse<VirtualMachineExtension>} - The deserialized result object.
*
* @reject {Error} - The error object.
*/
createOrUpdateWithHttpOperationResponse(resourceGroupName, vmName, vmExtensionName, extensionParameters, options) {
let client = this.client;
let self = this;
return new Promise((resolve, reject) => {
self._createOrUpdate(resourceGroupName, vmName, vmExtensionName, extensionParameters, options, (err, result, request, response) => {
let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
httpOperationResponse.body = result;
if (err) { reject(err); }
else { resolve(httpOperationResponse); }
return;
});
});
}
/**
* The operation to create or update the extension.
*
* @param {string} resourceGroupName The name of the resource group.
*
* @param {string} vmName The name of the virtual machine where the extension
* should be create or updated.
*
* @param {string} vmExtensionName The name of the virtual machine extension.
*
* @param {object} extensionParameters Parameters supplied to the Create
* Virtual Machine Extension operation.
*
* @param {string} [extensionParameters.forceUpdateTag] How the extension
* handler should be forced to update even if the extension configuration has
* not changed.
*
* @param {string} [extensionParameters.publisher] The name of the extension
* handler publisher.
*
* @param {string} [extensionParameters.virtualMachineExtensionType] Specifies
* the type of the extension; an example is "CustomScriptExtension".
*
* @param {string} [extensionParameters.typeHandlerVersion] Specifies the
* version of the script handler.
*
* @param {boolean} [extensionParameters.autoUpgradeMinorVersion] Indicates
* whether the extension should use a newer minor version if one is available
* at deployment time. Once deployed, however, the extension will not upgrade
* minor versions unless redeployed, even with this property set to true.
*
* @param {object} [extensionParameters.settings] Json formatted public
* settings for the extension.
*
* @param {object} [extensionParameters.protectedSettings] The extension can
* contain either protectedSettings or protectedSettingsFromKeyVault or no
* protected settings at all.
*
* @param {object} [extensionParameters.instanceView] The virtual machine
* extension instance view.
*
* @param {string} [extensionParameters.instanceView.name] The virtual machine
* extension name.
*
* @param {string} [extensionParameters.instanceView.type] Specifies the type
* of the extension; an example is "CustomScriptExtension".
*
* @param {string} [extensionParameters.instanceView.typeHandlerVersion]
* Specifies the version of the script handler.
*
* @param {array} [extensionParameters.instanceView.substatuses] The resource
* status information.
*
* @param {array} [extensionParameters.instanceView.statuses] The resource
* status information.
*
* @param {string} extensionParameters.location Resource location
*
* @param {object} [extensionParameters.tags] Resource tags
*
* @param {object} [options] Optional Parameters.
*
* @param {object} [options.customHeaders] Headers that will be added to the
* request
*
* @param {function} [optionalCallback] - The optional callback.
*
* @returns {function|Promise} If a callback was passed as the last parameter
* then it returns the callback else returns a Promise.
*
* {Promise} A promise is returned
*
* @resolve {VirtualMachineExtension} - The deserialized result object.
*
* @reject {Error} - The error object.
*
* {function} optionalCallback(err, result, request, response)
*
* {Error} err - The Error object if an error occurred, null otherwise.
*
* {object} [result] - The deserialized result object if an error did not occur.
* See {@link VirtualMachineExtension} for more
* information.
*
* {object} [request] - The HTTP Request object if an error did not occur.
*
* {stream} [response] - The HTTP Response stream if an error did not occur.
*/
createOrUpdate(resourceGroupName, vmName, vmExtensionName, extensionParameters, options, optionalCallback) {
let client = this.client;
let self = this;
if (!optionalCallback && typeof options === 'function') {
optionalCallback = options;
options = null;
}
if (!optionalCallback) {
return new Promise((resolve, reject) => {
self._createOrUpdate(resourceGroupName, vmName, vmExtensionName, extensionParameters, options, (err, result, request, response) => {
if (err) { reject(err); }
else { resolve(result); }
return;
});
});
} else {
return self._createOrUpdate(resourceGroupName, vmName, vmExtensionName, extensionParameters, options, optionalCallback);
}
}
/**
* The operation to delete the extension.
*
* @param {string} resourceGroupName The name of the resource group.
*
* @param {string} vmName The name of the virtual machine where the extension
* should be deleted.
*
* @param {string} vmExtensionName The name of the virtual machine extension.
*
* @param {object} [options] Optional Parameters.
*
* @param {object} [options.customHeaders] Headers that will be added to the
* request
*
* @returns {Promise} A promise is returned
*
* @resolve {HttpOperationResponse<OperationStatusResponse>} - The deserialized result object.
*
* @reject {Error} - The error object.
*/
deleteMethodWithHttpOperationResponse(resourceGroupName, vmName, vmExtensionName, options) {
let client = this.client;
let self = this;
return new Promise((resolve, reject) => {
self._deleteMethod(resourceGroupName, vmName, vmExtensionName, options, (err, result, request, response) => {
let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
httpOperationResponse.body = result;
if (err) { reject(err); }
else { resolve(httpOperationResponse); }
return;
});
});
}
/**
* The operation to delete the extension.
*
* @param {string} resourceGroupName The name of the resource group.
*
* @param {string} vmName The name of the virtual machine where the extension
* should be deleted.
*
* @param {string} vmExtensionName The name of the virtual machine extension.
*
* @param {object} [options] Optional Parameters.
*
* @param {object} [options.customHeaders] Headers that will be added to the
* request
*
* @param {function} [optionalCallback] - The optional callback.
*
* @returns {function|Promise} If a callback was passed as the last parameter
* then it returns the callback else returns a Promise.
*
* {Promise} A promise is returned
*
* @resolve {OperationStatusResponse} - The deserialized result object.
*
* @reject {Error} - The error object.
*
* {function} optionalCallback(err, result, request, response)
*
* {Error} err - The Error object if an error occurred, null otherwise.
*
* {object} [result] - The deserialized result object if an error did not occur.
* See {@link OperationStatusResponse} for more
* information.
*
* {object} [request] - The HTTP Request object if an error did not occur.
*
* {stream} [response] - The HTTP Response stream if an error did not occur.
*/
deleteMethod(resourceGroupName, vmName, vmExtensionName, options, optionalCallback) {
let client = this.client;
let self = this;
if (!optionalCallback && typeof options === 'function') {
optionalCallback = options;
options = null;
}
if (!optionalCallback) {
return new Promise((resolve, reject) => {
self._deleteMethod(resourceGroupName, vmName, vmExtensionName, options, (err, result, request, response) => {
if (err) { reject(err); }
else { resolve(result); }
return;
});
});
} else {
return self._deleteMethod(resourceGroupName, vmName, vmExtensionName, options, optionalCallback);
}
}
/**
* The operation to get the extension.
*
* @param {string} resourceGroupName The name of the resource group.
*
* @param {string} vmName The name of the virtual machine containing the
* extension.
*
* @param {string} vmExtensionName The name of the virtual machine extension.
*
* @param {object} [options] Optional Parameters.
*
* @param {string} [options.expand] The expand expression to apply on the
* operation.
*
* @param {object} [options.customHeaders] Headers that will be added to the
* request
*
* @returns {Promise} A promise is returned
*
* @resolve {HttpOperationResponse<VirtualMachineExtension>} - The deserialized result object.
*
* @reject {Error} - The error object.
*/
getWithHttpOperationResponse(resourceGroupName, vmName, vmExtensionName, options) {
let client = this.client;
let self = this;
return new Promise((resolve, reject) => {
self._get(resourceGroupName, vmName, vmExtensionName, options, (err, result, request, response) => {
let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
httpOperationResponse.body = result;
if (err) { reject(err); }
else { resolve(httpOperationResponse); }
return;
});
});
}
/**
* The operation to get the extension.
*
* @param {string} resourceGroupName The name of the resource group.
*
* @param {string} vmName The name of the virtual machine containing the
* extension.
*
* @param {string} vmExtensionName The name of the virtual machine extension.
*
* @param {object} [options] Optional Parameters.
*
* @param {string} [options.expand] The expand expression to apply on the
* operation.
*
* @param {object} [options.customHeaders] Headers that will be added to the
* request
*
* @param {function} [optionalCallback] - The optional callback.
*
* @returns {function|Promise} If a callback was passed as the last parameter
* then it returns the callback else returns a Promise.
*
* {Promise} A promise is returned
*
* @resolve {VirtualMachineExtension} - The deserialized result object.
*
* @reject {Error} - The error object.
*
* {function} optionalCallback(err, result, request, response)
*
* {Error} err - The Error object if an error occurred, null otherwise.
*
* {object} [result] - The deserialized result object if an error did not occur.
* See {@link VirtualMachineExtension} for more
* information.
*
* {object} [request] - The HTTP Request object if an error did not occur.
*
* {stream} [response] - The HTTP Response stream if an error did not occur.
*/
get(resourceGroupName, vmName, vmExtensionName, options, optionalCallback) {
let client = this.client;
let self = this;
if (!optionalCallback && typeof options === 'function') {
optionalCallback = options;
options = null;
}
if (!optionalCallback) {
return new Promise((resolve, reject) => {
self._get(resourceGroupName, vmName, vmExtensionName, options, (err, result, request, response) => {
if (err) { reject(err); }
else { resolve(result); }
return;
});
});
} else {
return self._get(resourceGroupName, vmName, vmExtensionName, options, optionalCallback);
}
}
/**
* The operation to create or update the extension.
*
* @param {string} resourceGroupName The name of the resource group.
*
* @param {string} vmName The name of the virtual machine where the extension
* should be create or updated.
*
* @param {string} vmExtensionName The name of the virtual machine extension.
*
* @param {object} extensionParameters Parameters supplied to the Create
* Virtual Machine Extension operation.
*
* @param {string} [extensionParameters.forceUpdateTag] How the extension
* handler should be forced to update even if the extension configuration has
* not changed.
*
* @param {string} [extensionParameters.publisher] The name of the extension
* handler publisher.
*
* @param {string} [extensionParameters.virtualMachineExtensionType] Specifies
* the type of the extension; an example is "CustomScriptExtension".
*
* @param {string} [extensionParameters.typeHandlerVersion] Specifies the
* version of the script handler.
*
* @param {boolean} [extensionParameters.autoUpgradeMinorVersion] Indicates
* whether the extension should use a newer minor version if one is available
* at deployment time. Once deployed, however, the extension will not upgrade
* minor versions unless redeployed, even with this property set to true.
*
* @param {object} [extensionParameters.settings] Json formatted public
* settings for the extension.
*
* @param {object} [extensionParameters.protectedSettings] The extension can
* contain either protectedSettings or protectedSettingsFromKeyVault or no
* protected settings at all.
*
* @param {object} [extensionParameters.instanceView] The virtual machine
* extension instance view.
*
* @param {string} [extensionParameters.