azure-cli
Version:
Microsoft Azure Cross Platform Command Line tool
1,285 lines (1,149 loc) • 342 kB
JavaScript
/* jshint latedef:false */
/* jshint forin:false */
/* jshint noempty:false */
//
// Copyright (c) Microsoft and contributors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Warning: This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if the
// code is regenerated.
'use strict';
var util = require('util');
var _ = require('underscore');
var moment = require('moment');
var azureCommon = require('azure-common');
var Service = azureCommon.Service;
var WebResource = azureCommon.WebResource;
var OperationStatus = azureCommon.OperationStatus;
var ResourceManagementClient = ( /** @lends ResourceManagementClient */ function() {
/**
* @class
* Initializes a new instance of the ResourceManagementClient class.
* @constructor
*
* @param {SubscriptionCloudCredentials} credentials Gets subscription
* credentials which uniquely identify Microsoft Azure subscription. The
* subscription ID forms part of the URI for every service call.
*
* @param {string} [credentials.subscriptionId]
*
* @param {string} [baseUri] Gets the URI used as the base for all cloud
* service requests.
*
* @param {Array} filters
*/
function ResourceManagementClient(credentials, baseUri, filters) {
if (credentials === null || credentials === undefined) {
throw new Error('credentials cannot be null.');
}
ResourceManagementClient['super_'].call(this, credentials, filters);
this.credentials = credentials;
this.baseUri = baseUri;
if (this.baseUri === null || this.baseUri === undefined) {
this.baseUri = 'https://management.azure.com/';
}
if (this.apiVersion === null || this.apiVersion === undefined) {
this.apiVersion = '2015-11-01';
}
if (this.longRunningOperationInitialTimeout === null || this.longRunningOperationInitialTimeout === undefined) {
this.longRunningOperationInitialTimeout = -1;
}
if (this.longRunningOperationRetryTimeout === null || this.longRunningOperationRetryTimeout === undefined) {
this.longRunningOperationRetryTimeout = -1;
}
/**
* Provides an instance of the
* [DeploymentOperationOperations](-DeploymentOperationOperations.html)
* object.
* @type {object}
*/
this.deploymentOperations = new DeploymentOperationOperations(this);
/**
* Provides an instance of the
* [DeploymentOperations](-DeploymentOperations.html) object.
* @type {object}
*/
this.deployments = new DeploymentOperations(this);
/**
* Provides an instance of the
* [ProviderOperations](-ProviderOperations.html) object.
* @type {object}
*/
this.providers = new ProviderOperations(this);
/**
* Provides an instance of the
* [ProviderOperationsMetadataOperations](-ProviderOperationsMetadataOperations.html)
* object.
* @type {object}
*/
this.providerOperationsMetadata = new ProviderOperationsMetadataOperations(this);
/**
* Provides an instance of the
* [ResourceGroupOperations](-ResourceGroupOperations.html) object.
* @type {object}
*/
this.resourceGroups = new ResourceGroupOperations(this);
/**
* Provides an instance of the
* [ResourceOperations](-ResourceOperations.html) object.
* @type {object}
*/
this.resources = new ResourceOperations(this);
/**
* Provides an instance of the
* [ResourceProviderOperationDetailsOperations](-ResourceProviderOperationDetailsOperations.html)
* object.
* @type {object}
*/
this.resourceProviderOperationDetails = new ResourceProviderOperationDetailsOperations(this);
/**
* Provides an instance of the [TagOperations](-TagOperations.html) object.
* @type {object}
*/
this.tags = new TagOperations(this);
}
util.inherits(ResourceManagementClient, Service);
/**
* The Get Operation Status operation returns the status of the specified
* operation. After calling an asynchronous operation, you can call Get
* Operation Status to determine whether the operation has succeeded,
* failed, or is still in progress.
*
* @param {string} operationStatusLink Location value returned by the Begin
* operation.
*
* @param {function} callback
*
* @returns {Stream} The response stream.
*/
ResourceManagementClient.prototype.getLongRunningOperationStatus = function(operationStatusLink, callback) {
if (callback === null || callback === undefined) {
throw new Error('callback cannot be null.');
}
// Validate
if (operationStatusLink === null || operationStatusLink === undefined) {
return callback(new Error('operationStatusLink cannot be null.'));
}
// Tracing
// Construct URL
var url2 = '';
url2 = url2 + operationStatusLink;
url2 = url2.replace(' ', '%20');
// Create HTTP transport objects
var httpRequest = new WebResource();
httpRequest.method = 'GET';
httpRequest.headers = {};
httpRequest.url = url2;
// Set Headers
httpRequest.headers['x-ms-version'] = '2015-11-01';
// Send Request
return this.pipeline(httpRequest, function (err, response, body) {
if (err !== null && err !== undefined) {
return callback(err);
}
var statusCode = response.statusCode;
if (statusCode !== 200 && statusCode !== 202 && statusCode !== 204) {
var error = new Error(body);
error.statusCode = response.statusCode;
return callback(error);
}
// Create Result
var result = null;
// Deserialize Response
result = {};
result.statusCode = statusCode;
result.retryAfter = parseInt(response.headers['retry-after'], 10);
result.requestId = response.headers['x-ms-request-id'];
if (statusCode === 400) {
result.status = OperationStatus.Failed;
}
if (statusCode === 409) {
result.status = OperationStatus.Failed;
}
if (statusCode === 202) {
result.status = OperationStatus.InProgress;
}
if (statusCode === 204) {
result.status = OperationStatus.Succeeded;
}
if (statusCode === 200) {
result.status = OperationStatus.Succeeded;
}
return callback(null, result);
});
};
return ResourceManagementClient;
})();
exports.ResourceManagementClient = ResourceManagementClient;
var DeploymentOperationOperations = ( /** @lends DeploymentOperationOperations */ function() {
/**
* @class
* Operations for managing deployment operations.
* __NOTE__: An instance of this class is automatically created for an
* instance of the [ResourceManagementClient] {@link
* ResourceManagementClient~ResourceManagementClient}.
* See [deploymentOperations] {@link
* ResourceManagementClient~ResourceManagementClient#deploymentOperations}.
* Initializes a new instance of the DeploymentOperationOperations class.
* @constructor
*
* @param {ResourceManagementClient} client Reference to the service client.
*/
function DeploymentOperationOperations(client) {
this.client = client;
}
/**
* Get a list of deployments operations.
*
* @param {string} resourceGroupName The name of the resource group. The name
* is case insensitive.
*
* @param {string} deploymentName The name of the deployment.
*
* @param {string} operationId Operation Id.
*
* @param {function} callback
*
* @returns {Stream} The response stream.
*/
DeploymentOperationOperations.prototype.get = function(resourceGroupName, deploymentName, operationId, callback) {
if (callback === null || callback === undefined) {
throw new Error('callback cannot be null.');
}
// Validate
if (resourceGroupName === null || resourceGroupName === undefined) {
return callback(new Error('resourceGroupName cannot be null.'));
}
if (resourceGroupName !== null && resourceGroupName !== undefined && resourceGroupName.length > 1000) {
return callback(new Error('resourceGroupName is outside the valid range.'));
}
if (/^[-\w\._]+$/.test(resourceGroupName) === false) {
return callback(new Error('resourceGroupName is outside the valid range.'));
}
if (deploymentName === null || deploymentName === undefined) {
return callback(new Error('deploymentName cannot be null.'));
}
if (operationId === null || operationId === undefined) {
return callback(new Error('operationId cannot be null.'));
}
// Tracing
// Construct URL
var url2 = '';
url2 = url2 + '/subscriptions/';
if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
}
url2 = url2 + '/resourcegroups/';
url2 = url2 + encodeURIComponent(resourceGroupName);
url2 = url2 + '/deployments/';
url2 = url2 + encodeURIComponent(deploymentName);
url2 = url2 + '/operations/';
url2 = url2 + encodeURIComponent(operationId);
var queryParameters = [];
queryParameters.push('api-version=2015-11-01');
if (queryParameters.length > 0) {
url2 = url2 + '?' + queryParameters.join('&');
}
var baseUrl = this.client.baseUri;
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl[baseUrl.length - 1] === '/') {
baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
}
if (url2[0] === '/') {
url2 = url2.substring(1);
}
url2 = baseUrl + '/' + url2;
url2 = url2.replace(' ', '%20');
// Create HTTP transport objects
var httpRequest = new WebResource();
httpRequest.method = 'GET';
httpRequest.headers = {};
httpRequest.url = url2;
// Set Headers
httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
// Send Request
return this.client.pipeline(httpRequest, function (err, response, body) {
if (err !== null && err !== undefined) {
return callback(err);
}
var statusCode = response.statusCode;
if (statusCode !== 200) {
var error = new Error(body);
error.statusCode = response.statusCode;
return callback(error);
}
// Create Result
var result = null;
// Deserialize Response
if (statusCode === 200) {
var responseContent = body;
result = {};
var responseDoc = null;
if (responseContent) {
responseDoc = JSON.parse(responseContent);
}
if (responseDoc !== null && responseDoc !== undefined) {
var operationInstance = {};
result.operation = operationInstance;
var idValue = responseDoc['id'];
if (idValue !== null && idValue !== undefined) {
var idInstance = idValue;
operationInstance.id = idInstance;
}
var operationIdValue = responseDoc['operationId'];
if (operationIdValue !== null && operationIdValue !== undefined) {
var operationIdInstance = operationIdValue;
operationInstance.operationId = operationIdInstance;
}
var propertiesValue = responseDoc['properties'];
if (propertiesValue !== null && propertiesValue !== undefined) {
var propertiesInstance = {};
operationInstance.properties = propertiesInstance;
var provisioningStateValue = propertiesValue['provisioningState'];
if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
var provisioningStateInstance = provisioningStateValue;
propertiesInstance.provisioningState = provisioningStateInstance;
}
var timestampValue = propertiesValue['timestamp'];
if (timestampValue !== null && timestampValue !== undefined) {
var timestampInstance = timestampValue;
propertiesInstance.timestamp = timestampInstance;
}
var statusCodeValue = propertiesValue['statusCode'];
if (statusCodeValue !== null && statusCodeValue !== undefined) {
var statusCodeInstance = statusCodeValue;
propertiesInstance.statusCode = statusCodeInstance;
}
var statusMessageValue = propertiesValue['statusMessage'];
if (statusMessageValue !== null && statusMessageValue !== undefined) {
var statusMessageInstance = statusMessageValue;
propertiesInstance.statusMessage = statusMessageInstance;
}
var targetResourceValue = propertiesValue['targetResource'];
if (targetResourceValue !== null && targetResourceValue !== undefined) {
var targetResourceInstance = {};
propertiesInstance.targetResource = targetResourceInstance;
var idValue2 = targetResourceValue['id'];
if (idValue2 !== null && idValue2 !== undefined) {
var idInstance2 = idValue2;
targetResourceInstance.id = idInstance2;
}
var resourceNameValue = targetResourceValue['resourceName'];
if (resourceNameValue !== null && resourceNameValue !== undefined) {
var resourceNameInstance = resourceNameValue;
targetResourceInstance.resourceName = resourceNameInstance;
}
var resourceTypeValue = targetResourceValue['resourceType'];
if (resourceTypeValue !== null && resourceTypeValue !== undefined) {
var resourceTypeInstance = resourceTypeValue;
targetResourceInstance.resourceType = resourceTypeInstance;
}
}
}
}
}
result.statusCode = statusCode;
result.requestId = response.headers['x-ms-request-id'];
return callback(null, result);
});
};
/**
* Gets a list of deployments operations.
*
* @param {string} resourceGroupName The name of the resource group. The name
* is case insensitive.
*
* @param {string} deploymentName The name of the deployment.
*
* @param {DeploymentOperationsListParameters} [parametersOrCallback] Query
* parameters.
*
* @param {number} [parametersOrCallback.top] Get or sets the number of
* records to return. Optional.
*
* @param {function} callback
*
* @returns {Stream} The response stream.
*/
DeploymentOperationOperations.prototype.list = function(resourceGroupName, deploymentName, parametersOrCallback, callback) {
var parameters = parametersOrCallback;
if (_.isFunction(parameters)) {
callback = parameters;
parameters = null;
}
if (callback === null || callback === undefined) {
throw new Error('callback cannot be null.');
}
// Validate
if (resourceGroupName === null || resourceGroupName === undefined) {
return callback(new Error('resourceGroupName cannot be null.'));
}
if (resourceGroupName !== null && resourceGroupName !== undefined && resourceGroupName.length > 1000) {
return callback(new Error('resourceGroupName is outside the valid range.'));
}
if (/^[-\w\._]+$/.test(resourceGroupName) === false) {
return callback(new Error('resourceGroupName is outside the valid range.'));
}
if (deploymentName === null || deploymentName === undefined) {
return callback(new Error('deploymentName cannot be null.'));
}
// Tracing
// Construct URL
var url2 = '';
url2 = url2 + '/subscriptions/';
if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
}
url2 = url2 + '/resourcegroups/';
url2 = url2 + encodeURIComponent(resourceGroupName);
url2 = url2 + '/deployments/';
url2 = url2 + encodeURIComponent(deploymentName);
url2 = url2 + '/operations';
var queryParameters = [];
if (parameters !== null && parameters !== undefined && parameters.top !== null && parameters.top !== undefined) {
queryParameters.push('$top=' + encodeURIComponent(parameters.top.toString()));
}
queryParameters.push('api-version=2015-11-01');
if (queryParameters.length > 0) {
url2 = url2 + '?' + queryParameters.join('&');
}
var baseUrl = this.client.baseUri;
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl[baseUrl.length - 1] === '/') {
baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
}
if (url2[0] === '/') {
url2 = url2.substring(1);
}
url2 = baseUrl + '/' + url2;
url2 = url2.replace(' ', '%20');
// Create HTTP transport objects
var httpRequest = new WebResource();
httpRequest.method = 'GET';
httpRequest.headers = {};
httpRequest.url = url2;
// Set Headers
httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
// Send Request
return this.client.pipeline(httpRequest, function (err, response, body) {
if (err !== null && err !== undefined) {
return callback(err);
}
var statusCode = response.statusCode;
if (statusCode !== 200) {
var error = new Error(body);
error.statusCode = response.statusCode;
return callback(error);
}
// Create Result
var result = null;
// Deserialize Response
if (statusCode === 200) {
var responseContent = body;
result = { operations: [] };
var responseDoc = null;
if (responseContent) {
responseDoc = JSON.parse(responseContent);
}
if (responseDoc !== null && responseDoc !== undefined) {
var valueArray = responseDoc['value'];
if (valueArray !== null && valueArray !== undefined) {
for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
var valueValue = valueArray[loweredIndex1];
var deploymentOperationInstance = {};
result.operations.push(deploymentOperationInstance);
var idValue = valueValue['id'];
if (idValue !== null && idValue !== undefined) {
var idInstance = idValue;
deploymentOperationInstance.id = idInstance;
}
var operationIdValue = valueValue['operationId'];
if (operationIdValue !== null && operationIdValue !== undefined) {
var operationIdInstance = operationIdValue;
deploymentOperationInstance.operationId = operationIdInstance;
}
var propertiesValue = valueValue['properties'];
if (propertiesValue !== null && propertiesValue !== undefined) {
var propertiesInstance = {};
deploymentOperationInstance.properties = propertiesInstance;
var provisioningStateValue = propertiesValue['provisioningState'];
if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
var provisioningStateInstance = provisioningStateValue;
propertiesInstance.provisioningState = provisioningStateInstance;
}
var timestampValue = propertiesValue['timestamp'];
if (timestampValue !== null && timestampValue !== undefined) {
var timestampInstance = timestampValue;
propertiesInstance.timestamp = timestampInstance;
}
var statusCodeValue = propertiesValue['statusCode'];
if (statusCodeValue !== null && statusCodeValue !== undefined) {
var statusCodeInstance = statusCodeValue;
propertiesInstance.statusCode = statusCodeInstance;
}
var statusMessageValue = propertiesValue['statusMessage'];
if (statusMessageValue !== null && statusMessageValue !== undefined) {
var statusMessageInstance = statusMessageValue;
propertiesInstance.statusMessage = statusMessageInstance;
}
var targetResourceValue = propertiesValue['targetResource'];
if (targetResourceValue !== null && targetResourceValue !== undefined) {
var targetResourceInstance = {};
propertiesInstance.targetResource = targetResourceInstance;
var idValue2 = targetResourceValue['id'];
if (idValue2 !== null && idValue2 !== undefined) {
var idInstance2 = idValue2;
targetResourceInstance.id = idInstance2;
}
var resourceNameValue = targetResourceValue['resourceName'];
if (resourceNameValue !== null && resourceNameValue !== undefined) {
var resourceNameInstance = resourceNameValue;
targetResourceInstance.resourceName = resourceNameInstance;
}
var resourceTypeValue = targetResourceValue['resourceType'];
if (resourceTypeValue !== null && resourceTypeValue !== undefined) {
var resourceTypeInstance = resourceTypeValue;
targetResourceInstance.resourceType = resourceTypeInstance;
}
}
}
}
}
var nextLinkValue = responseDoc['nextLink'];
if (nextLinkValue !== null && nextLinkValue !== undefined) {
var nextLinkInstance = nextLinkValue;
result.nextLink = nextLinkInstance;
}
}
}
result.statusCode = statusCode;
result.requestId = response.headers['x-ms-request-id'];
return callback(null, result);
});
};
/**
* Gets a next list of deployments operations.
*
* @param {string} nextLink NextLink from the previous successful call to
* List operation.
*
* @param {function} callback
*
* @returns {Stream} The response stream.
*/
DeploymentOperationOperations.prototype.listNext = function(nextLink, callback) {
if (callback === null || callback === undefined) {
throw new Error('callback cannot be null.');
}
// Validate
if (nextLink === null || nextLink === undefined) {
return callback(new Error('nextLink cannot be null.'));
}
// Tracing
// Construct URL
var url2 = '';
url2 = url2 + nextLink;
url2 = url2.replace(' ', '%20');
// Create HTTP transport objects
var httpRequest = new WebResource();
httpRequest.method = 'GET';
httpRequest.headers = {};
httpRequest.url = url2;
// Set Headers
httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
// Send Request
return this.client.pipeline(httpRequest, function (err, response, body) {
if (err !== null && err !== undefined) {
return callback(err);
}
var statusCode = response.statusCode;
if (statusCode !== 200) {
var error = new Error(body);
error.statusCode = response.statusCode;
return callback(error);
}
// Create Result
var result = null;
// Deserialize Response
if (statusCode === 200) {
var responseContent = body;
result = { operations: [] };
var responseDoc = null;
if (responseContent) {
responseDoc = JSON.parse(responseContent);
}
if (responseDoc !== null && responseDoc !== undefined) {
var valueArray = responseDoc['value'];
if (valueArray !== null && valueArray !== undefined) {
for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
var valueValue = valueArray[loweredIndex1];
var deploymentOperationInstance = {};
result.operations.push(deploymentOperationInstance);
var idValue = valueValue['id'];
if (idValue !== null && idValue !== undefined) {
var idInstance = idValue;
deploymentOperationInstance.id = idInstance;
}
var operationIdValue = valueValue['operationId'];
if (operationIdValue !== null && operationIdValue !== undefined) {
var operationIdInstance = operationIdValue;
deploymentOperationInstance.operationId = operationIdInstance;
}
var propertiesValue = valueValue['properties'];
if (propertiesValue !== null && propertiesValue !== undefined) {
var propertiesInstance = {};
deploymentOperationInstance.properties = propertiesInstance;
var provisioningStateValue = propertiesValue['provisioningState'];
if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
var provisioningStateInstance = provisioningStateValue;
propertiesInstance.provisioningState = provisioningStateInstance;
}
var timestampValue = propertiesValue['timestamp'];
if (timestampValue !== null && timestampValue !== undefined) {
var timestampInstance = timestampValue;
propertiesInstance.timestamp = timestampInstance;
}
var statusCodeValue = propertiesValue['statusCode'];
if (statusCodeValue !== null && statusCodeValue !== undefined) {
var statusCodeInstance = statusCodeValue;
propertiesInstance.statusCode = statusCodeInstance;
}
var statusMessageValue = propertiesValue['statusMessage'];
if (statusMessageValue !== null && statusMessageValue !== undefined) {
var statusMessageInstance = statusMessageValue;
propertiesInstance.statusMessage = statusMessageInstance;
}
var targetResourceValue = propertiesValue['targetResource'];
if (targetResourceValue !== null && targetResourceValue !== undefined) {
var targetResourceInstance = {};
propertiesInstance.targetResource = targetResourceInstance;
var idValue2 = targetResourceValue['id'];
if (idValue2 !== null && idValue2 !== undefined) {
var idInstance2 = idValue2;
targetResourceInstance.id = idInstance2;
}
var resourceNameValue = targetResourceValue['resourceName'];
if (resourceNameValue !== null && resourceNameValue !== undefined) {
var resourceNameInstance = resourceNameValue;
targetResourceInstance.resourceName = resourceNameInstance;
}
var resourceTypeValue = targetResourceValue['resourceType'];
if (resourceTypeValue !== null && resourceTypeValue !== undefined) {
var resourceTypeInstance = resourceTypeValue;
targetResourceInstance.resourceType = resourceTypeInstance;
}
}
}
}
}
var nextLinkValue = responseDoc['nextLink'];
if (nextLinkValue !== null && nextLinkValue !== undefined) {
var nextLinkInstance = nextLinkValue;
result.nextLink = nextLinkInstance;
}
}
}
result.statusCode = statusCode;
result.requestId = response.headers['x-ms-request-id'];
return callback(null, result);
});
};
return DeploymentOperationOperations;
})();
var DeploymentOperations = ( /** @lends DeploymentOperations */ function() {
/**
* @class
* Operations for managing deployments.
* __NOTE__: An instance of this class is automatically created for an
* instance of the [ResourceManagementClient] {@link
* ResourceManagementClient~ResourceManagementClient}.
* See [deployments] {@link
* ResourceManagementClient~ResourceManagementClient#deployments}.
* Initializes a new instance of the DeploymentOperations class.
* @constructor
*
* @param {ResourceManagementClient} client Reference to the service client.
*/
function DeploymentOperations(client) {
this.client = client;
}
/**
* Begin deleting deployment.To determine whether the operation has finished
* processing the request, call GetLongRunningOperationStatus.
*
* @param {string} resourceGroupName The name of the resource group. The name
* is case insensitive.
*
* @param {string} deploymentName The name of the deployment to be deleted.
*
* @param {function} callback
*
* @returns {Stream} The response stream.
*/
DeploymentOperations.prototype.beginDeleting = function(resourceGroupName, deploymentName, callback) {
if (callback === null || callback === undefined) {
throw new Error('callback cannot be null.');
}
// Validate
if (resourceGroupName === null || resourceGroupName === undefined) {
return callback(new Error('resourceGroupName cannot be null.'));
}
if (resourceGroupName !== null && resourceGroupName !== undefined && resourceGroupName.length > 1000) {
return callback(new Error('resourceGroupName is outside the valid range.'));
}
if (/^[-\w\._]+$/.test(resourceGroupName) === false) {
return callback(new Error('resourceGroupName is outside the valid range.'));
}
if (deploymentName === null || deploymentName === undefined) {
return callback(new Error('deploymentName cannot be null.'));
}
// Tracing
// Construct URL
var url2 = '';
url2 = url2 + '/subscriptions/';
if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
}
url2 = url2 + '/resourcegroups/';
url2 = url2 + encodeURIComponent(resourceGroupName);
url2 = url2 + '/deployments/';
url2 = url2 + encodeURIComponent(deploymentName);
var queryParameters = [];
queryParameters.push('api-version=2015-11-01');
if (queryParameters.length > 0) {
url2 = url2 + '?' + queryParameters.join('&');
}
var baseUrl = this.client.baseUri;
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl[baseUrl.length - 1] === '/') {
baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
}
if (url2[0] === '/') {
url2 = url2.substring(1);
}
url2 = baseUrl + '/' + url2;
url2 = url2.replace(' ', '%20');
// Create HTTP transport objects
var httpRequest = new WebResource();
httpRequest.method = 'DELETE';
httpRequest.headers = {};
httpRequest.url = url2;
// Set Headers
httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
// Send Request
return this.client.pipeline(httpRequest, function (err, response, body) {
if (err !== null && err !== undefined) {
return callback(err);
}
var statusCode = response.statusCode;
if (statusCode !== 202 && statusCode !== 204) {
var error = new Error(body);
error.statusCode = response.statusCode;
return callback(error);
}
// Create Result
var result = null;
// Deserialize Response
result = {};
result.statusCode = statusCode;
result.operationStatusLink = response.headers['location'];
result.retryAfter = parseInt(response.headers['retry-after'], 10);
result.requestId = response.headers['x-ms-request-id'];
if (statusCode === 409) {
result.status = OperationStatus.Failed;
}
if (statusCode === 202) {
result.status = OperationStatus.InProgress;
}
if (statusCode === 204) {
result.status = OperationStatus.Succeeded;
}
return callback(null, result);
});
};
/**
* Cancel a currently running template deployment.
*
* @param {string} resourceGroupName The name of the resource group. The name
* is case insensitive.
*
* @param {string} deploymentName The name of the deployment.
*
* @param {function} callback
*
* @returns {Stream} The response stream.
*/
DeploymentOperations.prototype.cancel = function(resourceGroupName, deploymentName, callback) {
if (callback === null || callback === undefined) {
throw new Error('callback cannot be null.');
}
// Validate
if (resourceGroupName === null || resourceGroupName === undefined) {
return callback(new Error('resourceGroupName cannot be null.'));
}
if (resourceGroupName !== null && resourceGroupName !== undefined && resourceGroupName.length > 1000) {
return callback(new Error('resourceGroupName is outside the valid range.'));
}
if (/^[-\w\._]+$/.test(resourceGroupName) === false) {
return callback(new Error('resourceGroupName is outside the valid range.'));
}
if (deploymentName === null || deploymentName === undefined) {
return callback(new Error('deploymentName cannot be null.'));
}
// Tracing
// Construct URL
var url2 = '';
url2 = url2 + '/subscriptions/';
if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
}
url2 = url2 + '/resourcegroups/';
url2 = url2 + encodeURIComponent(resourceGroupName);
url2 = url2 + '/deployments/';
url2 = url2 + encodeURIComponent(deploymentName);
url2 = url2 + '/cancel';
var queryParameters = [];
queryParameters.push('api-version=2015-11-01');
if (queryParameters.length > 0) {
url2 = url2 + '?' + queryParameters.join('&');
}
var baseUrl = this.client.baseUri;
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl[baseUrl.length - 1] === '/') {
baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
}
if (url2[0] === '/') {
url2 = url2.substring(1);
}
url2 = baseUrl + '/' + url2;
url2 = url2.replace(' ', '%20');
// Create HTTP transport objects
var httpRequest = new WebResource();
httpRequest.method = 'POST';
httpRequest.headers = {};
httpRequest.url = url2;
// Set Headers
// Send Request
return this.client.pipeline(httpRequest, function (err, response, body) {
if (err !== null && err !== undefined) {
return callback(err);
}
var statusCode = response.statusCode;
if (statusCode !== 204) {
var error = new Error(body);
error.statusCode = response.statusCode;
return callback(error);
}
// Create Result
var result = null;
// Deserialize Response
result = {};
result.statusCode = statusCode;
result.requestId = response.headers['x-ms-request-id'];
return callback(null, result);
});
};
/**
* Checks whether deployment exists.
*
* @param {string} resourceGroupName The name of the resource group to check.
* The name is case insensitive.
*
* @param {string} deploymentName The name of the deployment.
*
* @param {function} callback
*
* @returns {Stream} The response stream.
*/
DeploymentOperations.prototype.checkExistence = function(resourceGroupName, deploymentName, callback) {
if (callback === null || callback === undefined) {
throw new Error('callback cannot be null.');
}
// Validate
if (resourceGroupName === null || resourceGroupName === undefined) {
return callback(new Error('resourceGroupName cannot be null.'));
}
if (resourceGroupName !== null && resourceGroupName !== undefined && resourceGroupName.length > 1000) {
return callback(new Error('resourceGroupName is outside the valid range.'));
}
if (/^[-\w\._]+$/.test(resourceGroupName) === false) {
return callback(new Error('resourceGroupName is outside the valid range.'));
}
if (deploymentName === null || deploymentName === undefined) {
return callback(new Error('deploymentName cannot be null.'));
}
// Tracing
// Construct URL
var url2 = '';
url2 = url2 + 'subscriptions/';
if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
}
url2 = url2 + '/resourcegroups/';
url2 = url2 + encodeURIComponent(resourceGroupName);
url2 = url2 + '/deployments/';
url2 = url2 + encodeURIComponent(deploymentName);
var queryParameters = [];
queryParameters.push('api-version=2015-11-01');
if (queryParameters.length > 0) {
url2 = url2 + '?' + queryParameters.join('&');
}
var baseUrl = this.client.baseUri;
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl[baseUrl.length - 1] === '/') {
baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
}
if (url2[0] === '/') {
url2 = url2.substring(1);
}
url2 = baseUrl + '/' + url2;
url2 = url2.replace(' ', '%20');
// Create HTTP transport objects
var httpRequest = new WebResource();
httpRequest.method = 'HEAD';
httpRequest.headers = {};
httpRequest.url = url2;
// Set Headers
httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
// Send Request
return this.client.pipeline(httpRequest, function (err, response, body) {
if (err !== null && err !== undefined) {
return callback(err);
}
var statusCode = response.statusCode;
if (statusCode !== 204 && statusCode !== 404) {
var error = new Error(body);
error.statusCode = response.statusCode;
return callback(error);
}
// Create Result
var result = null;
// Deserialize Response
result = {};
result.statusCode = statusCode;
result.requestId = response.headers['x-ms-request-id'];
if (statusCode === 204) {
result.exists = true;
}
return callback(null, result);
});
};
/**
* Create a named template deployment using a template.
*
* @param {string} resourceGroupName The name of the resource group. The name
* is case insensitive.
*
* @param {string} deploymentName The name of the deployment.
*
* @param {Deployment} parameters Additional parameters supplied to the
* operation.
*
* @param {DeploymentProperties} [parameters.properties] Gets or sets the
* deployment properties.
*
* @param {string} [parameters.properties.template] Gets or sets the template
* content. Use only one of Template or TemplateLink.
*
* @param {TemplateLink} [parameters.properties.templateLink] Gets or sets
* the URI referencing the template. Use only one of Template or
* TemplateLink.
*
* @param {string} [parameters.properties.templateLink.uri] URI referencing
* the template.
*
* @param {string} [parameters.properties.templateLink.contentVersion] If
* included it must match the ContentVersion in the template.
*
* @param {string} [parameters.properties.parameters] Deployment parameters.
* Use only one of Parameters or ParametersLink.
*
* @param {ParametersLink} [parameters.properties.parametersLink] Gets or
* sets the URI referencing the parameters. Use only one of Parameters or
* ParametersLink.
*
* @param {string} [parameters.properties.parametersLink.uri] URI referencing
* the template.
*
* @param {string} [parameters.properties.parametersLink.contentVersion] If
* included it must match the ContentVersion in the template.
*
* @param {DeploymentMode} [parameters.properties.mode] Gets or sets the
* deployment mode.
*
* @param {function} callback
*
* @returns {Stream} The response stream.
*/
DeploymentOperations.prototype.createOrUpdate = function(resourceGroupName, deploymentName, parameters, callback) {
if (callback === null || callback === undefined) {
throw new Error('callback cannot be null.');
}
// Validate
if (resourceGroupName === null || resourceGroupName === undefined) {
return callback(new Error('resourceGroupName cannot be null.'));
}
if (resourceGroupName !== null && resourceGroupName !== undefined && resourceGroupName.length > 1000) {
return callback(new Error('resourceGroupName is outside the valid range.'));
}
if (/^[-\w\._]+$/.test(resourceGroupName) === false) {
return callback(new Error('resourceGroupName is outside the valid range.'));
}
if (deploymentName === null || deploymentName === undefined) {
return callback(new Error('deploymentName cannot be null.'));
}
if (parameters === null || parameters === undefined) {
return callback(new Error('parameters cannot be null.'));
}
if (parameters.properties !== null && parameters.properties !== undefined) {
if (parameters.properties.parametersLink !== null && parameters.properties.parametersLink !== undefined) {
if (parameters.properties.parametersLink.uri === null || parameters.properties.parametersLink.uri === undefined) {
return callback(new Error('parameters.properties.parametersLink.uri cannot be null.'));
}
}
if (parameters.properties.templateLink !== null && parameters.properties.templateLink !== undefined) {
if (parameters.properties.templateLink.uri === null || parameters.properties.templateLink.uri === undefined) {
return callback(new Error('parameters.properties.templateLink.uri cannot be null.'));
}
}
}
// Tracing
// Construct URL
var url2 = '';
url2 = url2 + '/subscriptions/';
if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
}
url2 = url2 + '/resourcegroups/';
url2 = url2 + encodeURIComponent(resourceGroupName);
url2 = url2 + '/deployments/';
url2 = url2 + encodeURIComponent(deploymentName);
var queryParameters = [];
queryParameters.push('api-version=2015-11-01');
if (queryParameters.length > 0) {
url2 = url2 + '?' + queryParameters.join('&');
}
var baseUrl = this.client.baseUri;
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl[baseUrl.length - 1] === '/') {
baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
}
if (url2[0] === '/') {
url2 = url2.substring(1);
}
url2 = baseUrl + '/' + url2;
url2 = url2.replace(' ', '%20');
// Create HTTP transport objects
var httpRequest = new WebResource();
httpRequest.method = 'PUT';
httpRequest.headers = {};
httpRequest.url = url2;
// Set Headers
httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
// Serialize Request
var requestContent = null;
var requestDoc = null;
var deploymentValue = {};
requestDoc = deploymentValue;
if (parameters.properties !== null && parameters.properties !== undefined) {
var propertiesValue = {};
deploymentValue['properties'] = propertiesValue;
if (parameters.properties.template !== null && parameters.properties.template !== undefined) {
propertiesValue['template'] = parameters.properties.template;
}
if (parameters.properties.templateLink !== null && parameters.properties.templateLink !== undefined) {
var templateLinkValue = {};
propertiesValue['templateLink'] = templateLinkValue;
templateLinkValue['uri'] = parameters.properties.templateLink.uri;
if (parameters.properties.templateLink.contentVersion !== null && parameters.properties.templateLink.contentVersion !== undefined) {
templateLinkValue['contentVersion'] = parameters.properties.templateLink.contentVersion;
}
}
if (parameters.properties.parameters !== null && parameters.properties.parameters !== undefined) {
propertiesValue['parameters'] = parameters.properties.parameters;
}
if (parameters.properties.parametersLink !== null && parameters.properties.parametersLink !== undefined) {
var parametersLinkValue = {};
propertiesValue['parametersLink'] = parametersLinkValue;
parametersLinkValue['uri'] = parameters.properties.parametersLink.uri;
if (parameters.properties.parametersLink.contentVersion !== null && parameters.properties.parametersLink.contentVersion !== undefined) {
parametersLinkValue['contentVersion'] = parameters.properties.parametersLink.contentVersion;
}
}
if (parameters.properties.mode !== null && parameters.properties.mode !== undefined) {
propertiesValue['mode'] = parameters.properties.mode !== null && parameters.properties.mode !== undefined ? parameters.properties.mode.toString() : 'Incremental';
}
}
requestContent = JSON.stringify(requestDoc);
httpRequest.body = requestContent;
httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
// Send Request
return this.client.pipeline(httpRequest, function (err, response, body) {
if (err !== null && err !== undefined) {
return callback(err);
}
var statusCode = response.statusCode;
if (statusCode !== 200 && statusCode !== 201) {
var error = new Error(body);
error.statusCode = response.statusCode;
return callback(error);
}
// Create Result
var result = null;
// Deserialize Response
if (statusCode === 200 || statusCode === 201) {
var responseContent = body;
result = {};
var responseDoc = null;
if (responseContent) {
responseDoc = JSON.parse(responseContent);
}
if (responseDoc !== null && responseDoc !== undefined) {
var deploymentInstance = {};
result.deployment = deploymentInstance;
var idValue = responseDoc['id'];
if (idValue !== null && idValue !== undefined) {
var idInstance = idValue;
deploymentInstance.id = idInstance;
}
var nameValue = responseDoc['name'];
if (nameValue !== null && nameValue !== undefined) {
var nameInstance = nameValue;
deploymentInstance.name = nameInstance;
}
var propertiesValue2 = responseDoc['properties'];
if (propertiesValue2 !== null && propertiesValue2 !== undefined) {
var propertiesInstance = { dependencies: [], providers: [], validatedResources: [] };
deploymentInstance.properties = propertiesInstance;
var provisioningStateValue = propertiesValue2['provisioningState'];
if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
var provisioningStateInstance = provisioningStateValue;
propertiesInstance.provisioningState = provisioningStateInstance;
}
var correlationIdValue = propertiesValue2['correlationId'];
if (correlationIdValue !== null && correlationIdValue !== undefined) {
var correlationIdInstance = correlationIdValue;
propertiesInstance.correlationId = correlationIdInstance;
}
var timestampValue = propertiesValue2['timestamp'];
if (timestampValue !== null && timestampValue !== undefined) {
var timestampInstance = timestampValue;
propertiesInstance.timestamp = timestampInstance;
}
var durationValue = propertiesValue2['duration'];
if (durationValue !== null && durationValue !== undefined) {
var durationInstance = moment.duration(durationValue);
p