From e5c816ede75d8ad5481fd409e44a0686e0fb1ff5 Mon Sep 17 00:00:00 2001 From: Azure SDK for Python bot Date: Wed, 14 Nov 2018 00:55:03 +0000 Subject: [PATCH] Generated from 1f26996e492bf786c2acd06e0a4e46159c52df70 Adds storage account quick failover API --- .../storageManagement2/lib/models/index.d.ts | 3 + .../lib/models/storageAccount.js | 10 + .../lib/operations/index.d.ts | 140 ++++++ .../lib/operations/storageAccounts.js | 426 ++++++++++++++++++ 4 files changed, 579 insertions(+) diff --git a/lib/services/storageManagement2/lib/models/index.d.ts b/lib/services/storageManagement2/lib/models/index.d.ts index 0f466edafb..061f72282a 100644 --- a/lib/services/storageManagement2/lib/models/index.d.ts +++ b/lib/services/storageManagement2/lib/models/index.d.ts @@ -793,6 +793,8 @@ export interface TrackedResource extends Resource { * 'Allow', 'Deny' * @member {boolean} [isHnsEnabled] Account HierarchicalNamespace enabled if * sets to true. + * @member {boolean} [failoverInProgress] If the failover is in progress, the + * value will be true, otherwise, it will be null. */ export interface StorageAccount extends TrackedResource { readonly sku?: Sku; @@ -814,6 +816,7 @@ export interface StorageAccount extends TrackedResource { enableHttpsTrafficOnly?: boolean; readonly networkRuleSet?: NetworkRuleSet; isHnsEnabled?: boolean; + readonly failoverInProgress?: boolean; } /** diff --git a/lib/services/storageManagement2/lib/models/storageAccount.js b/lib/services/storageManagement2/lib/models/storageAccount.js index 8ff0c24b3a..46eefffb25 100644 --- a/lib/services/storageManagement2/lib/models/storageAccount.js +++ b/lib/services/storageManagement2/lib/models/storageAccount.js @@ -168,6 +168,8 @@ class StorageAccount extends models['TrackedResource'] { * include: 'Allow', 'Deny' * @member {boolean} [isHnsEnabled] Account HierarchicalNamespace enabled if * sets to true. + * @member {boolean} [failoverInProgress] If the failover is in progress, the + * value will be true, otherwise, it will be null. */ constructor() { super(); @@ -391,6 +393,14 @@ class StorageAccount extends models['TrackedResource'] { type: { name: 'Boolean' } + }, + failoverInProgress: { + required: false, + readOnly: true, + serializedName: 'properties.failoverInProgress', + type: { + name: 'Boolean' + } } } } diff --git a/lib/services/storageManagement2/lib/operations/index.d.ts b/lib/services/storageManagement2/lib/operations/index.d.ts index 46b6e267d7..dbf969abdb 100644 --- a/lib/services/storageManagement2/lib/operations/index.d.ts +++ b/lib/services/storageManagement2/lib/operations/index.d.ts @@ -1466,6 +1466,76 @@ export interface StorageAccounts { listServiceSAS(resourceGroupName: string, accountName: string, parameters: models.ServiceSasParameters, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + /** + * Failover request can be triggered for a storage account in case of + * availability issues. The failover occurs from the storage account's primary + * cluster to secondary cluster for RA-GRS accounts. The secondary cluster will + * become primary after failover. + * + * @param {string} resourceGroupName The name of the resource group within the + * user's subscription. The name is case insensitive. + * + * @param {string} accountName The name of the storage account within the + * specified resource group. Storage account names must be between 3 and 24 + * characters in length and use numbers and lower-case letters only. + * + * @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} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + failoverWithHttpOperationResponse(resourceGroupName: string, accountName: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Failover request can be triggered for a storage account in case of + * availability issues. The failover occurs from the storage account's primary + * cluster to secondary cluster for RA-GRS accounts. The secondary cluster will + * become primary after failover. + * + * @param {string} resourceGroupName The name of the resource group within the + * user's subscription. The name is case insensitive. + * + * @param {string} accountName The name of the storage account within the + * specified resource group. Storage account names must be between 3 and 24 + * characters in length and use numbers and lower-case letters only. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|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 {null} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + failover(resourceGroupName: string, accountName: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + failover(resourceGroupName: string, accountName: string, callback: ServiceCallback): void; + failover(resourceGroupName: string, accountName: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + /** * Asynchronously creates a new storage account with the specified parameters. * If an account is already created and a subsequent create request is issued @@ -1751,6 +1821,76 @@ export interface StorageAccounts { beginCreate(resourceGroupName: string, accountName: string, parameters: models.StorageAccountCreateParameters, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; beginCreate(resourceGroupName: string, accountName: string, parameters: models.StorageAccountCreateParameters, callback: ServiceCallback): void; beginCreate(resourceGroupName: string, accountName: string, parameters: models.StorageAccountCreateParameters, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * Failover request can be triggered for a storage account in case of + * availability issues. The failover occurs from the storage account's primary + * cluster to secondary cluster for RA-GRS accounts. The secondary cluster will + * become primary after failover. + * + * @param {string} resourceGroupName The name of the resource group within the + * user's subscription. The name is case insensitive. + * + * @param {string} accountName The name of the storage account within the + * specified resource group. Storage account names must be between 3 and 24 + * characters in length and use numbers and lower-case letters only. + * + * @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} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + beginFailoverWithHttpOperationResponse(resourceGroupName: string, accountName: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Failover request can be triggered for a storage account in case of + * availability issues. The failover occurs from the storage account's primary + * cluster to secondary cluster for RA-GRS accounts. The secondary cluster will + * become primary after failover. + * + * @param {string} resourceGroupName The name of the resource group within the + * user's subscription. The name is case insensitive. + * + * @param {string} accountName The name of the storage account within the + * specified resource group. Storage account names must be between 3 and 24 + * characters in length and use numbers and lower-case letters only. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|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 {null} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + beginFailover(resourceGroupName: string, accountName: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + beginFailover(resourceGroupName: string, accountName: string, callback: ServiceCallback): void; + beginFailover(resourceGroupName: string, accountName: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; } /** diff --git a/lib/services/storageManagement2/lib/operations/storageAccounts.js b/lib/services/storageManagement2/lib/operations/storageAccounts.js index 176c3f95b9..e48383fdbd 100644 --- a/lib/services/storageManagement2/lib/operations/storageAccounts.js +++ b/lib/services/storageManagement2/lib/operations/storageAccounts.js @@ -2170,6 +2170,75 @@ function _listServiceSAS(resourceGroupName, accountName, parameters, options, ca }); } + +/** + * Failover request can be triggered for a storage account in case of + * availability issues. The failover occurs from the storage account's primary + * cluster to secondary cluster for RA-GRS accounts. The secondary cluster will + * become primary after failover. + * + * @param {string} resourceGroupName The name of the resource group within the + * user's subscription. The name is case insensitive. + * + * @param {string} accountName The name of the storage account within the + * specified resource group. Storage account names must be between 3 and 24 + * characters in length and use numbers and lower-case letters only. + * + * @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. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {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 _failover(resourceGroupName, accountName, 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.beginFailover(resourceGroupName, accountName, 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 + + return callback(null, result, httpRequest, response); + }); + }); +} + /** * Asynchronously creates a new storage account with the specified parameters. * If an account is already created and a subsequent create request is issued @@ -2478,6 +2547,167 @@ function _beginCreate(resourceGroupName, accountName, parameters, options, callb }); } +/** + * Failover request can be triggered for a storage account in case of + * availability issues. The failover occurs from the storage account's primary + * cluster to secondary cluster for RA-GRS accounts. The secondary cluster will + * become primary after failover. + * + * @param {string} resourceGroupName The name of the resource group within the + * user's subscription. The name is case insensitive. + * + * @param {string} accountName The name of the storage account within the + * specified resource group. Storage account names must be between 3 and 24 + * characters in length and use numbers and lower-case letters only. + * + * @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. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {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 _beginFailover(resourceGroupName, accountName, 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 = '2018-07-01'; + // 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 (resourceGroupName !== null && resourceGroupName !== undefined) { + if (resourceGroupName.length > 90) + { + throw new Error('"resourceGroupName" should satisfy the constraint - "MaxLength": 90'); + } + if (resourceGroupName.length < 1) + { + throw new Error('"resourceGroupName" should satisfy the constraint - "MinLength": 1'); + } + if (resourceGroupName.match(/^[-\w\._\(\)]+$/) === null) + { + throw new Error('"resourceGroupName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/'); + } + } + if (accountName === null || accountName === undefined || typeof accountName.valueOf() !== 'string') { + throw new Error('accountName cannot be null or undefined and it must be of type string.'); + } + if (accountName !== null && accountName !== undefined) { + if (accountName.length > 24) + { + throw new Error('"accountName" should satisfy the constraint - "MaxLength": 24'); + } + if (accountName.length < 3) + { + throw new Error('"accountName" should satisfy the constraint - "MinLength": 3'); + } + } + 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.subscriptionId !== null && this.client.subscriptionId !== undefined) { + if (this.client.subscriptionId.length < 1) + { + throw new Error('"this.client.subscriptionId" should satisfy the constraint - "MinLength": 1'); + } + } + 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.Storage/storageAccounts/{accountName}/failover'; + requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName)); + requestUrl = requestUrl.replace('{accountName}', encodeURIComponent(accountName)); + 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 = 'POST'; + 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) { + 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; + + return callback(null, result, httpRequest, response); + }); +} + /** Class representing a StorageAccounts. */ class StorageAccounts { /** @@ -2497,7 +2727,9 @@ class StorageAccounts { this._regenerateKey = _regenerateKey; this._listAccountSAS = _listAccountSAS; this._listServiceSAS = _listServiceSAS; + this._failover = _failover; this._beginCreate = _beginCreate; + this._beginFailover = _beginFailover; } /** @@ -4120,6 +4352,103 @@ class StorageAccounts { } } + /** + * Failover request can be triggered for a storage account in case of + * availability issues. The failover occurs from the storage account's primary + * cluster to secondary cluster for RA-GRS accounts. The secondary cluster will + * become primary after failover. + * + * @param {string} resourceGroupName The name of the resource group within the + * user's subscription. The name is case insensitive. + * + * @param {string} accountName The name of the storage account within the + * specified resource group. Storage account names must be between 3 and 24 + * characters in length and use numbers and lower-case letters only. + * + * @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} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + failoverWithHttpOperationResponse(resourceGroupName, accountName, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._failover(resourceGroupName, accountName, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Failover request can be triggered for a storage account in case of + * availability issues. The failover occurs from the storage account's primary + * cluster to secondary cluster for RA-GRS accounts. The secondary cluster will + * become primary after failover. + * + * @param {string} resourceGroupName The name of the resource group within the + * user's subscription. The name is case insensitive. + * + * @param {string} accountName The name of the storage account within the + * specified resource group. Storage account names must be between 3 and 24 + * characters in length and use numbers and lower-case letters only. + * + * @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 {null} - 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. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + failover(resourceGroupName, accountName, 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._failover(resourceGroupName, accountName, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._failover(resourceGroupName, accountName, options, optionalCallback); + } + } + /** * Asynchronously creates a new storage account with the specified parameters. * If an account is already created and a subsequent create request is issued @@ -4434,6 +4763,103 @@ class StorageAccounts { } } + /** + * Failover request can be triggered for a storage account in case of + * availability issues. The failover occurs from the storage account's primary + * cluster to secondary cluster for RA-GRS accounts. The secondary cluster will + * become primary after failover. + * + * @param {string} resourceGroupName The name of the resource group within the + * user's subscription. The name is case insensitive. + * + * @param {string} accountName The name of the storage account within the + * specified resource group. Storage account names must be between 3 and 24 + * characters in length and use numbers and lower-case letters only. + * + * @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} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + beginFailoverWithHttpOperationResponse(resourceGroupName, accountName, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._beginFailover(resourceGroupName, accountName, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Failover request can be triggered for a storage account in case of + * availability issues. The failover occurs from the storage account's primary + * cluster to secondary cluster for RA-GRS accounts. The secondary cluster will + * become primary after failover. + * + * @param {string} resourceGroupName The name of the resource group within the + * user's subscription. The name is case insensitive. + * + * @param {string} accountName The name of the storage account within the + * specified resource group. Storage account names must be between 3 and 24 + * characters in length and use numbers and lower-case letters only. + * + * @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 {null} - 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. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + beginFailover(resourceGroupName, accountName, 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._beginFailover(resourceGroupName, accountName, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._beginFailover(resourceGroupName, accountName, options, optionalCallback); + } + } + } module.exports = StorageAccounts;