UNPKG

azure-mgmt-compute

Version:

Microsoft Azure Compute Management Client Library for node

968 lines (896 loc) 1.7 MB
/* 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 azureCommon = require('azure-common'); var xml = azureCommon.xml2js; var js2xml = azureCommon.js2xml; var Service = azureCommon.Service; var WebResource = azureCommon.WebResource; var ComputeManagementClient = ( /** @lends ComputeManagementClient */ function() { /** * @class * The Service Management API provides programmatic access to much of the * functionality available through the Management Portal. The Service * Management API is a REST API. All API operations are performed over SSL, * and are mutually authenticated using X.509 v3 certificates. (see * http://msdn.microsoft.com/en-us/library/windowsazure/ee460799.aspx for * more information) * Initializes a new instance of the ComputeManagementClient 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 ComputeManagementClient(credentials, baseUri, filters) { if (credentials === null || credentials === undefined) { throw new Error('credentials cannot be null.'); } ComputeManagementClient['super_'].call(this, credentials, filters); this.credentials = credentials; this.baseUri = baseUri; if (this.baseUri === null || this.baseUri === undefined) { this.baseUri = 'https://management.core.windows.net'; } if (this.apiVersion === null || this.apiVersion === undefined) { this.apiVersion = '2014-10-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 * [DeploymentOperations](-DeploymentOperations.html) object. * @type {object} */ this.deployments = new DeploymentOperations(this); /** * Provides an instance of the * [DNSServerOperations](-DNSServerOperations.html) object. * @type {object} */ this.dnsServer = new DNSServerOperations(this); /** * Provides an instance of the * [ExtensionImageOperations](-ExtensionImageOperations.html) object. * @type {object} */ this.extensionImages = new ExtensionImageOperations(this); /** * Provides an instance of the * [HostedServiceOperations](-HostedServiceOperations.html) object. * @type {object} */ this.hostedServices = new HostedServiceOperations(this); /** * Provides an instance of the * [LoadBalancerOperations](-LoadBalancerOperations.html) object. * @type {object} */ this.loadBalancers = new LoadBalancerOperations(this); /** * Provides an instance of the * [OperatingSystemOperations](-OperatingSystemOperations.html) object. * @type {object} */ this.operatingSystems = new OperatingSystemOperations(this); /** * Provides an instance of the * [ServiceCertificateOperations](-ServiceCertificateOperations.html) * object. * @type {object} */ this.serviceCertificates = new ServiceCertificateOperations(this); /** * Provides an instance of the * [VirtualMachineDiskOperations](-VirtualMachineDiskOperations.html) * object. * @type {object} */ this.virtualMachineDisks = new VirtualMachineDiskOperations(this); /** * Provides an instance of the * [VirtualMachineExtensionOperations](-VirtualMachineExtensionOperations.html) * object. * @type {object} */ this.virtualMachineExtensions = new VirtualMachineExtensionOperations(this); /** * Provides an instance of the * [VirtualMachineOperations](-VirtualMachineOperations.html) object. * @type {object} */ this.virtualMachines = new VirtualMachineOperations(this); /** * Provides an instance of the * [VirtualMachineOSImageOperations](-VirtualMachineOSImageOperations.html) * object. * @type {object} */ this.virtualMachineOSImages = new VirtualMachineOSImageOperations(this); /** * Provides an instance of the * [VirtualMachineVMImageOperations](-VirtualMachineVMImageOperations.html) * object. * @type {object} */ this.virtualMachineVMImages = new VirtualMachineVMImageOperations(this); } util.inherits(ComputeManagementClient, 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. (see * http://msdn.microsoft.com/en-us/library/windowsazure/ee460783.aspx for * more information) * * @param {string} requestId The request ID for the request you wish to * track. The request ID is returned in the x-ms-request-id response header * for every request. * * @param {function} callback * * @returns {Stream} The response stream. */ ComputeManagementClient.prototype.getOperationStatus = function(requestId, callback) { if (callback === null || callback === undefined) { throw new Error('callback cannot be null.'); } // Validate if (requestId === null || requestId === undefined) { return callback(new Error('requestId cannot be null.')); } // Tracing // Construct URL var url2 = ''; url2 = url2 + '/'; if (this.credentials.subscriptionId !== null && this.credentials.subscriptionId !== undefined) { url2 = url2 + encodeURIComponent(this.credentials.subscriptionId); } url2 = url2 + '/operations/'; url2 = url2 + encodeURIComponent(requestId); var baseUrl = this.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['x-ms-version'] = '2014-10-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) { 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 options = {}; options.trim = false; options.strict = false; xml.parseString(responseContent, options, function (err2, responseDoc) { if (err2 !== null && err2 !== undefined) { return callback(err2); } var operationElement = js2xml.getElement(responseDoc, responseDoc, 'OPERATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE'); if (operationElement !== null && operationElement !== undefined) { var idElement = js2xml.getElement(responseDoc, operationElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE'); if (idElement !== null && idElement !== undefined) { var idInstance = idElement; result.id = idInstance; } var statusElement = js2xml.getElement(responseDoc, operationElement, 'STATUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE'); if (statusElement !== null && statusElement !== undefined && statusElement.length !== 0) { var statusInstance = statusElement; result.status = statusInstance; } var httpStatusCodeElement = js2xml.getElement(responseDoc, operationElement, 'HTTPSTATUSCODE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE'); if (httpStatusCodeElement !== null && httpStatusCodeElement !== undefined && httpStatusCodeElement.length !== 0) { var httpStatusCodeInstance = httpStatusCodeElement; result.httpStatusCode = httpStatusCodeInstance; } var errorElement = js2xml.getElement(responseDoc, operationElement, 'ERROR', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE'); if (errorElement !== null && errorElement !== undefined) { var errorInstance = {}; result.error = errorInstance; var codeElement = js2xml.getElement(responseDoc, errorElement, 'CODE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE'); if (codeElement !== null && codeElement !== undefined) { var codeInstance = codeElement; errorInstance.code = codeInstance; } var messageElement = js2xml.getElement(responseDoc, errorElement, 'MESSAGE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE'); if (messageElement !== null && messageElement !== undefined) { var messageInstance = messageElement; errorInstance.message = messageInstance; } } } }); } result.statusCode = statusCode; result.requestId = response.headers['x-ms-request-id']; return callback(null, result); }); }; return ComputeManagementClient; })(); exports.ComputeManagementClient = ComputeManagementClient; var DeploymentOperations = ( /** @lends DeploymentOperations */ function() { /** * @class * The Service Management API includes operations for managing the * deployments in your subscription. (see * http://msdn.microsoft.com/en-us/library/windowsazure/ee460812.aspx for * more information) * __NOTE__: An instance of this class is automatically created for an * instance of the [ComputeManagementClient] {@link * ComputeManagementClient~ComputeManagementClient}. * See [deployments] {@link * ComputeManagementClient~ComputeManagementClient#deployments}. * Initializes a new instance of the DeploymentOperations class. * @constructor * * @param {ComputeManagementClient} client Reference to the service client. */ function DeploymentOperations(client) { this.client = client; } /** * The Begin Changing Deployment Configuration By Name operation initiates a * change to the deployment configuration. This operation is an asynchronous * operation. To determine whether the Management service has finished * processing the request, call Get Operation Status. For more information * on asynchronous operations, see Tracking Asynchronous Service Management * Requests at * http://msdn.microsoft.com/en-us/library/windowsazure/ee460791.aspx. (see * http://msdn.microsoft.com/en-us/library/windowsazure/ee460809.aspx for * more information) * * @param {string} serviceName The cloud service to change deployment * configuration for. * * @param {string} deploymentName The deployment to change configuration for. * * @param {DeploymentChangeConfigurationParameters} parameters Parameters * supplied to the Begin Changing Configuration Deployment By Name operation. * * @param {string} parameters.configuration The encoded service configuration * file for the deployment. * * @param {boolean} [parameters.treatWarningsAsError] Indicates whether to * treat package validation warnings as errors. The default value is false. * If set to true, the Created Deployment operation fails if there are * validation warnings on the service package. * * @param {DeploymentChangeConfigurationMode} [parameters.mode] The Change * Configuration Deployment mode. Possible values are: Auto and Manual. If * not specified, the default value is Auto. If set to Manual, * WalkUpgradeDomain must be called to apply the update. If set to Auto, the * update is automatically applied to each update domain for the service. * * @param {object} [parameters.extendedProperties] Represents the name of an * extended deployment property. Each extended property must have a defined * name and a value. You can have a maximum of 25 extended property * name/value pairs. The maximum length of the name element is 64 * characters, only alphanumeric characters and underscores are valid in the * name, and the name must start with a letter. Attempting to use other * characters, starting the name with a non-letter character, or entering a * name that is identical to that of another extended property owned by the * same hosted service will result in a status code 400 (Bad Request) error. * * @param {ExtensionConfiguration} [parameters.extensionConfiguration] * Represents an extension that is added to the cloud service. In Azure, a * process can run as an extension of a cloud service. For example, Remote * Desktop Access or the Azure Diagnostics Agent can run as extensions to * the cloud service. You must add an extension to the cloud service by * using Add Extension before it can be added to the deployment. * * @param {array} [parameters.extensionConfiguration.allRoles] Specifies a * list of extensions that are applied to all roles in a deployment. * * @param {array} [parameters.extensionConfiguration.namedRoles] Specifies a * list of extensions that are applied to specific roles in a deployment. * * @param {function} callback * * @returns {Stream} The response stream. */ DeploymentOperations.prototype.beginChangingConfigurationByName = function(serviceName, deploymentName, parameters, callback) { if (callback === null || callback === undefined) { throw new Error('callback cannot be null.'); } // Validate if (serviceName === null || serviceName === undefined) { return callback(new Error('serviceName cannot be null.')); } // TODO: Validate serviceName is a valid DNS name. 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.configuration === null || parameters.configuration === undefined) { return callback(new Error('parameters.configuration cannot be null.')); } if (parameters.extensionConfiguration !== null && parameters.extensionConfiguration !== undefined) { if (parameters.extensionConfiguration.allRoles !== null && parameters.extensionConfiguration.allRoles !== undefined) { for (var loweredIndex1 = 0; loweredIndex1 < parameters.extensionConfiguration.allRoles.length; loweredIndex1 = loweredIndex1 + 1) { var allRolesParameterItem = parameters.extensionConfiguration.allRoles[loweredIndex1]; if (allRolesParameterItem.id === null || allRolesParameterItem.id === undefined) { return callback(new Error('parameters.extensionConfiguration.allRoles. cannot be null.')); } } } if (parameters.extensionConfiguration.namedRoles !== null && parameters.extensionConfiguration.namedRoles !== undefined) { for (var loweredIndex2 = 0; loweredIndex2 < parameters.extensionConfiguration.namedRoles.length; loweredIndex2 = loweredIndex2 + 1) { var namedRolesParameterItem = parameters.extensionConfiguration.namedRoles[loweredIndex2]; if (namedRolesParameterItem.extensions === null || namedRolesParameterItem.extensions === undefined) { return callback(new Error('parameters.extensionConfiguration.namedRoles. cannot be null.')); } if (namedRolesParameterItem.extensions !== null && namedRolesParameterItem.extensions !== undefined) { for (var loweredIndex3 = 0; loweredIndex3 < namedRolesParameterItem.extensions.length; loweredIndex3 = loweredIndex3 + 1) { var extensionsParameterItem = namedRolesParameterItem.extensions[loweredIndex3]; if (extensionsParameterItem.id === null || extensionsParameterItem.id === undefined) { return callback(new Error('parameters.extensionConfiguration.namedRoles.. cannot be null.')); } } } if (namedRolesParameterItem.roleName === null || namedRolesParameterItem.roleName === undefined) { return callback(new Error('parameters.extensionConfiguration.namedRoles. cannot be null.')); } } } } // Tracing // Construct URL var url2 = ''; url2 = url2 + '/'; if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) { url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId); } url2 = url2 + '/services/hostedservices/'; url2 = url2 + encodeURIComponent(serviceName); url2 = url2 + '/deployments/'; url2 = url2 + encodeURIComponent(deploymentName); url2 = url2 + '/'; var queryParameters = []; queryParameters.push('comp=config'); 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 httpRequest.headers['Content-Type'] = 'application/xml'; httpRequest.headers['x-ms-version'] = '2014-10-01'; // Serialize Request var requestContent = null; var requestDoc = {}; var changeConfigurationElement = js2xml.createElement('ChangeConfiguration', 'http://schemas.microsoft.com/windowsazure'); js2xml.addChildElement(requestDoc, changeConfigurationElement); var configurationElement = js2xml.createElement('Configuration', 'http://schemas.microsoft.com/windowsazure'); js2xml.setElementValue(configurationElement, new Buffer(parameters.configuration).toString('base64')); js2xml.addChildElement(changeConfigurationElement, configurationElement); if (parameters.treatWarningsAsError !== null && parameters.treatWarningsAsError !== undefined) { var treatWarningsAsErrorElement = js2xml.createElement('TreatWarningsAsError', 'http://schemas.microsoft.com/windowsazure'); js2xml.setElementValue(treatWarningsAsErrorElement, parameters.treatWarningsAsError.toString()); js2xml.addChildElement(changeConfigurationElement, treatWarningsAsErrorElement); } if (parameters.mode !== null && parameters.mode !== undefined) { var modeElement = js2xml.createElement('Mode', 'http://schemas.microsoft.com/windowsazure'); js2xml.setElementValue(modeElement, parameters.mode !== null && parameters.mode !== undefined ? parameters.mode.toString() : 'Auto'); js2xml.addChildElement(changeConfigurationElement, modeElement); } if (parameters.extendedProperties !== null && parameters.extendedProperties !== undefined) { var extendedPropertiesDictionaryElement = js2xml.createElement('ExtendedProperties', 'http://schemas.microsoft.com/windowsazure'); for (var extendedPropertiesKey in parameters.extendedProperties) { var extendedPropertiesValue = parameters.extendedProperties[extendedPropertiesKey]; var extendedPropertiesElement = js2xml.createElement('ExtendedProperty', 'http://schemas.microsoft.com/windowsazure'); js2xml.addChildElement(extendedPropertiesDictionaryElement, extendedPropertiesElement); var extendedPropertiesKeyElement = js2xml.createElement('Name', 'http://schemas.microsoft.com/windowsazure'); js2xml.setElementValue(extendedPropertiesKeyElement, extendedPropertiesKey); js2xml.addChildElement(extendedPropertiesElement, extendedPropertiesKeyElement); var extendedPropertiesValueElement = js2xml.createElement('Value', 'http://schemas.microsoft.com/windowsazure'); js2xml.setElementValue(extendedPropertiesValueElement, extendedPropertiesValue); js2xml.addChildElement(extendedPropertiesElement, extendedPropertiesValueElement); } js2xml.addChildElement(changeConfigurationElement, extendedPropertiesDictionaryElement); } if (parameters.extensionConfiguration !== null && parameters.extensionConfiguration !== undefined) { var extensionConfigurationElement = js2xml.createElement('ExtensionConfiguration', 'http://schemas.microsoft.com/windowsazure'); js2xml.addChildElement(changeConfigurationElement, extensionConfigurationElement); if (parameters.extensionConfiguration.allRoles !== null && parameters.extensionConfiguration.allRoles !== undefined) { var allRolesSequenceElement = js2xml.createElement('AllRoles', 'http://schemas.microsoft.com/windowsazure'); for (var loweredIndex4 = 0; loweredIndex4 < parameters.extensionConfiguration.allRoles.length; loweredIndex4 = loweredIndex4 + 1) { var allRolesItem = parameters.extensionConfiguration.allRoles[loweredIndex4]; var extensionElement = js2xml.createElement('Extension', 'http://schemas.microsoft.com/windowsazure'); js2xml.addChildElement(allRolesSequenceElement, extensionElement); var idElement = js2xml.createElement('Id', 'http://schemas.microsoft.com/windowsazure'); js2xml.setElementValue(idElement, allRolesItem.id); js2xml.addChildElement(extensionElement, idElement); } js2xml.addChildElement(extensionConfigurationElement, allRolesSequenceElement); } if (parameters.extensionConfiguration.namedRoles !== null && parameters.extensionConfiguration.namedRoles !== undefined) { var namedRolesSequenceElement = js2xml.createElement('NamedRoles', 'http://schemas.microsoft.com/windowsazure'); for (var loweredIndex5 = 0; loweredIndex5 < parameters.extensionConfiguration.namedRoles.length; loweredIndex5 = loweredIndex5 + 1) { var namedRolesItem = parameters.extensionConfiguration.namedRoles[loweredIndex5]; var roleElement = js2xml.createElement('Role', 'http://schemas.microsoft.com/windowsazure'); js2xml.addChildElement(namedRolesSequenceElement, roleElement); var roleNameElement = js2xml.createElement('RoleName', 'http://schemas.microsoft.com/windowsazure'); js2xml.setElementValue(roleNameElement, namedRolesItem.roleName); js2xml.addChildElement(roleElement, roleNameElement); var extensionsSequenceElement = js2xml.createElement('Extensions', 'http://schemas.microsoft.com/windowsazure'); for (var loweredIndex6 = 0; loweredIndex6 < namedRolesItem.extensions.length; loweredIndex6 = loweredIndex6 + 1) { var extensionsItem = namedRolesItem.extensions[loweredIndex6]; var extensionElement2 = js2xml.createElement('Extension', 'http://schemas.microsoft.com/windowsazure'); js2xml.addChildElement(extensionsSequenceElement, extensionElement2); var idElement2 = js2xml.createElement('Id', 'http://schemas.microsoft.com/windowsazure'); js2xml.setElementValue(idElement2, extensionsItem.id); js2xml.addChildElement(extensionElement2, idElement2); } js2xml.addChildElement(roleElement, extensionsSequenceElement); } js2xml.addChildElement(extensionConfigurationElement, namedRolesSequenceElement); } } requestContent = js2xml.serializeDocument(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 !== 202) { 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); }); }; /** * The Begin Changing Deployment Configuration By Slot operation initiates a * change to the deployment configuration. This operation is an asynchronous * operation. To determine whether the Management service has finished * processing the request, call Get Operation Status. For more information * on asynchronous operations, see Tracking Asynchronous Service Management * Requests at * http://msdn.microsoft.com/en-us/library/windowsazure/ee460791.aspx. (see * http://msdn.microsoft.com/en-us/library/windowsazure/ee460809.aspx for * more information) * * @param {string} serviceName The cloud service to change deployment * configuration for. * * @param {DeploymentSlot} deploymentSlot The slot to change deployment * configuration for. * * @param {DeploymentChangeConfigurationParameters} parameters Parameters * supplied to the Begin Changing Configuration Deployment By Slot operation. * * @param {string} parameters.configuration The encoded service configuration * file for the deployment. * * @param {boolean} [parameters.treatWarningsAsError] Indicates whether to * treat package validation warnings as errors. The default value is false. * If set to true, the Created Deployment operation fails if there are * validation warnings on the service package. * * @param {DeploymentChangeConfigurationMode} [parameters.mode] The Change * Configuration Deployment mode. Possible values are: Auto and Manual. If * not specified, the default value is Auto. If set to Manual, * WalkUpgradeDomain must be called to apply the update. If set to Auto, the * update is automatically applied to each update domain for the service. * * @param {object} [parameters.extendedProperties] Represents the name of an * extended deployment property. Each extended property must have a defined * name and a value. You can have a maximum of 25 extended property * name/value pairs. The maximum length of the name element is 64 * characters, only alphanumeric characters and underscores are valid in the * name, and the name must start with a letter. Attempting to use other * characters, starting the name with a non-letter character, or entering a * name that is identical to that of another extended property owned by the * same hosted service will result in a status code 400 (Bad Request) error. * * @param {ExtensionConfiguration} [parameters.extensionConfiguration] * Represents an extension that is added to the cloud service. In Azure, a * process can run as an extension of a cloud service. For example, Remote * Desktop Access or the Azure Diagnostics Agent can run as extensions to * the cloud service. You must add an extension to the cloud service by * using Add Extension before it can be added to the deployment. * * @param {array} [parameters.extensionConfiguration.allRoles] Specifies a * list of extensions that are applied to all roles in a deployment. * * @param {array} [parameters.extensionConfiguration.namedRoles] Specifies a * list of extensions that are applied to specific roles in a deployment. * * @param {function} callback * * @returns {Stream} The response stream. */ DeploymentOperations.prototype.beginChangingConfigurationBySlot = function(serviceName, deploymentSlot, parameters, callback) { if (callback === null || callback === undefined) { throw new Error('callback cannot be null.'); } // Validate if (serviceName === null || serviceName === undefined) { return callback(new Error('serviceName cannot be null.')); } // TODO: Validate serviceName is a valid DNS name. if (deploymentSlot === null || deploymentSlot === undefined) { return callback(new Error('deploymentSlot cannot be null.')); } if (parameters === null || parameters === undefined) { return callback(new Error('parameters cannot be null.')); } if (parameters.configuration === null || parameters.configuration === undefined) { return callback(new Error('parameters.configuration cannot be null.')); } if (parameters.extensionConfiguration !== null && parameters.extensionConfiguration !== undefined) { if (parameters.extensionConfiguration.allRoles !== null && parameters.extensionConfiguration.allRoles !== undefined) { for (var loweredIndex1 = 0; loweredIndex1 < parameters.extensionConfiguration.allRoles.length; loweredIndex1 = loweredIndex1 + 1) { var allRolesParameterItem = parameters.extensionConfiguration.allRoles[loweredIndex1]; if (allRolesParameterItem.id === null || allRolesParameterItem.id === undefined) { return callback(new Error('parameters.extensionConfiguration.allRoles. cannot be null.')); } } } if (parameters.extensionConfiguration.namedRoles !== null && parameters.extensionConfiguration.namedRoles !== undefined) { for (var loweredIndex2 = 0; loweredIndex2 < parameters.extensionConfiguration.namedRoles.length; loweredIndex2 = loweredIndex2 + 1) { var namedRolesParameterItem = parameters.extensionConfiguration.namedRoles[loweredIndex2]; if (namedRolesParameterItem.extensions === null || namedRolesParameterItem.extensions === undefined) { return callback(new Error('parameters.extensionConfiguration.namedRoles. cannot be null.')); } if (namedRolesParameterItem.extensions !== null && namedRolesParameterItem.extensions !== undefined) { for (var loweredIndex3 = 0; loweredIndex3 < namedRolesParameterItem.extensions.length; loweredIndex3 = loweredIndex3 + 1) { var extensionsParameterItem = namedRolesParameterItem.extensions[loweredIndex3]; if (extensionsParameterItem.id === null || extensionsParameterItem.id === undefined) { return callback(new Error('parameters.extensionConfiguration.namedRoles.. cannot be null.')); } } } if (namedRolesParameterItem.roleName === null || namedRolesParameterItem.roleName === undefined) { return callback(new Error('parameters.extensionConfiguration.namedRoles. cannot be null.')); } } } } // Tracing // Construct URL var url2 = ''; url2 = url2 + '/'; if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) { url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId); } url2 = url2 + '/services/hostedservices/'; url2 = url2 + encodeURIComponent(serviceName); url2 = url2 + '/deploymentslots/'; url2 = url2 + encodeURIComponent(deploymentSlot !== null && deploymentSlot !== undefined ? deploymentSlot.toString() : 'Staging'); url2 = url2 + '/'; var queryParameters = []; queryParameters.push('comp=config'); 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 httpRequest.headers['Content-Type'] = 'application/xml'; httpRequest.headers['x-ms-version'] = '2014-10-01'; // Serialize Request var requestContent = null; var requestDoc = {}; var changeConfigurationElement = js2xml.createElement('ChangeConfiguration', 'http://schemas.microsoft.com/windowsazure'); js2xml.addChildElement(requestDoc, changeConfigurationElement); var configurationElement = js2xml.createElement('Configuration', 'http://schemas.microsoft.com/windowsazure'); js2xml.setElementValue(configurationElement, new Buffer(parameters.configuration).toString('base64')); js2xml.addChildElement(changeConfigurationElement, configurationElement); if (parameters.treatWarningsAsError !== null && parameters.treatWarningsAsError !== undefined) { var treatWarningsAsErrorElement = js2xml.createElement('TreatWarningsAsError', 'http://schemas.microsoft.com/windowsazure'); js2xml.setElementValue(treatWarningsAsErrorElement, parameters.treatWarningsAsError.toString()); js2xml.addChildElement(changeConfigurationElement, treatWarningsAsErrorElement); } if (parameters.mode !== null && parameters.mode !== undefined) { var modeElement = js2xml.createElement('Mode', 'http://schemas.microsoft.com/windowsazure'); js2xml.setElementValue(modeElement, parameters.mode !== null && parameters.mode !== undefined ? parameters.mode.toString() : 'Auto'); js2xml.addChildElement(changeConfigurationElement, modeElement); } if (parameters.extendedProperties !== null && parameters.extendedProperties !== undefined) { var extendedPropertiesDictionaryElement = js2xml.createElement('ExtendedProperties', 'http://schemas.microsoft.com/windowsazure'); for (var extendedPropertiesKey in parameters.extendedProperties) { var extendedPropertiesValue = parameters.extendedProperties[extendedPropertiesKey]; var extendedPropertiesElement = js2xml.createElement('ExtendedProperty', 'http://schemas.microsoft.com/windowsazure'); js2xml.addChildElement(extendedPropertiesDictionaryElement, extendedPropertiesElement); var extendedPropertiesKeyElement = js2xml.createElement('Name', 'http://schemas.microsoft.com/windowsazure'); js2xml.setElementValue(extendedPropertiesKeyElement, extendedPropertiesKey); js2xml.addChildElement(extendedPropertiesElement, extendedPropertiesKeyElement); var extendedPropertiesValueElement = js2xml.createElement('Value', 'http://schemas.microsoft.com/windowsazure'); js2xml.setElementValue(extendedPropertiesValueElement, extendedPropertiesValue); js2xml.addChildElement(extendedPropertiesElement, extendedPropertiesValueElement); } js2xml.addChildElement(changeConfigurationElement, extendedPropertiesDictionaryElement); } if (parameters.extensionConfiguration !== null && parameters.extensionConfiguration !== undefined) { var extensionConfigurationElement = js2xml.createElement('ExtensionConfiguration', 'http://schemas.microsoft.com/windowsazure'); js2xml.addChildElement(changeConfigurationElement, extensionConfigurationElement); if (parameters.extensionConfiguration.allRoles !== null && parameters.extensionConfiguration.allRoles !== undefined) { var allRolesSequenceElement = js2xml.createElement('AllRoles', 'http://schemas.microsoft.com/windowsazure'); for (var loweredIndex4 = 0; loweredIndex4 < parameters.extensionConfiguration.allRoles.length; loweredIndex4 = loweredIndex4 + 1) { var allRolesItem = parameters.extensionConfiguration.allRoles[loweredIndex4]; var extensionElement = js2xml.createElement('Extension', 'http://schemas.microsoft.com/windowsazure'); js2xml.addChildElement(allRolesSequenceElement, extensionElement); var idElement = js2xml.createElement('Id', 'http://schemas.microsoft.com/windowsazure'); js2xml.setElementValue(idElement, allRolesItem.id); js2xml.addChildElement(extensionElement, idElement); } js2xml.addChildElement(extensionConfigurationElement, allRolesSequenceElement); } if (parameters.extensionConfiguration.namedRoles !== null && parameters.extensionConfiguration.namedRoles !== undefined) { var namedRolesSequenceElement = js2xml.createElement('NamedRoles', 'http://schemas.microsoft.com/windowsazure'); for (var loweredIndex5 = 0; loweredIndex5 < parameters.extensionConfiguration.namedRoles.length; loweredIndex5 = loweredIndex5 + 1) { var namedRolesItem = parameters.extensionConfiguration.namedRoles[loweredIndex5]; var roleElement = js2xml.createElement('Role', 'http://schemas.microsoft.com/windowsazure'); js2xml.addChildElement(namedRolesSequenceElement, roleElement); var roleNameElement = js2xml.createElement('RoleName', 'http://schemas.microsoft.com/windowsazure'); js2xml.setElementValue(roleNameElement, namedRolesItem.roleName); js2xml.addChildElement(roleElement, roleNameElement); var extensionsSequenceElement = js2xml.createElement('Extensions', 'http://schemas.microsoft.com/windowsazure'); for (var loweredIndex6 = 0; loweredIndex6 < namedRolesItem.extensions.length; loweredIndex6 = loweredIndex6 + 1) { var extensionsItem = namedRolesItem.extensions[loweredIndex6]; var extensionElement2 = js2xml.createElement('Extension', 'http://schemas.microsoft.com/windowsazure'); js2xml.addChildElement(extensionsSequenceElement, extensionElement2); var idElement2 = js2xml.createElement('Id', 'http://schemas.microsoft.com/windowsazure'); js2xml.setElementValue(idElement2, extensionsItem.id); js2xml.addChildElement(extensionElement2, idElement2); } js2xml.addChildElement(roleElement, extensionsSequenceElement); } js2xml.addChildElement(extensionConfigurationElement, namedRolesSequenceElement); } } requestContent = js2xml.serializeDocument(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 !== 202) { 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); }); }; /** * The Begin Creating Deployment operation uploads a new service package and * creates a new deployment in the staging or production environments. This * operation is an asynchronous operation. To determine whether the * management service has finished processing the request, call Get * Operation Status. For more information on asynchronous operations, see * Tracking Asynchronous Service Management Requests at * http://msdn.microsoft.com/en-us/library/windowsazure/ee460791.aspx. (see * http://msdn.microsoft.com/en-us/library/windowsazure/ee460813.aspx for * more information) * * @param {string} serviceName The cloud service to create a deployment for. * * @param {DeploymentSlot} deploymentSlot The slot to create a deployment for. * * @param {DeploymentCreateParameters} parameters Parameters supplied to the * Begin Creating Deployment operation. * * @param {string} parameters.name The name for the deployment. The * deployment name must be unique among other deployments for the cloud * service. * * @param {string} parameters.packageUri A URL that refers to the location of * the service package in the Blob service. The service package can be * located either in a storage account beneath the same subscription or a * Shared Access Signature (SAS) URI from any storage account. For more info * about Shared Access Signatures, see Delegating Access with a Shared * Access Signature (REST API) at * http://msdn.microsoft.com/en-us/library/windowsazure/ee395415.aspx. * * @param {string} parameters.label A name for the hosted service. The name * can be up to 100 characters in length. It is recommended that the label * be unique within the subscription. The name can be used identify the * hosted service for your tracking purposes. * * @param {string} parameters.configuration The service configuration file * for the deployment. The client library does the base-64 encoding from the * plain text input. * * @param {boolean} [parameters.startDeployment] Indicates whether to start * the deployment immediately after it is created. The default value is * false. If false, the service model is still deployed to the virtual * machines but the code is not run immediately. Instead, the service is * Suspended until you call Update Deployment Status and set the status * toRunning, at which time the service will be started. A deployed service * still incurs charges, even if it is suspended. * * @param {boolean} [parameters.treatWarningsAsError] Indicates whether to * treat package validation warnings as errors. The default value is false. * If set to true, the Created Deployment operation fails if there are * validation warnings on the service package. * * @param {object} [parameters.extendedProperties] Represents the name of an * extended deployment property. Each extended property must have a defined * name and a value. You can have a maximum of 25 extended property * name/value pairs. The maximum length of the name element is 64 * characters, only alphanumeric characters and underscores are valid in the * name, and the name must start with a letter. Attempting to use other * characters, starting the name with a non-letter character, or entering a * name that is identical to that of another extended property owned by the * same hosted service will result in a status code 400 (Bad Request) error. * * @param {ExtensionConfiguration} [parameters.extensionConfiguration] * Represents an extension that is added to the cloud service. In Azure, a * process can run as an extension of a cloud service. For example, Remote * Desktop Access or the Azure Diagnostics Agent can run as extensions to * the cloud service. You must add an extension to the cloud service by * using Add Extension before it can be added to the deployment. * * @param {array} [parameters.extensionConfiguration.allRoles] Specifies a * list of extensions that are applied to all roles in a deployment. * * @param {array} [parameters.extensionConfiguration.namedRoles] Specifies a * list of extensions that are applied to specific roles in a deployment. * * @param {function} callback * * @returns {Stream} The response stream. */ DeploymentOperations.prototype.beginCreating = function(serviceName, deploymentSlot, parameters, callback) { if (callback === null || callback === undefined) { throw new Error('callback cannot be null.'); } // Validate if (serviceName === null || serviceName === undefined) { return callback(new Error('serviceName cannot be null.')); } // TODO: Validate serviceName is a valid DNS name. if (deploymentSlot === null || deploymentSlot === undefined) { return callback(new Error('deploymentSlot cannot be null.')); } if (parameters === null || parameters === undefined) { return callback(new Error('parameters cannot be null.')); } if (parameters.configuration === null || parameters.configuration === undefined) { return callback(new Error('parameters.configuration cannot be null.')); } if (parameters.extensionConfiguration !== null && parameters.extensionConfiguration !== undefined) { if (parameters.extensionConfiguration.allRoles !== null && parameters.extensionConfiguration.allRoles !== undefined) { for (var loweredIndex1 = 0; loweredIndex1 < parameters.extensionConfiguration.allRoles.length; loweredIndex1 = loweredIndex1 + 1) { var allRolesParameterItem = parameters.extensionConfiguration.allRoles[loweredIndex1]; if (allRolesParameterItem.id === null || allRolesParameterItem.id === undefined) { return callback(new Error('parameters.extensionConfiguration.allRoles. cannot be null.')); } } } if (parameters.extensionConfiguration.namedRoles !== null && parameters.extensionConfiguration.namedRoles !== undefined) { for (var loweredIndex2 = 0; loweredIndex2 < parameters.extensionConfiguration.namedRoles.length; loweredIndex2 = loweredIndex2 + 1) { var namedRolesParameterItem = parameters.extensionConfiguration.namedRoles[loweredIndex2]; if (namedRolesParameterItem.extensions === null || namedRolesParameterItem.extensions === undefined) { return callback(new Error('parameters.extensionConfiguration.namedRoles. cannot be null.')); } if (namedRolesParameterItem.extensions !== null && namedRolesParameterItem.extensions !== undefined) { for (var loweredIndex3 = 0; loweredIndex3 < namedRolesParameterItem.extensions.length; loweredIndex3 = loweredIndex3 + 1) { var extensionsParameterItem = namedRolesParameterItem.extensions[loweredIndex3]; if (extensionsParameterItem.id === null || extensionsParameterItem.id === undefined) { return callback(new Error('parameters.extensionConfiguration.namedRoles.. cannot be null.')); } } } if (namedRolesParameterItem.roleName === null || namedRolesParameterItem.roleName === undefined) { return callback(new Error('parameters.extensionConfiguration.namedRoles. cannot be null.')); } } } } if (parameters.label === null || parameters.label === undefined) { return callback(new Error('parameters.label cannot be null.')); } if (parameters.label.length > 100) { return callback(new Error('parameters.label is outside the valid range.')); } if (parameters.name === null || parameters.name === undefined) { return callback(new Error('parameters.name cannot be null.')); } if (parameters.packageUri === null || parameters.packageUri === undefined)