UNPKG

azure-cli

Version:

Microsoft Azure Cross Platform Command Line tool

1,236 lines (1,172 loc) 162 kB
/* * 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; /** * Creates or updates a snapshot. * * @param {string} resourceGroupName The name of the resource group. * * @param {string} snapshotName The name of the snapshot within the given * subscription and resource group. * * @param {object} snapshot Snapshot object supplied in the body of the Put * disk operation. * * @param {object} [snapshot.sku] * * @param {string} [snapshot.sku.name] The sku name. Possible values include: * 'Standard_LRS', 'Premium_LRS' * * @param {string} [snapshot.osType] The Operating System type. Possible values * include: 'Windows', 'Linux' * * @param {object} snapshot.creationData Disk source information. CreationData * information cannot be changed after the disk has been created. * * @param {string} snapshot.creationData.createOption This enumerates the * possible sources of a disk's creation. Possible values include: 'Empty', * 'Attach', 'FromImage', 'Import', 'Copy' * * @param {string} [snapshot.creationData.storageAccountId] If createOption is * Import, the Azure Resource Manager identifier of the storage account * containing the blob to import as a disk. Required only if the blob is in a * different subscription * * @param {object} [snapshot.creationData.imageReference] Disk source * information. * * @param {string} snapshot.creationData.imageReference.id A relative uri * containing either a Platform Imgage Repository or user image reference. * * @param {number} [snapshot.creationData.imageReference.lun] If the disk is * created from an image's data disk, this is an index that indicates which of * the data disks in the image to use. For OS disks, this field is null. * * @param {string} [snapshot.creationData.sourceUri] If creationOption is * Import, this is the URI of a blob to be imported into a managed disk. * * @param {string} [snapshot.creationData.sourceResourceId] If createOption is * Copy, this is the ARM id of the source snapshot or disk. * * @param {number} [snapshot.diskSizeGB] If creationData.createOption is Empty, * this field is mandatory and it indicates the size of the VHD to create. If * this field is present for updates or creation with other options, it * indicates a resize. Resizes are only allowed if the disk is not attached to * a running VM, and can only increase the disk's size. * * @param {object} [snapshot.encryptionSettings] Encryption settings for disk * or snapshot * * @param {boolean} [snapshot.encryptionSettings.enabled] Set this flag to true * and provide DiskEncryptionKey and optional KeyEncryptionKey to enable * encryption. Set this flag to false and remove DiskEncryptionKey and * KeyEncryptionKey to disable encryption. If EncryptionSettings is null in the * request object, the existing settings remain unchanged. * * @param {object} [snapshot.encryptionSettings.diskEncryptionKey] Key Vault * Secret Url and vault id of the disk encryption key * * @param {object} snapshot.encryptionSettings.diskEncryptionKey.sourceVault * Resource id of the KeyVault containing the key or secret * * @param {string} snapshot.encryptionSettings.diskEncryptionKey.secretUrl Url * pointing to a key or secret in KeyVault * * @param {object} [snapshot.encryptionSettings.keyEncryptionKey] Key Vault Key * Url and vault id of the key encryption key * * @param {object} snapshot.encryptionSettings.keyEncryptionKey.sourceVault * Resource id of the KeyVault containing the key or secret * * @param {string} * [snapshot.encryptionSettings.keyEncryptionKey.sourceVault.id] Resource Id * * @param {string} snapshot.encryptionSettings.keyEncryptionKey.keyUrl Url * pointing to a key or secret in KeyVault * * @param {string} snapshot.location Resource location * * @param {object} [snapshot.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 Snapshot} 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, snapshotName, snapshot, 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, snapshotName, snapshot, 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['Snapshot']().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); }); }); } /** * Updates (patches) a snapshot. * * @param {string} resourceGroupName The name of the resource group. * * @param {string} snapshotName The name of the snapshot within the given * subscription and resource group. * * @param {object} snapshot Snapshot object supplied in the body of the Patch * snapshot operation. * * @param {string} [snapshot.osType] the Operating System type. Possible values * include: 'Windows', 'Linux' * * @param {number} [snapshot.diskSizeGB] If creationData.createOption is Empty, * this field is mandatory and it indicates the size of the VHD to create. If * this field is present for updates or creation with other options, it * indicates a resize. Resizes are only allowed if the disk is not attached to * a running VM, and can only increase the disk's size. * * @param {object} [snapshot.encryptionSettings] Encryption settings for disk * or snapshot * * @param {boolean} [snapshot.encryptionSettings.enabled] Set this flag to true * and provide DiskEncryptionKey and optional KeyEncryptionKey to enable * encryption. Set this flag to false and remove DiskEncryptionKey and * KeyEncryptionKey to disable encryption. If EncryptionSettings is null in the * request object, the existing settings remain unchanged. * * @param {object} [snapshot.encryptionSettings.diskEncryptionKey] Key Vault * Secret Url and vault id of the disk encryption key * * @param {object} snapshot.encryptionSettings.diskEncryptionKey.sourceVault * Resource id of the KeyVault containing the key or secret * * @param {string} snapshot.encryptionSettings.diskEncryptionKey.secretUrl Url * pointing to a key or secret in KeyVault * * @param {object} [snapshot.encryptionSettings.keyEncryptionKey] Key Vault Key * Url and vault id of the key encryption key * * @param {object} snapshot.encryptionSettings.keyEncryptionKey.sourceVault * Resource id of the KeyVault containing the key or secret * * @param {string} * [snapshot.encryptionSettings.keyEncryptionKey.sourceVault.id] Resource Id * * @param {string} snapshot.encryptionSettings.keyEncryptionKey.keyUrl Url * pointing to a key or secret in KeyVault * * @param {object} [snapshot.tags] Resource tags * * @param {object} [snapshot.sku] * * @param {string} [snapshot.sku.name] The sku name. Possible values include: * 'Standard_LRS', 'Premium_LRS' * * @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 Snapshot} 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 _update(resourceGroupName, snapshotName, snapshot, 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.beginUpdate(resourceGroupName, snapshotName, snapshot, 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['Snapshot']().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); }); }); } /** * Gets information about a snapshot. * * @param {string} resourceGroupName The name of the resource group. * * @param {string} snapshotName The name of the snapshot within the given * subscription and resource group. * * @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 Snapshot} 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, snapshotName, 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 (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 (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 (snapshotName === null || snapshotName === undefined || typeof snapshotName.valueOf() !== 'string') { throw new Error('snapshotName 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/snapshots/{snapshotName}'; requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId)); requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName)); requestUrl = requestUrl.replace('{snapshotName}', encodeURIComponent(snapshotName)); 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 = '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['Snapshot']().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); }); } /** * Deletes a snapshot. * * @param {string} resourceGroupName The name of the resource group. * * @param {string} snapshotName The name of the snapshot within the given * subscription and resource group. * * @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, snapshotName, 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, snapshotName, 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); }); }); } /** * Lists snapshots under a resource group. * * @param {string} resourceGroupName The name of the resource group. * * @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 SnapshotList} 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 _listByResourceGroup(resourceGroupName, 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 (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 (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 (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/snapshots'; requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId)); requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName)); 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 = '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['SnapshotList']().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); }); } /** * Lists snapshots under a subscription. * * @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 SnapshotList} 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 _list(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 (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}/providers/Microsoft.Compute/snapshots'; 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 = '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['SnapshotList']().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); }); } /** * Grants access to a snapshot. * * @param {string} resourceGroupName The name of the resource group. * * @param {string} snapshotName The name of the snapshot within the given * subscription and resource group. * * @param {object} grantAccessData Access data object supplied in the body of * the get snapshot access operation. * * @param {string} grantAccessData.access Possible values include: 'None', * 'Read' * * @param {number} grantAccessData.durationInSeconds Time duration in seconds * until the SAS access expires. * * @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 AccessUri} 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 _grantAccess(resourceGroupName, snapshotName, grantAccessData, 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.beginGrantAccess(resourceGroupName, snapshotName, grantAccessData, 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['AccessUri']().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); }); }); } /** * Revokes access to a snapshot. * * @param {string} resourceGroupName The name of the resource group. * * @param {string} snapshotName The name of the snapshot within the given * subscription and resource group. * * @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 _revokeAccess(resourceGroupName, snapshotName, 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.beginRevokeAccess(resourceGroupName, snapshotName, 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); }); }); } /** * Creates or updates a snapshot. * * @param {string} resourceGroupName The name of the resource group. * * @param {string} snapshotName The name of the snapshot within the given * subscription and resource group. * * @param {object} snapshot Snapshot object supplied in the body of the Put * disk operation. * * @param {object} [snapshot.sku] * * @param {string} [snapshot.sku.name] The sku name. Possible values include: * 'Standard_LRS', 'Premium_LRS' * * @param {string} [snapshot.osType] The Operating System type. Possible values * include: 'Windows', 'Linux' * * @param {object} snapshot.creationData Disk source information. CreationData * information cannot be changed after the disk has been created. * * @param {string} snapshot.creationData.createOption This enumerates the * possible sources of a disk's creation. Possible values include: 'Empty', * 'Attach', 'FromImage', 'Import', 'Copy' * * @param {string} [snapshot.creationData.storageAccountId] If createOption is * Import, the Azure Resource Manager identifier of the storage account * containing the blob to import as a disk. Required only if the blob is in a * different subscription * * @param {object} [snapshot.creationData.imageReference] Disk source * information. * * @param {string} snapshot.creationData.imageReference.id A relative uri * containing either a Platform Imgage Repository or user image reference. * * @param {number} [snapshot.creationData.imageReference.lun] If the disk is * created from an image's data disk, this is an index that indicates which of * the data disks in the image to use. For OS disks, this field is null. * * @param {string} [snapshot.creationData.sourceUri] If creationOption is * Import, this is the URI of a blob to be imported into a managed disk. * * @param {string} [snapshot.creationData.sourceResourceId] If createOption is * Copy, this is the ARM id of the source snapshot or disk. * * @param {number} [snapshot.diskSizeGB] If creationData.createOption is Empty, * this field is mandatory and it indicates the size of the VHD to create. If * this field is present for updates or creation with other options, it * indicates a resize. Resizes are only allowed if the disk is not attached to * a running VM, and can only increase the disk's size. * * @param {object} [snapshot.encryptionSettings] Encryption settings for disk * or snapshot * * @param {boolean} [snapshot.encryptionSettings.enabled] Set this flag to true * and provide DiskEncryptionKey and optional KeyEncryptionKey to enable * encryption. Set this flag to false and remove DiskEncryptionKey and * KeyEncryptionKey to disable encryption. If EncryptionSettings is null in the * request object, the existing settings remain unchanged. * * @param {object} [snapshot.encryptionSettings.diskEncryptionKey] Key Vault * Secret Url and vault id of the disk encryption key * * @param {object} snapshot.encryptionSettings.diskEncryptionKey.sourceVault * Resource id of the KeyVault containing the key or secret * * @param {string} snapshot.encryptionSettings.diskEncryptionKey.secretUrl Url * pointing to a key or secret in KeyVault * * @param {object} [snapshot.encryptionSettings.keyEncryptionKey] Key Vault Key * Url and vault id of the key encryption key * * @param {object} snapshot.encryptionSettings.keyEncryptionKey.sourceVault * Resource id of the KeyVault containing the key or secret * * @param {string} * [snapshot.encryptionSettings.keyEncryptionKey.sourceVault.id] Resource Id * * @param {string} snapshot.encryptionSettings.keyEncryptionKey.keyUrl Url * pointing to a key or secret in KeyVault * * @param {string} snapshot.location Resource location * * @param {object} [snapshot.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 Snapshot} 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, snapshotName, snapshot, 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 (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 (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 (snapshotName === null || snapshotName === undefined || typeof snapshotName.valueOf() !== 'string') { throw new Error('snapshotName cannot be null or undefined and it must be of type string.'); } if (snapshot === null || snapshot === undefined) { throw new Error('snapshot cannot be null or undefined.'); } 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/snapshots/{snapshotName}'; requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId)); requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName)); requestUrl = requestUrl.replace('{snapshotName}', encodeURIComponent(snapshotName)); 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 (snapshot !== null && snapshot !== undefined) { let requestModelMapper = new client.models['Snapshot']().mapper(); requestModel = client.serialize(requestModelMapper, snapshot, 'snapshot'); requestContent = JSON.stringify(requestModel); } } catch (error) { let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + `payload - ${JSON.stringify(snapshot, 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 !== 202) { 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['Snapshot']().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 === 202) { let parsedResponse = null; try { parsedResponse = JSON.parse(responseBody); result = JSON.parse(responseBody); if (parsedResponse !== null && parsedResponse !== undefined) { let resultMapper = new client.models['Snapshot']().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); }); } /** * Updates (patches) a snapshot. * * @param {string} resourceGroupName The name of the resource group. * * @param {string} snapshotName The name of the snapshot within the given * subscription and resource group. * * @param {object} snapshot Snapshot object supplied in the body of the Patch * snapshot operation. * * @param {string} [snapshot.osType] the Operating System type. Possible values * include: 'Windows', 'Linux' * * @param {number} [snapshot.diskSizeGB] If creationData.createOption is Empty, * this field is mandatory and it indicates the size of the VHD to create. If * this field is present for updates or creati