/* 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 NetworkManagementClient = ( /** @lends NetworkManagementClient */ function() {
  /**
   * @class
   * The Service Management API includes operations for managing the virtual
   * networks for your subscription.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj157182.aspx for
   * more information)
   * Initializes a new instance of the NetworkManagementClient 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 NetworkManagementClient(credentials, baseUri, filters) {
    if (credentials === null || credentials === undefined) {
      throw new Error('credentials cannot be null.');
    }
    
    NetworkManagementClient['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 = '2016-03-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
     * [ApplicationGatewayOperations](-ApplicationGatewayOperations.html)
     * object.
     * @type {object}
     */
    this.applicationGateways = new ApplicationGatewayOperations(this);
    /**
     * Provides an instance of the
     * [ClientRootCertificateOperations](-ClientRootCertificateOperations.html)
     * object.
     * @type {object}
     */
    this.clientRootCertificates = new ClientRootCertificateOperations(this);
    /**
     * Provides an instance of the [GatewayOperations](-GatewayOperations.html)
     * object.
     * @type {object}
     */
    this.gateways = new GatewayOperations(this);
    /**
     * Provides an instance of the
     * [IPForwardingOperations](-IPForwardingOperations.html) object.
     * @type {object}
     */
    this.iPForwarding = new IPForwardingOperations(this);
    /**
     * Provides an instance of the [NetworkOperations](-NetworkOperations.html)
     * object.
     * @type {object}
     */
    this.networks = new NetworkOperations(this);
    /**
     * Provides an instance of the
     * [NetworkSecurityGroupOperations](-NetworkSecurityGroupOperations.html)
     * object.
     * @type {object}
     */
    this.networkSecurityGroups = new NetworkSecurityGroupOperations(this);
    /**
     * Provides an instance of the
     * [ReservedIPOperations](-ReservedIPOperations.html) object.
     * @type {object}
     */
    this.reservedIPs = new ReservedIPOperations(this);
    /**
     * Provides an instance of the [RouteOperations](-RouteOperations.html)
     * object.
     * @type {object}
     */
    this.routes = new RouteOperations(this);
    /**
     * Provides an instance of the
     * [StaticIPOperations](-StaticIPOperations.html) object.
     * @type {object}
     */
    this.staticIPs = new StaticIPOperations(this);
    /**
     * Provides an instance of the
     * [VirtualIPOperations](-VirtualIPOperations.html) object.
     * @type {object}
     */
    this.virtualIPs = new VirtualIPOperations(this);
  }
  
  util.inherits(NetworkManagementClient, 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.
   */
  NetworkManagementClient.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'] = '2016-03-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 NetworkManagementClient;
})();
exports.NetworkManagementClient = NetworkManagementClient;

var ApplicationGatewayOperations = ( /** @lends ApplicationGatewayOperations */ function() {
  /**
   * @class
   * The Application Gateway Management API includes operations for managing
   * application gateways in your subscription.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154113.aspx for
   * more information)
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [NetworkManagementClient] {@link
   * NetworkManagementClient~NetworkManagementClient}.
   * See [applicationGateways] {@link
   * NetworkManagementClient~NetworkManagementClient#applicationGateways}.
   * Initializes a new instance of the ApplicationGatewayOperations class.
   * @constructor
   * 
   * @param {NetworkManagementClient} client Reference to the service client.
   */
  function ApplicationGatewayOperations(client) {
    this.client = client;
  }
  
  /**
   * The Add certificate operation adds the ssl certificate to the application
   * gateway  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
   * more information)
   * 
   * @param {string} gatewayName Gateway name
   * 
   * @param {string} certificateName Certificate name
   * 
   * @param {ApplicationGatewayCertificate} certificate The application gateway
   * ssl certificate
   * 
   * @param {string} [certificate.data] Certificate file data.
   * 
   * @param {string} [certificate.certificateFormat] Certificate file format.
   * 
   * @param {string} [certificate.password] Certificate file password.
   * 
   * @param {HttpStatusCode} [certificate.statusCode]
   * 
   * @param {string} [certificate.requestId]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ApplicationGatewayOperations.prototype.addCertificate = function(gatewayName, certificateName, certificate, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.applicationGateways.beginAddCertificate(gatewayName, certificateName, certificate, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.applicationGateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Begin Add certificate operation adds the ssl certificate to the
   * application gateway  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
   * more information)
   * 
   * @param {string} gatewayName Gateway name
   * 
   * @param {string} certificateName Certificate name
   * 
   * @param {ApplicationGatewayCertificate} certificate The application gateway
   * ssl certificate
   * 
   * @param {string} [certificate.data] Certificate file data.
   * 
   * @param {string} [certificate.certificateFormat] Certificate file format.
   * 
   * @param {string} [certificate.password] Certificate file password.
   * 
   * @param {HttpStatusCode} [certificate.statusCode]
   * 
   * @param {string} [certificate.requestId]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ApplicationGatewayOperations.prototype.beginAddCertificate = function(gatewayName, certificateName, certificate, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayName === null || gatewayName === undefined) {
      return callback(new Error('gatewayName cannot be null.'));
    }
    if (certificateName === null || certificateName === undefined) {
      return callback(new Error('certificateName cannot be null.'));
    }
    if (certificate === null || certificate === undefined) {
      return callback(new Error('certificate 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/networking/ApplicationGateways/';
    url2 = url2 + encodeURIComponent(gatewayName);
    url2 = url2 + '/sslcertificates/';
    url2 = url2 + encodeURIComponent(certificateName);
    var queryParameters = [];
    queryParameters.push('api-version=2016-03-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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var certificateFileElement = js2xml.createElement('CertificateFile', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, certificateFileElement);
    
    if (certificate.data !== null && certificate.data !== undefined) {
      var dataElement = js2xml.createElement('Data', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(dataElement, certificate.data);
      js2xml.addChildElement(certificateFileElement, dataElement);
    }
    
    if (certificate.certificateFormat !== null && certificate.certificateFormat !== undefined) {
      var certificateFormatElement = js2xml.createElement('CertificateFormat', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(certificateFormatElement, certificate.certificateFormat);
      js2xml.addChildElement(certificateFileElement, certificateFormatElement);
    }
    
    if (certificate.password !== null && certificate.password !== undefined) {
      var passwordElement = js2xml.createElement('Password', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(passwordElement, certificate.password);
      js2xml.addChildElement(certificateFileElement, passwordElement);
    }
    
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Create Application Gateway operation  creates Application
   * Gateway with the specified  parameters.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
   * more information)
   * 
   * @param {CreateApplicationGatewayParameters} parameters Parameters supplied
   * to the Begin CreateApplication Gateway request.
   * 
   * @param {string} [parameters.description] Gateway Description.
   * 
   * @param {string} [parameters.gatewaySize] The size of each gateway instance.
   * 
   * @param {number} [parameters.instanceCount] The number of instances to
   * create for this gateway.
   * 
   * @param {string} [parameters.name] Friendly Name of the gateway.
   * 
   * @param {IEnumerable} [parameters.subnets] Subnets in the vnet to which the
   * gateway belongs.
   * 
   * @param {string} [parameters.vnetName] The vnet to which the gateway
   * belongs.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ApplicationGatewayOperations.prototype.beginCreateApplicationGateway = function(parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/ApplicationGateways';
    var queryParameters = [];
    queryParameters.push('api-version=2016-03-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
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var createApplicationGatewayParametersElement = js2xml.createElement('CreateApplicationGatewayParameters', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, createApplicationGatewayParametersElement);
    
    if (parameters.description !== null && parameters.description !== undefined) {
      var descriptionElement = js2xml.createElement('Description', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(descriptionElement, parameters.description);
      js2xml.addChildElement(createApplicationGatewayParametersElement, descriptionElement);
    }
    
    if (parameters.gatewaySize !== null && parameters.gatewaySize !== undefined) {
      var gatewaySizeElement = js2xml.createElement('GatewaySize', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(gatewaySizeElement, parameters.gatewaySize);
      js2xml.addChildElement(createApplicationGatewayParametersElement, gatewaySizeElement);
    }
    
    if (parameters.instanceCount !== null && parameters.instanceCount !== undefined) {
      var instanceCountElement = js2xml.createElement('InstanceCount', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(instanceCountElement, parameters.instanceCount.toString());
      js2xml.addChildElement(createApplicationGatewayParametersElement, instanceCountElement);
    }
    
    if (parameters.name !== null && parameters.name !== undefined) {
      var nameElement = js2xml.createElement('Name', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(nameElement, parameters.name);
      js2xml.addChildElement(createApplicationGatewayParametersElement, nameElement);
    }
    
    if (parameters.subnets !== null && parameters.subnets !== undefined) {
      var subnetsSequenceElement = js2xml.createElement('Subnets', 'http://schemas.microsoft.com/windowsazure');
      for (var loweredIndex1 = 0; loweredIndex1 < parameters.subnets.length; loweredIndex1 = loweredIndex1 + 1) {
        var subnetsItem = parameters.subnets[loweredIndex1];
        var subnetsItemElement = js2xml.createElement('Subnet', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(subnetsItemElement, subnetsItem);
        js2xml.addChildElement(subnetsSequenceElement, subnetsItemElement);
      }
      js2xml.addChildElement(createApplicationGatewayParametersElement, subnetsSequenceElement);
    }
    
    if (parameters.vnetName !== null && parameters.vnetName !== undefined) {
      var vnetNameElement = js2xml.createElement('VnetName', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(vnetNameElement, parameters.vnetName);
      js2xml.addChildElement(createApplicationGatewayParametersElement, vnetNameElement);
    }
    
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Delete Application Gateway operation  deletes Application
   * Gateway with the specified  parameters.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
   * more information)
   * 
   * @param {string} gatewayName The name of the gateway.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ApplicationGatewayOperations.prototype.beginDeleteApplicationGateway = function(gatewayName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayName === null || gatewayName === undefined) {
      return callback(new Error('gatewayName 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/networking/ApplicationGateways/';
    url2 = url2 + encodeURIComponent(gatewayName);
    var queryParameters = [];
    queryParameters.push('api-version=2016-03-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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // 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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Delete Application Gateway certificate.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
   * more information)
   * 
   * @param {string} gatewayName The name of the gateway.
   * 
   * @param {string} certificateName The name of the certificate.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ApplicationGatewayOperations.prototype.beginDeleteApplicationGatewayCertificate = function(gatewayName, certificateName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayName === null || gatewayName === undefined) {
      return callback(new Error('gatewayName cannot be null.'));
    }
    if (certificateName === null || certificateName === undefined) {
      return callback(new Error('certificateName 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/networking/ApplicationGateways/';
    url2 = url2 + encodeURIComponent(gatewayName);
    url2 = url2 + '/sslcertificates/';
    url2 = url2 + encodeURIComponent(certificateName);
    var queryParameters = [];
    queryParameters.push('api-version=2016-03-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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // 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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Execute Application Gateway Operation executes specified operation on
   * Application Gateway .  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
   * more information)
   * 
   * @param {string} gatewayName Name of the gateway
   * 
   * @param {ApplicationGatewayOperation} parameters Parameters supplied to the
   * Begin Execute Operation request.
   * 
   * @param {string} [parameters.operationType] Operation Type.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ApplicationGatewayOperations.prototype.beginExecuteOperation = function(gatewayName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayName === null || gatewayName === undefined) {
      return callback(new Error('gatewayName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/ApplicationGateways/';
    url2 = url2 + encodeURIComponent(gatewayName);
    url2 = url2 + '/Operations';
    var queryParameters = [];
    queryParameters.push('api-version=2016-03-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
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var applicationGatewayOperationElement = js2xml.createElement('ApplicationGatewayOperation', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, applicationGatewayOperationElement);
    
    if (parameters.operationType !== null && parameters.operationType !== undefined) {
      var operationTypeElement = js2xml.createElement('OperationType', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(operationTypeElement, parameters.operationType);
      js2xml.addChildElement(applicationGatewayOperationElement, operationTypeElement);
    }
    
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Set Application Gateway config operation  sets the specified
   * config on the application gateway  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
   * more information)
   * 
   * @param {string} gatewayName Gateway name
   * 
   * @param {ApplicationGatewaySetConfiguration} config The Begin Set
   * Application Gateway Config operation  sets the specified config on the
   * application gateway
   * 
   * @param {IEnumerable} [config.frontendIPConfigurations] Frontend IPs of
   * application gateway.
   * 
   * @param {IEnumerable} [config.frontendPorts] Frontend ports on the
   * application gateway.
   * 
   * @param {IEnumerable} [config.probes] Probes of application gateway.
   * 
   * @param {IEnumerable} [config.backendAddressPools] Backend Address Pool
   * 
   * @param {IEnumerable} [config.backendHttpSettingsList] Backend Http Setting
   * 
   * @param {IEnumerable} [config.httpListeners] Backend Http Setting
   * 
   * @param {IEnumerable} [config.httpLoadBalancingRules] Backend Http Setting
   * 
   * @param {HttpStatusCode} [config.statusCode]
   * 
   * @param {string} [config.requestId]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ApplicationGatewayOperations.prototype.beginSetConfig = function(gatewayName, config, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayName === null || gatewayName === undefined) {
      return callback(new Error('gatewayName cannot be null.'));
    }
    if (config === null || config === undefined) {
      return callback(new Error('config 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/networking/ApplicationGateways/';
    url2 = url2 + encodeURIComponent(gatewayName);
    url2 = url2 + '/configuration';
    var queryParameters = [];
    queryParameters.push('api-version=2016-03-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
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var applicationGatewayConfigurationElement = js2xml.createElement('ApplicationGatewayConfiguration', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, applicationGatewayConfigurationElement);
    
    if (config.frontendIPConfigurations !== null && config.frontendIPConfigurations !== undefined) {
      var frontendIPConfigurationsSequenceElement = js2xml.createElement('FrontendIPConfigurations', 'http://schemas.microsoft.com/windowsazure');
      for (var loweredIndex1 = 0; loweredIndex1 < config.frontendIPConfigurations.length; loweredIndex1 = loweredIndex1 + 1) {
        var frontendIPConfigurationsItem = config.frontendIPConfigurations[loweredIndex1];
        var frontendIPConfigurationElement = js2xml.createElement('FrontendIPConfiguration', 'http://schemas.microsoft.com/windowsazure');
        js2xml.addChildElement(frontendIPConfigurationsSequenceElement, frontendIPConfigurationElement);
        
        if (frontendIPConfigurationsItem.name !== null && frontendIPConfigurationsItem.name !== undefined) {
          var nameElement = js2xml.createElement('Name', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(nameElement, frontendIPConfigurationsItem.name);
          js2xml.addChildElement(frontendIPConfigurationElement, nameElement);
        }
        
        if (frontendIPConfigurationsItem.type !== null && frontendIPConfigurationsItem.type !== undefined) {
          var typeElement = js2xml.createElement('Type', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(typeElement, frontendIPConfigurationsItem.type);
          js2xml.addChildElement(frontendIPConfigurationElement, typeElement);
        }
        
        if (frontendIPConfigurationsItem.staticIPAddress !== null && frontendIPConfigurationsItem.staticIPAddress !== undefined) {
          var staticIPAddressElement = js2xml.createElement('StaticIPAddress', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(staticIPAddressElement, frontendIPConfigurationsItem.staticIPAddress);
          js2xml.addChildElement(frontendIPConfigurationElement, staticIPAddressElement);
        }
      }
      js2xml.addChildElement(applicationGatewayConfigurationElement, frontendIPConfigurationsSequenceElement);
    }
    
    if (config.frontendPorts !== null && config.frontendPorts !== undefined) {
      var frontendPortsSequenceElement = js2xml.createElement('FrontendPorts', 'http://schemas.microsoft.com/windowsazure');
      for (var loweredIndex2 = 0; loweredIndex2 < config.frontendPorts.length; loweredIndex2 = loweredIndex2 + 1) {
        var frontendPortsItem = config.frontendPorts[loweredIndex2];
        var frontendPortElement = js2xml.createElement('FrontendPort', 'http://schemas.microsoft.com/windowsazure');
        js2xml.addChildElement(frontendPortsSequenceElement, frontendPortElement);
        
        if (frontendPortsItem.name !== null && frontendPortsItem.name !== undefined) {
          var nameElement2 = js2xml.createElement('Name', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(nameElement2, frontendPortsItem.name);
          js2xml.addChildElement(frontendPortElement, nameElement2);
        }
        
        if (frontendPortsItem.port !== null && frontendPortsItem.port !== undefined) {
          var portElement = js2xml.createElement('Port', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(portElement, frontendPortsItem.port.toString());
          js2xml.addChildElement(frontendPortElement, portElement);
        }
      }
      js2xml.addChildElement(applicationGatewayConfigurationElement, frontendPortsSequenceElement);
    }
    
    if (config.probes !== null && config.probes !== undefined) {
      var probesSequenceElement = js2xml.createElement('Probes', 'http://schemas.microsoft.com/windowsazure');
      for (var loweredIndex3 = 0; loweredIndex3 < config.probes.length; loweredIndex3 = loweredIndex3 + 1) {
        var probesItem = config.probes[loweredIndex3];
        var probeElement = js2xml.createElement('Probe', 'http://schemas.microsoft.com/windowsazure');
        js2xml.addChildElement(probesSequenceElement, probeElement);
        
        if (probesItem.name !== null && probesItem.name !== undefined) {
          var nameElement3 = js2xml.createElement('Name', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(nameElement3, probesItem.name);
          js2xml.addChildElement(probeElement, nameElement3);
        }
        
        if (probesItem.protocol !== null && probesItem.protocol !== undefined) {
          var protocolElement = js2xml.createElement('Protocol', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(protocolElement, probesItem.protocol);
          js2xml.addChildElement(probeElement, protocolElement);
        }
        
        if (probesItem.host !== null && probesItem.host !== undefined) {
          var hostElement = js2xml.createElement('Host', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(hostElement, probesItem.host);
          js2xml.addChildElement(probeElement, hostElement);
        }
        
        if (probesItem.path !== null && probesItem.path !== undefined) {
          var pathElement = js2xml.createElement('Path', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(pathElement, probesItem.path);
          js2xml.addChildElement(probeElement, pathElement);
        }
        
        if (probesItem.interval !== null && probesItem.interval !== undefined) {
          var intervalElement = js2xml.createElement('Interval', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(intervalElement, probesItem.interval.toString());
          js2xml.addChildElement(probeElement, intervalElement);
        }
        
        if (probesItem.timeout !== null && probesItem.timeout !== undefined) {
          var timeoutElement = js2xml.createElement('Timeout', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(timeoutElement, probesItem.timeout.toString());
          js2xml.addChildElement(probeElement, timeoutElement);
        }
        
        if (probesItem.unhealthyThreshold !== null && probesItem.unhealthyThreshold !== undefined) {
          var unhealthyThresholdElement = js2xml.createElement('UnhealthyThreshold', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(unhealthyThresholdElement, probesItem.unhealthyThreshold.toString());
          js2xml.addChildElement(probeElement, unhealthyThresholdElement);
        }
      }
      js2xml.addChildElement(applicationGatewayConfigurationElement, probesSequenceElement);
    }
    
    if (config.backendAddressPools !== null && config.backendAddressPools !== undefined) {
      var backendAddressPoolsSequenceElement = js2xml.createElement('BackendAddressPools', 'http://schemas.microsoft.com/windowsazure');
      for (var loweredIndex4 = 0; loweredIndex4 < config.backendAddressPools.length; loweredIndex4 = loweredIndex4 + 1) {
        var backendAddressPoolsItem = config.backendAddressPools[loweredIndex4];
        var backendAddressPoolElement = js2xml.createElement('BackendAddressPool', 'http://schemas.microsoft.com/windowsazure');
        js2xml.addChildElement(backendAddressPoolsSequenceElement, backendAddressPoolElement);
        
        if (backendAddressPoolsItem.name !== null && backendAddressPoolsItem.name !== undefined) {
          var nameElement4 = js2xml.createElement('Name', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(nameElement4, backendAddressPoolsItem.name);
          js2xml.addChildElement(backendAddressPoolElement, nameElement4);
        }
        
        if (backendAddressPoolsItem.backendServers !== null && backendAddressPoolsItem.backendServers !== undefined) {
          var iPAddressesSequenceElement = js2xml.createElement('IPAddresses', 'http://schemas.microsoft.com/windowsazure');
          for (var loweredIndex5 = 0; loweredIndex5 < backendAddressPoolsItem.backendServers.length; loweredIndex5 = loweredIndex5 + 1) {
            var iPAddressesItem = backendAddressPoolsItem.backendServers[loweredIndex5];
            var iPAddressElement = js2xml.createElement('IPAddress', 'http://schemas.microsoft.com/windowsazure');
            js2xml.addChildElement(iPAddressesSequenceElement, iPAddressElement);
            
            if (iPAddressesItem.iPAddress !== null && iPAddressesItem.iPAddress !== undefined) {
              js2xml.setElementValue(iPAddressElement, iPAddressesItem.iPAddress);
            }
          }
          js2xml.addChildElement(backendAddressPoolElement, iPAddressesSequenceElement);
        }
      }
      js2xml.addChildElement(applicationGatewayConfigurationElement, backendAddressPoolsSequenceElement);
    }
    
    if (config.backendHttpSettingsList !== null && config.backendHttpSettingsList !== undefined) {
      var backendHttpSettingsListSequenceElement = js2xml.createElement('BackendHttpSettingsList', 'http://schemas.microsoft.com/windowsazure');
      for (var loweredIndex6 = 0; loweredIndex6 < config.backendHttpSettingsList.length; loweredIndex6 = loweredIndex6 + 1) {
        var backendHttpSettingsListItem = config.backendHttpSettingsList[loweredIndex6];
        var backendHttpSettingsElement = js2xml.createElement('BackendHttpSettings', 'http://schemas.microsoft.com/windowsazure');
        js2xml.addChildElement(backendHttpSettingsListSequenceElement, backendHttpSettingsElement);
        
        if (backendHttpSettingsListItem.name !== null && backendHttpSettingsListItem.name !== undefined) {
          var nameElement5 = js2xml.createElement('Name', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(nameElement5, backendHttpSettingsListItem.name);
          js2xml.addChildElement(backendHttpSettingsElement, nameElement5);
        }
        
        if (backendHttpSettingsListItem.port !== null && backendHttpSettingsListItem.port !== undefined) {
          var portElement2 = js2xml.createElement('Port', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(portElement2, backendHttpSettingsListItem.port.toString());
          js2xml.addChildElement(backendHttpSettingsElement, portElement2);
        }
        
        if (backendHttpSettingsListItem.protocol !== null && backendHttpSettingsListItem.protocol !== undefined) {
          var protocolElement2 = js2xml.createElement('Protocol', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(protocolElement2, backendHttpSettingsListItem.protocol !== null && backendHttpSettingsListItem.protocol !== undefined ? backendHttpSettingsListItem.protocol.toString() : 'Http');
          js2xml.addChildElement(backendHttpSettingsElement, protocolElement2);
        }
        
        if (backendHttpSettingsListItem.cookieBasedAffinity !== null && backendHttpSettingsListItem.cookieBasedAffinity !== undefined) {
          var cookieBasedAffinityElement = js2xml.createElement('CookieBasedAffinity', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(cookieBasedAffinityElement, backendHttpSettingsListItem.cookieBasedAffinity);
          js2xml.addChildElement(backendHttpSettingsElement, cookieBasedAffinityElement);
        }
        
        if (backendHttpSettingsListItem.requestTimeout !== null && backendHttpSettingsListItem.requestTimeout !== undefined) {
          var requestTimeoutElement = js2xml.createElement('RequestTimeout', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(requestTimeoutElement, backendHttpSettingsListItem.requestTimeout.toString());
          js2xml.addChildElement(backendHttpSettingsElement, requestTimeoutElement);
        }
        
        if (backendHttpSettingsListItem.probe !== null && backendHttpSettingsListItem.probe !== undefined) {
          var probeElement2 = js2xml.createElement('Probe', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(probeElement2, backendHttpSettingsListItem.probe);
          js2xml.addChildElement(backendHttpSettingsElement, probeElement2);
        }
      }
      js2xml.addChildElement(applicationGatewayConfigurationElement, backendHttpSettingsListSequenceElement);
    }
    
    if (config.httpListeners !== null && config.httpListeners !== undefined) {
      var httpListenersSequenceElement = js2xml.createElement('HttpListeners', 'http://schemas.microsoft.com/windowsazure');
      for (var loweredIndex7 = 0; loweredIndex7 < config.httpListeners.length; loweredIndex7 = loweredIndex7 + 1) {
        var httpListenersItem = config.httpListeners[loweredIndex7];
        var httpListenerElement = js2xml.createElement('HttpListener', 'http://schemas.microsoft.com/windowsazure');
        js2xml.addChildElement(httpListenersSequenceElement, httpListenerElement);
        
        if (httpListenersItem.name !== null && httpListenersItem.name !== undefined) {
          var nameElement6 = js2xml.createElement('Name', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(nameElement6, httpListenersItem.name);
          js2xml.addChildElement(httpListenerElement, nameElement6);
        }
        
        if (httpListenersItem.frontendIP !== null && httpListenersItem.frontendIP !== undefined) {
          var frontendIPElement = js2xml.createElement('FrontendIP', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(frontendIPElement, httpListenersItem.frontendIP);
          js2xml.addChildElement(httpListenerElement, frontendIPElement);
        }
        
        if (httpListenersItem.frontendPort !== null && httpListenersItem.frontendPort !== undefined) {
          var frontendPortElement2 = js2xml.createElement('FrontendPort', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(frontendPortElement2, httpListenersItem.frontendPort);
          js2xml.addChildElement(httpListenerElement, frontendPortElement2);
        }
        
        if (httpListenersItem.protocol !== null && httpListenersItem.protocol !== undefined) {
          var protocolElement3 = js2xml.createElement('Protocol', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(protocolElement3, httpListenersItem.protocol !== null && httpListenersItem.protocol !== undefined ? httpListenersItem.protocol.toString() : 'Http');
          js2xml.addChildElement(httpListenerElement, protocolElement3);
        }
        
        if (httpListenersItem.sslCert !== null && httpListenersItem.sslCert !== undefined) {
          var sslCertElement = js2xml.createElement('SslCert', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(sslCertElement, httpListenersItem.sslCert);
          js2xml.addChildElement(httpListenerElement, sslCertElement);
        }
      }
      js2xml.addChildElement(applicationGatewayConfigurationElement, httpListenersSequenceElement);
    }
    
    if (config.httpLoadBalancingRules !== null && config.httpLoadBalancingRules !== undefined) {
      var httpLoadBalancingRulesSequenceElement = js2xml.createElement('HttpLoadBalancingRules', 'http://schemas.microsoft.com/windowsazure');
      for (var loweredIndex8 = 0; loweredIndex8 < config.httpLoadBalancingRules.length; loweredIndex8 = loweredIndex8 + 1) {
        var httpLoadBalancingRulesItem = config.httpLoadBalancingRules[loweredIndex8];
        var httpLoadBalancingRuleElement = js2xml.createElement('HttpLoadBalancingRule', 'http://schemas.microsoft.com/windowsazure');
        js2xml.addChildElement(httpLoadBalancingRulesSequenceElement, httpLoadBalancingRuleElement);
        
        if (httpLoadBalancingRulesItem.name !== null && httpLoadBalancingRulesItem.name !== undefined) {
          var nameElement7 = js2xml.createElement('Name', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(nameElement7, httpLoadBalancingRulesItem.name);
          js2xml.addChildElement(httpLoadBalancingRuleElement, nameElement7);
        }
        
        if (httpLoadBalancingRulesItem.type !== null && httpLoadBalancingRulesItem.type !== undefined) {
          var typeElement2 = js2xml.createElement('Type', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(typeElement2, httpLoadBalancingRulesItem.type);
          js2xml.addChildElement(httpLoadBalancingRuleElement, typeElement2);
        }
        
        if (httpLoadBalancingRulesItem.backendHttpSettings !== null && httpLoadBalancingRulesItem.backendHttpSettings !== undefined) {
          var backendHttpSettingsElement2 = js2xml.createElement('BackendHttpSettings', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(backendHttpSettingsElement2, httpLoadBalancingRulesItem.backendHttpSettings);
          js2xml.addChildElement(httpLoadBalancingRuleElement, backendHttpSettingsElement2);
        }
        
        if (httpLoadBalancingRulesItem.listener !== null && httpLoadBalancingRulesItem.listener !== undefined) {
          var listenerElement = js2xml.createElement('Listener', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(listenerElement, httpLoadBalancingRulesItem.listener);
          js2xml.addChildElement(httpLoadBalancingRuleElement, listenerElement);
        }
        
        if (httpLoadBalancingRulesItem.backendAddressPool !== null && httpLoadBalancingRulesItem.backendAddressPool !== undefined) {
          var backendAddressPoolElement2 = js2xml.createElement('BackendAddressPool', 'http://schemas.microsoft.com/windowsazure');
          js2xml.setElementValue(backendAddressPoolElement2, httpLoadBalancingRulesItem.backendAddressPool);
          js2xml.addChildElement(httpLoadBalancingRuleElement, backendAddressPoolElement2);
        }
      }
      js2xml.addChildElement(applicationGatewayConfigurationElement, httpLoadBalancingRulesSequenceElement);
    }
    
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Update Application Gateway operation  updates Application
   * Gateway with the specified  parameters.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
   * more information)
   * 
   * @param {string} gatewayName Gateway name
   * 
   * @param {UpdateApplicationGatewayParameters} updateParameters Parameters
   * supplied to the Begin UpdateApplication Gateway request.
   * 
   * @param {string} [updateParameters.description] Gateway Description.
   * 
   * @param {string} [updateParameters.gatewaySize] The size of each gateway
   * instance.
   * 
   * @param {number} [updateParameters.instanceCount] The number of instances
   * to create for this gateway.
   * 
   * @param {IEnumerable} [updateParameters.subnets] Subnets in the vnet to
   * which the gateway belongs.
   * 
   * @param {string} [updateParameters.vnetName] The vnet to which the gateway
   * belongs.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ApplicationGatewayOperations.prototype.beginUpdateApplicationGateway = function(gatewayName, updateParameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayName === null || gatewayName === undefined) {
      return callback(new Error('gatewayName cannot be null.'));
    }
    if (updateParameters === null || updateParameters === undefined) {
      return callback(new Error('updateParameters 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/networking/ApplicationGateways/';
    url2 = url2 + encodeURIComponent(gatewayName);
    var queryParameters = [];
    queryParameters.push('api-version=2016-03-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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var updateApplicationGatewayParametersElement = js2xml.createElement('UpdateApplicationGatewayParameters', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, updateApplicationGatewayParametersElement);
    
    if (updateParameters.description !== null && updateParameters.description !== undefined) {
      var descriptionElement = js2xml.createElement('Description', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(descriptionElement, updateParameters.description);
      js2xml.addChildElement(updateApplicationGatewayParametersElement, descriptionElement);
    }
    
    if (updateParameters.gatewaySize !== null && updateParameters.gatewaySize !== undefined) {
      var gatewaySizeElement = js2xml.createElement('GatewaySize', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(gatewaySizeElement, updateParameters.gatewaySize);
      js2xml.addChildElement(updateApplicationGatewayParametersElement, gatewaySizeElement);
    }
    
    if (updateParameters.instanceCount !== null && updateParameters.instanceCount !== undefined) {
      var instanceCountElement = js2xml.createElement('InstanceCount', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(instanceCountElement, updateParameters.instanceCount.toString());
      js2xml.addChildElement(updateApplicationGatewayParametersElement, instanceCountElement);
    }
    
    if (updateParameters.subnets !== null && updateParameters.subnets !== undefined) {
      var subnetsSequenceElement = js2xml.createElement('Subnets', 'http://schemas.microsoft.com/windowsazure');
      for (var loweredIndex1 = 0; loweredIndex1 < updateParameters.subnets.length; loweredIndex1 = loweredIndex1 + 1) {
        var subnetsItem = updateParameters.subnets[loweredIndex1];
        var subnetsItemElement = js2xml.createElement('Subnet', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(subnetsItemElement, subnetsItem);
        js2xml.addChildElement(subnetsSequenceElement, subnetsItemElement);
      }
      js2xml.addChildElement(updateApplicationGatewayParametersElement, subnetsSequenceElement);
    }
    
    if (updateParameters.vnetName !== null && updateParameters.vnetName !== undefined) {
      var vnetNameElement = js2xml.createElement('VnetName', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(vnetNameElement, updateParameters.vnetName);
      js2xml.addChildElement(updateApplicationGatewayParametersElement, vnetNameElement);
    }
    
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Create Application Gateway operation  creates Application Gateway with
   * the specified parameters.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
   * more information)
   * 
   * @param {CreateApplicationGatewayParameters} parameters Parameters supplied
   * to CreateApplication Gateway request.
   * 
   * @param {string} [parameters.description] Gateway Description.
   * 
   * @param {string} [parameters.gatewaySize] The size of each gateway instance.
   * 
   * @param {number} [parameters.instanceCount] The number of instances to
   * create for this gateway.
   * 
   * @param {string} [parameters.name] Friendly Name of the gateway.
   * 
   * @param {IEnumerable} [parameters.subnets] Subnets in the vnet to which the
   * gateway belongs.
   * 
   * @param {string} [parameters.vnetName] The vnet to which the gateway
   * belongs.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ApplicationGatewayOperations.prototype.create = function(parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.applicationGateways.beginCreateApplicationGateway(parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.applicationGateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Delete Application Gateway operation  deletes Application Gateway with
   * the specified  parameters.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
   * more information)
   * 
   * @param {string} gatewayName The name of the gateway.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ApplicationGatewayOperations.prototype.deleteMethod = function(gatewayName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.applicationGateways.beginDeleteApplicationGateway(gatewayName, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.applicationGateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Delete Application Gateway certificate operation.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
   * more information)
   * 
   * @param {string} gatewayName The name of the gateway.
   * 
   * @param {string} certificateName The name of the certificate.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ApplicationGatewayOperations.prototype.deleteCertificate = function(gatewayName, certificateName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.applicationGateways.beginDeleteApplicationGatewayCertificate(gatewayName, certificateName, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.applicationGateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Execute Application Gateway Operation executes specofoed operation in
   * the Application Gateway.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
   * more information)
   * 
   * @param {string} gatewayName Name of the gateway
   * 
   * @param {ApplicationGatewayOperation} parameters Parameters supplied to
   * Execute Operation request.
   * 
   * @param {string} [parameters.operationType] Operation Type.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ApplicationGatewayOperations.prototype.executeOperation = function(gatewayName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.applicationGateways.beginExecuteOperation(gatewayName, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.applicationGateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Get Application Gateway operation retrieves the application gateway
   * provisioned for the given subscription.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj157196.aspx for
   * more information)
   * 
   * @param {string} gatewayName The name of the gateway.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ApplicationGatewayOperations.prototype.get = function(gatewayName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayName === null || gatewayName === undefined) {
      return callback(new Error('gatewayName 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/networking/ApplicationGateways/';
    url2 = url2 + encodeURIComponent(gatewayName);
    var queryParameters = [];
    queryParameters.push('api-version=2016-03-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['x-ms-version'] = '2016-03-01';
    
    // 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 = { subnets: [], virtualIPs: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var applicationGatewayElement = js2xml.getElement(responseDoc, responseDoc, 'APPLICATIONGATEWAY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (applicationGatewayElement !== null && applicationGatewayElement !== undefined) {
            var descriptionElement = js2xml.getElement(responseDoc, applicationGatewayElement, 'DESCRIPTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (descriptionElement !== null && descriptionElement !== undefined) {
              var descriptionInstance = descriptionElement;
              result.description = descriptionInstance;
            }
            
            var dnsNameElement = js2xml.getElement(responseDoc, applicationGatewayElement, 'DNSNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (dnsNameElement !== null && dnsNameElement !== undefined) {
              var dnsNameInstance = dnsNameElement;
              result.dnsName = dnsNameInstance;
            }
            
            var gatewaySizeElement = js2xml.getElement(responseDoc, applicationGatewayElement, 'GATEWAYSIZE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (gatewaySizeElement !== null && gatewaySizeElement !== undefined) {
              var gatewaySizeInstance = gatewaySizeElement;
              result.gatewaySize = gatewaySizeInstance;
            }
            
            var instanceCountElement = js2xml.getElement(responseDoc, applicationGatewayElement, 'INSTANCECOUNT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (instanceCountElement !== null && instanceCountElement !== undefined && instanceCountElement.length !== 0) {
              var instanceCountInstance = parseInt(instanceCountElement, 10);
              result.instanceCount = instanceCountInstance;
            }
            
            var nameElement = js2xml.getElement(responseDoc, applicationGatewayElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement !== null && nameElement !== undefined) {
              var nameInstance = nameElement;
              result.name = nameInstance;
            }
            
            var stateElement = js2xml.getElement(responseDoc, applicationGatewayElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined) {
              var stateInstance = stateElement;
              result.state = stateInstance;
            }
            
            var subnetsSequenceElement = js2xml.getElement(responseDoc, applicationGatewayElement, 'SUBNETS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (subnetsSequenceElement !== null && subnetsSequenceElement !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, subnetsSequenceElement, 'SUBNET', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
                var subnetsElement = js2xml.getElements(responseDoc, subnetsSequenceElement, 'SUBNET', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
                result.subnets.push(subnetsElement);
              }
            }
            
            var vnetNameElement = js2xml.getElement(responseDoc, applicationGatewayElement, 'VNETNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (vnetNameElement !== null && vnetNameElement !== undefined) {
              var vnetNameInstance = vnetNameElement;
              result.vnetName = vnetNameInstance;
            }
            
            var virtualIPsSequenceElement = js2xml.getElement(responseDoc, applicationGatewayElement, 'VIRTUALIPS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (virtualIPsSequenceElement !== null && virtualIPsSequenceElement !== undefined) {
              for (var loweredIndex2 = 0; loweredIndex2 < js2xml.getElements(responseDoc, virtualIPsSequenceElement, 'VIRTUALIP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex2 = loweredIndex2 + 1) {
                var virtualIPsElement = js2xml.getElements(responseDoc, virtualIPsSequenceElement, 'VIRTUALIP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex2];
                result.virtualIPs.push(virtualIPsElement);
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Get Application Gateway certificate operation retrieves the ssl
   * certificate provisioned for the given gateway.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj157196.aspx for
   * more information)
   * 
   * @param {string} gatewayName The name of the gateway.
   * 
   * @param {string} certificateName The name of the certificate.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ApplicationGatewayOperations.prototype.getCertificate = function(gatewayName, certificateName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayName === null || gatewayName === undefined) {
      return callback(new Error('gatewayName cannot be null.'));
    }
    if (certificateName === null || certificateName === undefined) {
      return callback(new Error('certificateName 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/networking/ApplicationGateways/';
    url2 = url2 + encodeURIComponent(gatewayName);
    url2 = url2 + '/sslcertificates/';
    url2 = url2 + encodeURIComponent(certificateName);
    var queryParameters = [];
    queryParameters.push('api-version=2016-03-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['x-ms-version'] = '2016-03-01';
    
    // 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 options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var applicationGatewayCertificateElement = js2xml.getElement(responseDoc, responseDoc, 'APPLICATIONGATEWAYCERTIFICATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (applicationGatewayCertificateElement !== null && applicationGatewayCertificateElement !== undefined) {
            var nameElement = js2xml.getElement(responseDoc, applicationGatewayCertificateElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement !== null && nameElement !== undefined) {
              var nameInstance = nameElement;
              result.name = nameInstance;
            }
            
            var dataElement = js2xml.getElement(responseDoc, applicationGatewayCertificateElement, 'DATA', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (dataElement !== null && dataElement !== undefined) {
              var dataInstance = dataElement;
              result.data = dataInstance;
            }
            
            var stateElement = js2xml.getElement(responseDoc, applicationGatewayCertificateElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined) {
              var stateInstance = stateElement;
              result.state = stateInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Get Application Gateway Configuration operation retrieves the
   * configuration of the gateway.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj157196.aspx for
   * more information)
   * 
   * @param {string} gatewayName The id  of the gateway.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ApplicationGatewayOperations.prototype.getConfig = function(gatewayName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayName === null || gatewayName === undefined) {
      return callback(new Error('gatewayName 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/networking/ApplicationGateways/';
    url2 = url2 + encodeURIComponent(gatewayName);
    url2 = url2 + '/configuration';
    var queryParameters = [];
    queryParameters.push('api-version=2016-03-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['x-ms-version'] = '2016-03-01';
    
    // 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 = { backendAddressPools: [], backendHttpSettingsList: [], frontendIPConfigurations: [], frontendPorts: [], httpListeners: [], httpLoadBalancingRules: [], probes: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var applicationGatewayConfigurationElement = js2xml.getElement(responseDoc, responseDoc, 'APPLICATIONGATEWAYCONFIGURATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (applicationGatewayConfigurationElement !== null && applicationGatewayConfigurationElement !== undefined) {
            var frontendIPConfigurationsSequenceElement = js2xml.getElement(responseDoc, applicationGatewayConfigurationElement, 'FRONTENDIPCONFIGURATIONS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (frontendIPConfigurationsSequenceElement !== null && frontendIPConfigurationsSequenceElement !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, frontendIPConfigurationsSequenceElement, 'FRONTENDIPCONFIGURATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
                var frontendIPConfigurationsElement = js2xml.getElements(responseDoc, frontendIPConfigurationsSequenceElement, 'FRONTENDIPCONFIGURATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
                var frontendIPConfigurationInstance = {};
                result.frontendIPConfigurations.push(frontendIPConfigurationInstance);
                
                var nameElement = js2xml.getElement(responseDoc, frontendIPConfigurationsElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (nameElement !== null && nameElement !== undefined) {
                  var nameInstance = nameElement;
                  frontendIPConfigurationInstance.name = nameInstance;
                }
                
                var typeElement = js2xml.getElement(responseDoc, frontendIPConfigurationsElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (typeElement !== null && typeElement !== undefined) {
                  var typeInstance = typeElement;
                  frontendIPConfigurationInstance.type = typeInstance;
                }
                
                var staticIPAddressElement = js2xml.getElement(responseDoc, frontendIPConfigurationsElement, 'STATICIPADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (staticIPAddressElement !== null && staticIPAddressElement !== undefined) {
                  var staticIPAddressInstance = staticIPAddressElement;
                  frontendIPConfigurationInstance.staticIPAddress = staticIPAddressInstance;
                }
              }
            }
            
            var frontendPortsSequenceElement = js2xml.getElement(responseDoc, applicationGatewayConfigurationElement, 'FRONTENDPORTS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (frontendPortsSequenceElement !== null && frontendPortsSequenceElement !== undefined) {
              for (var loweredIndex2 = 0; loweredIndex2 < js2xml.getElements(responseDoc, frontendPortsSequenceElement, 'FRONTENDPORT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex2 = loweredIndex2 + 1) {
                var frontendPortsElement = js2xml.getElements(responseDoc, frontendPortsSequenceElement, 'FRONTENDPORT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex2];
                var frontendPortInstance = {};
                result.frontendPorts.push(frontendPortInstance);
                
                var nameElement2 = js2xml.getElement(responseDoc, frontendPortsElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (nameElement2 !== null && nameElement2 !== undefined) {
                  var nameInstance2 = nameElement2;
                  frontendPortInstance.name = nameInstance2;
                }
                
                var portElement = js2xml.getElement(responseDoc, frontendPortsElement, 'PORT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (portElement !== null && portElement !== undefined && portElement.length !== 0) {
                  var portInstance = parseInt(portElement, 10);
                  frontendPortInstance.port = portInstance;
                }
              }
            }
            
            var probesSequenceElement = js2xml.getElement(responseDoc, applicationGatewayConfigurationElement, 'PROBES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (probesSequenceElement !== null && probesSequenceElement !== undefined) {
              for (var loweredIndex3 = 0; loweredIndex3 < js2xml.getElements(responseDoc, probesSequenceElement, 'PROBE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex3 = loweredIndex3 + 1) {
                var probesElement = js2xml.getElements(responseDoc, probesSequenceElement, 'PROBE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex3];
                var probeInstance = {};
                result.probes.push(probeInstance);
                
                var nameElement3 = js2xml.getElement(responseDoc, probesElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (nameElement3 !== null && nameElement3 !== undefined) {
                  var nameInstance3 = nameElement3;
                  probeInstance.name = nameInstance3;
                }
                
                var protocolElement = js2xml.getElement(responseDoc, probesElement, 'PROTOCOL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (protocolElement !== null && protocolElement !== undefined) {
                  var protocolInstance = protocolElement;
                  probeInstance.protocol = protocolInstance;
                }
                
                var hostElement = js2xml.getElement(responseDoc, probesElement, 'HOST', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (hostElement !== null && hostElement !== undefined) {
                  var hostInstance = hostElement;
                  probeInstance.host = hostInstance;
                }
                
                var pathElement = js2xml.getElement(responseDoc, probesElement, 'PATH', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (pathElement !== null && pathElement !== undefined) {
                  var pathInstance = pathElement;
                  probeInstance.path = pathInstance;
                }
                
                var intervalElement = js2xml.getElement(responseDoc, probesElement, 'INTERVAL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (intervalElement !== null && intervalElement !== undefined && intervalElement.length !== 0) {
                  var intervalInstance = parseInt(intervalElement, 10);
                  probeInstance.interval = intervalInstance;
                }
                
                var timeoutElement = js2xml.getElement(responseDoc, probesElement, 'TIMEOUT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (timeoutElement !== null && timeoutElement !== undefined && timeoutElement.length !== 0) {
                  var timeoutInstance = parseInt(timeoutElement, 10);
                  probeInstance.timeout = timeoutInstance;
                }
                
                var unhealthyThresholdElement = js2xml.getElement(responseDoc, probesElement, 'UNHEALTHYTHRESHOLD', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (unhealthyThresholdElement !== null && unhealthyThresholdElement !== undefined && unhealthyThresholdElement.length !== 0) {
                  var unhealthyThresholdInstance = parseInt(unhealthyThresholdElement, 10);
                  probeInstance.unhealthyThreshold = unhealthyThresholdInstance;
                }
              }
            }
            
            var backendAddressPoolsSequenceElement = js2xml.getElement(responseDoc, applicationGatewayConfigurationElement, 'BACKENDADDRESSPOOLS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (backendAddressPoolsSequenceElement !== null && backendAddressPoolsSequenceElement !== undefined) {
              for (var loweredIndex4 = 0; loweredIndex4 < js2xml.getElements(responseDoc, backendAddressPoolsSequenceElement, 'BACKENDADDRESSPOOL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex4 = loweredIndex4 + 1) {
                var backendAddressPoolsElement = js2xml.getElements(responseDoc, backendAddressPoolsSequenceElement, 'BACKENDADDRESSPOOL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex4];
                var backendAddressPoolInstance = { backendServers: [] };
                result.backendAddressPools.push(backendAddressPoolInstance);
                
                var nameElement4 = js2xml.getElement(responseDoc, backendAddressPoolsElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (nameElement4 !== null && nameElement4 !== undefined) {
                  var nameInstance4 = nameElement4;
                  backendAddressPoolInstance.name = nameInstance4;
                }
                
                var iPAddressesSequenceElement = js2xml.getElement(responseDoc, backendAddressPoolsElement, 'IPADDRESSES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (iPAddressesSequenceElement !== null && iPAddressesSequenceElement !== undefined) {
                  for (var loweredIndex5 = 0; loweredIndex5 < js2xml.getElements(responseDoc, iPAddressesSequenceElement, 'IPADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex5 = loweredIndex5 + 1) {
                    var iPAddressesElement = js2xml.getElements(responseDoc, iPAddressesSequenceElement, 'IPADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex5];
                    var iPAddressInstance = {};
                    backendAddressPoolInstance.backendServers.push(iPAddressInstance);
                    
                    var iPAddressInstance2 = iPAddressesElement;
                    iPAddressInstance.iPAddress = iPAddressInstance2;
                  }
                }
              }
            }
            
            var backendHttpSettingsListSequenceElement = js2xml.getElement(responseDoc, applicationGatewayConfigurationElement, 'BACKENDHTTPSETTINGSLIST', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (backendHttpSettingsListSequenceElement !== null && backendHttpSettingsListSequenceElement !== undefined) {
              for (var loweredIndex6 = 0; loweredIndex6 < js2xml.getElements(responseDoc, backendHttpSettingsListSequenceElement, 'BACKENDHTTPSETTINGS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex6 = loweredIndex6 + 1) {
                var backendHttpSettingsListElement = js2xml.getElements(responseDoc, backendHttpSettingsListSequenceElement, 'BACKENDHTTPSETTINGS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex6];
                var backendHttpSettingsInstance = {};
                result.backendHttpSettingsList.push(backendHttpSettingsInstance);
                
                var nameElement5 = js2xml.getElement(responseDoc, backendHttpSettingsListElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (nameElement5 !== null && nameElement5 !== undefined) {
                  var nameInstance5 = nameElement5;
                  backendHttpSettingsInstance.name = nameInstance5;
                }
                
                var portElement2 = js2xml.getElement(responseDoc, backendHttpSettingsListElement, 'PORT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (portElement2 !== null && portElement2 !== undefined && portElement2.length !== 0) {
                  var portInstance2 = parseInt(portElement2, 10);
                  backendHttpSettingsInstance.port = portInstance2;
                }
                
                var protocolElement2 = js2xml.getElement(responseDoc, backendHttpSettingsListElement, 'PROTOCOL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (protocolElement2 !== null && protocolElement2 !== undefined && protocolElement2.length !== 0) {
                  var protocolInstance2 = protocolElement2;
                  backendHttpSettingsInstance.protocol = protocolInstance2;
                }
                
                var cookieBasedAffinityElement = js2xml.getElement(responseDoc, backendHttpSettingsListElement, 'COOKIEBASEDAFFINITY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (cookieBasedAffinityElement !== null && cookieBasedAffinityElement !== undefined) {
                  var cookieBasedAffinityInstance = cookieBasedAffinityElement;
                  backendHttpSettingsInstance.cookieBasedAffinity = cookieBasedAffinityInstance;
                }
                
                var requestTimeoutElement = js2xml.getElement(responseDoc, backendHttpSettingsListElement, 'REQUESTTIMEOUT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (requestTimeoutElement !== null && requestTimeoutElement !== undefined && requestTimeoutElement.length !== 0) {
                  var requestTimeoutInstance = parseInt(requestTimeoutElement, 10);
                  backendHttpSettingsInstance.requestTimeout = requestTimeoutInstance;
                }
                
                var probeElement = js2xml.getElement(responseDoc, backendHttpSettingsListElement, 'PROBE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (probeElement !== null && probeElement !== undefined) {
                  var probeInstance2 = probeElement;
                  backendHttpSettingsInstance.probe = probeInstance2;
                }
              }
            }
            
            var httpListenersSequenceElement = js2xml.getElement(responseDoc, applicationGatewayConfigurationElement, 'HTTPLISTENERS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (httpListenersSequenceElement !== null && httpListenersSequenceElement !== undefined) {
              for (var loweredIndex7 = 0; loweredIndex7 < js2xml.getElements(responseDoc, httpListenersSequenceElement, 'HTTPLISTENER', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex7 = loweredIndex7 + 1) {
                var httpListenersElement = js2xml.getElements(responseDoc, httpListenersSequenceElement, 'HTTPLISTENER', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex7];
                var httpListenerInstance = {};
                result.httpListeners.push(httpListenerInstance);
                
                var nameElement6 = js2xml.getElement(responseDoc, httpListenersElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (nameElement6 !== null && nameElement6 !== undefined) {
                  var nameInstance6 = nameElement6;
                  httpListenerInstance.name = nameInstance6;
                }
                
                var frontendIPElement = js2xml.getElement(responseDoc, httpListenersElement, 'FRONTENDIP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (frontendIPElement !== null && frontendIPElement !== undefined) {
                  var frontendIPInstance = frontendIPElement;
                  httpListenerInstance.frontendIP = frontendIPInstance;
                }
                
                var frontendPortElement = js2xml.getElement(responseDoc, httpListenersElement, 'FRONTENDPORT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (frontendPortElement !== null && frontendPortElement !== undefined) {
                  var frontendPortInstance2 = frontendPortElement;
                  httpListenerInstance.frontendPort = frontendPortInstance2;
                }
                
                var protocolElement3 = js2xml.getElement(responseDoc, httpListenersElement, 'PROTOCOL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (protocolElement3 !== null && protocolElement3 !== undefined && protocolElement3.length !== 0) {
                  var protocolInstance3 = protocolElement3;
                  httpListenerInstance.protocol = protocolInstance3;
                }
                
                var sslCertElement = js2xml.getElement(responseDoc, httpListenersElement, 'SSLCERT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (sslCertElement !== null && sslCertElement !== undefined) {
                  var sslCertInstance = sslCertElement;
                  httpListenerInstance.sslCert = sslCertInstance;
                }
              }
            }
            
            var httpLoadBalancingRulesSequenceElement = js2xml.getElement(responseDoc, applicationGatewayConfigurationElement, 'HTTPLOADBALANCINGRULES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (httpLoadBalancingRulesSequenceElement !== null && httpLoadBalancingRulesSequenceElement !== undefined) {
              for (var loweredIndex8 = 0; loweredIndex8 < js2xml.getElements(responseDoc, httpLoadBalancingRulesSequenceElement, 'HTTPLOADBALANCINGRULE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex8 = loweredIndex8 + 1) {
                var httpLoadBalancingRulesElement = js2xml.getElements(responseDoc, httpLoadBalancingRulesSequenceElement, 'HTTPLOADBALANCINGRULE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex8];
                var httpLoadBalancingRuleInstance = {};
                result.httpLoadBalancingRules.push(httpLoadBalancingRuleInstance);
                
                var nameElement7 = js2xml.getElement(responseDoc, httpLoadBalancingRulesElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (nameElement7 !== null && nameElement7 !== undefined) {
                  var nameInstance7 = nameElement7;
                  httpLoadBalancingRuleInstance.name = nameInstance7;
                }
                
                var typeElement2 = js2xml.getElement(responseDoc, httpLoadBalancingRulesElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (typeElement2 !== null && typeElement2 !== undefined) {
                  var typeInstance2 = typeElement2;
                  httpLoadBalancingRuleInstance.type = typeInstance2;
                }
                
                var backendHttpSettingsElement = js2xml.getElement(responseDoc, httpLoadBalancingRulesElement, 'BACKENDHTTPSETTINGS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (backendHttpSettingsElement !== null && backendHttpSettingsElement !== undefined) {
                  var backendHttpSettingsInstance2 = backendHttpSettingsElement;
                  httpLoadBalancingRuleInstance.backendHttpSettings = backendHttpSettingsInstance2;
                }
                
                var listenerElement = js2xml.getElement(responseDoc, httpLoadBalancingRulesElement, 'LISTENER', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (listenerElement !== null && listenerElement !== undefined) {
                  var listenerInstance = listenerElement;
                  httpLoadBalancingRuleInstance.listener = listenerInstance;
                }
                
                var backendAddressPoolElement = js2xml.getElement(responseDoc, httpLoadBalancingRulesElement, 'BACKENDADDRESSPOOL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (backendAddressPoolElement !== null && backendAddressPoolElement !== undefined) {
                  var backendAddressPoolInstance2 = backendAddressPoolElement;
                  httpLoadBalancingRuleInstance.backendAddressPool = backendAddressPoolInstance2;
                }
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * 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.
   */
  ApplicationGatewayOperations.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.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/networking/operation/';
    url2 = url2 + encodeURIComponent(requestId);
    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['x-ms-version'] = '2016-03-01';
    
    // 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 options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var gatewayOperationElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationElement !== null && gatewayOperationElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.id = idInstance;
            }
            
            var statusElement = js2xml.getElement(responseDoc, gatewayOperationElement, '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, gatewayOperationElement, 'HTTPSTATUSCODE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (httpStatusCodeElement !== null && httpStatusCodeElement !== undefined && httpStatusCodeElement.length !== 0) {
              var httpStatusCodeInstance = httpStatusCodeElement;
              result.httpStatusCode = httpStatusCodeInstance;
            }
            
            var dataElement = js2xml.getElement(responseDoc, gatewayOperationElement, 'DATA', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (dataElement !== null && dataElement !== undefined) {
              var dataInstance = dataElement;
              result.data = dataInstance;
            }
            
            var errorElement = js2xml.getElement(responseDoc, gatewayOperationElement, '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);
    });
  };
  
  /**
   * The List Application Gateway operation retrieves all application gateays
   * for the given subscription.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj157196.aspx for
   * more information)
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ApplicationGatewayOperations.prototype.list = function(callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // 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/networking/ApplicationGateways';
    var queryParameters = [];
    queryParameters.push('api-version=2016-03-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['x-ms-version'] = '2016-03-01';
    
    // 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 = { applicationGateways: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var applicationGatewaysSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'APPLICATIONGATEWAYS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (applicationGatewaysSequenceElement !== null && applicationGatewaysSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, applicationGatewaysSequenceElement, 'APPLICATIONGATEWAY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var applicationGatewaysElement = js2xml.getElements(responseDoc, applicationGatewaysSequenceElement, 'APPLICATIONGATEWAY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var applicationGatewayInstance = { subnets: [], virtualIPs: [] };
              result.applicationGateways.push(applicationGatewayInstance);
              
              var descriptionElement = js2xml.getElement(responseDoc, applicationGatewaysElement, 'DESCRIPTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (descriptionElement !== null && descriptionElement !== undefined) {
                var descriptionInstance = descriptionElement;
                applicationGatewayInstance.description = descriptionInstance;
              }
              
              var dnsNameElement = js2xml.getElement(responseDoc, applicationGatewaysElement, 'DNSNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (dnsNameElement !== null && dnsNameElement !== undefined) {
                var dnsNameInstance = dnsNameElement;
                applicationGatewayInstance.dnsName = dnsNameInstance;
              }
              
              var gatewaySizeElement = js2xml.getElement(responseDoc, applicationGatewaysElement, 'GATEWAYSIZE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (gatewaySizeElement !== null && gatewaySizeElement !== undefined) {
                var gatewaySizeInstance = gatewaySizeElement;
                applicationGatewayInstance.gatewaySize = gatewaySizeInstance;
              }
              
              var instanceCountElement = js2xml.getElement(responseDoc, applicationGatewaysElement, 'INSTANCECOUNT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (instanceCountElement !== null && instanceCountElement !== undefined && instanceCountElement.length !== 0) {
                var instanceCountInstance = parseInt(instanceCountElement, 10);
                applicationGatewayInstance.instanceCount = instanceCountInstance;
              }
              
              var nameElement = js2xml.getElement(responseDoc, applicationGatewaysElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (nameElement !== null && nameElement !== undefined) {
                var nameInstance = nameElement;
                applicationGatewayInstance.name = nameInstance;
              }
              
              var stateElement = js2xml.getElement(responseDoc, applicationGatewaysElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (stateElement !== null && stateElement !== undefined) {
                var stateInstance = stateElement;
                applicationGatewayInstance.state = stateInstance;
              }
              
              var subnetsSequenceElement = js2xml.getElement(responseDoc, applicationGatewaysElement, 'SUBNETS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (subnetsSequenceElement !== null && subnetsSequenceElement !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < js2xml.getElements(responseDoc, subnetsSequenceElement, 'SUBNET', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex2 = loweredIndex2 + 1) {
                  var subnetsElement = js2xml.getElements(responseDoc, subnetsSequenceElement, 'SUBNET', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex2];
                  applicationGatewayInstance.subnets.push(subnetsElement);
                }
              }
              
              var vnetNameElement = js2xml.getElement(responseDoc, applicationGatewaysElement, 'VNETNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (vnetNameElement !== null && vnetNameElement !== undefined) {
                var vnetNameInstance = vnetNameElement;
                applicationGatewayInstance.vnetName = vnetNameInstance;
              }
              
              var virtualIPsSequenceElement = js2xml.getElement(responseDoc, applicationGatewaysElement, 'VIRTUALIPS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (virtualIPsSequenceElement !== null && virtualIPsSequenceElement !== undefined) {
                for (var loweredIndex3 = 0; loweredIndex3 < js2xml.getElements(responseDoc, virtualIPsSequenceElement, 'VIRTUALIP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex3 = loweredIndex3 + 1) {
                  var virtualIPsElement = js2xml.getElements(responseDoc, virtualIPsSequenceElement, 'VIRTUALIP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex3];
                  applicationGatewayInstance.virtualIPs.push(virtualIPsElement);
                }
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The List Application Gateway certificates.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj157196.aspx for
   * more information)
   * 
   * @param {string} gatewayName Gateway name
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ApplicationGatewayOperations.prototype.listCertificate = function(gatewayName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayName === null || gatewayName === undefined) {
      return callback(new Error('gatewayName 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/networking/ApplicationGateways/';
    url2 = url2 + encodeURIComponent(gatewayName);
    url2 = url2 + '/sslcertificates';
    var queryParameters = [];
    queryParameters.push('api-version=2016-03-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['x-ms-version'] = '2016-03-01';
    
    // 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 = { applicationGatewayCertificates: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var applicationGatewayCertificatesSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'APPLICATIONGATEWAYCERTIFICATES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (applicationGatewayCertificatesSequenceElement !== null && applicationGatewayCertificatesSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, applicationGatewayCertificatesSequenceElement, 'APPLICATIONGATEWAYCERTIFICATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var applicationGatewayCertificatesElement = js2xml.getElements(responseDoc, applicationGatewayCertificatesSequenceElement, 'APPLICATIONGATEWAYCERTIFICATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var applicationGatewayCertificateInstance = {};
              result.applicationGatewayCertificates.push(applicationGatewayCertificateInstance);
              
              var nameElement = js2xml.getElement(responseDoc, applicationGatewayCertificatesElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (nameElement !== null && nameElement !== undefined) {
                var nameInstance = nameElement;
                applicationGatewayCertificateInstance.name = nameInstance;
              }
              
              var dataElement = js2xml.getElement(responseDoc, applicationGatewayCertificatesElement, 'DATA', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (dataElement !== null && dataElement !== undefined) {
                var dataInstance = dataElement;
                applicationGatewayCertificateInstance.data = dataInstance;
              }
              
              var stateElement = js2xml.getElement(responseDoc, applicationGatewayCertificatesElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (stateElement !== null && stateElement !== undefined) {
                var stateInstance = stateElement;
                applicationGatewayCertificateInstance.state = stateInstance;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Set Application Gateway Config operation  sets the specified config on
   * the application gateway  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
   * more information)
   * 
   * @param {string} gatewayName Gateway name
   * 
   * @param {ApplicationGatewaySetConfiguration} config Parameters supplied to
   * Set Application Gateway config request.
   * 
   * @param {IEnumerable} [config.frontendIPConfigurations] Frontend IPs of
   * application gateway.
   * 
   * @param {IEnumerable} [config.frontendPorts] Frontend ports on the
   * application gateway.
   * 
   * @param {IEnumerable} [config.probes] Probes of application gateway.
   * 
   * @param {IEnumerable} [config.backendAddressPools] Backend Address Pool
   * 
   * @param {IEnumerable} [config.backendHttpSettingsList] Backend Http Setting
   * 
   * @param {IEnumerable} [config.httpListeners] Backend Http Setting
   * 
   * @param {IEnumerable} [config.httpLoadBalancingRules] Backend Http Setting
   * 
   * @param {HttpStatusCode} [config.statusCode]
   * 
   * @param {string} [config.requestId]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ApplicationGatewayOperations.prototype.setConfig = function(gatewayName, config, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.applicationGateways.beginSetConfig(gatewayName, config, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.applicationGateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Update Application Gateway operation  updates Application Gateway with
   * the specified  parameters.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
   * more information)
   * 
   * @param {string} gatewayName Gateway name
   * 
   * @param {UpdateApplicationGatewayParameters} updateParameters Parameters
   * supplied to UpdateApplication Gateway request.
   * 
   * @param {string} [updateParameters.description] Gateway Description.
   * 
   * @param {string} [updateParameters.gatewaySize] The size of each gateway
   * instance.
   * 
   * @param {number} [updateParameters.instanceCount] The number of instances
   * to create for this gateway.
   * 
   * @param {IEnumerable} [updateParameters.subnets] Subnets in the vnet to
   * which the gateway belongs.
   * 
   * @param {string} [updateParameters.vnetName] The vnet to which the gateway
   * belongs.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ApplicationGatewayOperations.prototype.update = function(gatewayName, updateParameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.applicationGateways.beginUpdateApplicationGateway(gatewayName, updateParameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.applicationGateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  return ApplicationGatewayOperations;
})();

var ClientRootCertificateOperations = ( /** @lends ClientRootCertificateOperations */ function() {
  /**
   * @class
   * The Network Management API includes operations for managing the client
   * root certificates for your subscription.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154113.aspx for
   * more information)
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [NetworkManagementClient] {@link
   * NetworkManagementClient~NetworkManagementClient}.
   * See [clientRootCertificates] {@link
   * NetworkManagementClient~NetworkManagementClient#clientRootCertificates}.
   * Initializes a new instance of the ClientRootCertificateOperations class.
   * @constructor
   * 
   * @param {NetworkManagementClient} client Reference to the service client.
   */
  function ClientRootCertificateOperations(client) {
    this.client = client;
  }
  
  /**
   * The Upload Client Root Certificate operation is used to upload a new
   * client root certificate to Azure.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/dn205129.aspx for
   * more information)
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {ClientRootCertificateCreateParameters} parameters Parameters
   * supplied to the Upload Client Root Certificate Virtual Network Gateway
   * operation.
   * 
   * @param {string} parameters.certificate The new client root certificate to
   * upload, represented as a hex-encoded string.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClientRootCertificateOperations.prototype.create = function(networkName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.certificate === null || parameters.certificate === undefined) {
      return callback(new Error('parameters.certificate 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    url2 = url2 + '/gateway/clientrootcertificates';
    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'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = parameters.certificate;
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Delete Client Root Certificate operation deletes a previously uploaded
   * client root certificate from Azure.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/dn205128.aspx for
   * more information)
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {string} certificateThumbprint The X509 certificate thumbprint.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClientRootCertificateOperations.prototype.deleteMethod = function(networkName, certificateThumbprint, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName cannot be null.'));
    }
    if (certificateThumbprint === null || certificateThumbprint === undefined) {
      return callback(new Error('certificateThumbprint 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    url2 = url2 + '/gateway/clientrootcertificates/';
    url2 = url2 + encodeURIComponent(certificateThumbprint);
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // 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 options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Get Client Root Certificate operation returns the public portion of a
   * previously uploaded client root certificate in a base-64-encoded format
   * from Azure.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/dn205127.aspx for
   * more information)
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {string} certificateThumbprint The X509 certificate thumbprint.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClientRootCertificateOperations.prototype.get = function(networkName, certificateThumbprint, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName cannot be null.'));
    }
    if (certificateThumbprint === null || certificateThumbprint === undefined) {
      return callback(new Error('certificateThumbprint 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    url2 = url2 + '/gateway/clientrootcertificates/';
    url2 = url2 + encodeURIComponent(certificateThumbprint);
    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['x-ms-version'] = '2016-03-01';
    
    // 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 = {};
        result.certificate = responseContent;
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The List Client Root Certificates operation returns a list of all the
   * client root certificates that are associated with the specified virtual
   * network in Azure.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/dn205130.aspx for
   * more information)
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ClientRootCertificateOperations.prototype.list = function(networkName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    url2 = url2 + '/gateway/clientrootcertificates';
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // 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 = { clientRootCertificates: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var clientRootCertificatesSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'CLIENTROOTCERTIFICATES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (clientRootCertificatesSequenceElement !== null && clientRootCertificatesSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, clientRootCertificatesSequenceElement, 'CLIENTROOTCERTIFICATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var clientRootCertificatesElement = js2xml.getElements(responseDoc, clientRootCertificatesSequenceElement, 'CLIENTROOTCERTIFICATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var clientRootCertificateInstance = {};
              result.clientRootCertificates.push(clientRootCertificateInstance);
              
              var expirationTimeElement = js2xml.getElement(responseDoc, clientRootCertificatesElement, 'EXPIRATIONTIME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (expirationTimeElement !== null && expirationTimeElement !== undefined && expirationTimeElement.length !== 0) {
                var expirationTimeInstance = new Date(expirationTimeElement);
                clientRootCertificateInstance.expirationTime = expirationTimeInstance;
              }
              
              var subjectElement = js2xml.getElement(responseDoc, clientRootCertificatesElement, 'SUBJECT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (subjectElement !== null && subjectElement !== undefined) {
                var subjectInstance = subjectElement;
                clientRootCertificateInstance.subject = subjectInstance;
              }
              
              var thumbprintElement = js2xml.getElement(responseDoc, clientRootCertificatesElement, 'THUMBPRINT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (thumbprintElement !== null && thumbprintElement !== undefined) {
                var thumbprintInstance = thumbprintElement;
                clientRootCertificateInstance.thumbprint = thumbprintInstance;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return ClientRootCertificateOperations;
})();

var GatewayOperations = ( /** @lends GatewayOperations */ function() {
  /**
   * @class
   * The Network Management API includes operations for managing the gateways
   * for your subscription.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154113.aspx for
   * more information)
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [NetworkManagementClient] {@link
   * NetworkManagementClient~NetworkManagementClient}.
   * See [gateways] {@link
   * NetworkManagementClient~NetworkManagementClient#gateways}.
   * Initializes a new instance of the GatewayOperations class.
   * @constructor
   * 
   * @param {NetworkManagementClient} client Reference to the service client.
   */
  function GatewayOperations(client) {
    this.client = client;
  }
  
  /**
   * To connect to, disconnect from, or test your connection to a local network
   * site, access the connection resource representing the local network and
   * specify Connect, Disconnect or Test to perform the desired operation.
   * (see http://msdn.microsoft.com/en-us/library/windowsazure/jj154107.aspx
   * for more information)
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {string} localNetworkSiteName The name of the site to connect to.
   * 
   * @param {GatewayConnectDisconnectOrTestParameters} parameters Parameters
   * supplied to the Begin Connect Disconnect Or Testing Gateway operation.
   * 
   * @param {GatewayConnectionUpdateOperation} parameters.operation Specifies
   * the operation to perform on the connection. Can be set to Connect,
   * Disconnect, or Test to connect to a local network, disconnect from a
   * local network, or test the gateway's connection to a local network site.
   * 
   * @param {string} [parameters.iPAddress] Required if operation is set to
   * Test; otherwise not used. Specifies the IP address of the target local
   * network site with which the gateway will test connectivity.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.beginConnectDisconnectOrTesting = function(networkName, localNetworkSiteName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName cannot be null.'));
    }
    if (localNetworkSiteName === null || localNetworkSiteName === undefined) {
      return callback(new Error('localNetworkSiteName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.operation === null || parameters.operation === undefined) {
      return callback(new Error('parameters.operation 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    url2 = url2 + '/gateway/connection/';
    url2 = url2 + encodeURIComponent(localNetworkSiteName);
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var updateConnectionElement = js2xml.createElement('UpdateConnection', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, updateConnectionElement);
    
    var operationElement = js2xml.createElement('Operation', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(operationElement, parameters.operation !== null && parameters.operation !== undefined ? parameters.operation.toString() : 'Connect');
    js2xml.addChildElement(updateConnectionElement, operationElement);
    
    if (parameters.iPAddress !== null && parameters.iPAddress !== undefined) {
      var iPAddressElement = js2xml.createElement('IPAddress', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(iPAddressElement, parameters.iPAddress);
      js2xml.addChildElement(updateConnectionElement, iPAddressElement);
    }
    
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Creating Virtual network Gateway operation creates a new network
   * gateway for the specified virtual network in Azure.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154119.aspx for
   * more information)
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {GatewayCreateParameters} parameters Parameters supplied to the
   * Begin Creating Virtual Network Gateway operation.
   * 
   * @param {string} [parameters.gatewaySKU] The SKU of this virtual network
   * gateway. Valid values are Default and HighPerformance.
   * 
   * @param {string} [parameters.gatewayType] The routing type for this virtual
   * network gateway.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.beginCreating = function(networkName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    url2 = url2 + '/gateway';
    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'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var createGatewayParametersElement = js2xml.createElement('CreateGatewayParameters', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, createGatewayParametersElement);
    
    if (parameters.gatewaySKU !== null && parameters.gatewaySKU !== undefined) {
      var gatewaySizeElement = js2xml.createElement('GatewaySize', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(gatewaySizeElement, parameters.gatewaySKU);
      js2xml.addChildElement(createGatewayParametersElement, gatewaySizeElement);
    }
    
    if (parameters.gatewayType !== null && parameters.gatewayType !== undefined) {
      var gatewayTypeElement = js2xml.createElement('gatewayType', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(gatewayTypeElement, parameters.gatewayType);
      js2xml.addChildElement(createGatewayParametersElement, gatewayTypeElement);
    }
    
    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 !== 201) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 201) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Creating Virtual network Gateway connection operation creates a
   * new network gateway connection.
   * 
   * @param {GatewayConnectionCreateParameters} parameters Parameters supplied
   * to the Begin Creating Gateway Connection operation.
   * 
   * @param {string} [parameters.connectedEntityId] The Service Key / Local
   * network gateway Id / Vnet Network Gateway Id.
   * 
   * @param {string} [parameters.gatewayConnectionName] The name of the virtual
   * network gateway connection.
   * 
   * @param {string} [parameters.gatewayConnectionType] The connection type of
   * gateway: Ipsec/Dedicated/VpnClient/Vnet2Vnet.
   * 
   * @param {Guid} [parameters.virtualNetworkGatewayId] The Virtual network
   * gateway Id.
   * 
   * @param {number} [parameters.routingWeight] The Routing Weight.
   * 
   * @param {string} [parameters.sharedKey] The Ipsec share key.
   * 
   * @param {boolean} [parameters.enableBgp] Whether to establish a BGP session
   * over this connection
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.beginCreatingGatewayConnection = function(parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/gatewayconnections';
    var queryParameters = [];
    queryParameters.push('api-version=2016-03-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
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var createGatewayConnectionParametersElement = js2xml.createElement('CreateGatewayConnectionParameters', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, createGatewayConnectionParametersElement);
    
    if (parameters.connectedEntityId !== null && parameters.connectedEntityId !== undefined) {
      var connectedEntityIdElement = js2xml.createElement('ConnectedEntityId', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(connectedEntityIdElement, parameters.connectedEntityId);
      js2xml.addChildElement(createGatewayConnectionParametersElement, connectedEntityIdElement);
    }
    
    if (parameters.gatewayConnectionName !== null && parameters.gatewayConnectionName !== undefined) {
      var gatewayConnectionNameElement = js2xml.createElement('GatewayConnectionName', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(gatewayConnectionNameElement, parameters.gatewayConnectionName);
      js2xml.addChildElement(createGatewayConnectionParametersElement, gatewayConnectionNameElement);
    }
    
    if (parameters.gatewayConnectionType !== null && parameters.gatewayConnectionType !== undefined) {
      var gatewayConnectionTypeElement = js2xml.createElement('GatewayConnectionType', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(gatewayConnectionTypeElement, parameters.gatewayConnectionType);
      js2xml.addChildElement(createGatewayConnectionParametersElement, gatewayConnectionTypeElement);
    }
    
    if (parameters.virtualNetworkGatewayId !== null && parameters.virtualNetworkGatewayId !== undefined) {
      var virtualNetworkGatewayIdElement = js2xml.createElement('VirtualNetworkGatewayId', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(virtualNetworkGatewayIdElement, parameters.virtualNetworkGatewayId);
      js2xml.addChildElement(createGatewayConnectionParametersElement, virtualNetworkGatewayIdElement);
    }
    
    if (parameters.routingWeight !== null && parameters.routingWeight !== undefined) {
      var routingWeightElement = js2xml.createElement('RoutingWeight', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(routingWeightElement, parameters.routingWeight.toString());
      js2xml.addChildElement(createGatewayConnectionParametersElement, routingWeightElement);
    }
    
    if (parameters.sharedKey !== null && parameters.sharedKey !== undefined) {
      var sharedKeyElement = js2xml.createElement('SharedKey', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(sharedKeyElement, parameters.sharedKey);
      js2xml.addChildElement(createGatewayConnectionParametersElement, sharedKeyElement);
    }
    
    if (parameters.enableBgp !== null && parameters.enableBgp !== undefined) {
      var enableBgpElement = js2xml.createElement('EnableBgp', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(enableBgpElement, parameters.enableBgp.toString());
      js2xml.addChildElement(createGatewayConnectionParametersElement, enableBgpElement);
    }
    
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Creating Virtual network Gateway operation creates a new network
   * gateway.
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {VirtualNetworkGatewayCreateParameters} parameters Parameters
   * supplied to the Begin Creating Virtual Network Gateway operation.
   * 
   * @param {string} [parameters.gatewayName] The name of the virtual network
   * gateway.
   * 
   * @param {string} [parameters.gatewaySKU] The SKU of this virtual network
   * gateway. Valid values are Default, HighPerformance and Standard.
   * 
   * @param {string} [parameters.gatewayType] The routing type for this virtual
   * network gateway.
   * 
   * @param {string} [parameters.location] The location of the virtual network
   * gateway.
   * 
   * @param {string} [parameters.vnetId] Virtual network Id.
   * 
   * @param {BgpSettings} [parameters.bgpSettings] BGP settings for this
   * virtual network gateway
   * 
   * @param {number} [parameters.bgpSettings.asn] Autonomous System Number
   * 
   * @param {string} [parameters.bgpSettings.bgpPeeringAddress] IP address/BGP
   * identifier
   * 
   * @param {number} [parameters.bgpSettings.peerWeight] Weight for routes
   * learned from this peer
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.beginCreatingVirtualNetworkGateway = function(networkName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    url2 = url2 + '/virtualnetworkgateways';
    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'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var createVirtualNetworkGatewayParametersElement = js2xml.createElement('CreateVirtualNetworkGatewayParameters', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, createVirtualNetworkGatewayParametersElement);
    
    if (parameters.gatewayName !== null && parameters.gatewayName !== undefined) {
      var gatewayNameElement = js2xml.createElement('GatewayName', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(gatewayNameElement, parameters.gatewayName);
      js2xml.addChildElement(createVirtualNetworkGatewayParametersElement, gatewayNameElement);
    }
    
    if (parameters.gatewaySKU !== null && parameters.gatewaySKU !== undefined) {
      var gatewaySizeElement = js2xml.createElement('GatewaySize', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(gatewaySizeElement, parameters.gatewaySKU);
      js2xml.addChildElement(createVirtualNetworkGatewayParametersElement, gatewaySizeElement);
    }
    
    if (parameters.gatewayType !== null && parameters.gatewayType !== undefined) {
      var gatewayTypeElement = js2xml.createElement('GatewayType', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(gatewayTypeElement, parameters.gatewayType);
      js2xml.addChildElement(createVirtualNetworkGatewayParametersElement, gatewayTypeElement);
    }
    
    if (parameters.location !== null && parameters.location !== undefined) {
      var locationElement = js2xml.createElement('Location', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(locationElement, parameters.location);
      js2xml.addChildElement(createVirtualNetworkGatewayParametersElement, locationElement);
    }
    
    if (parameters.vnetId !== null && parameters.vnetId !== undefined) {
      var vnetIdElement = js2xml.createElement('VnetId', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(vnetIdElement, parameters.vnetId);
      js2xml.addChildElement(createVirtualNetworkGatewayParametersElement, vnetIdElement);
    }
    
    if (parameters.bgpSettings !== null && parameters.bgpSettings !== undefined) {
      var bgpSettingsElement = js2xml.createElement('BgpSettings', 'http://schemas.microsoft.com/windowsazure');
      js2xml.addChildElement(createVirtualNetworkGatewayParametersElement, bgpSettingsElement);
      
      if (parameters.bgpSettings.asn !== null && parameters.bgpSettings.asn !== undefined) {
        var asnElement = js2xml.createElement('Asn', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(asnElement, parameters.bgpSettings.asn.toString());
        js2xml.addChildElement(bgpSettingsElement, asnElement);
      }
      
      if (parameters.bgpSettings.bgpPeeringAddress !== null && parameters.bgpSettings.bgpPeeringAddress !== undefined) {
        var bgpPeeringAddressElement = js2xml.createElement('BgpPeeringAddress', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(bgpPeeringAddressElement, parameters.bgpSettings.bgpPeeringAddress);
        js2xml.addChildElement(bgpSettingsElement, bgpPeeringAddressElement);
      }
      
      if (parameters.bgpSettings.peerWeight !== null && parameters.bgpSettings.peerWeight !== undefined) {
        var peerWeightElement = js2xml.createElement('PeerWeight', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(peerWeightElement, parameters.bgpSettings.peerWeight.toString());
        js2xml.addChildElement(bgpSettingsElement, peerWeightElement);
      }
    }
    
    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 !== 201) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 201) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Deleting Virtual Network Gateway operation deletes a network
   * gateway for the specified virtual network in Azure.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154129.aspx for
   * more information)
   * 
   * @param {string} networkName The name of the virtual network.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.beginDeleting = function(networkName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    url2 = url2 + '/gateway';
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // 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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Deleting Virtual Network Gateway connection deletes a network
   * gateway connection.
   * 
   * @param {string} gatewayId The virtual network gateway Id.
   * 
   * @param {string} connectedentityId The connected entity Id.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.beginDeletingGatewayConnection = function(gatewayId, connectedentityId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayId === null || gatewayId === undefined) {
      return callback(new Error('gatewayId cannot be null.'));
    }
    if (connectedentityId === null || connectedentityId === undefined) {
      return callback(new Error('connectedentityId 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/networking/gatewayconnections/virtualnetworkgateway/';
    url2 = url2 + encodeURIComponent(gatewayId);
    url2 = url2 + '/connectedentity/';
    url2 = url2 + encodeURIComponent(connectedentityId);
    var queryParameters = [];
    queryParameters.push('api-version=2016-03-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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // 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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Deleting Virtual Network Gateway operation deletes a network
   * gateway
   * 
   * @param {string} gatewayId The virtual network gateway id.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.beginDeletingVirtualNetworkGateway = function(gatewayId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayId === null || gatewayId === undefined) {
      return callback(new Error('gatewayId 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/networking/virtualnetworkgateways/';
    url2 = url2 + encodeURIComponent(gatewayId);
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // 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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Failover Virtual Network Gateway operation causes a network
   * gateway failover for the specified virtual network in Azure.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154118.aspx for
   * more information)
   * 
   * @param {string} networkName The name of the virtual network in Azure.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.beginFailover = function(networkName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    url2 = url2 + '/gateway';
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = '<?xml version="1.0" encoding="utf-8"?><UpdateGateway xmlns="http://schemas.microsoft.com/windowsazure"><UpdateGatewayOperation>Failover</UpdateGatewayOperation></UpdateGateway>';
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Generate VPN Client Package operation creates a VPN client package for
   * the specified virtual network and gateway in Azure.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/dn205126.aspx for
   * more information)
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {GatewayGenerateVpnClientPackageParameters} parameters Parameters
   * supplied to the Generate VPN Client Package operation.
   * 
   * @param {GatewayProcessorArchitecture} parameters.processorArchitecture The
   * client processor architecture.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.beginGenerateVpnClientPackage = function(networkName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.processorArchitecture === null || parameters.processorArchitecture === undefined) {
      return callback(new Error('parameters.processorArchitecture 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    url2 = url2 + '/gateway/vpnclientpackage';
    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'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var vpnClientParametersElement = js2xml.createElement('VpnClientParameters', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, vpnClientParametersElement);
    
    var processorArchitectureElement = js2xml.createElement('ProcessorArchitecture', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(processorArchitectureElement, parameters.processorArchitecture !== null && parameters.processorArchitecture !== undefined ? parameters.processorArchitecture.toString() : 'Amd64');
    js2xml.addChildElement(vpnClientParametersElement, processorArchitectureElement);
    
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Remove Virtual Network Gateway Shared Key operation removes the
   * default sites on the virtual network gateway for the specified virtual
   * network.
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.beginRemoveDefaultSites = function(networkName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    url2 = url2 + '/gateway/defaultsites';
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // 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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Reset Virtual network Gateway operation resets an existing
   * gateway.
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {ResetGatewayParameters} parameters Parameters supplied to the
   * Begin Reset Virtual Network Gateway operation.
   * 
   * @param {UpdateGatewayOperation} [parameters.operation]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.beginReset = function(networkName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    url2 = url2 + '/gateway';
    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 = 'PATCH';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var updateGatewayParametersElement = js2xml.createElement('UpdateGatewayParameters', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, updateGatewayParametersElement);
    
    if (parameters.operation !== null && parameters.operation !== undefined) {
      var operationElement = js2xml.createElement('Operation', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(operationElement, 'Reset');
      js2xml.addChildElement(updateGatewayParametersElement, operationElement);
    }
    
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Reset Virtual Network Gateway Shared Key operation resets the
   * shared key on the virtual network gateway for the specified virtual
   * network connection to the specified local network in Azure.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
   * more information)
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {string} localNetworkName The name of the local network.
   * 
   * @param {GatewayResetSharedKeyParameters} parameters Parameters supplied to
   * the Begin Virtual Network Gateway Reset Shared Key request.
   * 
   * @param {number} [parameters.keyLength] The number of bytes in the shared
   * key. Minimum is 1 and maximum is 128
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.beginResetSharedKey = function(networkName, localNetworkName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName cannot be null.'));
    }
    if (localNetworkName === null || localNetworkName === undefined) {
      return callback(new Error('localNetworkName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    url2 = url2 + '/gateway/connection/';
    url2 = url2 + encodeURIComponent(localNetworkName);
    url2 = url2 + '/sharedkey';
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var resetSharedKeyElement = js2xml.createElement('ResetSharedKey', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, resetSharedKeyElement);
    
    if (parameters.keyLength !== null && parameters.keyLength !== undefined) {
      var keyLengthElement = js2xml.createElement('KeyLength', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(keyLengthElement, parameters.keyLength.toString());
      js2xml.addChildElement(resetSharedKeyElement, keyLengthElement);
    }
    
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Reset Virtual Network Gateway Shared Key V2 operation resets the
   * shared key used between the gateway and customer vpn.
   * 
   * @param {string} gatewayId The virtual network for this gateway Id.
   * 
   * @param {string} connectedentityId The connected entity Id.
   * 
   * @param {GatewayResetSharedKeyParameters} parameters Parameters supplied to
   * the Begin Virtual Network Gateway Reset Shared Key V2 request.
   * 
   * @param {number} [parameters.keyLength] The number of bytes in the shared
   * key. Minimum is 1 and maximum is 128
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.beginResetSharedKeyV2 = function(gatewayId, connectedentityId, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayId === null || gatewayId === undefined) {
      return callback(new Error('gatewayId cannot be null.'));
    }
    if (connectedentityId === null || connectedentityId === undefined) {
      return callback(new Error('connectedentityId cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/virtualnetworkgateways/';
    url2 = url2 + encodeURIComponent(gatewayId);
    url2 = url2 + '/connectedentity/';
    url2 = url2 + encodeURIComponent(connectedentityId);
    url2 = url2 + '/sharedkey';
    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 = 'PATCH';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var resetSharedKeyElement = js2xml.createElement('ResetSharedKey', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, resetSharedKeyElement);
    
    if (parameters.keyLength !== null && parameters.keyLength !== undefined) {
      var keyLengthElement = js2xml.createElement('KeyLength', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(keyLengthElement, parameters.keyLength.toString());
      js2xml.addChildElement(resetSharedKeyElement, keyLengthElement);
    }
    
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Reset Virtual network Gateway operation resets an existing
   * gateway.
   * 
   * @param {string} gatewayId The virtual network for this gateway.
   * 
   * @param {ResetGatewayParameters} parameters Parameters supplied to the
   * Begin Reset Virtual Network Gateway operation.
   * 
   * @param {UpdateGatewayOperation} [parameters.operation]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.beginResetVirtualNetworkGateway = function(gatewayId, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayId === null || gatewayId === undefined) {
      return callback(new Error('gatewayId cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/virtualnetworkgateways/';
    url2 = url2 + encodeURIComponent(gatewayId);
    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 = 'PATCH';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var updateGatewayParametersElement = js2xml.createElement('UpdateGatewayParameters', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, updateGatewayParametersElement);
    
    if (parameters.operation !== null && parameters.operation !== undefined) {
      var operationElement = js2xml.createElement('Operation', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(operationElement, 'Reset');
      js2xml.addChildElement(updateGatewayParametersElement, operationElement);
    }
    
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Resize Virtual network Gateway operation resizes an existing
   * gateway to a different GatewaySKU.
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {ResizeGatewayParameters} parameters Parameters supplied to the
   * Begin Resize Virtual Network Gateway operation.
   * 
   * @param {string} [parameters.gatewaySKU]
   * 
   * @param {UpdateGatewayOperation} [parameters.operation]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.beginResize = function(networkName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    url2 = url2 + '/gateway';
    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 = 'PATCH';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var updateGatewayParametersElement = js2xml.createElement('UpdateGatewayParameters', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, updateGatewayParametersElement);
    
    if (parameters.gatewaySKU !== null && parameters.gatewaySKU !== undefined) {
      var gatewaySizeElement = js2xml.createElement('GatewaySize', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(gatewaySizeElement, parameters.gatewaySKU);
      js2xml.addChildElement(updateGatewayParametersElement, gatewaySizeElement);
    }
    
    if (parameters.operation !== null && parameters.operation !== undefined) {
      var operationElement = js2xml.createElement('Operation', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(operationElement, 'Resize');
      js2xml.addChildElement(updateGatewayParametersElement, operationElement);
    }
    
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Resize Virtual network Gateway operation resizes an existing
   * gateway to a different GatewaySKU.
   * 
   * @param {string} gatewayId The virtual network for this gateway id.
   * 
   * @param {ResizeGatewayParameters} parameters Parameters supplied to the
   * Begin Resize Virtual Network Gateway operation.
   * 
   * @param {string} [parameters.gatewaySKU]
   * 
   * @param {UpdateGatewayOperation} [parameters.operation]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.beginResizeVirtualNetworkGateway = function(gatewayId, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayId === null || gatewayId === undefined) {
      return callback(new Error('gatewayId cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/virtualnetworkgateways/';
    url2 = url2 + encodeURIComponent(gatewayId);
    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 = 'PATCH';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var updateGatewayParametersElement = js2xml.createElement('UpdateGatewayParameters', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, updateGatewayParametersElement);
    
    if (parameters.gatewaySKU !== null && parameters.gatewaySKU !== undefined) {
      var gatewaySizeElement = js2xml.createElement('GatewaySize', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(gatewaySizeElement, parameters.gatewaySKU);
      js2xml.addChildElement(updateGatewayParametersElement, gatewaySizeElement);
    }
    
    if (parameters.operation !== null && parameters.operation !== undefined) {
      var operationElement = js2xml.createElement('Operation', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(operationElement, 'Resize');
      js2xml.addChildElement(updateGatewayParametersElement, operationElement);
    }
    
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Set Virtual Network Gateway Shared Key operation sets the
   * default sites on the virtual network gateway for the specified virtual
   * network.
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {GatewaySetDefaultSiteListParameters} parameters Parameters
   * supplied to the Begin Virtual Network Gateway Set Default Sites request.
   * 
   * @param {string} [parameters.defaultSite] The default local network site.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.beginSetDefaultSites = function(networkName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    url2 = url2 + '/gateway/defaultsites';
    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'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var defaultSiteListElement = js2xml.createElement('DefaultSiteList', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, defaultSiteListElement);
    
    if (parameters.defaultSite !== null && parameters.defaultSite !== undefined) {
      var stringElement = js2xml.createElement('string', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(stringElement, parameters.defaultSite);
      js2xml.addChildElement(defaultSiteListElement, stringElement);
    }
    
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Set Virtual Network Gateway IPsec Parameters operation sets the
   * IPsec parameters on the virtual network gateway for the specified
   * connection to the specified local network in Azure.
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {string} localNetworkName The name of the local network.
   * 
   * @param {GatewaySetIPsecParametersParameters} parameters Parameters
   * supplied to the Begin Virtual Network Gateway Set IPsec Parameters
   * request.
   * 
   * @param {IPsecParameters} [parameters.parameters]
   * 
   * @param {string} [parameters.parameters.encryptionType] The encryption type
   * that will be used on the connection.
   * 
   * @param {string} [parameters.parameters.pfsGroup] The PfsGroup type that
   * will be used on the connection.
   * 
   * @param {number} [parameters.parameters.sADataSizeKilobytes]
   * 
   * @param {number} [parameters.parameters.sALifeTimeSeconds]
   * 
   * @param {string} [parameters.parameters.hashAlgorithm]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.beginSetIPsecParameters = function(networkName, localNetworkName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName cannot be null.'));
    }
    if (localNetworkName === null || localNetworkName === undefined) {
      return callback(new Error('localNetworkName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    url2 = url2 + '/gateway/connection/';
    url2 = url2 + encodeURIComponent(localNetworkName);
    url2 = url2 + '/ipsecparameters';
    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 = 'PATCH';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    if (parameters.parameters !== null && parameters.parameters !== undefined) {
      var iPsecParametersElement = js2xml.createElement('IPsecParameters', 'http://schemas.microsoft.com/windowsazure');
      js2xml.addChildElement(requestDoc, iPsecParametersElement);
      
      if (parameters.parameters.encryptionType !== null && parameters.parameters.encryptionType !== undefined) {
        var encryptionTypeElement = js2xml.createElement('EncryptionType', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(encryptionTypeElement, parameters.parameters.encryptionType);
        js2xml.addChildElement(iPsecParametersElement, encryptionTypeElement);
      }
      
      if (parameters.parameters.pfsGroup !== null && parameters.parameters.pfsGroup !== undefined) {
        var pfsGroupElement = js2xml.createElement('PfsGroup', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(pfsGroupElement, parameters.parameters.pfsGroup);
        js2xml.addChildElement(iPsecParametersElement, pfsGroupElement);
      }
      
      if (parameters.parameters.sADataSizeKilobytes !== null && parameters.parameters.sADataSizeKilobytes !== undefined) {
        var sADataSizeKilobytesElement = js2xml.createElement('SADataSizeKilobytes', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(sADataSizeKilobytesElement, parameters.parameters.sADataSizeKilobytes.toString());
        js2xml.addChildElement(iPsecParametersElement, sADataSizeKilobytesElement);
      }
      
      if (parameters.parameters.sALifeTimeSeconds !== null && parameters.parameters.sALifeTimeSeconds !== undefined) {
        var sALifeTimeSecondsElement = js2xml.createElement('SALifeTimeSeconds', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(sALifeTimeSecondsElement, parameters.parameters.sALifeTimeSeconds.toString());
        js2xml.addChildElement(iPsecParametersElement, sALifeTimeSecondsElement);
      }
      
      if (parameters.parameters.hashAlgorithm !== null && parameters.parameters.hashAlgorithm !== undefined) {
        var hashAlgorithmElement = js2xml.createElement('HashAlgorithm', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(hashAlgorithmElement, parameters.parameters.hashAlgorithm);
        js2xml.addChildElement(iPsecParametersElement, hashAlgorithmElement);
      }
    }
    
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Set Virtual Network Gateway IPsec Parameters V2 operation sets
   * the IPsec parameters on the virtual network gateway connection.
   * 
   * @param {string} gatewayId The virtual network for this gateway Id.
   * 
   * @param {string} connectedentityId The connected entity Id.
   * 
   * @param {GatewaySetIPsecParametersParameters} parameters Parameters
   * supplied to the Begin Virtual Network Gateway Set IPsec Parameters V2
   * request.
   * 
   * @param {IPsecParameters} [parameters.parameters]
   * 
   * @param {string} [parameters.parameters.encryptionType] The encryption type
   * that will be used on the connection.
   * 
   * @param {string} [parameters.parameters.pfsGroup] The PfsGroup type that
   * will be used on the connection.
   * 
   * @param {number} [parameters.parameters.sADataSizeKilobytes]
   * 
   * @param {number} [parameters.parameters.sALifeTimeSeconds]
   * 
   * @param {string} [parameters.parameters.hashAlgorithm]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.beginSetIPsecParametersV2 = function(gatewayId, connectedentityId, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayId === null || gatewayId === undefined) {
      return callback(new Error('gatewayId cannot be null.'));
    }
    if (connectedentityId === null || connectedentityId === undefined) {
      return callback(new Error('connectedentityId cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/virtualnetworkgateways/';
    url2 = url2 + encodeURIComponent(gatewayId);
    url2 = url2 + '/connectedentity/';
    url2 = url2 + encodeURIComponent(connectedentityId);
    url2 = url2 + '/ipsecparameters';
    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 = 'PATCH';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    if (parameters.parameters !== null && parameters.parameters !== undefined) {
      var iPsecParametersElement = js2xml.createElement('IPsecParameters', 'http://schemas.microsoft.com/windowsazure');
      js2xml.addChildElement(requestDoc, iPsecParametersElement);
      
      if (parameters.parameters.encryptionType !== null && parameters.parameters.encryptionType !== undefined) {
        var encryptionTypeElement = js2xml.createElement('EncryptionType', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(encryptionTypeElement, parameters.parameters.encryptionType);
        js2xml.addChildElement(iPsecParametersElement, encryptionTypeElement);
      }
      
      if (parameters.parameters.pfsGroup !== null && parameters.parameters.pfsGroup !== undefined) {
        var pfsGroupElement = js2xml.createElement('PfsGroup', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(pfsGroupElement, parameters.parameters.pfsGroup);
        js2xml.addChildElement(iPsecParametersElement, pfsGroupElement);
      }
      
      if (parameters.parameters.sADataSizeKilobytes !== null && parameters.parameters.sADataSizeKilobytes !== undefined) {
        var sADataSizeKilobytesElement = js2xml.createElement('SADataSizeKilobytes', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(sADataSizeKilobytesElement, parameters.parameters.sADataSizeKilobytes.toString());
        js2xml.addChildElement(iPsecParametersElement, sADataSizeKilobytesElement);
      }
      
      if (parameters.parameters.sALifeTimeSeconds !== null && parameters.parameters.sALifeTimeSeconds !== undefined) {
        var sALifeTimeSecondsElement = js2xml.createElement('SALifeTimeSeconds', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(sALifeTimeSecondsElement, parameters.parameters.sALifeTimeSeconds.toString());
        js2xml.addChildElement(iPsecParametersElement, sALifeTimeSecondsElement);
      }
      
      if (parameters.parameters.hashAlgorithm !== null && parameters.parameters.hashAlgorithm !== undefined) {
        var hashAlgorithmElement = js2xml.createElement('HashAlgorithm', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(hashAlgorithmElement, parameters.parameters.hashAlgorithm);
        js2xml.addChildElement(iPsecParametersElement, hashAlgorithmElement);
      }
    }
    
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Set Virtual Network Gateway Shared Key operation sets the shared
   * key on the virtual network gateway for the specified virtual network
   * connection to the specified local network in Azure.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
   * more information)
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {string} localNetworkName The name of the local network.
   * 
   * @param {GatewaySetSharedKeyParameters} parameters Parameters supplied to
   * the Begin Virtual Network Gateway Set Shared Key request.
   * 
   * @param {string} [parameters.value] Contains the shared key used by the
   * gateway to authenticate connections to sites on a virtual network.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.beginSetSharedKey = function(networkName, localNetworkName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName cannot be null.'));
    }
    if (localNetworkName === null || localNetworkName === undefined) {
      return callback(new Error('localNetworkName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    url2 = url2 + '/gateway/connection/';
    url2 = url2 + encodeURIComponent(localNetworkName);
    url2 = url2 + '/sharedkey';
    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'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var sharedKeyElement = js2xml.createElement('SharedKey', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, sharedKeyElement);
    
    if (parameters.value !== null && parameters.value !== undefined) {
      var valueElement = js2xml.createElement('Value', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(valueElement, parameters.value);
      js2xml.addChildElement(sharedKeyElement, valueElement);
    }
    
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Set Virtual Network Gateway Shared Key V2 operation sets the
   * shared key used between the gateway and customer vpn for the specified
   * site.
   * 
   * @param {string} gatewayId The virtual network for this gateway Id.
   * 
   * @param {string} connectedentityId The connected entity Id.
   * 
   * @param {GatewaySetSharedKeyParameters} parameters Parameters supplied to
   * the Begin Virtual Network Gateway Set Shared Key V2 request.
   * 
   * @param {string} [parameters.value] Contains the shared key used by the
   * gateway to authenticate connections to sites on a virtual network.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.beginSetSharedKeyV2 = function(gatewayId, connectedentityId, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayId === null || gatewayId === undefined) {
      return callback(new Error('gatewayId cannot be null.'));
    }
    if (connectedentityId === null || connectedentityId === undefined) {
      return callback(new Error('connectedentityId cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/virtualnetworkgateways/';
    url2 = url2 + encodeURIComponent(gatewayId);
    url2 = url2 + '/connectedentity/';
    url2 = url2 + encodeURIComponent(connectedentityId);
    url2 = url2 + '/sharedkey';
    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'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var sharedKeyElement = js2xml.createElement('SharedKey', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, sharedKeyElement);
    
    if (parameters.value !== null && parameters.value !== undefined) {
      var valueElement = js2xml.createElement('Value', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(valueElement, parameters.value);
      js2xml.addChildElement(sharedKeyElement, valueElement);
    }
    
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Start Diagnostics operation begins an asynchronous operation to
   * starta diagnostics session for the specified virtual network gateway in
   * Azure.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154119.aspx for
   * more information)
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {StartGatewayPublicDiagnosticsParameters} parameters Parameters
   * supplied to the Begin Start Diagnostics operation.
   * 
   * @param {string} [parameters.captureDurationInSeconds] The duration of the
   * capture in seconds (between 1 and 300)
   * 
   * @param {string} [parameters.containerName] The container name provided by
   * customer (optional)
   * 
   * @param {string} [parameters.customerStorageKey] The customer's storage
   * account key
   * 
   * @param {string} [parameters.customerStorageName] The customer's storage
   * account name
   * 
   * @param {UpdateGatewayPublicDiagnosticsOperation} [parameters.operation]
   * The update gateway diagnostics operation to perform on the gateway tenant
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.beginStartDiagnostics = function(networkName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    url2 = url2 + '/gateway/publicdiagnostics';
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var updateGatewayPublicDiagnosticsElement = js2xml.createElement('UpdateGatewayPublicDiagnostics', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, updateGatewayPublicDiagnosticsElement);
    
    if (parameters.captureDurationInSeconds !== null && parameters.captureDurationInSeconds !== undefined) {
      var captureDurationInSecondsElement = js2xml.createElement('CaptureDurationInSeconds', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(captureDurationInSecondsElement, parameters.captureDurationInSeconds);
      js2xml.addChildElement(updateGatewayPublicDiagnosticsElement, captureDurationInSecondsElement);
    }
    
    if (parameters.containerName !== null && parameters.containerName !== undefined) {
      var containerNameElement = js2xml.createElement('ContainerName', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(containerNameElement, parameters.containerName);
      js2xml.addChildElement(updateGatewayPublicDiagnosticsElement, containerNameElement);
    }
    
    if (parameters.customerStorageKey !== null && parameters.customerStorageKey !== undefined) {
      var customerStorageKeyElement = js2xml.createElement('CustomerStorageKey', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(customerStorageKeyElement, parameters.customerStorageKey);
      js2xml.addChildElement(updateGatewayPublicDiagnosticsElement, customerStorageKeyElement);
    }
    
    if (parameters.customerStorageName !== null && parameters.customerStorageName !== undefined) {
      var customerStorageNameElement = js2xml.createElement('CustomerStorageName', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(customerStorageNameElement, parameters.customerStorageName);
      js2xml.addChildElement(updateGatewayPublicDiagnosticsElement, customerStorageNameElement);
    }
    
    if (parameters.operation !== null && parameters.operation !== undefined) {
      var operationElement = js2xml.createElement('Operation', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(operationElement, 'StartDiagnostics');
      js2xml.addChildElement(updateGatewayPublicDiagnosticsElement, operationElement);
    }
    
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Begin Start Diagnostics V2 operation begins an asynchronous operation
   * to starta diagnostics session for the specified virtual network gateway.
   * 
   * @param {string} gatewayId The virtual network for this gateway Id.
   * 
   * @param {StartGatewayPublicDiagnosticsParameters} parameters Parameters
   * supplied to the Begin Start Diagnostics V2 operation.
   * 
   * @param {string} [parameters.captureDurationInSeconds] The duration of the
   * capture in seconds (between 1 and 300)
   * 
   * @param {string} [parameters.containerName] The container name provided by
   * customer (optional)
   * 
   * @param {string} [parameters.customerStorageKey] The customer's storage
   * account key
   * 
   * @param {string} [parameters.customerStorageName] The customer's storage
   * account name
   * 
   * @param {UpdateGatewayPublicDiagnosticsOperation} [parameters.operation]
   * The update gateway diagnostics operation to perform on the gateway tenant
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.beginStartDiagnosticsV2 = function(gatewayId, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayId === null || gatewayId === undefined) {
      return callback(new Error('gatewayId cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/virtualnetworkgateways/';
    url2 = url2 + encodeURIComponent(gatewayId);
    url2 = url2 + '/publicdiagnostics';
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var updateGatewayPublicDiagnosticsElement = js2xml.createElement('UpdateGatewayPublicDiagnostics', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, updateGatewayPublicDiagnosticsElement);
    
    if (parameters.captureDurationInSeconds !== null && parameters.captureDurationInSeconds !== undefined) {
      var captureDurationInSecondsElement = js2xml.createElement('CaptureDurationInSeconds', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(captureDurationInSecondsElement, parameters.captureDurationInSeconds);
      js2xml.addChildElement(updateGatewayPublicDiagnosticsElement, captureDurationInSecondsElement);
    }
    
    if (parameters.containerName !== null && parameters.containerName !== undefined) {
      var containerNameElement = js2xml.createElement('ContainerName', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(containerNameElement, parameters.containerName);
      js2xml.addChildElement(updateGatewayPublicDiagnosticsElement, containerNameElement);
    }
    
    if (parameters.customerStorageKey !== null && parameters.customerStorageKey !== undefined) {
      var customerStorageKeyElement = js2xml.createElement('CustomerStorageKey', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(customerStorageKeyElement, parameters.customerStorageKey);
      js2xml.addChildElement(updateGatewayPublicDiagnosticsElement, customerStorageKeyElement);
    }
    
    if (parameters.customerStorageName !== null && parameters.customerStorageName !== undefined) {
      var customerStorageNameElement = js2xml.createElement('CustomerStorageName', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(customerStorageNameElement, parameters.customerStorageName);
      js2xml.addChildElement(updateGatewayPublicDiagnosticsElement, customerStorageNameElement);
    }
    
    if (parameters.operation !== null && parameters.operation !== undefined) {
      var operationElement = js2xml.createElement('Operation', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(operationElement, 'StartDiagnostics');
      js2xml.addChildElement(updateGatewayPublicDiagnosticsElement, operationElement);
    }
    
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Operation to update existing gateway connection.
   * 
   * @param {string} gatewayId The virtual network gateway Id.
   * 
   * @param {string} connectedentityId The connected entity Id.
   * 
   * @param {UpdateGatewayConnectionParameters} parameters Parameters supplied
   * to the Begin Update gateway conneciton operation.
   * 
   * @param {number} parameters.routingWeight The Routing Weight
   * 
   * @param {string} [parameters.sharedKey] Ipsec share key
   * 
   * @param {boolean} [parameters.enableBgp] Whether to establish a BGP session
   * over this connection
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.beginUpdateGatewayConnection = function(gatewayId, connectedentityId, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayId === null || gatewayId === undefined) {
      return callback(new Error('gatewayId cannot be null.'));
    }
    if (connectedentityId === null || connectedentityId === undefined) {
      return callback(new Error('connectedentityId cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.routingWeight === null || parameters.routingWeight === undefined) {
      return callback(new Error('parameters.routingWeight 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/networking/gatewayconnections/virtualnetworkgateway/';
    url2 = url2 + encodeURIComponent(gatewayId);
    url2 = url2 + '/connectedentity/';
    url2 = url2 + encodeURIComponent(connectedentityId);
    var queryParameters = [];
    queryParameters.push('api-version=2016-03-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 = 'PATCH';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var updateGatewayConnectionParametersElement = js2xml.createElement('UpdateGatewayConnectionParameters', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, updateGatewayConnectionParametersElement);
    
    var routingWeightElement = js2xml.createElement('RoutingWeight', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(routingWeightElement, parameters.routingWeight.toString());
    js2xml.addChildElement(updateGatewayConnectionParametersElement, routingWeightElement);
    
    if (parameters.sharedKey !== null && parameters.sharedKey !== undefined) {
      var sharedKeyElement = js2xml.createElement('SharedKey', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(sharedKeyElement, parameters.sharedKey);
      js2xml.addChildElement(updateGatewayConnectionParametersElement, sharedKeyElement);
    }
    
    if (parameters.enableBgp !== null && parameters.enableBgp !== undefined) {
      var enableBgpElement = js2xml.createElement('EnableBgp', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(enableBgpElement, parameters.enableBgp.toString());
      js2xml.addChildElement(updateGatewayConnectionParametersElement, enableBgpElement);
    }
    
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * To connect to, disconnect from, or test your connection to a local network
   * site, access the connection resource representing the local network and
   * specify Connect, Disconnect or Test to perform the desired operation.
   * (see http://msdn.microsoft.com/en-us/library/windowsazure/jj154107.aspx
   * for more information)
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {string} localNetworkSiteName The name of the site to connect to.
   * 
   * @param {GatewayConnectDisconnectOrTestParameters} parameters Parameters
   * supplied to the Connect Disconnect Or Testing Gateway operation.
   * 
   * @param {GatewayConnectionUpdateOperation} parameters.operation Specifies
   * the operation to perform on the connection. Can be set to Connect,
   * Disconnect, or Test to connect to a local network, disconnect from a
   * local network, or test the gateway's connection to a local network site.
   * 
   * @param {string} [parameters.iPAddress] Required if operation is set to
   * Test; otherwise not used. Specifies the IP address of the target local
   * network site with which the gateway will test connectivity.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.connectDisconnectOrTest = function(networkName, localNetworkSiteName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.gateways.beginConnectDisconnectOrTesting(networkName, localNetworkSiteName, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.gateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Create Virtual network Gateway operation creates a new network gateway
   * for the specified virtual network in Azure.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154119.aspx for
   * more information)
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {GatewayCreateParameters} parameters Parameters supplied to the
   * Create Virtual Network Gateway operation.
   * 
   * @param {string} [parameters.gatewaySKU] The SKU of this virtual network
   * gateway. Valid values are Default and HighPerformance.
   * 
   * @param {string} [parameters.gatewayType] The routing type for this virtual
   * network gateway.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.create = function(networkName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.gateways.beginCreating(networkName, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.gateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Create Virtual network Gateway Connection operation creates a new
   * network gateway.
   * 
   * @param {GatewayConnectionCreateParameters} parameters Parameters supplied
   * to the Begin Creating Gateway Connection operation.
   * 
   * @param {string} [parameters.connectedEntityId] The Service Key / Local
   * network gateway Id / Vnet Network Gateway Id.
   * 
   * @param {string} [parameters.gatewayConnectionName] The name of the virtual
   * network gateway connection.
   * 
   * @param {string} [parameters.gatewayConnectionType] The connection type of
   * gateway: Ipsec/Dedicated/VpnClient/Vnet2Vnet.
   * 
   * @param {Guid} [parameters.virtualNetworkGatewayId] The Virtual network
   * gateway Id.
   * 
   * @param {number} [parameters.routingWeight] The Routing Weight.
   * 
   * @param {string} [parameters.sharedKey] The Ipsec share key.
   * 
   * @param {boolean} [parameters.enableBgp] Whether to establish a BGP session
   * over this connection
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.createGatewayConnection = function(parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.gateways.beginCreatingGatewayConnection(parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.gateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Create Local network Gateway operation creates a new local network
   * gateway.
   * 
   * @param {LocalNetworkGatewayCreateParameters} parameters Parameters
   * supplied to Create Local Network Gateway operation.
   * 
   * @param {IEnumerable} [parameters.addressSpace] Address space of local
   * network gateway
   * 
   * @param {string} [parameters.gatewayName] The name of the local network
   * gateway.
   * 
   * @param {string} [parameters.ipAddress] The Ip address of the local network
   * gateway.
   * 
   * @param {BgpSettings} [parameters.bgpSettings] Local network gateway's BGP
   * settings
   * 
   * @param {number} [parameters.bgpSettings.asn] Autonomous System Number
   * 
   * @param {string} [parameters.bgpSettings.bgpPeeringAddress] IP address/BGP
   * identifier
   * 
   * @param {number} [parameters.bgpSettings.peerWeight] Weight for routes
   * learned from this peer
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.createLocalNetworkGateway = function(parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/localnetworkgateways';
    var queryParameters = [];
    queryParameters.push('api-version=2016-03-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
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var createLocalNetworkGatewayParametersElement = js2xml.createElement('CreateLocalNetworkGatewayParameters', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, createLocalNetworkGatewayParametersElement);
    
    if (parameters.addressSpace !== null && parameters.addressSpace !== undefined) {
      var addressSpaceSequenceElement = js2xml.createElement('AddressSpace', 'http://schemas.microsoft.com/2003/10/Serialization/Arrays');
      for (var loweredIndex1 = 0; loweredIndex1 < parameters.addressSpace.length; loweredIndex1 = loweredIndex1 + 1) {
        var addressSpaceItem = parameters.addressSpace[loweredIndex1];
        var addressSpaceItemElement = js2xml.createElement('string', 'http://schemas.microsoft.com/2003/10/Serialization/Arrays');
        js2xml.setElementValue(addressSpaceItemElement, addressSpaceItem);
        js2xml.addChildElement(addressSpaceSequenceElement, addressSpaceItemElement);
      }
      js2xml.addChildElement(createLocalNetworkGatewayParametersElement, addressSpaceSequenceElement);
    }
    
    if (parameters.gatewayName !== null && parameters.gatewayName !== undefined) {
      var gatewayNameElement = js2xml.createElement('GatewayName', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(gatewayNameElement, parameters.gatewayName);
      js2xml.addChildElement(createLocalNetworkGatewayParametersElement, gatewayNameElement);
    }
    
    if (parameters.ipAddress !== null && parameters.ipAddress !== undefined) {
      var ipAddressElement = js2xml.createElement('IpAddress', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(ipAddressElement, parameters.ipAddress);
      js2xml.addChildElement(createLocalNetworkGatewayParametersElement, ipAddressElement);
    }
    
    if (parameters.bgpSettings !== null && parameters.bgpSettings !== undefined) {
      var bgpSettingsElement = js2xml.createElement('BgpSettings', 'http://schemas.microsoft.com/windowsazure');
      js2xml.addChildElement(createLocalNetworkGatewayParametersElement, bgpSettingsElement);
      
      if (parameters.bgpSettings.asn !== null && parameters.bgpSettings.asn !== undefined) {
        var asnElement = js2xml.createElement('Asn', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(asnElement, parameters.bgpSettings.asn.toString());
        js2xml.addChildElement(bgpSettingsElement, asnElement);
      }
      
      if (parameters.bgpSettings.bgpPeeringAddress !== null && parameters.bgpSettings.bgpPeeringAddress !== undefined) {
        var bgpPeeringAddressElement = js2xml.createElement('BgpPeeringAddress', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(bgpPeeringAddressElement, parameters.bgpSettings.bgpPeeringAddress);
        js2xml.addChildElement(bgpSettingsElement, bgpPeeringAddressElement);
      }
      
      if (parameters.bgpSettings.peerWeight !== null && parameters.bgpSettings.peerWeight !== undefined) {
        var peerWeightElement = js2xml.createElement('PeerWeight', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(peerWeightElement, parameters.bgpSettings.peerWeight.toString());
        js2xml.addChildElement(bgpSettingsElement, peerWeightElement);
      }
    }
    
    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 !== 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 = {};
        result.localNetworkGatewayId = responseContent;
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Create Virtual network Gateway operation creates a new network gateway.
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {VirtualNetworkGatewayCreateParameters} parameters Parameters
   * supplied to the Create Virtual Network Gateway operation.
   * 
   * @param {string} [parameters.gatewayName] The name of the virtual network
   * gateway.
   * 
   * @param {string} [parameters.gatewaySKU] The SKU of this virtual network
   * gateway. Valid values are Default, HighPerformance and Standard.
   * 
   * @param {string} [parameters.gatewayType] The routing type for this virtual
   * network gateway.
   * 
   * @param {string} [parameters.location] The location of the virtual network
   * gateway.
   * 
   * @param {string} [parameters.vnetId] Virtual network Id.
   * 
   * @param {BgpSettings} [parameters.bgpSettings] BGP settings for this
   * virtual network gateway
   * 
   * @param {number} [parameters.bgpSettings.asn] Autonomous System Number
   * 
   * @param {string} [parameters.bgpSettings.bgpPeeringAddress] IP address/BGP
   * identifier
   * 
   * @param {number} [parameters.bgpSettings.peerWeight] Weight for routes
   * learned from this peer
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.createVirtualNetworkGateway = function(networkName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.gateways.beginCreatingVirtualNetworkGateway(networkName, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.gateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Delete Virtual Network Gateway operation deletes a network gateway for
   * the specified virtual network in Azure.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154129.aspx for
   * more information)
   * 
   * @param {string} networkName The name of the virtual network.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.deleteMethod = function(networkName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.gateways.beginDeleting(networkName, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.gateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Delete Virtual network Gateway Connection operation deletes a network
   * gateway connection.
   * 
   * @param {string} gatewayId The virtual network gateway Id.
   * 
   * @param {string} connectedentityId The connected entity Id.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.deleteGatewayConnection = function(gatewayId, connectedentityId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.gateways.beginDeletingGatewayConnection(gatewayId, connectedentityId, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.gateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Delete Local Network Gateway operation deletes a local network gateway
   * 
   * @param {string} gatewayId The local network gateway id.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.deleteLocalNetworkGateway = function(gatewayId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayId === null || gatewayId === undefined) {
      return callback(new Error('gatewayId 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/networking/localnetworkgateways/';
    url2 = url2 + encodeURIComponent(gatewayId);
    var queryParameters = [];
    queryParameters.push('api-version=2016-03-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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // 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
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Delete Virtual Network Gateway operation deletes a network gateway
   * 
   * @param {string} gatewayId The virtual network gateway id.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.deleteVirtualNetworkGateway = function(gatewayId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.gateways.beginDeletingVirtualNetworkGateway(gatewayId, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.gateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Failover Virtual Network Gateway operation causes a network gateway
   * failover for the specified virtual network in Azure.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154118.aspx for
   * more information)
   * 
   * @param {string} networkName The name of the virtual network in Azure.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.failover = function(networkName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.gateways.beginFailover(networkName, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.gateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Generate VPN Client Package operation creates a VPN client package for
   * the specified virtual network and gateway in Azure.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154119.aspx for
   * more information)
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {GatewayGenerateVpnClientPackageParameters} parameters Parameters
   * supplied to the Generate VPN Client Package operation.
   * 
   * @param {GatewayProcessorArchitecture} parameters.processorArchitecture The
   * client processor architecture.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.generateVpnClientPackage = function(networkName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.gateways.beginGenerateVpnClientPackage(networkName, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.gateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Get Virtual Network Gateway operation gets information about the
   * network gateway for the specified virtual network in Azure.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154109.aspx for
   * more information)
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.get = function(networkName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    url2 = url2 + '/gateway';
    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['x-ms-version'] = '2016-03-01';
    
    // 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 options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var gatewayElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayElement !== null && gatewayElement !== undefined) {
            var stateElement = js2xml.getElement(responseDoc, gatewayElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined) {
              var stateInstance = stateElement;
              result.state = stateInstance;
            }
            
            var vIPAddressElement = js2xml.getElement(responseDoc, gatewayElement, 'VIPADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (vIPAddressElement !== null && vIPAddressElement !== undefined) {
              var vIPAddressInstance = vIPAddressElement;
              result.vipAddress = vIPAddressInstance;
            }
            
            var lastEventElement = js2xml.getElement(responseDoc, gatewayElement, 'LASTEVENT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (lastEventElement !== null && lastEventElement !== undefined) {
              var lastEventInstance = {};
              result.lastEvent = lastEventInstance;
              
              var timestampElement = js2xml.getElement(responseDoc, lastEventElement, 'TIMESTAMP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (timestampElement !== null && timestampElement !== undefined && timestampElement.length !== 0) {
                var timestampInstance = new Date(timestampElement);
                lastEventInstance.timestamp = timestampInstance;
              }
              
              var idElement = js2xml.getElement(responseDoc, lastEventElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (idElement !== null && idElement !== undefined) {
                var idInstance = idElement;
                lastEventInstance.id = idInstance;
              }
              
              var messageElement = js2xml.getElement(responseDoc, lastEventElement, 'MESSAGE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (messageElement !== null && messageElement !== undefined) {
                var messageInstance = messageElement;
                lastEventInstance.message = messageInstance;
              }
              
              var dataElement = js2xml.getElement(responseDoc, lastEventElement, 'DATA', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (dataElement !== null && dataElement !== undefined) {
                var dataInstance = dataElement;
                lastEventInstance.data = dataInstance;
              }
            }
            
            var gatewayTypeElement = js2xml.getElement(responseDoc, gatewayElement, 'GATEWAYTYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (gatewayTypeElement !== null && gatewayTypeElement !== undefined) {
              var gatewayTypeInstance = gatewayTypeElement;
              result.gatewayType = gatewayTypeInstance;
            }
            
            var gatewaySizeElement = js2xml.getElement(responseDoc, gatewayElement, 'GATEWAYSIZE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (gatewaySizeElement !== null && gatewaySizeElement !== undefined) {
              var gatewaySizeInstance = gatewaySizeElement;
              result.gatewaySKU = gatewaySizeInstance;
            }
            
            var defaultSitesElement = js2xml.getElement(responseDoc, gatewayElement, 'DEFAULTSITES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (defaultSitesElement !== null && defaultSitesElement !== undefined) {
              var defaultSitesInstance = {};
              result.defaultSite = defaultSitesInstance;
              
              var stringElement = js2xml.getElement(responseDoc, defaultSitesElement, 'STRING', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (stringElement !== null && stringElement !== undefined) {
                var stringInstance = stringElement;
                defaultSitesInstance.name = stringInstance;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Get Device Configuration Script operation returns a script that you
   * can use to configure local VPN devices to connect to the gateway.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154115.aspx for
   * more information)
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {GatewayGetDeviceConfigurationScriptParameters} parameters The
   * parameters for the Get Device Configuration Script operation.
   * 
   * @param {string} [parameters.vendor] The name of the device vendor.
   * 
   * @param {string} [parameters.platform] The device platform.
   * 
   * @param {string} [parameters.oSFamily] The device OS family.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.getDeviceConfigurationScript = function(networkName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    url2 = url2 + '/gateway/vpndeviceconfigurationscript';
    var queryParameters = [];
    if (parameters.vendor !== null && parameters.vendor !== undefined) {
      queryParameters.push('vendor=' + encodeURIComponent(parameters.vendor));
    }
    if (parameters.platform !== null && parameters.platform !== undefined) {
      queryParameters.push('platform=' + encodeURIComponent(parameters.platform));
    }
    if (parameters.oSFamily !== null && parameters.oSFamily !== undefined) {
      queryParameters.push('OSfamily=' + encodeURIComponent(parameters.oSFamily));
    }
    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['x-ms-version'] = '2016-03-01';
    
    // 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 = {};
        result.configurationScript = responseContent;
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Get Diagnostics operation gets information about the current gateway
   * diagnostics session for the specified virtual network in Azure.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154119.aspx for
   * more information)
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.getDiagnostics = function(networkName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    url2 = url2 + '/gateway/publicdiagnostics';
    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['x-ms-version'] = '2016-03-01';
    
    // 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 options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var gatewayPublicDiagnosticsStatusElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYPUBLICDIAGNOSTICSSTATUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayPublicDiagnosticsStatusElement !== null && gatewayPublicDiagnosticsStatusElement !== undefined) {
            var stateElement = js2xml.getElement(responseDoc, gatewayPublicDiagnosticsStatusElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined && stateElement.length !== 0) {
              var stateInstance = stateElement;
              result.state = stateInstance;
            }
            
            var publicDiagnosticsUrlElement = js2xml.getElement(responseDoc, gatewayPublicDiagnosticsStatusElement, 'PUBLICDIAGNOSTICSURL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (publicDiagnosticsUrlElement !== null && publicDiagnosticsUrlElement !== undefined) {
              var publicDiagnosticsUrlInstance = publicDiagnosticsUrlElement;
              result.diagnosticsUrl = publicDiagnosticsUrlInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Get Diagnostics V2 operation gets information about the current
   * virtual network gateway diagnostics session
   * 
   * @param {string} gatewayId The virtual network gateway Id.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.getDiagnosticsV2 = function(gatewayId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayId === null || gatewayId === undefined) {
      return callback(new Error('gatewayId 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/networking/virtualnetworkgateways/';
    url2 = url2 + encodeURIComponent(gatewayId);
    url2 = url2 + '/publicdiagnostics';
    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['x-ms-version'] = '2016-03-01';
    
    // 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 options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var gatewayPublicDiagnosticsStatusElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYPUBLICDIAGNOSTICSSTATUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayPublicDiagnosticsStatusElement !== null && gatewayPublicDiagnosticsStatusElement !== undefined) {
            var stateElement = js2xml.getElement(responseDoc, gatewayPublicDiagnosticsStatusElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined && stateElement.length !== 0) {
              var stateInstance = stateElement;
              result.state = stateInstance;
            }
            
            var publicDiagnosticsUrlElement = js2xml.getElement(responseDoc, gatewayPublicDiagnosticsStatusElement, 'PUBLICDIAGNOSTICSURL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (publicDiagnosticsUrlElement !== null && publicDiagnosticsUrlElement !== undefined) {
              var publicDiagnosticsUrlInstance = publicDiagnosticsUrlElement;
              result.diagnosticsUrl = publicDiagnosticsUrlInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Get Virtual Network Gateway Connection operation gets information
   * about the virtual network gateway connection.
   * 
   * @param {string} gatewayId The virtual network gateway id.
   * 
   * @param {string} connectedentityId The virtual network gateway connected
   * entity Id.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.getGatewayConnection = function(gatewayId, connectedentityId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayId === null || gatewayId === undefined) {
      return callback(new Error('gatewayId cannot be null.'));
    }
    if (connectedentityId === null || connectedentityId === undefined) {
      return callback(new Error('connectedentityId 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/networking/gatewayconnections/virtualnetworkgateway/';
    url2 = url2 + encodeURIComponent(gatewayId);
    url2 = url2 + '/connectedentity/';
    url2 = url2 + encodeURIComponent(connectedentityId);
    var queryParameters = [];
    queryParameters.push('api-version=2016-03-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['x-ms-version'] = '2016-03-01';
    
    // 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 options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var gatewayConnectionElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYCONNECTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayConnectionElement !== null && gatewayConnectionElement !== undefined) {
            var gatewayConnectionNameElement = js2xml.getElement(responseDoc, gatewayConnectionElement, 'GATEWAYCONNECTIONNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (gatewayConnectionNameElement !== null && gatewayConnectionNameElement !== undefined) {
              var gatewayConnectionNameInstance = gatewayConnectionNameElement;
              result.gatewayConnectionName = gatewayConnectionNameInstance;
            }
            
            var virtualNetworkGatewayIdElement = js2xml.getElement(responseDoc, gatewayConnectionElement, 'VIRTUALNETWORKGATEWAYID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (virtualNetworkGatewayIdElement !== null && virtualNetworkGatewayIdElement !== undefined && virtualNetworkGatewayIdElement.length !== 0) {
              var virtualNetworkGatewayIdInstance = virtualNetworkGatewayIdElement;
              result.virtualNetworkGatewayId = virtualNetworkGatewayIdInstance;
            }
            
            var connectedEntityIdElement = js2xml.getElement(responseDoc, gatewayConnectionElement, 'CONNECTEDENTITYID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (connectedEntityIdElement !== null && connectedEntityIdElement !== undefined) {
              var connectedEntityIdInstance = connectedEntityIdElement;
              result.connectedEntityId = connectedEntityIdInstance;
            }
            
            var gatewayConnectionTypeElement = js2xml.getElement(responseDoc, gatewayConnectionElement, 'GATEWAYCONNECTIONTYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (gatewayConnectionTypeElement !== null && gatewayConnectionTypeElement !== undefined) {
              var gatewayConnectionTypeInstance = gatewayConnectionTypeElement;
              result.gatewayConnectionType = gatewayConnectionTypeInstance;
            }
            
            var routingWeightElement = js2xml.getElement(responseDoc, gatewayConnectionElement, 'ROUTINGWEIGHT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (routingWeightElement !== null && routingWeightElement !== undefined && routingWeightElement.length !== 0) {
              var routingWeightInstance = parseInt(routingWeightElement, 10);
              result.routingWeight = routingWeightInstance;
            }
            
            var sharedKeyElement = js2xml.getElement(responseDoc, gatewayConnectionElement, 'SHAREDKEY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (sharedKeyElement !== null && sharedKeyElement !== undefined) {
              var sharedKeyInstance = sharedKeyElement;
              result.sharedKey = sharedKeyInstance;
            }
            
            var enableBgpElement = js2xml.getElement(responseDoc, gatewayConnectionElement, 'ENABLEBGP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (enableBgpElement !== null && enableBgpElement !== undefined && enableBgpElement.length !== 0) {
              var enableBgpInstance = enableBgpElement === 'true';
              result.enableBgp = enableBgpInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Get IPsec Parameters operation gets the IPsec parameters that have
   * been set for the connection between the provided virtual network gateway
   * and the provided local network site.
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {string} localNetworkName The name of the local network.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.getIPsecParameters = function(networkName, localNetworkName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName cannot be null.'));
    }
    if (localNetworkName === null || localNetworkName === undefined) {
      return callback(new Error('localNetworkName 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    url2 = url2 + '/gateway/connection/';
    url2 = url2 + encodeURIComponent(localNetworkName);
    url2 = url2 + '/ipsecparameters';
    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['x-ms-version'] = '2016-03-01';
    
    // 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 options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var iPsecParametersElement = js2xml.getElement(responseDoc, responseDoc, 'IPSECPARAMETERS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (iPsecParametersElement !== null && iPsecParametersElement !== undefined) {
            var iPsecParametersInstance = {};
            result.iPsecParameters = iPsecParametersInstance;
            
            var encryptionTypeElement = js2xml.getElement(responseDoc, iPsecParametersElement, 'ENCRYPTIONTYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (encryptionTypeElement !== null && encryptionTypeElement !== undefined) {
              var encryptionTypeInstance = encryptionTypeElement;
              iPsecParametersInstance.encryptionType = encryptionTypeInstance;
            }
            
            var pfsGroupElement = js2xml.getElement(responseDoc, iPsecParametersElement, 'PFSGROUP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (pfsGroupElement !== null && pfsGroupElement !== undefined) {
              var pfsGroupInstance = pfsGroupElement;
              iPsecParametersInstance.pfsGroup = pfsGroupInstance;
            }
            
            var sADataSizeKilobytesElement = js2xml.getElement(responseDoc, iPsecParametersElement, 'SADATASIZEKILOBYTES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (sADataSizeKilobytesElement !== null && sADataSizeKilobytesElement !== undefined && sADataSizeKilobytesElement.length !== 0) {
              var sADataSizeKilobytesInstance = parseInt(sADataSizeKilobytesElement, 10);
              iPsecParametersInstance.sADataSizeKilobytes = sADataSizeKilobytesInstance;
            }
            
            var sALifeTimeSecondsElement = js2xml.getElement(responseDoc, iPsecParametersElement, 'SALIFETIMESECONDS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (sALifeTimeSecondsElement !== null && sALifeTimeSecondsElement !== undefined && sALifeTimeSecondsElement.length !== 0) {
              var sALifeTimeSecondsInstance = parseInt(sALifeTimeSecondsElement, 10);
              iPsecParametersInstance.sALifeTimeSeconds = sALifeTimeSecondsInstance;
            }
            
            var hashAlgorithmElement = js2xml.getElement(responseDoc, iPsecParametersElement, 'HASHALGORITHM', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (hashAlgorithmElement !== null && hashAlgorithmElement !== undefined) {
              var hashAlgorithmInstance = hashAlgorithmElement;
              iPsecParametersInstance.hashAlgorithm = hashAlgorithmInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Get IPsec Parameters V2 operation gets the IPsec parameters that have
   * been set for the virtual network gateway  connection
   * 
   * @param {string} gatewayId The virtual network for this gateway Id.
   * 
   * @param {string} connectedentityId The connected entity Id.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.getIPsecParametersV2 = function(gatewayId, connectedentityId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayId === null || gatewayId === undefined) {
      return callback(new Error('gatewayId cannot be null.'));
    }
    if (connectedentityId === null || connectedentityId === undefined) {
      return callback(new Error('connectedentityId 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/networking/virtualnetworkgateways/';
    url2 = url2 + encodeURIComponent(gatewayId);
    url2 = url2 + '/connectedentity/';
    url2 = url2 + encodeURIComponent(connectedentityId);
    url2 = url2 + '/ipsecparameters';
    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['x-ms-version'] = '2016-03-01';
    
    // 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 options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var iPsecParametersElement = js2xml.getElement(responseDoc, responseDoc, 'IPSECPARAMETERS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (iPsecParametersElement !== null && iPsecParametersElement !== undefined) {
            var iPsecParametersInstance = {};
            result.iPsecParameters = iPsecParametersInstance;
            
            var encryptionTypeElement = js2xml.getElement(responseDoc, iPsecParametersElement, 'ENCRYPTIONTYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (encryptionTypeElement !== null && encryptionTypeElement !== undefined) {
              var encryptionTypeInstance = encryptionTypeElement;
              iPsecParametersInstance.encryptionType = encryptionTypeInstance;
            }
            
            var pfsGroupElement = js2xml.getElement(responseDoc, iPsecParametersElement, 'PFSGROUP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (pfsGroupElement !== null && pfsGroupElement !== undefined) {
              var pfsGroupInstance = pfsGroupElement;
              iPsecParametersInstance.pfsGroup = pfsGroupInstance;
            }
            
            var sADataSizeKilobytesElement = js2xml.getElement(responseDoc, iPsecParametersElement, 'SADATASIZEKILOBYTES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (sADataSizeKilobytesElement !== null && sADataSizeKilobytesElement !== undefined && sADataSizeKilobytesElement.length !== 0) {
              var sADataSizeKilobytesInstance = parseInt(sADataSizeKilobytesElement, 10);
              iPsecParametersInstance.sADataSizeKilobytes = sADataSizeKilobytesInstance;
            }
            
            var sALifeTimeSecondsElement = js2xml.getElement(responseDoc, iPsecParametersElement, 'SALIFETIMESECONDS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (sALifeTimeSecondsElement !== null && sALifeTimeSecondsElement !== undefined && sALifeTimeSecondsElement.length !== 0) {
              var sALifeTimeSecondsInstance = parseInt(sALifeTimeSecondsElement, 10);
              iPsecParametersInstance.sALifeTimeSeconds = sALifeTimeSecondsInstance;
            }
            
            var hashAlgorithmElement = js2xml.getElement(responseDoc, iPsecParametersElement, 'HASHALGORITHM', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (hashAlgorithmElement !== null && hashAlgorithmElement !== undefined) {
              var hashAlgorithmInstance = hashAlgorithmElement;
              iPsecParametersInstance.hashAlgorithm = hashAlgorithmInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Get Local Network Gateway operation gets information about the local
   * network gateway
   * 
   * @param {string} gatewayId The local network gateway id.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.getLocalNetworkGateway = function(gatewayId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayId === null || gatewayId === undefined) {
      return callback(new Error('gatewayId 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/networking/localnetworkgateways/';
    url2 = url2 + encodeURIComponent(gatewayId);
    var queryParameters = [];
    queryParameters.push('api-version=2016-03-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['x-ms-version'] = '2016-03-01';
    
    // 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 = { addressSpace: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var localNetworkGatewayElement = js2xml.getElement(responseDoc, responseDoc, 'LOCALNETWORKGATEWAY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (localNetworkGatewayElement !== null && localNetworkGatewayElement !== undefined) {
            var addressSpaceSequenceElement = js2xml.getElement(responseDoc, localNetworkGatewayElement, 'ADDRESSSPACE', 'HTTP://SCHEMAS.MICROSOFT.COM/2003/10/SERIALIZATION/ARRAYS');
            if (addressSpaceSequenceElement !== null && addressSpaceSequenceElement !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, addressSpaceSequenceElement, 'STRING', 'HTTP://SCHEMAS.MICROSOFT.COM/2003/10/SERIALIZATION/ARRAYS').length; loweredIndex1 = loweredIndex1 + 1) {
                var addressSpaceElement = js2xml.getElements(responseDoc, addressSpaceSequenceElement, 'STRING', 'HTTP://SCHEMAS.MICROSOFT.COM/2003/10/SERIALIZATION/ARRAYS')[loweredIndex1];
                result.addressSpace.push(addressSpaceElement);
              }
            }
            
            var idElement = js2xml.getElement(responseDoc, localNetworkGatewayElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined && idElement.length !== 0) {
              var idInstance = idElement;
              result.id = idInstance;
            }
            
            var gatewayNameElement = js2xml.getElement(responseDoc, localNetworkGatewayElement, 'GATEWAYNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (gatewayNameElement !== null && gatewayNameElement !== undefined) {
              var gatewayNameInstance = gatewayNameElement;
              result.gatewayName = gatewayNameInstance;
            }
            
            var ipAddressElement = js2xml.getElement(responseDoc, localNetworkGatewayElement, 'IPADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (ipAddressElement !== null && ipAddressElement !== undefined) {
              var ipAddressInstance = ipAddressElement;
              result.ipAddress = ipAddressInstance;
            }
            
            var bgpSettingsElement = js2xml.getElement(responseDoc, localNetworkGatewayElement, 'BGPSETTINGS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (bgpSettingsElement !== null && bgpSettingsElement !== undefined) {
              var bgpSettingsInstance = {};
              result.bgpSettings = bgpSettingsInstance;
              
              var asnElement = js2xml.getElement(responseDoc, bgpSettingsElement, 'ASN', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (asnElement !== null && asnElement !== undefined && asnElement.length !== 0) {
                var asnInstance = parseInt(asnElement, 10);
                bgpSettingsInstance.asn = asnInstance;
              }
              
              var bgpPeeringAddressElement = js2xml.getElement(responseDoc, bgpSettingsElement, 'BGPPEERINGADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (bgpPeeringAddressElement !== null && bgpPeeringAddressElement !== undefined) {
                var bgpPeeringAddressInstance = bgpPeeringAddressElement;
                bgpSettingsInstance.bgpPeeringAddress = bgpPeeringAddressInstance;
              }
              
              var peerWeightElement = js2xml.getElement(responseDoc, bgpSettingsElement, 'PEERWEIGHT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (peerWeightElement !== null && peerWeightElement !== undefined && peerWeightElement.length !== 0) {
                var peerWeightInstance = parseInt(peerWeightElement, 10);
                bgpSettingsInstance.peerWeight = peerWeightInstance;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Get Virtual Network Gateway Operation Status gets information on the
   * status of network gateway operations in Azure.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154112.aspx for
   * more information)
   * 
   * @param {string} operationId The ID of the network operation.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.getOperationStatus = function(operationId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (operationId === null || operationId === undefined) {
      return callback(new Error('operationId 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/networking/operation/';
    url2 = url2 + encodeURIComponent(operationId);
    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['x-ms-version'] = '2016-03-01';
    
    // 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 options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var gatewayOperationElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationElement !== null && gatewayOperationElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.id = idInstance;
            }
            
            var statusElement = js2xml.getElement(responseDoc, gatewayOperationElement, '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, gatewayOperationElement, '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, gatewayOperationElement, '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);
    });
  };
  
  /**
   * The Get Virtual Network Gateway Shared Key operation gets the shared key
   * on the virtual network gateway for the specified virtual network
   * connection to the specified local network in Azure.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154122.aspx for
   * more information)
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {string} localNetworkName The name of the local network.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.getSharedKey = function(networkName, localNetworkName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName cannot be null.'));
    }
    if (localNetworkName === null || localNetworkName === undefined) {
      return callback(new Error('localNetworkName 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    url2 = url2 + '/gateway/connection/';
    url2 = url2 + encodeURIComponent(localNetworkName);
    url2 = url2 + '/sharedkey';
    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['x-ms-version'] = '2016-03-01';
    
    // 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 options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var sharedKeyElement = js2xml.getElement(responseDoc, responseDoc, 'SHAREDKEY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (sharedKeyElement !== null && sharedKeyElement !== undefined) {
            var valueElement = js2xml.getElement(responseDoc, sharedKeyElement, 'VALUE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (valueElement !== null && valueElement !== undefined) {
              var valueInstance = valueElement;
              result.sharedKey = valueInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Get Virtual Network Gateway Shared Key V2 operation gets the shared
   * key used between the gateway and customer vpn.
   * 
   * @param {string} gatewayId The virtual network for this gateway Id.
   * 
   * @param {string} connectedentityId The connected entity Id.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.getSharedKeyV2 = function(gatewayId, connectedentityId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayId === null || gatewayId === undefined) {
      return callback(new Error('gatewayId cannot be null.'));
    }
    if (connectedentityId === null || connectedentityId === undefined) {
      return callback(new Error('connectedentityId 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/networking/virtualnetworkgateways/';
    url2 = url2 + encodeURIComponent(gatewayId);
    url2 = url2 + '/connectedentity/';
    url2 = url2 + encodeURIComponent(connectedentityId);
    url2 = url2 + '/sharedkey';
    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['x-ms-version'] = '2016-03-01';
    
    // 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 options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var sharedKeyElement = js2xml.getElement(responseDoc, responseDoc, 'SHAREDKEY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (sharedKeyElement !== null && sharedKeyElement !== undefined) {
            var valueElement = js2xml.getElement(responseDoc, sharedKeyElement, 'VALUE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (valueElement !== null && valueElement !== undefined) {
              var valueInstance = valueElement;
              result.sharedKey = valueInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Get Virtual Network Gateway operation gets information about the
   * virtual network gateway
   * 
   * @param {string} gatewayId The virtual network gateway id.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.getVirtualNetworkGateway = function(gatewayId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayId === null || gatewayId === undefined) {
      return callback(new Error('gatewayId 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/networking/virtualnetworkgateways/';
    url2 = url2 + encodeURIComponent(gatewayId);
    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['x-ms-version'] = '2016-03-01';
    
    // 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 options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var virtualNetworkGatewayElement = js2xml.getElement(responseDoc, responseDoc, 'VIRTUALNETWORKGATEWAY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (virtualNetworkGatewayElement !== null && virtualNetworkGatewayElement !== undefined) {
            var gatewayIdElement = js2xml.getElement(responseDoc, virtualNetworkGatewayElement, 'GATEWAYID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (gatewayIdElement !== null && gatewayIdElement !== undefined && gatewayIdElement.length !== 0) {
              var gatewayIdInstance = gatewayIdElement;
              result.gatewayId = gatewayIdInstance;
            }
            
            var lastEventElement = js2xml.getElement(responseDoc, virtualNetworkGatewayElement, 'LASTEVENT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (lastEventElement !== null && lastEventElement !== undefined) {
              var lastEventInstance = {};
              result.lastEvent = lastEventInstance;
              
              var timestampElement = js2xml.getElement(responseDoc, lastEventElement, 'TIMESTAMP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (timestampElement !== null && timestampElement !== undefined && timestampElement.length !== 0) {
                var timestampInstance = new Date(timestampElement);
                lastEventInstance.timestamp = timestampInstance;
              }
              
              var idElement = js2xml.getElement(responseDoc, lastEventElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (idElement !== null && idElement !== undefined) {
                var idInstance = idElement;
                lastEventInstance.id = idInstance;
              }
              
              var messageElement = js2xml.getElement(responseDoc, lastEventElement, 'MESSAGE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (messageElement !== null && messageElement !== undefined) {
                var messageInstance = messageElement;
                lastEventInstance.message = messageInstance;
              }
              
              var dataElement = js2xml.getElement(responseDoc, lastEventElement, 'DATA', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (dataElement !== null && dataElement !== undefined) {
                var dataInstance = dataElement;
                lastEventInstance.data = dataInstance;
              }
            }
            
            var gatewayNameElement = js2xml.getElement(responseDoc, virtualNetworkGatewayElement, 'GATEWAYNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (gatewayNameElement !== null && gatewayNameElement !== undefined) {
              var gatewayNameInstance = gatewayNameElement;
              result.gatewayName = gatewayNameInstance;
            }
            
            var gatewayTypeElement = js2xml.getElement(responseDoc, virtualNetworkGatewayElement, 'GATEWAYTYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (gatewayTypeElement !== null && gatewayTypeElement !== undefined) {
              var gatewayTypeInstance = gatewayTypeElement;
              result.gatewayType = gatewayTypeInstance;
            }
            
            var gatewaySizeElement = js2xml.getElement(responseDoc, virtualNetworkGatewayElement, 'GATEWAYSIZE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (gatewaySizeElement !== null && gatewaySizeElement !== undefined) {
              var gatewaySizeInstance = gatewaySizeElement;
              result.gatewaySKU = gatewaySizeInstance;
            }
            
            var stateElement = js2xml.getElement(responseDoc, virtualNetworkGatewayElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined) {
              var stateInstance = stateElement;
              result.state = stateInstance;
            }
            
            var vIPAddressElement = js2xml.getElement(responseDoc, virtualNetworkGatewayElement, 'VIPADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (vIPAddressElement !== null && vIPAddressElement !== undefined) {
              var vIPAddressInstance = vIPAddressElement;
              result.vipAddress = vIPAddressInstance;
            }
            
            var locationElement = js2xml.getElement(responseDoc, virtualNetworkGatewayElement, 'LOCATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (locationElement !== null && locationElement !== undefined) {
              var locationInstance = locationElement;
              result.location = locationInstance;
            }
            
            var vnetIdElement = js2xml.getElement(responseDoc, virtualNetworkGatewayElement, 'VNETID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (vnetIdElement !== null && vnetIdElement !== undefined) {
              var vnetIdInstance = vnetIdElement;
              result.vnetId = vnetIdInstance;
            }
            
            var subnetIdElement = js2xml.getElement(responseDoc, virtualNetworkGatewayElement, 'SUBNETID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (subnetIdElement !== null && subnetIdElement !== undefined) {
              var subnetIdInstance = subnetIdElement;
              result.subnetId = subnetIdInstance;
            }
            
            var defaultSitesElement = js2xml.getElement(responseDoc, virtualNetworkGatewayElement, 'DEFAULTSITES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (defaultSitesElement !== null && defaultSitesElement !== undefined) {
              var defaultSitesInstance = {};
              result.defaultSite = defaultSitesInstance;
              
              var stringElement = js2xml.getElement(responseDoc, defaultSitesElement, 'STRING', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (stringElement !== null && stringElement !== undefined) {
                var stringInstance = stringElement;
                defaultSitesInstance.name = stringInstance;
              }
            }
            
            var enableBgpElement = js2xml.getElement(responseDoc, virtualNetworkGatewayElement, 'ENABLEBGP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (enableBgpElement !== null && enableBgpElement !== undefined && enableBgpElement.length !== 0) {
              var enableBgpInstance = enableBgpElement === 'true';
              result.enableBgp = enableBgpInstance;
            }
            
            var bgpSettingsElement = js2xml.getElement(responseDoc, virtualNetworkGatewayElement, 'BGPSETTINGS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (bgpSettingsElement !== null && bgpSettingsElement !== undefined) {
              var bgpSettingsInstance = {};
              result.bgpSettings = bgpSettingsInstance;
              
              var asnElement = js2xml.getElement(responseDoc, bgpSettingsElement, 'ASN', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (asnElement !== null && asnElement !== undefined && asnElement.length !== 0) {
                var asnInstance = parseInt(asnElement, 10);
                bgpSettingsInstance.asn = asnInstance;
              }
              
              var bgpPeeringAddressElement = js2xml.getElement(responseDoc, bgpSettingsElement, 'BGPPEERINGADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (bgpPeeringAddressElement !== null && bgpPeeringAddressElement !== undefined) {
                var bgpPeeringAddressInstance = bgpPeeringAddressElement;
                bgpSettingsInstance.bgpPeeringAddress = bgpPeeringAddressInstance;
              }
              
              var peerWeightElement = js2xml.getElement(responseDoc, bgpSettingsElement, 'PEERWEIGHT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (peerWeightElement !== null && peerWeightElement !== undefined && peerWeightElement.length !== 0) {
                var peerWeightInstance = parseInt(peerWeightElement, 10);
                bgpSettingsInstance.peerWeight = peerWeightInstance;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The List Connections operation returns a list of the local network
   * connections that can be accessed through the gateway.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154120.aspx for
   * more information)
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.listConnections = function(networkName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    url2 = url2 + '/gateway/connections';
    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['x-ms-version'] = '2016-03-01';
    
    // 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 = { connections: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var connectionsSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'CONNECTIONS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (connectionsSequenceElement !== null && connectionsSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, connectionsSequenceElement, 'CONNECTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var connectionsElement = js2xml.getElements(responseDoc, connectionsSequenceElement, 'CONNECTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var connectionInstance = { allocatedIPAddresses: [] };
              result.connections.push(connectionInstance);
              
              var localNetworkSiteNameElement = js2xml.getElement(responseDoc, connectionsElement, 'LOCALNETWORKSITENAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (localNetworkSiteNameElement !== null && localNetworkSiteNameElement !== undefined) {
                var localNetworkSiteNameInstance = localNetworkSiteNameElement;
                connectionInstance.localNetworkSiteName = localNetworkSiteNameInstance;
              }
              
              var connectivityStateElement = js2xml.getElement(responseDoc, connectionsElement, 'CONNECTIVITYSTATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (connectivityStateElement !== null && connectivityStateElement !== undefined && connectivityStateElement.length !== 0) {
                var connectivityStateInstance = connectivityStateElement;
                connectionInstance.connectivityState = connectivityStateInstance;
              }
              
              var lastEventElement = js2xml.getElement(responseDoc, connectionsElement, 'LASTEVENT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (lastEventElement !== null && lastEventElement !== undefined) {
                var lastEventInstance = {};
                connectionInstance.lastEvent = lastEventInstance;
                
                var timestampElement = js2xml.getElement(responseDoc, lastEventElement, 'TIMESTAMP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (timestampElement !== null && timestampElement !== undefined && timestampElement.length !== 0) {
                  var timestampInstance = new Date(timestampElement);
                  lastEventInstance.timestamp = timestampInstance;
                }
                
                var idElement = js2xml.getElement(responseDoc, lastEventElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (idElement !== null && idElement !== undefined) {
                  var idInstance = idElement;
                  lastEventInstance.id = idInstance;
                }
                
                var messageElement = js2xml.getElement(responseDoc, lastEventElement, 'MESSAGE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (messageElement !== null && messageElement !== undefined) {
                  var messageInstance = messageElement;
                  lastEventInstance.message = messageInstance;
                }
                
                var dataElement = js2xml.getElement(responseDoc, lastEventElement, 'DATA', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (dataElement !== null && dataElement !== undefined) {
                  var dataInstance = dataElement;
                  lastEventInstance.data = dataInstance;
                }
              }
              
              var ingressBytesTransferredElement = js2xml.getElement(responseDoc, connectionsElement, 'INGRESSBYTESTRANSFERRED', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (ingressBytesTransferredElement !== null && ingressBytesTransferredElement !== undefined && ingressBytesTransferredElement.length !== 0) {
                var ingressBytesTransferredInstance = parseInt(ingressBytesTransferredElement, 10);
                connectionInstance.ingressBytesTransferred = ingressBytesTransferredInstance;
              }
              
              var egressBytesTransferredElement = js2xml.getElement(responseDoc, connectionsElement, 'EGRESSBYTESTRANSFERRED', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (egressBytesTransferredElement !== null && egressBytesTransferredElement !== undefined && egressBytesTransferredElement.length !== 0) {
                var egressBytesTransferredInstance = parseInt(egressBytesTransferredElement, 10);
                connectionInstance.egressBytesTransferred = egressBytesTransferredInstance;
              }
              
              var lastConnectionEstablishedElement = js2xml.getElement(responseDoc, connectionsElement, 'LASTCONNECTIONESTABLISHED', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (lastConnectionEstablishedElement !== null && lastConnectionEstablishedElement !== undefined && lastConnectionEstablishedElement.length !== 0) {
                var lastConnectionEstablishedInstance = new Date(lastConnectionEstablishedElement);
                connectionInstance.lastConnectionEstablished = lastConnectionEstablishedInstance;
              }
              
              var allocatedIPAddressesSequenceElement = js2xml.getElement(responseDoc, connectionsElement, 'ALLOCATEDIPADDRESSES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (allocatedIPAddressesSequenceElement !== null && allocatedIPAddressesSequenceElement !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < js2xml.getElements(responseDoc, allocatedIPAddressesSequenceElement, 'STRING', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex2 = loweredIndex2 + 1) {
                  var allocatedIPAddressesElement = js2xml.getElements(responseDoc, allocatedIPAddressesSequenceElement, 'STRING', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex2];
                  connectionInstance.allocatedIPAddresses.push(allocatedIPAddressesElement);
                }
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The List Connections operation Lists all GatewayConnections.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.listGatewayConnections = function(callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // 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/networking/gatewayconnections';
    var queryParameters = [];
    queryParameters.push('api-version=2016-03-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['x-ms-version'] = '2016-03-01';
    
    // 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 = { virtualNetworkGatewayConnections: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var gatewayConnectionsSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYCONNECTIONS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayConnectionsSequenceElement !== null && gatewayConnectionsSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, gatewayConnectionsSequenceElement, 'GATEWAYCONNECTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var gatewayConnectionsElement = js2xml.getElements(responseDoc, gatewayConnectionsSequenceElement, 'GATEWAYCONNECTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var gatewayConnectionInstance = {};
              result.virtualNetworkGatewayConnections.push(gatewayConnectionInstance);
              
              var gatewayConnectionNameElement = js2xml.getElement(responseDoc, gatewayConnectionsElement, 'GATEWAYCONNECTIONNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (gatewayConnectionNameElement !== null && gatewayConnectionNameElement !== undefined) {
                var gatewayConnectionNameInstance = gatewayConnectionNameElement;
                gatewayConnectionInstance.gatewayConnectionName = gatewayConnectionNameInstance;
              }
              
              var virtualNetworkGatewayIdElement = js2xml.getElement(responseDoc, gatewayConnectionsElement, 'VIRTUALNETWORKGATEWAYID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (virtualNetworkGatewayIdElement !== null && virtualNetworkGatewayIdElement !== undefined && virtualNetworkGatewayIdElement.length !== 0) {
                var virtualNetworkGatewayIdInstance = virtualNetworkGatewayIdElement;
                gatewayConnectionInstance.virtualNetworkGatewayId = virtualNetworkGatewayIdInstance;
              }
              
              var connectedEntityIdElement = js2xml.getElement(responseDoc, gatewayConnectionsElement, 'CONNECTEDENTITYID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (connectedEntityIdElement !== null && connectedEntityIdElement !== undefined) {
                var connectedEntityIdInstance = connectedEntityIdElement;
                gatewayConnectionInstance.connectedEntityId = connectedEntityIdInstance;
              }
              
              var gatewayConnectionTypeElement = js2xml.getElement(responseDoc, gatewayConnectionsElement, 'GATEWAYCONNECTIONTYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (gatewayConnectionTypeElement !== null && gatewayConnectionTypeElement !== undefined) {
                var gatewayConnectionTypeInstance = gatewayConnectionTypeElement;
                gatewayConnectionInstance.gatewayConnectionType = gatewayConnectionTypeInstance;
              }
              
              var routingWeightElement = js2xml.getElement(responseDoc, gatewayConnectionsElement, 'ROUTINGWEIGHT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (routingWeightElement !== null && routingWeightElement !== undefined && routingWeightElement.length !== 0) {
                var routingWeightInstance = parseInt(routingWeightElement, 10);
                gatewayConnectionInstance.routingWeight = routingWeightInstance;
              }
              
              var sharedKeyElement = js2xml.getElement(responseDoc, gatewayConnectionsElement, 'SHAREDKEY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (sharedKeyElement !== null && sharedKeyElement !== undefined) {
                var sharedKeyInstance = sharedKeyElement;
                gatewayConnectionInstance.sharedKey = sharedKeyInstance;
              }
              
              var enableBgpElement = js2xml.getElement(responseDoc, gatewayConnectionsElement, 'ENABLEBGP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (enableBgpElement !== null && enableBgpElement !== undefined && enableBgpElement.length !== 0) {
                var enableBgpInstance = enableBgpElement === 'true';
                gatewayConnectionInstance.enableBgp = enableBgpInstance;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The List Local network gateways operation returns a list of the local
   * network gateways.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.listLocalNetworkGateways = function(callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // 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/networking/localnetworkgateways';
    var queryParameters = [];
    queryParameters.push('api-version=2016-03-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['x-ms-version'] = '2016-03-01';
    
    // 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 = { localNetworkGateways: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var localNetworkGatewaysSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'LOCALNETWORKGATEWAYS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (localNetworkGatewaysSequenceElement !== null && localNetworkGatewaysSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, localNetworkGatewaysSequenceElement, 'LOCALNETWORKGATEWAY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var localNetworkGatewaysElement = js2xml.getElements(responseDoc, localNetworkGatewaysSequenceElement, 'LOCALNETWORKGATEWAY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var localNetworkGatewayInstance = { addressSpace: [] };
              result.localNetworkGateways.push(localNetworkGatewayInstance);
              
              var idElement = js2xml.getElement(responseDoc, localNetworkGatewaysElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (idElement !== null && idElement !== undefined && idElement.length !== 0) {
                var idInstance = idElement;
                localNetworkGatewayInstance.id = idInstance;
              }
              
              var gatewayNameElement = js2xml.getElement(responseDoc, localNetworkGatewaysElement, 'GATEWAYNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (gatewayNameElement !== null && gatewayNameElement !== undefined) {
                var gatewayNameInstance = gatewayNameElement;
                localNetworkGatewayInstance.gatewayName = gatewayNameInstance;
              }
              
              var ipAddressElement = js2xml.getElement(responseDoc, localNetworkGatewaysElement, 'IPADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (ipAddressElement !== null && ipAddressElement !== undefined) {
                var ipAddressInstance = ipAddressElement;
                localNetworkGatewayInstance.ipAddress = ipAddressInstance;
              }
              
              var addressSpaceSequenceElement = js2xml.getElement(responseDoc, localNetworkGatewaysElement, 'ADDRESSSPACE', 'HTTP://SCHEMAS.MICROSOFT.COM/2003/10/SERIALIZATION/ARRAYS');
              if (addressSpaceSequenceElement !== null && addressSpaceSequenceElement !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < js2xml.getElements(responseDoc, addressSpaceSequenceElement, 'STRING', 'HTTP://SCHEMAS.MICROSOFT.COM/2003/10/SERIALIZATION/ARRAYS').length; loweredIndex2 = loweredIndex2 + 1) {
                  var addressSpaceElement = js2xml.getElements(responseDoc, addressSpaceSequenceElement, 'STRING', 'HTTP://SCHEMAS.MICROSOFT.COM/2003/10/SERIALIZATION/ARRAYS')[loweredIndex2];
                  localNetworkGatewayInstance.addressSpace.push(addressSpaceElement);
                }
              }
              
              var bgpSettingsElement = js2xml.getElement(responseDoc, localNetworkGatewaysElement, 'BGPSETTINGS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (bgpSettingsElement !== null && bgpSettingsElement !== undefined) {
                var bgpSettingsInstance = {};
                localNetworkGatewayInstance.bgpSettings = bgpSettingsInstance;
                
                var asnElement = js2xml.getElement(responseDoc, bgpSettingsElement, 'ASN', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (asnElement !== null && asnElement !== undefined && asnElement.length !== 0) {
                  var asnInstance = parseInt(asnElement, 10);
                  bgpSettingsInstance.asn = asnInstance;
                }
                
                var bgpPeeringAddressElement = js2xml.getElement(responseDoc, bgpSettingsElement, 'BGPPEERINGADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (bgpPeeringAddressElement !== null && bgpPeeringAddressElement !== undefined) {
                  var bgpPeeringAddressInstance = bgpPeeringAddressElement;
                  bgpSettingsInstance.bgpPeeringAddress = bgpPeeringAddressInstance;
                }
                
                var peerWeightElement = js2xml.getElement(responseDoc, bgpSettingsElement, 'PEERWEIGHT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (peerWeightElement !== null && peerWeightElement !== undefined && peerWeightElement.length !== 0) {
                  var peerWeightInstance = parseInt(peerWeightElement, 10);
                  bgpSettingsInstance.peerWeight = peerWeightInstance;
                }
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The List Virtual Network Gateway Supported Devices operation lists the
   * supported, on-premise network devices that can connect to the gateway.
   * (see http://msdn.microsoft.com/en-us/library/windowsazure/jj154102.aspx
   * for more information)
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.listSupportedDevices = function(callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // 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/networking/supporteddevices';
    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['x-ms-version'] = '2016-03-01';
    
    // 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 = { vendors: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var vpnDeviceListElement = js2xml.getElement(responseDoc, responseDoc, 'VPNDEVICELIST', '');
          if (vpnDeviceListElement !== null && vpnDeviceListElement !== undefined) {
            var versionAttribute = js2xml.getAttribute(responseDoc, vpnDeviceListElement, 'VERSION', '');
            if (versionAttribute !== null && versionAttribute !== undefined) {
              result.version = versionAttribute;
            }
            
            if (vpnDeviceListElement !== null && vpnDeviceListElement !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, vpnDeviceListElement, 'VENDOR', '').length; loweredIndex1 = loweredIndex1 + 1) {
                var vendorsElement = js2xml.getElements(responseDoc, vpnDeviceListElement, 'VENDOR', '')[loweredIndex1];
                var vendorInstance = { platforms: [] };
                result.vendors.push(vendorInstance);
                
                var nameAttribute = js2xml.getAttribute(responseDoc, vendorsElement, 'NAME', '');
                if (nameAttribute !== null && nameAttribute !== undefined) {
                  vendorInstance.name = nameAttribute;
                }
                
                if (vendorsElement !== null && vendorsElement !== undefined) {
                  for (var loweredIndex2 = 0; loweredIndex2 < js2xml.getElements(responseDoc, vendorsElement, 'PLATFORM', '').length; loweredIndex2 = loweredIndex2 + 1) {
                    var platformsElement = js2xml.getElements(responseDoc, vendorsElement, 'PLATFORM', '')[loweredIndex2];
                    var platformInstance = { oSFamilies: [] };
                    vendorInstance.platforms.push(platformInstance);
                    
                    var nameAttribute2 = js2xml.getAttribute(responseDoc, platformsElement, 'NAME', '');
                    if (nameAttribute2 !== null && nameAttribute2 !== undefined) {
                      platformInstance.name = nameAttribute2;
                    }
                    
                    if (platformsElement !== null && platformsElement !== undefined) {
                      for (var loweredIndex3 = 0; loweredIndex3 < js2xml.getElements(responseDoc, platformsElement, 'OSFAMILY', '').length; loweredIndex3 = loweredIndex3 + 1) {
                        var oSFamiliesElement = js2xml.getElements(responseDoc, platformsElement, 'OSFAMILY', '')[loweredIndex3];
                        var oSFamilyInstance = {};
                        platformInstance.oSFamilies.push(oSFamilyInstance);
                        
                        var nameAttribute3 = js2xml.getAttribute(responseDoc, oSFamiliesElement, 'NAME', '');
                        if (nameAttribute3 !== null && nameAttribute3 !== undefined) {
                          oSFamilyInstance.name = nameAttribute3;
                        }
                      }
                    }
                  }
                }
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The List Virtual network gateways operation returns a list of the virtual
   * network gateways.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.listVirtualNetworkGateways = function(callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // 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/networking/virtualnetworkgateways';
    var queryParameters = [];
    queryParameters.push('api-version=2016-03-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['x-ms-version'] = '2016-03-01';
    
    // 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 = { virtualNetworkGateways: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var virtualNetworkGatewaysSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'VIRTUALNETWORKGATEWAYS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (virtualNetworkGatewaysSequenceElement !== null && virtualNetworkGatewaysSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, virtualNetworkGatewaysSequenceElement, 'VIRTUALNETWORKGATEWAY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var virtualNetworkGatewaysElement = js2xml.getElements(responseDoc, virtualNetworkGatewaysSequenceElement, 'VIRTUALNETWORKGATEWAY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var virtualNetworkGatewayInstance = {};
              result.virtualNetworkGateways.push(virtualNetworkGatewayInstance);
              
              var gatewayIdElement = js2xml.getElement(responseDoc, virtualNetworkGatewaysElement, 'GATEWAYID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (gatewayIdElement !== null && gatewayIdElement !== undefined && gatewayIdElement.length !== 0) {
                var gatewayIdInstance = gatewayIdElement;
                virtualNetworkGatewayInstance.gatewayId = gatewayIdInstance;
              }
              
              var lastEventElement = js2xml.getElement(responseDoc, virtualNetworkGatewaysElement, 'LASTEVENT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (lastEventElement !== null && lastEventElement !== undefined) {
                var lastEventInstance = {};
                virtualNetworkGatewayInstance.lastEvent = lastEventInstance;
                
                var timestampElement = js2xml.getElement(responseDoc, lastEventElement, 'TIMESTAMP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (timestampElement !== null && timestampElement !== undefined && timestampElement.length !== 0) {
                  var timestampInstance = new Date(timestampElement);
                  lastEventInstance.timestamp = timestampInstance;
                }
                
                var idElement = js2xml.getElement(responseDoc, lastEventElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (idElement !== null && idElement !== undefined) {
                  var idInstance = idElement;
                  lastEventInstance.id = idInstance;
                }
                
                var messageElement = js2xml.getElement(responseDoc, lastEventElement, 'MESSAGE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (messageElement !== null && messageElement !== undefined) {
                  var messageInstance = messageElement;
                  lastEventInstance.message = messageInstance;
                }
                
                var dataElement = js2xml.getElement(responseDoc, lastEventElement, 'DATA', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (dataElement !== null && dataElement !== undefined) {
                  var dataInstance = dataElement;
                  lastEventInstance.data = dataInstance;
                }
              }
              
              var gatewayNameElement = js2xml.getElement(responseDoc, virtualNetworkGatewaysElement, 'GATEWAYNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (gatewayNameElement !== null && gatewayNameElement !== undefined) {
                var gatewayNameInstance = gatewayNameElement;
                virtualNetworkGatewayInstance.gatewayName = gatewayNameInstance;
              }
              
              var gatewayTypeElement = js2xml.getElement(responseDoc, virtualNetworkGatewaysElement, 'GATEWAYTYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (gatewayTypeElement !== null && gatewayTypeElement !== undefined) {
                var gatewayTypeInstance = gatewayTypeElement;
                virtualNetworkGatewayInstance.gatewayType = gatewayTypeInstance;
              }
              
              var gatewaySizeElement = js2xml.getElement(responseDoc, virtualNetworkGatewaysElement, 'GATEWAYSIZE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (gatewaySizeElement !== null && gatewaySizeElement !== undefined) {
                var gatewaySizeInstance = gatewaySizeElement;
                virtualNetworkGatewayInstance.gatewaySKU = gatewaySizeInstance;
              }
              
              var stateElement = js2xml.getElement(responseDoc, virtualNetworkGatewaysElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (stateElement !== null && stateElement !== undefined) {
                var stateInstance = stateElement;
                virtualNetworkGatewayInstance.state = stateInstance;
              }
              
              var vIPAddressElement = js2xml.getElement(responseDoc, virtualNetworkGatewaysElement, 'VIPADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (vIPAddressElement !== null && vIPAddressElement !== undefined) {
                var vIPAddressInstance = vIPAddressElement;
                virtualNetworkGatewayInstance.vipAddress = vIPAddressInstance;
              }
              
              var locationElement = js2xml.getElement(responseDoc, virtualNetworkGatewaysElement, 'LOCATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (locationElement !== null && locationElement !== undefined) {
                var locationInstance = locationElement;
                virtualNetworkGatewayInstance.location = locationInstance;
              }
              
              var vnetIdElement = js2xml.getElement(responseDoc, virtualNetworkGatewaysElement, 'VNETID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (vnetIdElement !== null && vnetIdElement !== undefined) {
                var vnetIdInstance = vnetIdElement;
                virtualNetworkGatewayInstance.vnetId = vnetIdInstance;
              }
              
              var subnetIdElement = js2xml.getElement(responseDoc, virtualNetworkGatewaysElement, 'SUBNETID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (subnetIdElement !== null && subnetIdElement !== undefined) {
                var subnetIdInstance = subnetIdElement;
                virtualNetworkGatewayInstance.subnetId = subnetIdInstance;
              }
              
              var defaultSitesElement = js2xml.getElement(responseDoc, virtualNetworkGatewaysElement, 'DEFAULTSITES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (defaultSitesElement !== null && defaultSitesElement !== undefined) {
                var defaultSitesInstance = {};
                virtualNetworkGatewayInstance.defaultSite = defaultSitesInstance;
                
                var stringElement = js2xml.getElement(responseDoc, defaultSitesElement, 'STRING', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (stringElement !== null && stringElement !== undefined) {
                  var stringInstance = stringElement;
                  defaultSitesInstance.name = stringInstance;
                }
              }
              
              var enableBgpElement = js2xml.getElement(responseDoc, virtualNetworkGatewaysElement, 'ENABLEBGP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (enableBgpElement !== null && enableBgpElement !== undefined && enableBgpElement.length !== 0) {
                var enableBgpInstance = enableBgpElement === 'true';
                virtualNetworkGatewayInstance.enableBgp = enableBgpInstance;
              }
              
              var bgpSettingsElement = js2xml.getElement(responseDoc, virtualNetworkGatewaysElement, 'BGPSETTINGS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (bgpSettingsElement !== null && bgpSettingsElement !== undefined) {
                var bgpSettingsInstance = {};
                virtualNetworkGatewayInstance.bgpSettings = bgpSettingsInstance;
                
                var asnElement = js2xml.getElement(responseDoc, bgpSettingsElement, 'ASN', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (asnElement !== null && asnElement !== undefined && asnElement.length !== 0) {
                  var asnInstance = parseInt(asnElement, 10);
                  bgpSettingsInstance.asn = asnInstance;
                }
                
                var bgpPeeringAddressElement = js2xml.getElement(responseDoc, bgpSettingsElement, 'BGPPEERINGADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (bgpPeeringAddressElement !== null && bgpPeeringAddressElement !== undefined) {
                  var bgpPeeringAddressInstance = bgpPeeringAddressElement;
                  bgpSettingsInstance.bgpPeeringAddress = bgpPeeringAddressInstance;
                }
                
                var peerWeightElement = js2xml.getElement(responseDoc, bgpSettingsElement, 'PEERWEIGHT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (peerWeightElement !== null && peerWeightElement !== undefined && peerWeightElement.length !== 0) {
                  var peerWeightInstance = parseInt(peerWeightElement, 10);
                  bgpSettingsInstance.peerWeight = peerWeightInstance;
                }
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Remove Virtual Network Gateway Shared Key operation sets the default
   * sites on the virtual network gateway for the specified virtual network.
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.removeDefaultSites = function(networkName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.gateways.beginRemoveDefaultSites(networkName, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.gateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Begin Reset Virtual network Gateway operation resets an existing
   * gateway.
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {ResetGatewayParameters} parameters Parameters supplied to the
   * Reset Virtual Network Gateway operation.
   * 
   * @param {UpdateGatewayOperation} [parameters.operation]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.reset = function(networkName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.gateways.beginReset(networkName, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.gateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Reset Virtual Network Gateway Shared Key operation resets the shared
   * key on the virtual network gateway for the specified virtual network
   * connection to the specified local network in Azure.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
   * more information)
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {string} localNetworkName The name of the local network.
   * 
   * @param {GatewayResetSharedKeyParameters} parameters The parameters to the
   * Virtual Network Gateway Reset Shared Key request.
   * 
   * @param {number} [parameters.keyLength] The number of bytes in the shared
   * key. Minimum is 1 and maximum is 128
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.resetSharedKey = function(networkName, localNetworkName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.gateways.beginResetSharedKey(networkName, localNetworkName, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.gateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Reset Virtual Network Gateway Shared Key V2 operation resets the
   * shared key used between the gateway and customer vpn.
   * 
   * @param {string} gatewayId The virtual network for this gateway Id.
   * 
   * @param {string} connectedentityId The connected entity Id.
   * 
   * @param {GatewayResetSharedKeyParameters} parameters Parameters supplied to
   * the Begin Virtual Network Gateway Reset Shared Key request.
   * 
   * @param {number} [parameters.keyLength] The number of bytes in the shared
   * key. Minimum is 1 and maximum is 128
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.resetSharedKeyV2 = function(gatewayId, connectedentityId, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.gateways.beginResetSharedKeyV2(gatewayId, connectedentityId, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.gateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Begin Reset Virtual network Gateway operation resets an existing
   * gateway.
   * 
   * @param {string} gatewayId The virtual network for this gateway.
   * 
   * @param {ResetGatewayParameters} parameters Parameters supplied to the
   * Reset Virtual Network Gateway operation.
   * 
   * @param {UpdateGatewayOperation} [parameters.operation]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.resetVirtualNetworkGateway = function(gatewayId, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.gateways.beginResetVirtualNetworkGateway(gatewayId, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.gateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Begin Resize Virtual network Gateway operation resizes an existing
   * gateway to a different GatewaySKU.
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {ResizeGatewayParameters} parameters Parameters supplied to the
   * Resize Virtual Network Gateway operation.
   * 
   * @param {string} [parameters.gatewaySKU]
   * 
   * @param {UpdateGatewayOperation} [parameters.operation]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.resize = function(networkName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.gateways.beginResize(networkName, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.gateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Begin Resize Virtual network Gateway operation resizes an existing
   * gateway to a different GatewaySKU.
   * 
   * @param {string} gatewayId The virtual network for this gateway id.
   * 
   * @param {ResizeGatewayParameters} parameters Parameters supplied to the
   * Resize Virtual Network Gateway operation.
   * 
   * @param {string} [parameters.gatewaySKU]
   * 
   * @param {UpdateGatewayOperation} [parameters.operation]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.resizeVirtualNetworkGateway = function(gatewayId, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.gateways.beginResizeVirtualNetworkGateway(gatewayId, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.gateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Set Virtual Network Gateway Shared Key operation sets the default
   * sites on the virtual network gateway for the specified virtual network.
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {GatewaySetDefaultSiteListParameters} parameters Parameters
   * supplied to the Begin Virtual Network Gateway Set Default Sites request.
   * 
   * @param {string} [parameters.defaultSite] The default local network site.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.setDefaultSites = function(networkName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.gateways.beginSetDefaultSites(networkName, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.gateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Begin Set Virtual Network Gateway IPsec Parameters operation sets the
   * IPsec parameters on the virtual network gateway for the specified
   * connection to the specified local network in Azure.
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {string} localNetworkName The name of the local network.
   * 
   * @param {GatewaySetIPsecParametersParameters} parameters Parameters
   * supplied to the Begin Virtual Network Gateway Set IPsec Parameters
   * request.
   * 
   * @param {IPsecParameters} [parameters.parameters]
   * 
   * @param {string} [parameters.parameters.encryptionType] The encryption type
   * that will be used on the connection.
   * 
   * @param {string} [parameters.parameters.pfsGroup] The PfsGroup type that
   * will be used on the connection.
   * 
   * @param {number} [parameters.parameters.sADataSizeKilobytes]
   * 
   * @param {number} [parameters.parameters.sALifeTimeSeconds]
   * 
   * @param {string} [parameters.parameters.hashAlgorithm]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.setIPsecParameters = function(networkName, localNetworkName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.gateways.beginSetIPsecParameters(networkName, localNetworkName, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.gateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Begin Set Virtual Network Gateway IPsec Parameters V2 operation sets
   * the IPsec parameters on the virtual network gateway connection.
   * 
   * @param {string} gatewayId The virtual network for this gateway Id.
   * 
   * @param {string} connectedentityId The connected entity Id.
   * 
   * @param {GatewaySetIPsecParametersParameters} parameters Parameters
   * supplied to the Begin Virtual Network Gateway Set IPsec Parameters V2
   * request.
   * 
   * @param {IPsecParameters} [parameters.parameters]
   * 
   * @param {string} [parameters.parameters.encryptionType] The encryption type
   * that will be used on the connection.
   * 
   * @param {string} [parameters.parameters.pfsGroup] The PfsGroup type that
   * will be used on the connection.
   * 
   * @param {number} [parameters.parameters.sADataSizeKilobytes]
   * 
   * @param {number} [parameters.parameters.sALifeTimeSeconds]
   * 
   * @param {string} [parameters.parameters.hashAlgorithm]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.setIPsecParametersV2 = function(gatewayId, connectedentityId, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.gateways.beginSetIPsecParametersV2(gatewayId, connectedentityId, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.gateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Set Virtual Network Gateway Shared Key operation sets the shared key
   * on the virtual network gateway for the specified virtual network
   * connection to the specified local network in Azure.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
   * more information)
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {string} localNetworkName The name of the local network.
   * 
   * @param {GatewaySetSharedKeyParameters} parameters The parameters to the
   * Virtual Network Gateway Set Shared Key request.
   * 
   * @param {string} [parameters.value] Contains the shared key used by the
   * gateway to authenticate connections to sites on a virtual network.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.setSharedKey = function(networkName, localNetworkName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.gateways.beginSetSharedKey(networkName, localNetworkName, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.gateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Set Virtual Network Gateway Shared Key V2 operation sets the shared
   * key used between the gateway and customer vpn for the specified site.
   * 
   * @param {string} gatewayId The virtual network for this gateway Id.
   * 
   * @param {string} connectedentityId The connected entity Id.
   * 
   * @param {GatewaySetSharedKeyParameters} parameters Parameters supplied to
   * Virtual Network Gateway Set Shared Key V2 request.
   * 
   * @param {string} [parameters.value] Contains the shared key used by the
   * gateway to authenticate connections to sites on a virtual network.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.setSharedKeyV2 = function(gatewayId, connectedentityId, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.gateways.beginSetSharedKeyV2(gatewayId, connectedentityId, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.gateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Start Diagnostics operation starts a diagnostics session for the
   * specified virtual network gateway in Azure.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154119.aspx for
   * more information)
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {StartGatewayPublicDiagnosticsParameters} parameters Parameters
   * supplied to the Start Diagnostics operation.
   * 
   * @param {string} [parameters.captureDurationInSeconds] The duration of the
   * capture in seconds (between 1 and 300)
   * 
   * @param {string} [parameters.containerName] The container name provided by
   * customer (optional)
   * 
   * @param {string} [parameters.customerStorageKey] The customer's storage
   * account key
   * 
   * @param {string} [parameters.customerStorageName] The customer's storage
   * account name
   * 
   * @param {UpdateGatewayPublicDiagnosticsOperation} [parameters.operation]
   * The update gateway diagnostics operation to perform on the gateway tenant
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.startDiagnostics = function(networkName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.gateways.beginStartDiagnostics(networkName, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.gateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Start Diagnostics V2 operation starts a diagnostics session for the
   * specified virtual network gateway.
   * 
   * @param {string} gatewayId The virtual network for this gateway Id.
   * 
   * @param {StartGatewayPublicDiagnosticsParameters} parameters Parameters
   * supplied to the Start Diagnostics V2 operation.
   * 
   * @param {string} [parameters.captureDurationInSeconds] The duration of the
   * capture in seconds (between 1 and 300)
   * 
   * @param {string} [parameters.containerName] The container name provided by
   * customer (optional)
   * 
   * @param {string} [parameters.customerStorageKey] The customer's storage
   * account key
   * 
   * @param {string} [parameters.customerStorageName] The customer's storage
   * account name
   * 
   * @param {UpdateGatewayPublicDiagnosticsOperation} [parameters.operation]
   * The update gateway diagnostics operation to perform on the gateway tenant
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.startDiagnosticsV2 = function(gatewayId, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.gateways.beginStartDiagnosticsV2(gatewayId, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.gateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Stop Diagnostics operation begins an asynchronous operation to stopa
   * diagnostics session for the specified virtual network gateway in Azure.
   * (see http://msdn.microsoft.com/en-us/library/windowsazure/jj154119.aspx
   * for more information)
   * 
   * @param {string} networkName The name of the virtual network for this
   * gateway.
   * 
   * @param {StopGatewayPublicDiagnosticsParameters} parameters Parameters
   * supplied to Stop Diagnostics operation.
   * 
   * @param {UpdateGatewayPublicDiagnosticsOperation} [parameters.operation]
   * The update gateway diagnostics operation to perform on the gateway tenant
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.stopDiagnostics = function(networkName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    url2 = url2 + '/gateway/publicdiagnostics';
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var updateGatewayPublicDiagnosticsElement = js2xml.createElement('UpdateGatewayPublicDiagnostics', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, updateGatewayPublicDiagnosticsElement);
    
    if (parameters.operation !== null && parameters.operation !== undefined) {
      var operationElement = js2xml.createElement('Operation', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(operationElement, 'StopDiagnostics');
      js2xml.addChildElement(updateGatewayPublicDiagnosticsElement, operationElement);
    }
    
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Stop Diagnostics V2 operation begins an asynchronous operation to
   * stopa diagnostics session for the specified virtual network gateway.
   * 
   * @param {string} gatewayId The virtual network for this gateway Id.
   * 
   * @param {StopGatewayPublicDiagnosticsParameters} parameters Parameters
   * supplied to Stop Diagnostics V2 operation.
   * 
   * @param {UpdateGatewayPublicDiagnosticsOperation} [parameters.operation]
   * The update gateway diagnostics operation to perform on the gateway tenant
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.stopDiagnosticsV2 = function(gatewayId, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayId === null || gatewayId === undefined) {
      return callback(new Error('gatewayId cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/virtualnetworkgateways/';
    url2 = url2 + encodeURIComponent(gatewayId);
    url2 = url2 + '/publicdiagnostics';
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var updateGatewayPublicDiagnosticsElement = js2xml.createElement('UpdateGatewayPublicDiagnostics', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, updateGatewayPublicDiagnosticsElement);
    
    if (parameters.operation !== null && parameters.operation !== undefined) {
      var operationElement = js2xml.createElement('Operation', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(operationElement, 'StopDiagnostics');
      js2xml.addChildElement(updateGatewayPublicDiagnosticsElement, operationElement);
    }
    
    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
      if (statusCode === 202) {
        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 gatewayOperationAsyncResponseElement = js2xml.getElement(responseDoc, responseDoc, 'GATEWAYOPERATIONASYNCRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (gatewayOperationAsyncResponseElement !== null && gatewayOperationAsyncResponseElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, gatewayOperationAsyncResponseElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.operationId = idInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Operation to update existing gateway connection.
   * 
   * @param {string} gatewayId The virtual network gateway Id.
   * 
   * @param {string} connectedentityId The connected entity Id.
   * 
   * @param {UpdateGatewayConnectionParameters} parameters Parameters supplied
   * to the Begin Update gateway conneciton operation.
   * 
   * @param {number} parameters.routingWeight The Routing Weight
   * 
   * @param {string} [parameters.sharedKey] Ipsec share key
   * 
   * @param {boolean} [parameters.enableBgp] Whether to establish a BGP session
   * over this connection
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.updateGatewayConnection = function(gatewayId, connectedentityId, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.gateways.beginUpdateGatewayConnection(gatewayId, connectedentityId, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.gateways.getOperationStatus(result.operationId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Successful') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Update Local Network Gateway operation updates a local network gateway
   * 
   * @param {string} gatewayId The virtual network for this gateway.
   * 
   * @param {UpdateLocalNetworkGatewayParameters} parameters Parameters
   * supplied to update the Local Network Gateway operation.
   * 
   * @param {IEnumerable} [parameters.addressSpace] Address space of local
   * network gateway
   * 
   * @param {BgpSettings} [parameters.bgpSettings] Local network gateway's BGP
   * speaker settings
   * 
   * @param {number} [parameters.bgpSettings.asn] Autonomous System Number
   * 
   * @param {string} [parameters.bgpSettings.bgpPeeringAddress] IP address/BGP
   * identifier
   * 
   * @param {number} [parameters.bgpSettings.peerWeight] Weight for routes
   * learned from this peer
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  GatewayOperations.prototype.updateLocalNetworkGateway = function(gatewayId, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (gatewayId === null || gatewayId === undefined) {
      return callback(new Error('gatewayId cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/localnetworkgateways/';
    url2 = url2 + encodeURIComponent(gatewayId);
    var queryParameters = [];
    queryParameters.push('api-version=2016-03-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 = 'PATCH';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var updateLocalNetworkGatewayParametersElement = js2xml.createElement('UpdateLocalNetworkGatewayParameters', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, updateLocalNetworkGatewayParametersElement);
    
    if (parameters.addressSpace !== null && parameters.addressSpace !== undefined) {
      var addressSpaceSequenceElement = js2xml.createElement('AddressSpace', 'http://schemas.microsoft.com/2003/10/Serialization/Arrays');
      for (var loweredIndex1 = 0; loweredIndex1 < parameters.addressSpace.length; loweredIndex1 = loweredIndex1 + 1) {
        var addressSpaceItem = parameters.addressSpace[loweredIndex1];
        var addressSpaceItemElement = js2xml.createElement('string', 'http://schemas.microsoft.com/2003/10/Serialization/Arrays');
        js2xml.setElementValue(addressSpaceItemElement, addressSpaceItem);
        js2xml.addChildElement(addressSpaceSequenceElement, addressSpaceItemElement);
      }
      js2xml.addChildElement(updateLocalNetworkGatewayParametersElement, addressSpaceSequenceElement);
    }
    
    if (parameters.bgpSettings !== null && parameters.bgpSettings !== undefined) {
      var bgpSettingsElement = js2xml.createElement('BgpSettings', 'http://schemas.microsoft.com/windowsazure');
      js2xml.addChildElement(updateLocalNetworkGatewayParametersElement, bgpSettingsElement);
      
      if (parameters.bgpSettings.asn !== null && parameters.bgpSettings.asn !== undefined) {
        var asnElement = js2xml.createElement('Asn', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(asnElement, parameters.bgpSettings.asn.toString());
        js2xml.addChildElement(bgpSettingsElement, asnElement);
      }
      
      if (parameters.bgpSettings.bgpPeeringAddress !== null && parameters.bgpSettings.bgpPeeringAddress !== undefined) {
        var bgpPeeringAddressElement = js2xml.createElement('BgpPeeringAddress', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(bgpPeeringAddressElement, parameters.bgpSettings.bgpPeeringAddress);
        js2xml.addChildElement(bgpSettingsElement, bgpPeeringAddressElement);
      }
      
      if (parameters.bgpSettings.peerWeight !== null && parameters.bgpSettings.peerWeight !== undefined) {
        var peerWeightElement = js2xml.createElement('PeerWeight', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(peerWeightElement, parameters.bgpSettings.peerWeight.toString());
        js2xml.addChildElement(bgpSettingsElement, peerWeightElement);
      }
    }
    
    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 !== 200) {
        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);
    });
  };
  
  return GatewayOperations;
})();

var IPForwardingOperations = ( /** @lends IPForwardingOperations */ function() {
  /**
   * @class
   * The Network Management API includes operations for managing the IP
   * Forwarding for your roles and network interfaces in your subscription.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [NetworkManagementClient] {@link
   * NetworkManagementClient~NetworkManagementClient}.
   * See [iPForwarding] {@link
   * NetworkManagementClient~NetworkManagementClient#iPForwarding}.
   * Initializes a new instance of the IPForwardingOperations class.
   * @constructor
   * 
   * @param {NetworkManagementClient} client Reference to the service client.
   */
  function IPForwardingOperations(client) {
    this.client = client;
  }
  
  /**
   * Sets IP Forwarding on a network interface.
   * 
   * @param {string} serviceName
   * 
   * @param {string} deploymentName
   * 
   * @param {string} roleName
   * 
   * @param {string} networkInterfaceName
   * 
   * @param {IPForwardingSetParameters} parameters Parameters supplied to the
   * Set IP Forwarding on network interface operation.
   * 
   * @param {string} parameters.state Gets or sets state of IPForwarding for a
   * role or network interface.Allowed values are "Enabled", "Disabled".
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  IPForwardingOperations.prototype.beginSettingIPForwardingOnNetworkInterface = function(serviceName, deploymentName, roleName, networkInterfaceName, 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.'));
    }
    if (deploymentName === null || deploymentName === undefined) {
      return callback(new Error('deploymentName cannot be null.'));
    }
    if (roleName === null || roleName === undefined) {
      return callback(new Error('roleName cannot be null.'));
    }
    if (networkInterfaceName === null || networkInterfaceName === undefined) {
      return callback(new Error('networkInterfaceName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.state === null || parameters.state === undefined) {
      return callback(new Error('parameters.state 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 + '/roles/';
    url2 = url2 + encodeURIComponent(roleName);
    url2 = url2 + '/networkinterfaces/';
    url2 = url2 + encodeURIComponent(networkInterfaceName);
    url2 = url2 + '/ipforwarding';
    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'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var iPForwardingElement = js2xml.createElement('IPForwarding', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, iPForwardingElement);
    
    var stateElement = js2xml.createElement('State', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(stateElement, parameters.state);
    js2xml.addChildElement(iPForwardingElement, stateElement);
    
    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);
    });
  };
  
  /**
   * Sets IP Forwarding on a role.
   * 
   * @param {string} serviceName
   * 
   * @param {string} deploymentName
   * 
   * @param {string} roleName
   * 
   * @param {IPForwardingSetParameters} parameters Parameters supplied to the
   * Set IP Forwarding on role operation.
   * 
   * @param {string} parameters.state Gets or sets state of IPForwarding for a
   * role or network interface.Allowed values are "Enabled", "Disabled".
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  IPForwardingOperations.prototype.beginSettingIPForwardingOnRole = function(serviceName, deploymentName, roleName, 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.'));
    }
    if (deploymentName === null || deploymentName === undefined) {
      return callback(new Error('deploymentName cannot be null.'));
    }
    if (roleName === null || roleName === undefined) {
      return callback(new Error('roleName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.state === null || parameters.state === undefined) {
      return callback(new Error('parameters.state 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 + '/roles/';
    url2 = url2 + encodeURIComponent(roleName);
    url2 = url2 + '/ipforwarding';
    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'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var iPForwardingElement = js2xml.createElement('IPForwarding', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, iPForwardingElement);
    
    var stateElement = js2xml.createElement('State', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(stateElement, parameters.state);
    js2xml.addChildElement(iPForwardingElement, stateElement);
    
    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);
    });
  };
  
  /**
   * Gets the IP Forwarding applied to a network interface.
   * 
   * @param {string} serviceName
   * 
   * @param {string} deploymentName
   * 
   * @param {string} roleName
   * 
   * @param {string} networkInterfaceName
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  IPForwardingOperations.prototype.getForNetworkInterface = function(serviceName, deploymentName, roleName, networkInterfaceName, 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.'));
    }
    if (deploymentName === null || deploymentName === undefined) {
      return callback(new Error('deploymentName cannot be null.'));
    }
    if (roleName === null || roleName === undefined) {
      return callback(new Error('roleName cannot be null.'));
    }
    if (networkInterfaceName === null || networkInterfaceName === undefined) {
      return callback(new Error('networkInterfaceName 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 + '/roles/';
    url2 = url2 + encodeURIComponent(roleName);
    url2 = url2 + '/networkinterfaces/';
    url2 = url2 + encodeURIComponent(networkInterfaceName);
    url2 = url2 + '/ipforwarding';
    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['x-ms-version'] = '2016-03-01';
    
    // 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 options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var iPForwardingElement = js2xml.getElement(responseDoc, responseDoc, 'IPFORWARDING', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (iPForwardingElement !== null && iPForwardingElement !== undefined) {
            var stateElement = js2xml.getElement(responseDoc, iPForwardingElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined) {
              var stateInstance = stateElement;
              result.state = stateInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Gets the IP Forwarding applied to a role.
   * 
   * @param {string} serviceName
   * 
   * @param {string} deploymentName
   * 
   * @param {string} roleName
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  IPForwardingOperations.prototype.getForRole = function(serviceName, deploymentName, roleName, 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.'));
    }
    if (deploymentName === null || deploymentName === undefined) {
      return callback(new Error('deploymentName cannot be null.'));
    }
    if (roleName === null || roleName === undefined) {
      return callback(new Error('roleName 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 + '/roles/';
    url2 = url2 + encodeURIComponent(roleName);
    url2 = url2 + '/ipforwarding';
    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['x-ms-version'] = '2016-03-01';
    
    // 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 options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var iPForwardingElement = js2xml.getElement(responseDoc, responseDoc, 'IPFORWARDING', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (iPForwardingElement !== null && iPForwardingElement !== undefined) {
            var stateElement = js2xml.getElement(responseDoc, iPForwardingElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined) {
              var stateInstance = stateElement;
              result.state = stateInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Sets IP Forwarding on a network interface.
   * 
   * @param {string} serviceName
   * 
   * @param {string} deploymentName
   * 
   * @param {string} roleName
   * 
   * @param {string} networkInterfaceName
   * 
   * @param {IPForwardingSetParameters} parameters Parameters supplied to the
   * Set IP Forwarding on network interface operation.
   * 
   * @param {string} parameters.state Gets or sets state of IPForwarding for a
   * role or network interface.Allowed values are "Enabled", "Disabled".
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  IPForwardingOperations.prototype.setOnNetworkInterface = function(serviceName, deploymentName, roleName, networkInterfaceName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.iPForwarding.beginSettingIPForwardingOnNetworkInterface(serviceName, deploymentName, roleName, networkInterfaceName, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      if (result.status === 'Succeeded') {
        return callback(null, result);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * Sets IP Forwarding on a role.
   * 
   * @param {string} serviceName
   * 
   * @param {string} deploymentName
   * 
   * @param {string} roleName
   * 
   * @param {IPForwardingSetParameters} parameters Parameters supplied to the
   * Set IP Forwarding on role operation.
   * 
   * @param {string} parameters.state Gets or sets state of IPForwarding for a
   * role or network interface.Allowed values are "Enabled", "Disabled".
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  IPForwardingOperations.prototype.setOnRole = function(serviceName, deploymentName, roleName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.iPForwarding.beginSettingIPForwardingOnRole(serviceName, deploymentName, roleName, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      if (result.status === 'Succeeded') {
        return callback(null, result);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  return IPForwardingOperations;
})();

var NetworkOperations = ( /** @lends NetworkOperations */ function() {
  /**
   * @class
   * The Network Management API includes operations for managing the virtual
   * networks for your subscription.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj157182.aspx for
   * more information)
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [NetworkManagementClient] {@link
   * NetworkManagementClient~NetworkManagementClient}.
   * See [networks] {@link
   * NetworkManagementClient~NetworkManagementClient#networks}.
   * Initializes a new instance of the NetworkOperations class.
   * @constructor
   * 
   * @param {NetworkManagementClient} client Reference to the service client.
   */
  function NetworkOperations(client) {
    this.client = client;
  }
  
  /**
   * Abort Virtual Network migration api validates and aborts the given virtual
   * network for IaaS Classic to ARM migration.
   * 
   * @param {string} virtualNetworkName Name of the Virtual Network to be
   * migrated.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkOperations.prototype.abortMigration = function(virtualNetworkName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.networks.beginAbortMigration(virtualNetworkName, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * Abort Virtual Network migration api validates and aborts the given virtual
   * network for IaaS Classic to ARM migration.
   * 
   * @param {string} virtualNetworkName Name of the Virtual Network to be
   * migrated.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkOperations.prototype.beginAbortMigration = function(virtualNetworkName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (virtualNetworkName === null || virtualNetworkName === undefined) {
      return callback(new Error('virtualNetworkName 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/networking/virtualnetwork/';
    url2 = url2 + encodeURIComponent(virtualNetworkName);
    url2 = url2 + '/migration';
    var queryParameters = [];
    queryParameters.push('comp=abort');
    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['x-ms-version'] = '2016-03-01';
    
    // 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);
    });
  };
  
  /**
   * Commit Virtual Network migration api validates and commits the given
   * virtual network for IaaS Classic to ARM migration.
   * 
   * @param {string} virtualNetworkName Name of the Virtual Network to be
   * migrated.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkOperations.prototype.beginCommitMigration = function(virtualNetworkName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (virtualNetworkName === null || virtualNetworkName === undefined) {
      return callback(new Error('virtualNetworkName 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/networking/virtualnetwork/';
    url2 = url2 + encodeURIComponent(virtualNetworkName);
    url2 = url2 + '/migration';
    var queryParameters = [];
    queryParameters.push('comp=commit');
    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['x-ms-version'] = '2016-03-01';
    
    // 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);
    });
  };
  
  /**
   * Prepare Virtual Network migration api validates and prepare the given
   * virtual network for IaaS Classic to ARM migration.
   * 
   * @param {string} virtualNetworkName Name of the Virtual Network to be
   * migrated.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkOperations.prototype.beginPrepareMigration = function(virtualNetworkName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (virtualNetworkName === null || virtualNetworkName === undefined) {
      return callback(new Error('virtualNetworkName 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/networking/virtualnetwork/';
    url2 = url2 + encodeURIComponent(virtualNetworkName);
    url2 = url2 + '/migration';
    var queryParameters = [];
    queryParameters.push('comp=prepare');
    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['x-ms-version'] = '2016-03-01';
    
    // 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 Setting Network Configuration operation asynchronously
   * configures the virtual network.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj157181.aspx for
   * more information)
   * 
   * @param {NetworkSetConfigurationParameters} parameters Parameters supplied
   * to the Set Network Configuration operation.
   * 
   * @param {string} parameters.configuration The network configuration for
   * this subscription.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkOperations.prototype.beginSettingConfiguration = function(parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    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.'));
    }
    
    // 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/networking/media';
    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/octet-stream';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = parameters.configuration;
    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);
    });
  };
  
  /**
   * Commit Virtual Network migration api validates and commits the given
   * virtual network for IaaS Classic to ARM migration.
   * 
   * @param {string} virtualNetworkName Name of the Virtual Network to be
   * migrated.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkOperations.prototype.commitMigration = function(virtualNetworkName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.networks.beginCommitMigration(virtualNetworkName, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Get Network Configuration operation retrieves the network
   * configuration file for the given subscription.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj157196.aspx for
   * more information)
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkOperations.prototype.getConfiguration = function(callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // 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/networking/media';
    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['x-ms-version'] = '2016-03-01';
    
    // 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 = {};
        result.configuration = responseContent;
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The List Virtual network sites operation retrieves the virtual networks
   * configured for the subscription.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj157185.aspx for
   * more information)
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkOperations.prototype.list = function(callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // 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/networking/virtualnetwork';
    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['x-ms-version'] = '2016-03-01';
    
    // 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 = { virtualNetworkSites: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var virtualNetworkSitesSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'VIRTUALNETWORKSITES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (virtualNetworkSitesSequenceElement !== null && virtualNetworkSitesSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, virtualNetworkSitesSequenceElement, 'VIRTUALNETWORKSITE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var virtualNetworkSitesElement = js2xml.getElements(responseDoc, virtualNetworkSitesSequenceElement, 'VIRTUALNETWORKSITE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var virtualNetworkSiteInstance = { dnsServers: [], subnets: [] };
              result.virtualNetworkSites.push(virtualNetworkSiteInstance);
              
              var nameElement = js2xml.getElement(responseDoc, virtualNetworkSitesElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (nameElement !== null && nameElement !== undefined) {
                var nameInstance = nameElement;
                virtualNetworkSiteInstance.name = nameInstance;
              }
              
              var labelElement = js2xml.getElement(responseDoc, virtualNetworkSitesElement, 'LABEL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (labelElement !== null && labelElement !== undefined) {
                var labelInstance = labelElement;
                virtualNetworkSiteInstance.label = labelInstance;
              }
              
              var idElement = js2xml.getElement(responseDoc, virtualNetworkSitesElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (idElement !== null && idElement !== undefined) {
                var idInstance = idElement;
                virtualNetworkSiteInstance.id = idInstance;
              }
              
              var affinityGroupElement = js2xml.getElement(responseDoc, virtualNetworkSitesElement, 'AFFINITYGROUP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (affinityGroupElement !== null && affinityGroupElement !== undefined) {
                var affinityGroupInstance = affinityGroupElement;
                virtualNetworkSiteInstance.affinityGroup = affinityGroupInstance;
              }
              
              var locationElement = js2xml.getElement(responseDoc, virtualNetworkSitesElement, 'LOCATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (locationElement !== null && locationElement !== undefined) {
                var locationInstance = locationElement;
                virtualNetworkSiteInstance.location = locationInstance;
              }
              
              var stateElement = js2xml.getElement(responseDoc, virtualNetworkSitesElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (stateElement !== null && stateElement !== undefined) {
                var stateInstance = stateElement;
                virtualNetworkSiteInstance.state = stateInstance;
              }
              
              var addressSpaceElement = js2xml.getElement(responseDoc, virtualNetworkSitesElement, 'ADDRESSSPACE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (addressSpaceElement !== null && addressSpaceElement !== undefined) {
                var addressSpaceInstance = { addressPrefixes: [] };
                virtualNetworkSiteInstance.addressSpace = addressSpaceInstance;
                
                var addressPrefixesSequenceElement = js2xml.getElement(responseDoc, addressSpaceElement, 'ADDRESSPREFIXES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (addressPrefixesSequenceElement !== null && addressPrefixesSequenceElement !== undefined) {
                  for (var loweredIndex2 = 0; loweredIndex2 < js2xml.getElements(responseDoc, addressPrefixesSequenceElement, 'ADDRESSPREFIX', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex2 = loweredIndex2 + 1) {
                    var addressPrefixesElement = js2xml.getElements(responseDoc, addressPrefixesSequenceElement, 'ADDRESSPREFIX', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex2];
                    addressSpaceInstance.addressPrefixes.push(addressPrefixesElement);
                  }
                }
              }
              
              var subnetsSequenceElement = js2xml.getElement(responseDoc, virtualNetworkSitesElement, 'SUBNETS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (subnetsSequenceElement !== null && subnetsSequenceElement !== undefined) {
                for (var loweredIndex3 = 0; loweredIndex3 < js2xml.getElements(responseDoc, subnetsSequenceElement, 'SUBNET', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex3 = loweredIndex3 + 1) {
                  var subnetsElement = js2xml.getElements(responseDoc, subnetsSequenceElement, 'SUBNET', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex3];
                  var subnetInstance = {};
                  virtualNetworkSiteInstance.subnets.push(subnetInstance);
                  
                  var nameElement2 = js2xml.getElement(responseDoc, subnetsElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (nameElement2 !== null && nameElement2 !== undefined) {
                    var nameInstance2 = nameElement2;
                    subnetInstance.name = nameInstance2;
                  }
                  
                  var addressPrefixElement = js2xml.getElement(responseDoc, subnetsElement, 'ADDRESSPREFIX', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (addressPrefixElement !== null && addressPrefixElement !== undefined) {
                    var addressPrefixInstance = addressPrefixElement;
                    subnetInstance.addressPrefix = addressPrefixInstance;
                  }
                  
                  var networkSecurityGroupElement = js2xml.getElement(responseDoc, subnetsElement, 'NETWORKSECURITYGROUP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (networkSecurityGroupElement !== null && networkSecurityGroupElement !== undefined) {
                    var networkSecurityGroupInstance = networkSecurityGroupElement;
                    subnetInstance.networkSecurityGroup = networkSecurityGroupInstance;
                  }
                }
              }
              
              var dnsElement = js2xml.getElement(responseDoc, virtualNetworkSitesElement, 'DNS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (dnsElement !== null && dnsElement !== undefined) {
                var dnsServersSequenceElement = js2xml.getElement(responseDoc, dnsElement, 'DNSSERVERS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (dnsServersSequenceElement !== null && dnsServersSequenceElement !== undefined) {
                  for (var loweredIndex4 = 0; loweredIndex4 < js2xml.getElements(responseDoc, dnsServersSequenceElement, 'DNSSERVER', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex4 = loweredIndex4 + 1) {
                    var dnsServersElement = js2xml.getElements(responseDoc, dnsServersSequenceElement, 'DNSSERVER', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex4];
                    var dnsServerInstance = {};
                    virtualNetworkSiteInstance.dnsServers.push(dnsServerInstance);
                    
                    var nameElement3 = js2xml.getElement(responseDoc, dnsServersElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                    if (nameElement3 !== null && nameElement3 !== undefined) {
                      var nameInstance3 = nameElement3;
                      dnsServerInstance.name = nameInstance3;
                    }
                    
                    var addressElement = js2xml.getElement(responseDoc, dnsServersElement, 'ADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                    if (addressElement !== null && addressElement !== undefined) {
                      var addressInstance = addressElement;
                      dnsServerInstance.address = addressInstance;
                    }
                  }
                }
              }
              
              var gatewayElement = js2xml.getElement(responseDoc, virtualNetworkSitesElement, 'GATEWAY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (gatewayElement !== null && gatewayElement !== undefined) {
                var gatewayInstance = { sites: [] };
                virtualNetworkSiteInstance.gateway = gatewayInstance;
                
                var profileElement = js2xml.getElement(responseDoc, gatewayElement, 'PROFILE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (profileElement !== null && profileElement !== undefined) {
                  var profileInstance = profileElement;
                  gatewayInstance.profile = profileInstance;
                }
                
                var sitesSequenceElement = js2xml.getElement(responseDoc, gatewayElement, 'SITES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (sitesSequenceElement !== null && sitesSequenceElement !== undefined) {
                  for (var loweredIndex5 = 0; loweredIndex5 < js2xml.getElements(responseDoc, sitesSequenceElement, 'LOCALNETWORKSITE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex5 = loweredIndex5 + 1) {
                    var sitesElement = js2xml.getElements(responseDoc, sitesSequenceElement, 'LOCALNETWORKSITE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex5];
                    var localNetworkSiteInstance = { connections: [] };
                    gatewayInstance.sites.push(localNetworkSiteInstance);
                    
                    var nameElement4 = js2xml.getElement(responseDoc, sitesElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                    if (nameElement4 !== null && nameElement4 !== undefined) {
                      var nameInstance4 = nameElement4;
                      localNetworkSiteInstance.name = nameInstance4;
                    }
                    
                    var vpnGatewayAddressElement = js2xml.getElement(responseDoc, sitesElement, 'VPNGATEWAYADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                    if (vpnGatewayAddressElement !== null && vpnGatewayAddressElement !== undefined) {
                      var vpnGatewayAddressInstance = vpnGatewayAddressElement;
                      localNetworkSiteInstance.vpnGatewayAddress = vpnGatewayAddressInstance;
                    }
                    
                    var addressSpaceElement2 = js2xml.getElement(responseDoc, sitesElement, 'ADDRESSSPACE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                    if (addressSpaceElement2 !== null && addressSpaceElement2 !== undefined) {
                      var addressSpaceInstance2 = { addressPrefixes: [] };
                      localNetworkSiteInstance.addressSpace = addressSpaceInstance2;
                      
                      var addressPrefixesSequenceElement2 = js2xml.getElement(responseDoc, addressSpaceElement2, 'ADDRESSPREFIXES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                      if (addressPrefixesSequenceElement2 !== null && addressPrefixesSequenceElement2 !== undefined) {
                        for (var loweredIndex6 = 0; loweredIndex6 < js2xml.getElements(responseDoc, addressPrefixesSequenceElement2, 'ADDRESSPREFIX', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex6 = loweredIndex6 + 1) {
                          var addressPrefixesElement2 = js2xml.getElements(responseDoc, addressPrefixesSequenceElement2, 'ADDRESSPREFIX', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex6];
                          addressSpaceInstance2.addressPrefixes.push(addressPrefixesElement2);
                        }
                      }
                    }
                    
                    var connectionsSequenceElement = js2xml.getElement(responseDoc, sitesElement, 'CONNECTIONS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                    if (connectionsSequenceElement !== null && connectionsSequenceElement !== undefined) {
                      for (var loweredIndex7 = 0; loweredIndex7 < js2xml.getElements(responseDoc, connectionsSequenceElement, 'CONNECTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex7 = loweredIndex7 + 1) {
                        var connectionsElement = js2xml.getElements(responseDoc, connectionsSequenceElement, 'CONNECTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex7];
                        var connectionInstance = {};
                        localNetworkSiteInstance.connections.push(connectionInstance);
                        
                        var typeElement = js2xml.getElement(responseDoc, connectionsElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                        if (typeElement !== null && typeElement !== undefined) {
                          var typeInstance = typeElement;
                          connectionInstance.type = typeInstance;
                        }
                      }
                    }
                  }
                }
                
                var vPNClientAddressPoolElement = js2xml.getElement(responseDoc, gatewayElement, 'VPNCLIENTADDRESSPOOL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (vPNClientAddressPoolElement !== null && vPNClientAddressPoolElement !== undefined) {
                  var vPNClientAddressPoolInstance = { addressPrefixes: [] };
                  gatewayInstance.vPNClientAddressPool = vPNClientAddressPoolInstance;
                  
                  var addressPrefixesSequenceElement3 = js2xml.getElement(responseDoc, vPNClientAddressPoolElement, 'ADDRESSPREFIXES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (addressPrefixesSequenceElement3 !== null && addressPrefixesSequenceElement3 !== undefined) {
                    for (var loweredIndex8 = 0; loweredIndex8 < js2xml.getElements(responseDoc, addressPrefixesSequenceElement3, 'ADDRESSPREFIX', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex8 = loweredIndex8 + 1) {
                      var addressPrefixesElement3 = js2xml.getElements(responseDoc, addressPrefixesSequenceElement3, 'ADDRESSPREFIX', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex8];
                      vPNClientAddressPoolInstance.addressPrefixes.push(addressPrefixesElement3);
                    }
                  }
                }
              }
              
              var migrationStateElement = js2xml.getElement(responseDoc, virtualNetworkSitesElement, 'MIGRATIONSTATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (migrationStateElement !== null && migrationStateElement !== undefined) {
                var migrationStateInstance = migrationStateElement;
                virtualNetworkSiteInstance.migrationState = migrationStateInstance;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Prepare Virtual Network migration api validates and prepare the given
   * virtual network for IaaS Classic to ARM migration.
   * 
   * @param {string} virtualNetworkName Name of the Virtual Network to be
   * migrated.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkOperations.prototype.prepareMigration = function(virtualNetworkName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.networks.beginPrepareMigration(virtualNetworkName, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Set Network Configuration operation asynchronously configures the
   * virtual network.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj157181.aspx for
   * more information)
   * 
   * @param {NetworkSetConfigurationParameters} parameters Parameters supplied
   * to the Set Network Configuration operation.
   * 
   * @param {string} parameters.configuration The network configuration for
   * this subscription.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkOperations.prototype.setConfiguration = function(parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.networks.beginSettingConfiguration(parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * Prepare Virtual Network migration api validates the given virtual network
   * for IaaS Classic to ARM migration.
   * 
   * @param {string} virtualNetworkName Name of the Virtual Network to be
   * migrated.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkOperations.prototype.validateMigration = function(virtualNetworkName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (virtualNetworkName === null || virtualNetworkName === undefined) {
      return callback(new Error('virtualNetworkName 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/networking/virtualnetwork/';
    url2 = url2 + encodeURIComponent(virtualNetworkName);
    url2 = url2 + '/migration';
    var queryParameters = [];
    queryParameters.push('comp=validate');
    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['x-ms-version'] = '2016-03-01';
    
    // 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 = { validateVirtualNetworkMessages: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var validationMessagesSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'VALIDATIONMESSAGES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (validationMessagesSequenceElement !== null && validationMessagesSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, validationMessagesSequenceElement, 'VALIDATIONMESSAGE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var validationMessagesElement = js2xml.getElements(responseDoc, validationMessagesSequenceElement, 'VALIDATIONMESSAGE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var validationMessageInstance = {};
              result.validateVirtualNetworkMessages.push(validationMessageInstance);
              
              var resourceTypeElement = js2xml.getElement(responseDoc, validationMessagesElement, 'RESOURCETYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (resourceTypeElement !== null && resourceTypeElement !== undefined) {
                var resourceTypeInstance = resourceTypeElement;
                validationMessageInstance.resourceType = resourceTypeInstance;
              }
              
              var resourceNameElement = js2xml.getElement(responseDoc, validationMessagesElement, 'RESOURCENAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (resourceNameElement !== null && resourceNameElement !== undefined) {
                var resourceNameInstance = resourceNameElement;
                validationMessageInstance.resourceName = resourceNameInstance;
              }
              
              var categoryElement = js2xml.getElement(responseDoc, validationMessagesElement, 'CATEGORY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (categoryElement !== null && categoryElement !== undefined) {
                var categoryInstance = categoryElement;
                validationMessageInstance.category = categoryInstance;
              }
              
              var messageElement = js2xml.getElement(responseDoc, validationMessagesElement, 'MESSAGE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (messageElement !== null && messageElement !== undefined) {
                var messageInstance = messageElement;
                validationMessageInstance.message = messageInstance;
              }
              
              var virtualMachineElement = js2xml.getElement(responseDoc, validationMessagesElement, 'VIRTUALMACHINE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (virtualMachineElement !== null && virtualMachineElement !== undefined) {
                var virtualMachineInstance = virtualMachineElement;
                validationMessageInstance.virtualMachineName = virtualMachineInstance;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return NetworkOperations;
})();

var NetworkSecurityGroupOperations = ( /** @lends NetworkSecurityGroupOperations */ function() {
  /**
   * @class
   * The Network Management API includes operations for managing the Network
   * Security Groups for your subscription.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [NetworkManagementClient] {@link
   * NetworkManagementClient~NetworkManagementClient}.
   * See [networkSecurityGroups] {@link
   * NetworkManagementClient~NetworkManagementClient#networkSecurityGroups}.
   * Initializes a new instance of the NetworkSecurityGroupOperations class.
   * @constructor
   * 
   * @param {NetworkManagementClient} client Reference to the service client.
   */
  function NetworkSecurityGroupOperations(client) {
    this.client = client;
  }
  
  /**
   * Adds a Network Security Group to a network interface.
   * 
   * @param {string} serviceName
   * 
   * @param {string} deploymentName
   * 
   * @param {string} roleName
   * 
   * @param {string} networkInterfaceName
   * 
   * @param {NetworkSecurityGroupAddAssociationParameters} parameters
   * Parameters supplied to the Add Network Security Group to a network
   * interface operation.
   * 
   * @param {string} parameters.name Gets or sets name for a Network Security
   * Group from this subscription.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkSecurityGroupOperations.prototype.addToNetworkInterface = function(serviceName, deploymentName, roleName, networkInterfaceName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.networkSecurityGroups.beginAddingToNetworkInterface(serviceName, deploymentName, roleName, networkInterfaceName, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      if (result.status === 'Succeeded') {
        return callback(null, result);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * Adds a Network Security Group to a Role.
   * 
   * @param {string} serviceName
   * 
   * @param {string} deploymentName
   * 
   * @param {string} roleName
   * 
   * @param {NetworkSecurityGroupAddAssociationParameters} parameters
   * Parameters supplied to the Add Network Security Group to Role operation.
   * 
   * @param {string} parameters.name Gets or sets name for a Network Security
   * Group from this subscription.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkSecurityGroupOperations.prototype.addToRole = function(serviceName, deploymentName, roleName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.networkSecurityGroups.beginAddingToRole(serviceName, deploymentName, roleName, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      if (result.status === 'Succeeded') {
        return callback(null, result);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * Adds a Network Security Group to a subnet.
   * 
   * @param {string} virtualNetworkName
   * 
   * @param {string} subnetName
   * 
   * @param {NetworkSecurityGroupAddAssociationParameters} parameters
   * Parameters supplied to the Add Network Security Group to subnet operation.
   * 
   * @param {string} parameters.name Gets or sets name for a Network Security
   * Group from this subscription.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkSecurityGroupOperations.prototype.addToSubnet = function(virtualNetworkName, subnetName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.networkSecurityGroups.beginAddingToSubnet(virtualNetworkName, subnetName, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      if (result.status === 'Succeeded') {
        return callback(null, result);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * Adds a Network Security Group to a network interface.
   * 
   * @param {string} serviceName
   * 
   * @param {string} deploymentName
   * 
   * @param {string} roleName
   * 
   * @param {string} networkInterfaceName
   * 
   * @param {NetworkSecurityGroupAddAssociationParameters} parameters
   * Parameters supplied to the Add Network Security Group to a network
   * interface operation.
   * 
   * @param {string} parameters.name Gets or sets name for a Network Security
   * Group from this subscription.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkSecurityGroupOperations.prototype.beginAddingToNetworkInterface = function(serviceName, deploymentName, roleName, networkInterfaceName, 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.'));
    }
    if (deploymentName === null || deploymentName === undefined) {
      return callback(new Error('deploymentName cannot be null.'));
    }
    if (roleName === null || roleName === undefined) {
      return callback(new Error('roleName cannot be null.'));
    }
    if (networkInterfaceName === null || networkInterfaceName === undefined) {
      return callback(new Error('networkInterfaceName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.name === null || parameters.name === undefined) {
      return callback(new Error('parameters.name 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 + '/roles/';
    url2 = url2 + encodeURIComponent(roleName);
    url2 = url2 + '/networkinterfaces/';
    url2 = url2 + encodeURIComponent(networkInterfaceName);
    url2 = url2 + '/networksecuritygroups';
    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'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var networkSecurityGroupElement = js2xml.createElement('NetworkSecurityGroup', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, networkSecurityGroupElement);
    
    var nameElement = js2xml.createElement('Name', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(nameElement, parameters.name);
    js2xml.addChildElement(networkSecurityGroupElement, nameElement);
    
    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);
    });
  };
  
  /**
   * Adds a Network Security Group to a Role.
   * 
   * @param {string} serviceName
   * 
   * @param {string} deploymentName
   * 
   * @param {string} roleName
   * 
   * @param {NetworkSecurityGroupAddAssociationParameters} parameters
   * Parameters supplied to the Add Network Security Group to Role operation.
   * 
   * @param {string} parameters.name Gets or sets name for a Network Security
   * Group from this subscription.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkSecurityGroupOperations.prototype.beginAddingToRole = function(serviceName, deploymentName, roleName, 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.'));
    }
    if (deploymentName === null || deploymentName === undefined) {
      return callback(new Error('deploymentName cannot be null.'));
    }
    if (roleName === null || roleName === undefined) {
      return callback(new Error('roleName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.name === null || parameters.name === undefined) {
      return callback(new Error('parameters.name 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 + '/roles/';
    url2 = url2 + encodeURIComponent(roleName);
    url2 = url2 + '/networksecuritygroups';
    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'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var networkSecurityGroupElement = js2xml.createElement('NetworkSecurityGroup', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, networkSecurityGroupElement);
    
    var nameElement = js2xml.createElement('Name', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(nameElement, parameters.name);
    js2xml.addChildElement(networkSecurityGroupElement, nameElement);
    
    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);
    });
  };
  
  /**
   * Adds a Network Security Group to a subnet.
   * 
   * @param {string} virtualNetworkName
   * 
   * @param {string} subnetName
   * 
   * @param {NetworkSecurityGroupAddAssociationParameters} parameters
   * Parameters supplied to the Add Network Security Group to subnet operation.
   * 
   * @param {string} parameters.name Gets or sets name for a Network Security
   * Group from this subscription.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkSecurityGroupOperations.prototype.beginAddingToSubnet = function(virtualNetworkName, subnetName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (virtualNetworkName === null || virtualNetworkName === undefined) {
      return callback(new Error('virtualNetworkName cannot be null.'));
    }
    if (subnetName === null || subnetName === undefined) {
      return callback(new Error('subnetName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.name === null || parameters.name === undefined) {
      return callback(new Error('parameters.name 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/networking/virtualnetwork/';
    url2 = url2 + encodeURIComponent(virtualNetworkName);
    url2 = url2 + '/subnets/';
    url2 = url2 + encodeURIComponent(subnetName);
    url2 = url2 + '/networksecuritygroups';
    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'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var networkSecurityGroupElement = js2xml.createElement('NetworkSecurityGroup', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, networkSecurityGroupElement);
    
    var nameElement = js2xml.createElement('Name', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(nameElement, parameters.name);
    js2xml.addChildElement(networkSecurityGroupElement, nameElement);
    
    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);
    });
  };
  
  /**
   * Creates a new Network Security Group.
   * 
   * @param {NetworkSecurityGroupCreateParameters} parameters Parameters
   * supplied to the Create Network Security Group operation.
   * 
   * @param {string} parameters.name Gets or sets name for the Network Security
   * Group that is unique to the subscription.
   * 
   * @param {string} [parameters.label] Gets or sets description for the
   * Network Security Group. The description can be up to 1024 characters in
   * length.
   * 
   * @param {string} parameters.location Gets or sets the data center location
   * where the Network Security Group will be created.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkSecurityGroupOperations.prototype.beginCreating = function(parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.location === null || parameters.location === undefined) {
      return callback(new Error('parameters.location cannot be null.'));
    }
    if (parameters.name === null || parameters.name === undefined) {
      return callback(new Error('parameters.name 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/networking/networksecuritygroups';
    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'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var networkSecurityGroupElement = js2xml.createElement('NetworkSecurityGroup', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, networkSecurityGroupElement);
    
    var nameElement = js2xml.createElement('Name', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(nameElement, parameters.name);
    js2xml.addChildElement(networkSecurityGroupElement, nameElement);
    
    if (parameters.label !== null && parameters.label !== undefined) {
      var labelElement = js2xml.createElement('Label', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(labelElement, parameters.label);
      js2xml.addChildElement(networkSecurityGroupElement, labelElement);
    }
    
    var locationElement = js2xml.createElement('Location', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(locationElement, parameters.location);
    js2xml.addChildElement(networkSecurityGroupElement, locationElement);
    
    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);
    });
  };
  
  /**
   * Deletes the pecified Network Security Group from your subscription.If the
   * Network Security group is still associated with some VM/Role/Subnet, the
   * deletion will fail. In order to successfully delete the Network Security,
   * it needs to be not used.
   * 
   * @param {string} networkSecurityGroupName The name of the Network Security
   * Group to delete.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkSecurityGroupOperations.prototype.beginDeleting = function(networkSecurityGroupName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkSecurityGroupName === null || networkSecurityGroupName === undefined) {
      return callback(new Error('networkSecurityGroupName 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/networking/networksecuritygroups/';
    url2 = url2 + encodeURIComponent(networkSecurityGroupName);
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // 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);
    });
  };
  
  /**
   * Deletes a rule from the specified Network Security Group.
   * 
   * @param {string} networkSecurityGroupName The name of the Network Security
   * Group.
   * 
   * @param {string} ruleName The name of the rule to delete.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkSecurityGroupOperations.prototype.beginDeletingRule = function(networkSecurityGroupName, ruleName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkSecurityGroupName === null || networkSecurityGroupName === undefined) {
      return callback(new Error('networkSecurityGroupName cannot be null.'));
    }
    if (ruleName === null || ruleName === undefined) {
      return callback(new Error('ruleName 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/networking/networksecuritygroups/';
    url2 = url2 + encodeURIComponent(networkSecurityGroupName);
    url2 = url2 + '/rules/';
    url2 = url2 + encodeURIComponent(ruleName);
    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['x-ms-version'] = '2016-03-01';
    
    // 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);
    });
  };
  
  /**
   * Removes a Network Security Group from a network interface.
   * 
   * @param {string} serviceName
   * 
   * @param {string} deploymentName
   * 
   * @param {string} roleName
   * 
   * @param {string} networkInterfaceName
   * 
   * @param {string} networkSecurityGroupName
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkSecurityGroupOperations.prototype.beginRemovingFromNetworkInterface = function(serviceName, deploymentName, roleName, networkInterfaceName, networkSecurityGroupName, 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.'));
    }
    if (deploymentName === null || deploymentName === undefined) {
      return callback(new Error('deploymentName cannot be null.'));
    }
    if (roleName === null || roleName === undefined) {
      return callback(new Error('roleName cannot be null.'));
    }
    if (networkInterfaceName === null || networkInterfaceName === undefined) {
      return callback(new Error('networkInterfaceName cannot be null.'));
    }
    if (networkSecurityGroupName === null || networkSecurityGroupName === undefined) {
      return callback(new Error('networkSecurityGroupName 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 + '/roles/';
    url2 = url2 + encodeURIComponent(roleName);
    url2 = url2 + '/networkinterfaces/';
    url2 = url2 + encodeURIComponent(networkInterfaceName);
    url2 = url2 + '/networksecuritygroups/';
    url2 = url2 + encodeURIComponent(networkSecurityGroupName);
    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['x-ms-version'] = '2016-03-01';
    
    // 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);
    });
  };
  
  /**
   * Removes a Network Security Group from a role.
   * 
   * @param {string} serviceName
   * 
   * @param {string} deploymentName
   * 
   * @param {string} roleName
   * 
   * @param {string} networkSecurityGroupName
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkSecurityGroupOperations.prototype.beginRemovingFromRole = function(serviceName, deploymentName, roleName, networkSecurityGroupName, 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.'));
    }
    if (deploymentName === null || deploymentName === undefined) {
      return callback(new Error('deploymentName cannot be null.'));
    }
    if (roleName === null || roleName === undefined) {
      return callback(new Error('roleName cannot be null.'));
    }
    if (networkSecurityGroupName === null || networkSecurityGroupName === undefined) {
      return callback(new Error('networkSecurityGroupName 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 + '/roles/';
    url2 = url2 + encodeURIComponent(roleName);
    url2 = url2 + '/networksecuritygroups/';
    url2 = url2 + encodeURIComponent(networkSecurityGroupName);
    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['x-ms-version'] = '2016-03-01';
    
    // 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);
    });
  };
  
  /**
   * Removes a Network Security Group from a subnet.
   * 
   * @param {string} virtualNetworkName
   * 
   * @param {string} subnetName
   * 
   * @param {string} networkSecurityGroupName
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkSecurityGroupOperations.prototype.beginRemovingFromSubnet = function(virtualNetworkName, subnetName, networkSecurityGroupName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (virtualNetworkName === null || virtualNetworkName === undefined) {
      return callback(new Error('virtualNetworkName cannot be null.'));
    }
    if (subnetName === null || subnetName === undefined) {
      return callback(new Error('subnetName cannot be null.'));
    }
    if (networkSecurityGroupName === null || networkSecurityGroupName === undefined) {
      return callback(new Error('networkSecurityGroupName 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/networking/virtualnetwork/';
    url2 = url2 + encodeURIComponent(virtualNetworkName);
    url2 = url2 + '/subnets/';
    url2 = url2 + encodeURIComponent(subnetName);
    url2 = url2 + '/networksecuritygroups/';
    url2 = url2 + encodeURIComponent(networkSecurityGroupName);
    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['x-ms-version'] = '2016-03-01';
    
    // 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);
    });
  };
  
  /**
   * Sets a new Network Security Rule to existing Network Security Group.
   * 
   * @param {string} [networkSecurityGroupName]
   * 
   * @param {string} [ruleName]
   * 
   * @param {NetworkSecuritySetRuleParameters} parameters Parameters supplied
   * to the Set Network Security Rule operation.
   * 
   * @param {string} parameters.type Gets or sets type of Rule. Possible
   * values: Inbound (to be evaluated against ingress traffic), Outbound (to
   * be evaluated against egress traffic).
   * 
   * @param {number} parameters.priority Gets or sets Priority. Value from 100
   * – 4096.
   * 
   * @param {string} parameters.action Gets or sets Action. Allow/Deny. Whether
   * to allow or deny traffic.
   * 
   * @param {string} parameters.sourceAddressPrefix Gets or sets
   * SourceAddressPrefix. CIDR value of Source IP from which traffic is
   * coming. You can specify star (*) to map all traffic or one of pre-defined
   * TAGs
   * 
   * @param {string} parameters.sourcePortRange Gets or sets Source Port
   * (single port) or Source Port Range (separated by “-“) or star (*) for all
   * ports. All numbers are inclusive. Example: 80, 80-80, 80-81, *
   * 
   * @param {string} parameters.destinationAddressPrefix Gets or sets
   * DestinationAddressPrefix. CIDR value of Destination IP from which traffic
   * is coming. You can specify star (*) to map all traffic or one of
   * pre-defined TAGs.
   * 
   * @param {string} parameters.destinationPortRange Gets or sets destination
   * Port (single port) or Destination Port Range (separated by “-“) or star
   * (*) for all ports. All numbers are inclusive. Example: 80, 80-80, 80-81, *
   * 
   * @param {string} parameters.protocol Gets or sets Protocol. TCP, UDP, *.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkSecurityGroupOperations.prototype.beginSettingRule = function(networkSecurityGroupName, ruleName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.action === null || parameters.action === undefined) {
      return callback(new Error('parameters.action cannot be null.'));
    }
    if (parameters.destinationAddressPrefix === null || parameters.destinationAddressPrefix === undefined) {
      return callback(new Error('parameters.destinationAddressPrefix cannot be null.'));
    }
    if (parameters.destinationPortRange === null || parameters.destinationPortRange === undefined) {
      return callback(new Error('parameters.destinationPortRange cannot be null.'));
    }
    if (parameters.priority === null || parameters.priority === undefined) {
      return callback(new Error('parameters.priority cannot be null.'));
    }
    if (parameters.protocol === null || parameters.protocol === undefined) {
      return callback(new Error('parameters.protocol cannot be null.'));
    }
    if (parameters.sourceAddressPrefix === null || parameters.sourceAddressPrefix === undefined) {
      return callback(new Error('parameters.sourceAddressPrefix cannot be null.'));
    }
    if (parameters.sourcePortRange === null || parameters.sourcePortRange === undefined) {
      return callback(new Error('parameters.sourcePortRange cannot be null.'));
    }
    if (parameters.type === null || parameters.type === undefined) {
      return callback(new Error('parameters.type 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/networking/networksecuritygroups/';
    if (networkSecurityGroupName !== null && networkSecurityGroupName !== undefined) {
      url2 = url2 + encodeURIComponent(networkSecurityGroupName);
    }
    url2 = url2 + '/rules/';
    if (ruleName !== null && ruleName !== undefined) {
      url2 = url2 + encodeURIComponent(ruleName);
    }
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var ruleElement = js2xml.createElement('Rule', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, ruleElement);
    
    var typeElement = js2xml.createElement('Type', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(typeElement, parameters.type);
    js2xml.addChildElement(ruleElement, typeElement);
    
    var priorityElement = js2xml.createElement('Priority', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(priorityElement, parameters.priority.toString());
    js2xml.addChildElement(ruleElement, priorityElement);
    
    var actionElement = js2xml.createElement('Action', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(actionElement, parameters.action);
    js2xml.addChildElement(ruleElement, actionElement);
    
    var sourceAddressPrefixElement = js2xml.createElement('SourceAddressPrefix', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(sourceAddressPrefixElement, parameters.sourceAddressPrefix);
    js2xml.addChildElement(ruleElement, sourceAddressPrefixElement);
    
    var sourcePortRangeElement = js2xml.createElement('SourcePortRange', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(sourcePortRangeElement, parameters.sourcePortRange);
    js2xml.addChildElement(ruleElement, sourcePortRangeElement);
    
    var destinationAddressPrefixElement = js2xml.createElement('DestinationAddressPrefix', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(destinationAddressPrefixElement, parameters.destinationAddressPrefix);
    js2xml.addChildElement(ruleElement, destinationAddressPrefixElement);
    
    var destinationPortRangeElement = js2xml.createElement('DestinationPortRange', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(destinationPortRangeElement, parameters.destinationPortRange);
    js2xml.addChildElement(ruleElement, destinationPortRangeElement);
    
    var protocolElement = js2xml.createElement('Protocol', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(protocolElement, parameters.protocol);
    js2xml.addChildElement(ruleElement, protocolElement);
    
    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);
    });
  };
  
  /**
   * Creates a new Network Security Group.
   * 
   * @param {NetworkSecurityGroupCreateParameters} parameters Parameters
   * supplied to the Create Network Security Group operation.
   * 
   * @param {string} parameters.name Gets or sets name for the Network Security
   * Group that is unique to the subscription.
   * 
   * @param {string} [parameters.label] Gets or sets description for the
   * Network Security Group. The description can be up to 1024 characters in
   * length.
   * 
   * @param {string} parameters.location Gets or sets the data center location
   * where the Network Security Group will be created.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkSecurityGroupOperations.prototype.create = function(parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.networkSecurityGroups.beginCreating(parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      if (result.status === 'Succeeded') {
        return callback(null, result);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Delete Network Security Group operation removes thespecified Network
   * Security Group from your subscription.If the Network Security group is
   * still associated with some VM/Role/Subnet, the deletion will fail. In
   * order to successfully delete the Network Security, it needs to be not
   * used.
   * 
   * @param {string} networkSecurityGroupName The name of the Network Security
   * Group to delete.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkSecurityGroupOperations.prototype.deleteMethod = function(networkSecurityGroupName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.networkSecurityGroups.beginDeleting(networkSecurityGroupName, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      if (result.status === 'Succeeded') {
        return callback(null, result);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Delete Network Security Rule operation removes a rule from the
   * specified Network Security Group.
   * 
   * @param {string} networkSecurityGroupName The name of the Network Security
   * Group.
   * 
   * @param {string} ruleName The name of the rule to delete.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkSecurityGroupOperations.prototype.deleteRule = function(networkSecurityGroupName, ruleName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.networkSecurityGroups.beginDeletingRule(networkSecurityGroupName, ruleName, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      if (result.status === 'Succeeded') {
        return callback(null, result);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * Gets the details for the specified Network Security Group in the
   * subscription.
   * 
   * @param {string} networkSecurityGroupName The name of the Network Security
   * Group to retrieve.
   * 
   * @param {string} [detailLevel] Use 'Full' to list rules.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkSecurityGroupOperations.prototype.get = function(networkSecurityGroupName, detailLevel, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkSecurityGroupName === null || networkSecurityGroupName === undefined) {
      return callback(new Error('networkSecurityGroupName 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/networking/networksecuritygroups/';
    url2 = url2 + encodeURIComponent(networkSecurityGroupName);
    var queryParameters = [];
    if (detailLevel !== null && detailLevel !== undefined) {
      queryParameters.push('detaillevel=' + encodeURIComponent(detailLevel));
    }
    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['x-ms-version'] = '2016-03-01';
    
    // 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 = { rules: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var networkSecurityGroupElement = js2xml.getElement(responseDoc, responseDoc, 'NETWORKSECURITYGROUP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (networkSecurityGroupElement !== null && networkSecurityGroupElement !== undefined) {
            var nameElement = js2xml.getElement(responseDoc, networkSecurityGroupElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement !== null && nameElement !== undefined) {
              var nameInstance = nameElement;
              result.name = nameInstance;
            }
            
            var labelElement = js2xml.getElement(responseDoc, networkSecurityGroupElement, 'LABEL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (labelElement !== null && labelElement !== undefined) {
              var labelInstance = labelElement;
              result.label = labelInstance;
            }
            
            var locationElement = js2xml.getElement(responseDoc, networkSecurityGroupElement, 'LOCATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (locationElement !== null && locationElement !== undefined) {
              var locationInstance = locationElement;
              result.location = locationInstance;
            }
            
            var rulesSequenceElement = js2xml.getElement(responseDoc, networkSecurityGroupElement, 'RULES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (rulesSequenceElement !== null && rulesSequenceElement !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, rulesSequenceElement, 'RULE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
                var rulesElement = js2xml.getElements(responseDoc, rulesSequenceElement, 'RULE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
                var ruleInstance = {};
                result.rules.push(ruleInstance);
                
                var nameElement2 = js2xml.getElement(responseDoc, rulesElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (nameElement2 !== null && nameElement2 !== undefined) {
                  var nameInstance2 = nameElement2;
                  ruleInstance.name = nameInstance2;
                }
                
                var typeElement = js2xml.getElement(responseDoc, rulesElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (typeElement !== null && typeElement !== undefined) {
                  var typeInstance = typeElement;
                  ruleInstance.type = typeInstance;
                }
                
                var priorityElement = js2xml.getElement(responseDoc, rulesElement, 'PRIORITY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (priorityElement !== null && priorityElement !== undefined && priorityElement.length !== 0) {
                  var priorityInstance = parseInt(priorityElement, 10);
                  ruleInstance.priority = priorityInstance;
                }
                
                var actionElement = js2xml.getElement(responseDoc, rulesElement, 'ACTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (actionElement !== null && actionElement !== undefined) {
                  var actionInstance = actionElement;
                  ruleInstance.action = actionInstance;
                }
                
                var sourceAddressPrefixElement = js2xml.getElement(responseDoc, rulesElement, 'SOURCEADDRESSPREFIX', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (sourceAddressPrefixElement !== null && sourceAddressPrefixElement !== undefined) {
                  var sourceAddressPrefixInstance = sourceAddressPrefixElement;
                  ruleInstance.sourceAddressPrefix = sourceAddressPrefixInstance;
                }
                
                var sourcePortRangeElement = js2xml.getElement(responseDoc, rulesElement, 'SOURCEPORTRANGE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (sourcePortRangeElement !== null && sourcePortRangeElement !== undefined) {
                  var sourcePortRangeInstance = sourcePortRangeElement;
                  ruleInstance.sourcePortRange = sourcePortRangeInstance;
                }
                
                var destinationAddressPrefixElement = js2xml.getElement(responseDoc, rulesElement, 'DESTINATIONADDRESSPREFIX', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (destinationAddressPrefixElement !== null && destinationAddressPrefixElement !== undefined) {
                  var destinationAddressPrefixInstance = destinationAddressPrefixElement;
                  ruleInstance.destinationAddressPrefix = destinationAddressPrefixInstance;
                }
                
                var destinationPortRangeElement = js2xml.getElement(responseDoc, rulesElement, 'DESTINATIONPORTRANGE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (destinationPortRangeElement !== null && destinationPortRangeElement !== undefined) {
                  var destinationPortRangeInstance = destinationPortRangeElement;
                  ruleInstance.destinationPortRange = destinationPortRangeInstance;
                }
                
                var protocolElement = js2xml.getElement(responseDoc, rulesElement, 'PROTOCOL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (protocolElement !== null && protocolElement !== undefined) {
                  var protocolInstance = protocolElement;
                  ruleInstance.protocol = protocolInstance;
                }
                
                var stateElement = js2xml.getElement(responseDoc, rulesElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (stateElement !== null && stateElement !== undefined) {
                  var stateInstance = stateElement;
                  ruleInstance.state = stateInstance;
                }
                
                var isDefaultElement = js2xml.getElement(responseDoc, rulesElement, 'ISDEFAULT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (isDefaultElement !== null && isDefaultElement !== undefined && isDefaultElement.length !== 0) {
                  var isDefaultInstance = isDefaultElement === 'true';
                  ruleInstance.isDefault = isDefaultInstance;
                }
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Gets the Network Security Group applied to a specific network interface.
   * 
   * @param {string} serviceName
   * 
   * @param {string} deploymentName
   * 
   * @param {string} roleName
   * 
   * @param {string} networkInterfaceName
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkSecurityGroupOperations.prototype.getForNetworkInterface = function(serviceName, deploymentName, roleName, networkInterfaceName, 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.'));
    }
    if (deploymentName === null || deploymentName === undefined) {
      return callback(new Error('deploymentName cannot be null.'));
    }
    if (roleName === null || roleName === undefined) {
      return callback(new Error('roleName cannot be null.'));
    }
    if (networkInterfaceName === null || networkInterfaceName === undefined) {
      return callback(new Error('networkInterfaceName 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 + '/roles/';
    url2 = url2 + encodeURIComponent(roleName);
    url2 = url2 + '/networkinterfaces/';
    url2 = url2 + encodeURIComponent(networkInterfaceName);
    url2 = url2 + '/networksecuritygroups';
    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['x-ms-version'] = '2016-03-01';
    
    // 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 options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var networkSecurityGroupElement = js2xml.getElement(responseDoc, responseDoc, 'NETWORKSECURITYGROUP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (networkSecurityGroupElement !== null && networkSecurityGroupElement !== undefined) {
            var nameElement = js2xml.getElement(responseDoc, networkSecurityGroupElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement !== null && nameElement !== undefined) {
              var nameInstance = nameElement;
              result.name = nameInstance;
            }
            
            var stateElement = js2xml.getElement(responseDoc, networkSecurityGroupElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined) {
              var stateInstance = stateElement;
              result.state = stateInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Gets the Network Security Group applied to a specific role.
   * 
   * @param {string} serviceName
   * 
   * @param {string} deploymentName
   * 
   * @param {string} roleName
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkSecurityGroupOperations.prototype.getForRole = function(serviceName, deploymentName, roleName, 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.'));
    }
    if (deploymentName === null || deploymentName === undefined) {
      return callback(new Error('deploymentName cannot be null.'));
    }
    if (roleName === null || roleName === undefined) {
      return callback(new Error('roleName 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 + '/roles/';
    url2 = url2 + encodeURIComponent(roleName);
    url2 = url2 + '/networksecuritygroups';
    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['x-ms-version'] = '2016-03-01';
    
    // 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 options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var networkSecurityGroupElement = js2xml.getElement(responseDoc, responseDoc, 'NETWORKSECURITYGROUP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (networkSecurityGroupElement !== null && networkSecurityGroupElement !== undefined) {
            var nameElement = js2xml.getElement(responseDoc, networkSecurityGroupElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement !== null && nameElement !== undefined) {
              var nameInstance = nameElement;
              result.name = nameInstance;
            }
            
            var stateElement = js2xml.getElement(responseDoc, networkSecurityGroupElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined) {
              var stateInstance = stateElement;
              result.state = stateInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Gets the Network Security Group applied to a specific subnet.
   * 
   * @param {string} virtualNetworkName
   * 
   * @param {string} subnetName
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkSecurityGroupOperations.prototype.getForSubnet = function(virtualNetworkName, subnetName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (virtualNetworkName === null || virtualNetworkName === undefined) {
      return callback(new Error('virtualNetworkName cannot be null.'));
    }
    if (subnetName === null || subnetName === undefined) {
      return callback(new Error('subnetName 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/networking/virtualnetwork/';
    url2 = url2 + encodeURIComponent(virtualNetworkName);
    url2 = url2 + '/subnets/';
    url2 = url2 + encodeURIComponent(subnetName);
    url2 = url2 + '/networksecuritygroups';
    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['x-ms-version'] = '2016-03-01';
    
    // 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 options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var networkSecurityGroupElement = js2xml.getElement(responseDoc, responseDoc, 'NETWORKSECURITYGROUP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (networkSecurityGroupElement !== null && networkSecurityGroupElement !== undefined) {
            var nameElement = js2xml.getElement(responseDoc, networkSecurityGroupElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement !== null && nameElement !== undefined) {
              var nameInstance = nameElement;
              result.name = nameInstance;
            }
            
            var stateElement = js2xml.getElement(responseDoc, networkSecurityGroupElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined) {
              var stateInstance = stateElement;
              result.state = stateInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Lists all of the Network Security Groups for the subscription.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkSecurityGroupOperations.prototype.list = function(callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // 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/networking/networksecuritygroups';
    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['x-ms-version'] = '2016-03-01';
    
    // 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 = { networkSecurityGroups: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var networkSecurityGroupsSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'NETWORKSECURITYGROUPS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (networkSecurityGroupsSequenceElement !== null && networkSecurityGroupsSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, networkSecurityGroupsSequenceElement, 'NETWORKSECURITYGROUP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var networkSecurityGroupsElement = js2xml.getElements(responseDoc, networkSecurityGroupsSequenceElement, 'NETWORKSECURITYGROUP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var networkSecurityGroupInstance = {};
              result.networkSecurityGroups.push(networkSecurityGroupInstance);
              
              var nameElement = js2xml.getElement(responseDoc, networkSecurityGroupsElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (nameElement !== null && nameElement !== undefined) {
                var nameInstance = nameElement;
                networkSecurityGroupInstance.name = nameInstance;
              }
              
              var labelElement = js2xml.getElement(responseDoc, networkSecurityGroupsElement, 'LABEL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (labelElement !== null && labelElement !== undefined) {
                var labelInstance = labelElement;
                networkSecurityGroupInstance.label = labelInstance;
              }
              
              var locationElement = js2xml.getElement(responseDoc, networkSecurityGroupsElement, 'LOCATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (locationElement !== null && locationElement !== undefined) {
                var locationInstance = locationElement;
                networkSecurityGroupInstance.location = locationInstance;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Removes a Network Security Group from a network interface.
   * 
   * @param {string} serviceName
   * 
   * @param {string} deploymentName
   * 
   * @param {string} roleName
   * 
   * @param {string} networkInterfaceName
   * 
   * @param {string} networkSecurityGroupName
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkSecurityGroupOperations.prototype.removeFromNetworkInterface = function(serviceName, deploymentName, roleName, networkInterfaceName, networkSecurityGroupName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.networkSecurityGroups.beginRemovingFromNetworkInterface(serviceName, deploymentName, roleName, networkInterfaceName, networkSecurityGroupName, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      if (result.status === 'Succeeded') {
        return callback(null, result);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * Removes a Network Security Group from a role.
   * 
   * @param {string} serviceName
   * 
   * @param {string} deploymentName
   * 
   * @param {string} roleName
   * 
   * @param {string} networkSecurityGroupName
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkSecurityGroupOperations.prototype.removeFromRole = function(serviceName, deploymentName, roleName, networkSecurityGroupName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.networkSecurityGroups.beginRemovingFromRole(serviceName, deploymentName, roleName, networkSecurityGroupName, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      if (result.status === 'Succeeded') {
        return callback(null, result);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * Removes a Network Security Group from a subnet.
   * 
   * @param {string} virtualNetworkName
   * 
   * @param {string} subnetName
   * 
   * @param {string} networkSecurityGroupName
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkSecurityGroupOperations.prototype.removeFromSubnet = function(virtualNetworkName, subnetName, networkSecurityGroupName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.networkSecurityGroups.beginRemovingFromSubnet(virtualNetworkName, subnetName, networkSecurityGroupName, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      if (result.status === 'Succeeded') {
        return callback(null, result);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * Add new Network Security Rule to existing Network Security Group.
   * 
   * @param {string} [networkSecurityGroupName]
   * 
   * @param {string} [ruleName]
   * 
   * @param {NetworkSecuritySetRuleParameters} parameters Parameters supplied
   * to the Set Network Security Rule operation.
   * 
   * @param {string} parameters.type Gets or sets type of Rule. Possible
   * values: Inbound (to be evaluated against ingress traffic), Outbound (to
   * be evaluated against egress traffic).
   * 
   * @param {number} parameters.priority Gets or sets Priority. Value from 100
   * – 4096.
   * 
   * @param {string} parameters.action Gets or sets Action. Allow/Deny. Whether
   * to allow or deny traffic.
   * 
   * @param {string} parameters.sourceAddressPrefix Gets or sets
   * SourceAddressPrefix. CIDR value of Source IP from which traffic is
   * coming. You can specify star (*) to map all traffic or one of pre-defined
   * TAGs
   * 
   * @param {string} parameters.sourcePortRange Gets or sets Source Port
   * (single port) or Source Port Range (separated by “-“) or star (*) for all
   * ports. All numbers are inclusive. Example: 80, 80-80, 80-81, *
   * 
   * @param {string} parameters.destinationAddressPrefix Gets or sets
   * DestinationAddressPrefix. CIDR value of Destination IP from which traffic
   * is coming. You can specify star (*) to map all traffic or one of
   * pre-defined TAGs.
   * 
   * @param {string} parameters.destinationPortRange Gets or sets destination
   * Port (single port) or Destination Port Range (separated by “-“) or star
   * (*) for all ports. All numbers are inclusive. Example: 80, 80-80, 80-81, *
   * 
   * @param {string} parameters.protocol Gets or sets Protocol. TCP, UDP, *.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  NetworkSecurityGroupOperations.prototype.setRule = function(networkSecurityGroupName, ruleName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.networkSecurityGroups.beginSettingRule(networkSecurityGroupName, ruleName, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      if (result.status === 'Succeeded') {
        return callback(null, result);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  return NetworkSecurityGroupOperations;
})();

var ReservedIPOperations = ( /** @lends ReservedIPOperations */ function() {
  /**
   * @class
   * The Network Management API includes operations for managing the reserved
   * IPs for your subscription.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [NetworkManagementClient] {@link
   * NetworkManagementClient~NetworkManagementClient}.
   * See [reservedIPs] {@link
   * NetworkManagementClient~NetworkManagementClient#reservedIPs}.
   * Initializes a new instance of the ReservedIPOperations class.
   * @constructor
   * 
   * @param {NetworkManagementClient} client Reference to the service client.
   */
  function ReservedIPOperations(client) {
    this.client = client;
  }
  
  /**
   * The Associate Reserved IP operation associates a Reserved IP with a
   * service.
   * 
   * @param {string} reservedIpName The name of the reserved IP.
   * 
   * @param {NetworkReservedIPMobilityParameters} parameters Parameters
   * supplied to associate Reserved IP.
   * 
   * @param {string} [parameters.serviceName] The name of the service the IP
   * belongs to, if used.
   * 
   * @param {string} [parameters.deploymentName] The name of the deployment the
   * IP belongs to, if used.
   * 
   * @param {string} [parameters.virtualIPName] The name of the virtual IP on
   * which we want to perform the IP Mobility operation.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ReservedIPOperations.prototype.associate = function(reservedIpName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.reservedIPs.beginAssociating(reservedIpName, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      if (result.status === 'Succeeded') {
        return callback(null, result);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The BeginAssociate begins to associate a Reserved IP with a service.
   * 
   * @param {string} reservedIpName The name of the reserved IP.
   * 
   * @param {NetworkReservedIPMobilityParameters} parameters Parameters
   * supplied to the Begin associating Reserved IP.
   * 
   * @param {string} [parameters.serviceName] The name of the service the IP
   * belongs to, if used.
   * 
   * @param {string} [parameters.deploymentName] The name of the deployment the
   * IP belongs to, if used.
   * 
   * @param {string} [parameters.virtualIPName] The name of the virtual IP on
   * which we want to perform the IP Mobility operation.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ReservedIPOperations.prototype.beginAssociating = function(reservedIpName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (reservedIpName === null || reservedIpName === undefined) {
      return callback(new Error('reservedIpName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/reservedips/';
    url2 = url2 + encodeURIComponent(reservedIpName);
    url2 = url2 + '/operations/associate';
    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'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var reservedIPAssociationElement = js2xml.createElement('ReservedIPAssociation', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, reservedIPAssociationElement);
    
    if (parameters.serviceName !== null && parameters.serviceName !== undefined) {
      var serviceNameElement = js2xml.createElement('ServiceName', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(serviceNameElement, parameters.serviceName);
      js2xml.addChildElement(reservedIPAssociationElement, serviceNameElement);
    }
    
    if (parameters.deploymentName !== null && parameters.deploymentName !== undefined) {
      var deploymentNameElement = js2xml.createElement('DeploymentName', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(deploymentNameElement, parameters.deploymentName);
      js2xml.addChildElement(reservedIPAssociationElement, deploymentNameElement);
    }
    
    if (parameters.virtualIPName !== null && parameters.virtualIPName !== undefined) {
      var virtualIPNameElement = js2xml.createElement('VirtualIPName', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(virtualIPNameElement, parameters.virtualIPName);
      js2xml.addChildElement(reservedIPAssociationElement, virtualIPNameElement);
    }
    
    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 Reserved IP operation creates a reserved IP from your
   * the subscription.
   * 
   * @param {NetworkReservedIPCreateParameters} parameters Parameters supplied
   * to the Begin Creating Reserved IP operation.
   * 
   * @param {string} [parameters.name] Name of the reserved IP.
   * 
   * @param {string} [parameters.label] The friendly identifier for the site.
   * 
   * @param {string} [parameters.serviceName] The name of the service the IP
   * belongs to, if used.
   * 
   * @param {string} [parameters.deploymentName] The name of the deployment the
   * IP belongs to, if used.
   * 
   * @param {string} [parameters.location] Location where the virtual network
   * exists.
   * 
   * @param {string} [parameters.virtualIPName] The name of the virtual IP that
   * we should reserve.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ReservedIPOperations.prototype.beginCreating = function(parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/reservedips';
    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'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var reservedIPElement = js2xml.createElement('ReservedIP', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, reservedIPElement);
    
    if (parameters.name !== null && parameters.name !== undefined) {
      var nameElement = js2xml.createElement('Name', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(nameElement, parameters.name);
      js2xml.addChildElement(reservedIPElement, nameElement);
    }
    
    if (parameters.label !== null && parameters.label !== undefined) {
      var labelElement = js2xml.createElement('Label', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(labelElement, parameters.label);
      js2xml.addChildElement(reservedIPElement, labelElement);
    }
    
    if (parameters.serviceName !== null && parameters.serviceName !== undefined) {
      var serviceNameElement = js2xml.createElement('ServiceName', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(serviceNameElement, parameters.serviceName);
      js2xml.addChildElement(reservedIPElement, serviceNameElement);
    }
    
    if (parameters.deploymentName !== null && parameters.deploymentName !== undefined) {
      var deploymentNameElement = js2xml.createElement('DeploymentName', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(deploymentNameElement, parameters.deploymentName);
      js2xml.addChildElement(reservedIPElement, deploymentNameElement);
    }
    
    if (parameters.location !== null && parameters.location !== undefined) {
      var locationElement = js2xml.createElement('Location', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(locationElement, parameters.location);
      js2xml.addChildElement(reservedIPElement, locationElement);
    }
    
    if (parameters.virtualIPName !== null && parameters.virtualIPName !== undefined) {
      var virtualIPNameElement = js2xml.createElement('VirtualIPName', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(virtualIPNameElement, parameters.virtualIPName);
      js2xml.addChildElement(reservedIPElement, virtualIPNameElement);
    }
    
    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 Deleting Reserved IP operation removes a reserved IP from your
   * the subscription.
   * 
   * @param {string} ipName The name of the reserved IP.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ReservedIPOperations.prototype.beginDeleting = function(ipName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (ipName === null || ipName === undefined) {
      return callback(new Error('ipName 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/networking/reservedips/';
    url2 = url2 + encodeURIComponent(ipName);
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // 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 BeginDisassociate begins to disassociate a Reserved IP from a service.
   * 
   * @param {string} reservedIpName The name of the reserved IP.
   * 
   * @param {NetworkReservedIPMobilityParameters} parameters Parameters
   * supplied to the Begin disassociating Reserved IP.
   * 
   * @param {string} [parameters.serviceName] The name of the service the IP
   * belongs to, if used.
   * 
   * @param {string} [parameters.deploymentName] The name of the deployment the
   * IP belongs to, if used.
   * 
   * @param {string} [parameters.virtualIPName] The name of the virtual IP on
   * which we want to perform the IP Mobility operation.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ReservedIPOperations.prototype.beginDisassociating = function(reservedIpName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (reservedIpName === null || reservedIpName === undefined) {
      return callback(new Error('reservedIpName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/reservedips/';
    url2 = url2 + encodeURIComponent(reservedIpName);
    url2 = url2 + '/operations/disassociate';
    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'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var reservedIPAssociationElement = js2xml.createElement('ReservedIPAssociation', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, reservedIPAssociationElement);
    
    if (parameters.serviceName !== null && parameters.serviceName !== undefined) {
      var serviceNameElement = js2xml.createElement('ServiceName', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(serviceNameElement, parameters.serviceName);
      js2xml.addChildElement(reservedIPAssociationElement, serviceNameElement);
    }
    
    if (parameters.deploymentName !== null && parameters.deploymentName !== undefined) {
      var deploymentNameElement = js2xml.createElement('DeploymentName', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(deploymentNameElement, parameters.deploymentName);
      js2xml.addChildElement(reservedIPAssociationElement, deploymentNameElement);
    }
    
    if (parameters.virtualIPName !== null && parameters.virtualIPName !== undefined) {
      var virtualIPNameElement = js2xml.createElement('VirtualIPName', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(virtualIPNameElement, parameters.virtualIPName);
      js2xml.addChildElement(reservedIPAssociationElement, virtualIPNameElement);
    }
    
    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 Create Reserved IP operation creates a reserved IP from your the
   * subscription.
   * 
   * @param {NetworkReservedIPCreateParameters} parameters Parameters supplied
   * to the Create Reserved IP operation.
   * 
   * @param {string} [parameters.name] Name of the reserved IP.
   * 
   * @param {string} [parameters.label] The friendly identifier for the site.
   * 
   * @param {string} [parameters.serviceName] The name of the service the IP
   * belongs to, if used.
   * 
   * @param {string} [parameters.deploymentName] The name of the deployment the
   * IP belongs to, if used.
   * 
   * @param {string} [parameters.location] Location where the virtual network
   * exists.
   * 
   * @param {string} [parameters.virtualIPName] The name of the virtual IP that
   * we should reserve.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ReservedIPOperations.prototype.create = function(parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.reservedIPs.beginCreating(parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      if (result.status === 'Succeeded') {
        return callback(null, result);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Delete Reserved IP operation removes a reserved IP from your the
   * subscription.
   * 
   * @param {string} ipName The name of the reserved IP.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ReservedIPOperations.prototype.deleteMethod = function(ipName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.reservedIPs.beginDeleting(ipName, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Disassociate Reserved IP operation disassociates a Reserved IP from a
   * service.
   * 
   * @param {string} reservedIpName The name of the reserved IP.
   * 
   * @param {NetworkReservedIPMobilityParameters} parameters Parameters
   * supplied to disassociate Reserved IP.
   * 
   * @param {string} [parameters.serviceName] The name of the service the IP
   * belongs to, if used.
   * 
   * @param {string} [parameters.deploymentName] The name of the deployment the
   * IP belongs to, if used.
   * 
   * @param {string} [parameters.virtualIPName] The name of the virtual IP on
   * which we want to perform the IP Mobility operation.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ReservedIPOperations.prototype.disassociate = function(reservedIpName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.reservedIPs.beginDisassociating(reservedIpName, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      if (result.status === 'Succeeded') {
        return callback(null, result);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Get Reserved IP operation retrieves the details for the virtual IP
   * reserved for the subscription.
   * 
   * @param {string} ipName The name of the reserved IP to retrieve.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ReservedIPOperations.prototype.get = function(ipName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (ipName === null || ipName === undefined) {
      return callback(new Error('ipName 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/networking/reservedips/';
    url2 = url2 + encodeURIComponent(ipName);
    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['x-ms-version'] = '2016-03-01';
    
    // 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 options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var reservedIPElement = js2xml.getElement(responseDoc, responseDoc, 'RESERVEDIP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (reservedIPElement !== null && reservedIPElement !== undefined) {
            var nameElement = js2xml.getElement(responseDoc, reservedIPElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement !== null && nameElement !== undefined) {
              var nameInstance = nameElement;
              result.name = nameInstance;
            }
            
            var addressElement = js2xml.getElement(responseDoc, reservedIPElement, 'ADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (addressElement !== null && addressElement !== undefined) {
              var addressInstance = addressElement;
              result.address = addressInstance;
            }
            
            var idElement = js2xml.getElement(responseDoc, reservedIPElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.id = idInstance;
            }
            
            var labelElement = js2xml.getElement(responseDoc, reservedIPElement, 'LABEL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (labelElement !== null && labelElement !== undefined) {
              var labelInstance = labelElement;
              result.label = labelInstance;
            }
            
            var stateElement = js2xml.getElement(responseDoc, reservedIPElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined) {
              var stateInstance = stateElement;
              result.state = stateInstance;
            }
            
            var inUseElement = js2xml.getElement(responseDoc, reservedIPElement, 'INUSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (inUseElement !== null && inUseElement !== undefined && inUseElement.length !== 0) {
              var inUseInstance = inUseElement === 'true';
              result.inUse = inUseInstance;
            }
            
            var serviceNameElement = js2xml.getElement(responseDoc, reservedIPElement, 'SERVICENAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (serviceNameElement !== null && serviceNameElement !== undefined) {
              var serviceNameInstance = serviceNameElement;
              result.serviceName = serviceNameInstance;
            }
            
            var deploymentNameElement = js2xml.getElement(responseDoc, reservedIPElement, 'DEPLOYMENTNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (deploymentNameElement !== null && deploymentNameElement !== undefined) {
              var deploymentNameInstance = deploymentNameElement;
              result.deploymentName = deploymentNameInstance;
            }
            
            var locationElement = js2xml.getElement(responseDoc, reservedIPElement, 'LOCATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (locationElement !== null && locationElement !== undefined) {
              var locationInstance = locationElement;
              result.location = locationInstance;
            }
            
            var virtualIPNameElement = js2xml.getElement(responseDoc, reservedIPElement, 'VIRTUALIPNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (virtualIPNameElement !== null && virtualIPNameElement !== undefined) {
              var virtualIPNameInstance = virtualIPNameElement;
              result.virtualIPName = virtualIPNameInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The List Reserved IP operation retrieves all of the virtual IPs reserved
   * for the subscription.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ReservedIPOperations.prototype.list = function(callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // 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/networking/reservedips';
    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['x-ms-version'] = '2016-03-01';
    
    // 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 = { reservedIPs: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var reservedIPsSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'RESERVEDIPS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (reservedIPsSequenceElement !== null && reservedIPsSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, reservedIPsSequenceElement, 'RESERVEDIP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var reservedIPsElement = js2xml.getElements(responseDoc, reservedIPsSequenceElement, 'RESERVEDIP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var reservedIPInstance = {};
              result.reservedIPs.push(reservedIPInstance);
              
              var nameElement = js2xml.getElement(responseDoc, reservedIPsElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (nameElement !== null && nameElement !== undefined) {
                var nameInstance = nameElement;
                reservedIPInstance.name = nameInstance;
              }
              
              var addressElement = js2xml.getElement(responseDoc, reservedIPsElement, 'ADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (addressElement !== null && addressElement !== undefined) {
                var addressInstance = addressElement;
                reservedIPInstance.address = addressInstance;
              }
              
              var idElement = js2xml.getElement(responseDoc, reservedIPsElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (idElement !== null && idElement !== undefined) {
                var idInstance = idElement;
                reservedIPInstance.id = idInstance;
              }
              
              var labelElement = js2xml.getElement(responseDoc, reservedIPsElement, 'LABEL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (labelElement !== null && labelElement !== undefined) {
                var labelInstance = labelElement;
                reservedIPInstance.label = labelInstance;
              }
              
              var stateElement = js2xml.getElement(responseDoc, reservedIPsElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (stateElement !== null && stateElement !== undefined) {
                var stateInstance = stateElement;
                reservedIPInstance.state = stateInstance;
              }
              
              var inUseElement = js2xml.getElement(responseDoc, reservedIPsElement, 'INUSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (inUseElement !== null && inUseElement !== undefined && inUseElement.length !== 0) {
                var inUseInstance = inUseElement === 'true';
                reservedIPInstance.inUse = inUseInstance;
              }
              
              var serviceNameElement = js2xml.getElement(responseDoc, reservedIPsElement, 'SERVICENAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (serviceNameElement !== null && serviceNameElement !== undefined) {
                var serviceNameInstance = serviceNameElement;
                reservedIPInstance.serviceName = serviceNameInstance;
              }
              
              var deploymentNameElement = js2xml.getElement(responseDoc, reservedIPsElement, 'DEPLOYMENTNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (deploymentNameElement !== null && deploymentNameElement !== undefined) {
                var deploymentNameInstance = deploymentNameElement;
                reservedIPInstance.deploymentName = deploymentNameInstance;
              }
              
              var locationElement = js2xml.getElement(responseDoc, reservedIPsElement, 'LOCATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (locationElement !== null && locationElement !== undefined) {
                var locationInstance = locationElement;
                reservedIPInstance.location = locationInstance;
              }
              
              var virtualIPNameElement = js2xml.getElement(responseDoc, reservedIPsElement, 'VIRTUALIPNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (virtualIPNameElement !== null && virtualIPNameElement !== undefined) {
                var virtualIPNameInstance = virtualIPNameElement;
                reservedIPInstance.virtualIPName = virtualIPNameInstance;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return ReservedIPOperations;
})();

var RouteOperations = ( /** @lends RouteOperations */ function() {
  /**
   * @class
   * The Network Management API includes operations for managing the routes for
   * your subscription.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [NetworkManagementClient] {@link
   * NetworkManagementClient~NetworkManagementClient}.
   * See [routes] {@link
   * NetworkManagementClient~NetworkManagementClient#routes}.
   * Initializes a new instance of the RouteOperations class.
   * @constructor
   * 
   * @param {NetworkManagementClient} client Reference to the service client.
   */
  function RouteOperations(client) {
    this.client = client;
  }
  
  /**
   * Set the specified route table for the provided subnet in the provided
   * virtual network in this subscription.
   * 
   * @param {string} vnetName The name of the virtual network that contains the
   * provided subnet.
   * 
   * @param {string} subnetName The name of the subnet that the route table
   * will be added to.
   * 
   * @param {AddRouteTableToSubnetParameters} parameters The parameters
   * necessary to add a route table to the provided subnet.
   * 
   * @param {string} [parameters.routeTableName]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RouteOperations.prototype.addRouteTableToSubnet = function(vnetName, subnetName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.routes.beginAddRouteTableToSubnet(vnetName, subnetName, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * Set the specified route table for the provided subnet in the provided
   * virtual network in this subscription.
   * 
   * @param {string} vnetName The name of the virtual network that contains the
   * provided subnet.
   * 
   * @param {string} subnetName The name of the subnet that the route table
   * will be added to.
   * 
   * @param {AddRouteTableToSubnetParameters} parameters The parameters
   * necessary to add a route table to the provided subnet.
   * 
   * @param {string} [parameters.routeTableName]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RouteOperations.prototype.beginAddRouteTableToSubnet = function(vnetName, subnetName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (vnetName === null || vnetName === undefined) {
      return callback(new Error('vnetName cannot be null.'));
    }
    if (subnetName === null || subnetName === undefined) {
      return callback(new Error('subnetName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/virtualnetwork/';
    url2 = url2 + encodeURIComponent(vnetName);
    url2 = url2 + '/subnets/';
    url2 = url2 + encodeURIComponent(subnetName);
    url2 = url2 + '/routetables';
    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'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var routeTableAssociationElement = js2xml.createElement('RouteTableAssociation', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, routeTableAssociationElement);
    
    if (parameters.routeTableName !== null && parameters.routeTableName !== undefined) {
      var routeTableNameElement = js2xml.createElement('RouteTableName', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(routeTableNameElement, parameters.routeTableName);
      js2xml.addChildElement(routeTableAssociationElement, routeTableNameElement);
    }
    
    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);
    });
  };
  
  /**
   * Create the specified route table for this subscription.
   * 
   * @param {CreateRouteTableParameters} parameters The parameters necessary to
   * create a new route table.
   * 
   * @param {string} [parameters.name]
   * 
   * @param {string} [parameters.label]
   * 
   * @param {string} [parameters.location]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RouteOperations.prototype.beginCreateRouteTable = function(parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/routetables';
    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'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var routeTableElement = js2xml.createElement('RouteTable', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, routeTableElement);
    
    if (parameters.name !== null && parameters.name !== undefined) {
      var nameElement = js2xml.createElement('Name', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(nameElement, parameters.name);
      js2xml.addChildElement(routeTableElement, nameElement);
    }
    
    if (parameters.label !== null && parameters.label !== undefined) {
      var labelElement = js2xml.createElement('Label', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(labelElement, parameters.label);
      js2xml.addChildElement(routeTableElement, labelElement);
    }
    
    if (parameters.location !== null && parameters.location !== undefined) {
      var locationElement = js2xml.createElement('Location', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(locationElement, parameters.location);
      js2xml.addChildElement(routeTableElement, locationElement);
    }
    
    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);
    });
  };
  
  /**
   * Set the specified route for the provided table in this subscription.
   * 
   * @param {string} routeTableName The name of the route table where the
   * provided route will be set.
   * 
   * @param {string} routeName The name of the route that will be set on the
   * provided route table.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RouteOperations.prototype.beginDeleteRoute = function(routeTableName, routeName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (routeTableName === null || routeTableName === undefined) {
      return callback(new Error('routeTableName cannot be null.'));
    }
    if (routeName === null || routeName === undefined) {
      return callback(new Error('routeName 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/networking/routetables/';
    url2 = url2 + encodeURIComponent(routeTableName);
    url2 = url2 + '/routes/';
    url2 = url2 + encodeURIComponent(routeName);
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // 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);
    });
  };
  
  /**
   * Delete the specified route table for this subscription.
   * 
   * @param {string} routeTableName The name of the route table to delete.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RouteOperations.prototype.beginDeleteRouteTable = function(routeTableName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (routeTableName === null || routeTableName === undefined) {
      return callback(new Error('routeTableName 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/networking/routetables/';
    url2 = url2 + encodeURIComponent(routeTableName);
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // 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);
    });
  };
  
  /**
   * Remove the route table from the provided subnet in the provided virtual
   * network in this subscription.
   * 
   * @param {string} vnetName The name of the virtual network that contains the
   * provided subnet.
   * 
   * @param {string} subnetName The name of the subnet that the route table
   * will be removed from.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RouteOperations.prototype.beginRemoveRouteTableFromSubnet = function(vnetName, subnetName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (vnetName === null || vnetName === undefined) {
      return callback(new Error('vnetName cannot be null.'));
    }
    if (subnetName === null || subnetName === undefined) {
      return callback(new Error('subnetName 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/networking/virtualnetwork/';
    url2 = url2 + encodeURIComponent(vnetName);
    url2 = url2 + '/subnets/';
    url2 = url2 + encodeURIComponent(subnetName);
    url2 = url2 + '/routetables';
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // 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);
    });
  };
  
  /**
   * Set the specified route for the provided table in this subscription.
   * 
   * @param {string} routeTableName The name of the route table where the
   * provided route will be set.
   * 
   * @param {string} routeName The name of the route that will be set on the
   * provided route table.
   * 
   * @param {SetRouteParameters} parameters The parameters necessary to create
   * a new route table.
   * 
   * @param {string} [parameters.name]
   * 
   * @param {string} [parameters.addressPrefix]
   * 
   * @param {NextHop} [parameters.nextHop]
   * 
   * @param {string} [parameters.nextHop.type] Gets or sets the type of the
   * next hop.
   * 
   * @param {string} [parameters.nextHop.ipAddress] Gets or sets the next hop
   * IP addresses.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RouteOperations.prototype.beginSetRoute = function(routeTableName, routeName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (routeTableName === null || routeTableName === undefined) {
      return callback(new Error('routeTableName cannot be null.'));
    }
    if (routeName === null || routeName === undefined) {
      return callback(new Error('routeName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters 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/networking/routetables/';
    url2 = url2 + encodeURIComponent(routeTableName);
    url2 = url2 + '/routes/';
    url2 = url2 + encodeURIComponent(routeName);
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var routeElement = js2xml.createElement('Route', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, routeElement);
    
    if (parameters.name !== null && parameters.name !== undefined) {
      var nameElement = js2xml.createElement('Name', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(nameElement, parameters.name);
      js2xml.addChildElement(routeElement, nameElement);
    }
    
    if (parameters.addressPrefix !== null && parameters.addressPrefix !== undefined) {
      var addressPrefixElement = js2xml.createElement('AddressPrefix', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(addressPrefixElement, parameters.addressPrefix);
      js2xml.addChildElement(routeElement, addressPrefixElement);
    }
    
    if (parameters.nextHop !== null && parameters.nextHop !== undefined) {
      var nextHopTypeElement = js2xml.createElement('NextHopType', 'http://schemas.microsoft.com/windowsazure');
      js2xml.addChildElement(routeElement, nextHopTypeElement);
      
      if (parameters.nextHop.type !== null && parameters.nextHop.type !== undefined) {
        var typeElement = js2xml.createElement('Type', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(typeElement, parameters.nextHop.type);
        js2xml.addChildElement(nextHopTypeElement, typeElement);
      }
      
      if (parameters.nextHop.ipAddress !== null && parameters.nextHop.ipAddress !== undefined) {
        var ipAddressElement = js2xml.createElement('IpAddress', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(ipAddressElement, parameters.nextHop.ipAddress);
        js2xml.addChildElement(nextHopTypeElement, ipAddressElement);
      }
    }
    
    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);
    });
  };
  
  /**
   * Create the specified route table for this subscription.
   * 
   * @param {CreateRouteTableParameters} parameters The parameters necessary to
   * create a new route table.
   * 
   * @param {string} [parameters.name]
   * 
   * @param {string} [parameters.label]
   * 
   * @param {string} [parameters.location]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RouteOperations.prototype.createRouteTable = function(parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.routes.beginCreateRouteTable(parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * Set the specified route for the provided table in this subscription.
   * 
   * @param {string} routeTableName The name of the route table where the
   * provided route will be set.
   * 
   * @param {string} routeName The name of the route that will be set on the
   * provided route table.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RouteOperations.prototype.deleteRoute = function(routeTableName, routeName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.routes.beginDeleteRoute(routeTableName, routeName, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * Delete the specified route table for this subscription.
   * 
   * @param {string} routeTableName The name of the route table to delete.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RouteOperations.prototype.deleteRouteTable = function(routeTableName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.routes.beginDeleteRouteTable(routeTableName, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * Get the effective route table for the provided network interface in this
   * subscription.
   * 
   * @param {string} serviceName The name of the cloud service.
   * 
   * @param {string} deploymentName The name of the deployment.
   * 
   * @param {string} roleinstanceName The name of the role instance.
   * 
   * @param {string} networkInterfaceName The name of the network interface.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RouteOperations.prototype.getEffectiveRouteTableForNetworkInterface = function(serviceName, deploymentName, roleinstanceName, networkInterfaceName, 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.'));
    }
    if (deploymentName === null || deploymentName === undefined) {
      return callback(new Error('deploymentName cannot be null.'));
    }
    if (roleinstanceName === null || roleinstanceName === undefined) {
      return callback(new Error('roleinstanceName cannot be null.'));
    }
    if (networkInterfaceName === null || networkInterfaceName === undefined) {
      return callback(new Error('networkInterfaceName 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 + '/roleinstances/';
    url2 = url2 + encodeURIComponent(roleinstanceName);
    url2 = url2 + '/networkinterfaces/';
    url2 = url2 + encodeURIComponent(networkInterfaceName);
    url2 = url2 + '/effectiveroutetable';
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // 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 >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      var options = {};
      options.trim = false;
      options.strict = false;
      return xml.parseString(responseContent, options, function (err2, responseDoc) {
        if (err2 !== null && err2 !== undefined) {
          return callback(err2);
        }
        
        var effectiveRouteTableElement = js2xml.getElement(responseDoc, responseDoc, 'EFFECTIVEROUTETABLE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
        if (effectiveRouteTableElement !== null && effectiveRouteTableElement !== undefined) {
          var effectiveRouteTableInstance = { effectiveRoutes: [] };
          result.effectiveRouteTable = effectiveRouteTableInstance;
          
          var effectiveRouteListSequenceElement = js2xml.getElement(responseDoc, effectiveRouteTableElement, 'EFFECTIVEROUTELIST', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (effectiveRouteListSequenceElement !== null && effectiveRouteListSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, effectiveRouteListSequenceElement, 'EFFECTIVEROUTE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var effectiveRouteListElement = js2xml.getElements(responseDoc, effectiveRouteListSequenceElement, 'EFFECTIVEROUTE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var effectiveRouteInstance = { addressPrefixes: [] };
              effectiveRouteTableInstance.effectiveRoutes.push(effectiveRouteInstance);
              
              var nameElement = js2xml.getElement(responseDoc, effectiveRouteListElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (nameElement !== null && nameElement !== undefined) {
                var nameInstance = nameElement;
                effectiveRouteInstance.name = nameInstance;
              }
              
              var sourceElement = js2xml.getElement(responseDoc, effectiveRouteListElement, 'SOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (sourceElement !== null && sourceElement !== undefined) {
                var sourceInstance = sourceElement;
                effectiveRouteInstance.source = sourceInstance;
              }
              
              var statusElement = js2xml.getElement(responseDoc, effectiveRouteListElement, 'STATUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (statusElement !== null && statusElement !== undefined) {
                var statusInstance = statusElement;
                effectiveRouteInstance.status = statusInstance;
              }
              
              var addressPrefixesSequenceElement = js2xml.getElement(responseDoc, effectiveRouteListElement, 'ADDRESSPREFIXES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (addressPrefixesSequenceElement !== null && addressPrefixesSequenceElement !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < js2xml.getElements(responseDoc, addressPrefixesSequenceElement, 'ADDRESSPREFIX', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex2 = loweredIndex2 + 1) {
                  var addressPrefixesElement = js2xml.getElements(responseDoc, addressPrefixesSequenceElement, 'ADDRESSPREFIX', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex2];
                  effectiveRouteInstance.addressPrefixes.push(addressPrefixesElement);
                }
              }
              
              var effectiveNextHopElement = js2xml.getElement(responseDoc, effectiveRouteListElement, 'EFFECTIVENEXTHOP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (effectiveNextHopElement !== null && effectiveNextHopElement !== undefined) {
                var effectiveNextHopInstance = { ipAddresses: [] };
                effectiveRouteInstance.effectiveNextHop = effectiveNextHopInstance;
                
                var typeElement = js2xml.getElement(responseDoc, effectiveNextHopElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (typeElement !== null && typeElement !== undefined) {
                  var typeInstance = typeElement;
                  effectiveNextHopInstance.type = typeInstance;
                }
                
                var ipAddressesSequenceElement = js2xml.getElement(responseDoc, effectiveNextHopElement, 'IPADDRESSES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (ipAddressesSequenceElement !== null && ipAddressesSequenceElement !== undefined) {
                  for (var loweredIndex3 = 0; loweredIndex3 < js2xml.getElements(responseDoc, ipAddressesSequenceElement, 'IPADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex3 = loweredIndex3 + 1) {
                    var ipAddressesElement = js2xml.getElements(responseDoc, ipAddressesSequenceElement, 'IPADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex3];
                    effectiveNextHopInstance.ipAddresses.push(ipAddressesElement);
                  }
                }
              }
            }
          }
        }
        
        result.statusCode = statusCode;
        
        return callback(null, result);
      });
    });
  };
  
  /**
   * Get the effective route table for the provided role instance in this
   * subscription.
   * 
   * @param {string} serviceName The name of the cloud service.
   * 
   * @param {string} deploymentName The name of the deployment.
   * 
   * @param {string} roleinstanceName The name of the role instance.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RouteOperations.prototype.getEffectiveRouteTableForRoleInstance = function(serviceName, deploymentName, roleinstanceName, 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.'));
    }
    if (deploymentName === null || deploymentName === undefined) {
      return callback(new Error('deploymentName cannot be null.'));
    }
    if (roleinstanceName === null || roleinstanceName === undefined) {
      return callback(new Error('roleinstanceName 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 + '/roleinstances/';
    url2 = url2 + encodeURIComponent(roleinstanceName);
    url2 = url2 + '/effectiveroutetable';
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // 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 >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      var options = {};
      options.trim = false;
      options.strict = false;
      return xml.parseString(responseContent, options, function (err2, responseDoc) {
        if (err2 !== null && err2 !== undefined) {
          return callback(err2);
        }
        
        var effectiveRouteTableElement = js2xml.getElement(responseDoc, responseDoc, 'EFFECTIVEROUTETABLE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
        if (effectiveRouteTableElement !== null && effectiveRouteTableElement !== undefined) {
          var effectiveRouteTableInstance = { effectiveRoutes: [] };
          result.effectiveRouteTable = effectiveRouteTableInstance;
          
          var effectiveRouteListSequenceElement = js2xml.getElement(responseDoc, effectiveRouteTableElement, 'EFFECTIVEROUTELIST', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (effectiveRouteListSequenceElement !== null && effectiveRouteListSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, effectiveRouteListSequenceElement, 'EFFECTIVEROUTE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var effectiveRouteListElement = js2xml.getElements(responseDoc, effectiveRouteListSequenceElement, 'EFFECTIVEROUTE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var effectiveRouteInstance = { addressPrefixes: [] };
              effectiveRouteTableInstance.effectiveRoutes.push(effectiveRouteInstance);
              
              var nameElement = js2xml.getElement(responseDoc, effectiveRouteListElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (nameElement !== null && nameElement !== undefined) {
                var nameInstance = nameElement;
                effectiveRouteInstance.name = nameInstance;
              }
              
              var sourceElement = js2xml.getElement(responseDoc, effectiveRouteListElement, 'SOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (sourceElement !== null && sourceElement !== undefined) {
                var sourceInstance = sourceElement;
                effectiveRouteInstance.source = sourceInstance;
              }
              
              var statusElement = js2xml.getElement(responseDoc, effectiveRouteListElement, 'STATUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (statusElement !== null && statusElement !== undefined) {
                var statusInstance = statusElement;
                effectiveRouteInstance.status = statusInstance;
              }
              
              var addressPrefixesSequenceElement = js2xml.getElement(responseDoc, effectiveRouteListElement, 'ADDRESSPREFIXES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (addressPrefixesSequenceElement !== null && addressPrefixesSequenceElement !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < js2xml.getElements(responseDoc, addressPrefixesSequenceElement, 'ADDRESSPREFIX', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex2 = loweredIndex2 + 1) {
                  var addressPrefixesElement = js2xml.getElements(responseDoc, addressPrefixesSequenceElement, 'ADDRESSPREFIX', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex2];
                  effectiveRouteInstance.addressPrefixes.push(addressPrefixesElement);
                }
              }
              
              var effectiveNextHopElement = js2xml.getElement(responseDoc, effectiveRouteListElement, 'EFFECTIVENEXTHOP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (effectiveNextHopElement !== null && effectiveNextHopElement !== undefined) {
                var effectiveNextHopInstance = { ipAddresses: [] };
                effectiveRouteInstance.effectiveNextHop = effectiveNextHopInstance;
                
                var typeElement = js2xml.getElement(responseDoc, effectiveNextHopElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (typeElement !== null && typeElement !== undefined) {
                  var typeInstance = typeElement;
                  effectiveNextHopInstance.type = typeInstance;
                }
                
                var ipAddressesSequenceElement = js2xml.getElement(responseDoc, effectiveNextHopElement, 'IPADDRESSES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (ipAddressesSequenceElement !== null && ipAddressesSequenceElement !== undefined) {
                  for (var loweredIndex3 = 0; loweredIndex3 < js2xml.getElements(responseDoc, ipAddressesSequenceElement, 'IPADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex3 = loweredIndex3 + 1) {
                    var ipAddressesElement = js2xml.getElements(responseDoc, ipAddressesSequenceElement, 'IPADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex3];
                    effectiveNextHopInstance.ipAddresses.push(ipAddressesElement);
                  }
                }
              }
            }
          }
        }
        
        result.statusCode = statusCode;
        
        return callback(null, result);
      });
    });
  };
  
  /**
   * Get the specified route table for this subscription.
   * 
   * @param {string} routeTableName The name of the route table in this
   * subscription to retrieve.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RouteOperations.prototype.getRouteTable = function(routeTableName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (routeTableName === null || routeTableName === undefined) {
      return callback(new Error('routeTableName 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/networking/routetables/';
    url2 = url2 + encodeURIComponent(routeTableName);
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // 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 options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var routeTableElement = js2xml.getElement(responseDoc, responseDoc, 'ROUTETABLE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (routeTableElement !== null && routeTableElement !== undefined) {
            var routeTableInstance = { routeList: [] };
            result.routeTable = routeTableInstance;
            
            var nameElement = js2xml.getElement(responseDoc, routeTableElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement !== null && nameElement !== undefined) {
              var nameInstance = nameElement;
              routeTableInstance.name = nameInstance;
            }
            
            var labelElement = js2xml.getElement(responseDoc, routeTableElement, 'LABEL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (labelElement !== null && labelElement !== undefined) {
              var labelInstance = labelElement;
              routeTableInstance.label = labelInstance;
            }
            
            var locationElement = js2xml.getElement(responseDoc, routeTableElement, 'LOCATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (locationElement !== null && locationElement !== undefined) {
              var locationInstance = locationElement;
              routeTableInstance.location = locationInstance;
            }
            
            var routeTableStateElement = js2xml.getElement(responseDoc, routeTableElement, 'ROUTETABLESTATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (routeTableStateElement !== null && routeTableStateElement !== undefined && routeTableStateElement.length !== 0) {
              var routeTableStateInstance = routeTableStateElement;
              routeTableInstance.routeTableState = routeTableStateInstance;
            }
            
            var routeListSequenceElement = js2xml.getElement(responseDoc, routeTableElement, 'ROUTELIST', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (routeListSequenceElement !== null && routeListSequenceElement !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, routeListSequenceElement, 'ROUTE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
                var routeListElement = js2xml.getElements(responseDoc, routeListSequenceElement, 'ROUTE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
                var routeInstance = {};
                routeTableInstance.routeList.push(routeInstance);
                
                var nameElement2 = js2xml.getElement(responseDoc, routeListElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (nameElement2 !== null && nameElement2 !== undefined) {
                  var nameInstance2 = nameElement2;
                  routeInstance.name = nameInstance2;
                }
                
                var addressPrefixElement = js2xml.getElement(responseDoc, routeListElement, 'ADDRESSPREFIX', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (addressPrefixElement !== null && addressPrefixElement !== undefined) {
                  var addressPrefixInstance = addressPrefixElement;
                  routeInstance.addressPrefix = addressPrefixInstance;
                }
                
                var nextHopTypeElement = js2xml.getElement(responseDoc, routeListElement, 'NEXTHOPTYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (nextHopTypeElement !== null && nextHopTypeElement !== undefined) {
                  var nextHopTypeInstance = {};
                  routeInstance.nextHop = nextHopTypeInstance;
                  
                  var typeElement = js2xml.getElement(responseDoc, nextHopTypeElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (typeElement !== null && typeElement !== undefined) {
                    var typeInstance = typeElement;
                    nextHopTypeInstance.type = typeInstance;
                  }
                  
                  var ipAddressElement = js2xml.getElement(responseDoc, nextHopTypeElement, 'IPADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (ipAddressElement !== null && ipAddressElement !== undefined) {
                    var ipAddressInstance = ipAddressElement;
                    nextHopTypeInstance.ipAddress = ipAddressInstance;
                  }
                }
                
                var metricElement = js2xml.getElement(responseDoc, routeListElement, 'METRIC', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (metricElement !== null && metricElement !== undefined && metricElement.length !== 0) {
                  var metricInstance = parseInt(metricElement, 10);
                  routeInstance.metric = metricInstance;
                }
                
                var routeStateElement = js2xml.getElement(responseDoc, routeListElement, 'ROUTESTATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (routeStateElement !== null && routeStateElement !== undefined && routeStateElement.length !== 0) {
                  var routeStateInstance = routeStateElement;
                  routeInstance.state = routeStateInstance;
                }
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * Get the specified route table for the provided subnet in the provided
   * virtual network in this subscription.
   * 
   * @param {string} vnetName The name of the virtual network that contains the
   * provided subnet.
   * 
   * @param {string} subnetName The name of the subnet.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RouteOperations.prototype.getRouteTableForSubnet = function(vnetName, subnetName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (vnetName === null || vnetName === undefined) {
      return callback(new Error('vnetName cannot be null.'));
    }
    if (subnetName === null || subnetName === undefined) {
      return callback(new Error('subnetName 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/networking/virtualnetwork/';
    url2 = url2 + encodeURIComponent(vnetName);
    url2 = url2 + '/subnets/';
    url2 = url2 + encodeURIComponent(subnetName);
    url2 = url2 + '/routetables';
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // 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 >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      var options = {};
      options.trim = false;
      options.strict = false;
      return xml.parseString(responseContent, options, function (err2, responseDoc) {
        if (err2 !== null && err2 !== undefined) {
          return callback(err2);
        }
        
        var routeTableAssociationElement = js2xml.getElement(responseDoc, responseDoc, 'ROUTETABLEASSOCIATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
        if (routeTableAssociationElement !== null && routeTableAssociationElement !== undefined) {
          var routeTableNameElement = js2xml.getElement(responseDoc, routeTableAssociationElement, 'ROUTETABLENAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (routeTableNameElement !== null && routeTableNameElement !== undefined) {
            var routeTableNameInstance = routeTableNameElement;
            result.routeTableName = routeTableNameInstance;
          }
        }
        
        result.statusCode = statusCode;
        
        return callback(null, result);
      });
    });
  };
  
  /**
   * Get the specified route table for this subscription.
   * 
   * @param {string} routeTableName The name of the route table in this
   * subscription to retrieve.
   * 
   * @param {string} detailLevel The amount of detail about the requested route
   * table that will be returned.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RouteOperations.prototype.getRouteTableWithDetails = function(routeTableName, detailLevel, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (routeTableName === null || routeTableName === undefined) {
      return callback(new Error('routeTableName cannot be null.'));
    }
    if (detailLevel === null || detailLevel === undefined) {
      return callback(new Error('detailLevel 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/networking/routetables/';
    url2 = url2 + encodeURIComponent(routeTableName);
    var queryParameters = [];
    queryParameters.push('detailLevel=' + encodeURIComponent(detailLevel));
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // 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 options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var routeTableElement = js2xml.getElement(responseDoc, responseDoc, 'ROUTETABLE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (routeTableElement !== null && routeTableElement !== undefined) {
            var routeTableInstance = { routeList: [] };
            result.routeTable = routeTableInstance;
            
            var nameElement = js2xml.getElement(responseDoc, routeTableElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement !== null && nameElement !== undefined) {
              var nameInstance = nameElement;
              routeTableInstance.name = nameInstance;
            }
            
            var labelElement = js2xml.getElement(responseDoc, routeTableElement, 'LABEL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (labelElement !== null && labelElement !== undefined) {
              var labelInstance = labelElement;
              routeTableInstance.label = labelInstance;
            }
            
            var locationElement = js2xml.getElement(responseDoc, routeTableElement, 'LOCATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (locationElement !== null && locationElement !== undefined) {
              var locationInstance = locationElement;
              routeTableInstance.location = locationInstance;
            }
            
            var routeTableStateElement = js2xml.getElement(responseDoc, routeTableElement, 'ROUTETABLESTATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (routeTableStateElement !== null && routeTableStateElement !== undefined && routeTableStateElement.length !== 0) {
              var routeTableStateInstance = routeTableStateElement;
              routeTableInstance.routeTableState = routeTableStateInstance;
            }
            
            var routeListSequenceElement = js2xml.getElement(responseDoc, routeTableElement, 'ROUTELIST', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (routeListSequenceElement !== null && routeListSequenceElement !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, routeListSequenceElement, 'ROUTE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
                var routeListElement = js2xml.getElements(responseDoc, routeListSequenceElement, 'ROUTE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
                var routeInstance = {};
                routeTableInstance.routeList.push(routeInstance);
                
                var nameElement2 = js2xml.getElement(responseDoc, routeListElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (nameElement2 !== null && nameElement2 !== undefined) {
                  var nameInstance2 = nameElement2;
                  routeInstance.name = nameInstance2;
                }
                
                var addressPrefixElement = js2xml.getElement(responseDoc, routeListElement, 'ADDRESSPREFIX', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (addressPrefixElement !== null && addressPrefixElement !== undefined) {
                  var addressPrefixInstance = addressPrefixElement;
                  routeInstance.addressPrefix = addressPrefixInstance;
                }
                
                var nextHopTypeElement = js2xml.getElement(responseDoc, routeListElement, 'NEXTHOPTYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (nextHopTypeElement !== null && nextHopTypeElement !== undefined) {
                  var nextHopTypeInstance = {};
                  routeInstance.nextHop = nextHopTypeInstance;
                  
                  var typeElement = js2xml.getElement(responseDoc, nextHopTypeElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (typeElement !== null && typeElement !== undefined) {
                    var typeInstance = typeElement;
                    nextHopTypeInstance.type = typeInstance;
                  }
                  
                  var ipAddressElement = js2xml.getElement(responseDoc, nextHopTypeElement, 'IPADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (ipAddressElement !== null && ipAddressElement !== undefined) {
                    var ipAddressInstance = ipAddressElement;
                    nextHopTypeInstance.ipAddress = ipAddressInstance;
                  }
                }
                
                var metricElement = js2xml.getElement(responseDoc, routeListElement, 'METRIC', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (metricElement !== null && metricElement !== undefined && metricElement.length !== 0) {
                  var metricInstance = parseInt(metricElement, 10);
                  routeInstance.metric = metricInstance;
                }
                
                var routeStateElement = js2xml.getElement(responseDoc, routeListElement, 'ROUTESTATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (routeStateElement !== null && routeStateElement !== undefined && routeStateElement.length !== 0) {
                  var routeStateInstance = routeStateElement;
                  routeInstance.state = routeStateInstance;
                }
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * List the existing route tables for this subscription.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RouteOperations.prototype.listRouteTables = function(callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // 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/networking/routetables';
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // 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 = { routeTables: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var routeTablesSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'ROUTETABLES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (routeTablesSequenceElement !== null && routeTablesSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, routeTablesSequenceElement, 'ROUTETABLE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var routeTablesElement = js2xml.getElements(responseDoc, routeTablesSequenceElement, 'ROUTETABLE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var routeTableInstance = { routeList: [] };
              result.routeTables.push(routeTableInstance);
              
              var nameElement = js2xml.getElement(responseDoc, routeTablesElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (nameElement !== null && nameElement !== undefined) {
                var nameInstance = nameElement;
                routeTableInstance.name = nameInstance;
              }
              
              var labelElement = js2xml.getElement(responseDoc, routeTablesElement, 'LABEL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (labelElement !== null && labelElement !== undefined) {
                var labelInstance = labelElement;
                routeTableInstance.label = labelInstance;
              }
              
              var locationElement = js2xml.getElement(responseDoc, routeTablesElement, 'LOCATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (locationElement !== null && locationElement !== undefined) {
                var locationInstance = locationElement;
                routeTableInstance.location = locationInstance;
              }
              
              var routeTableStateElement = js2xml.getElement(responseDoc, routeTablesElement, 'ROUTETABLESTATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (routeTableStateElement !== null && routeTableStateElement !== undefined && routeTableStateElement.length !== 0) {
                var routeTableStateInstance = routeTableStateElement;
                routeTableInstance.routeTableState = routeTableStateInstance;
              }
              
              var routeListSequenceElement = js2xml.getElement(responseDoc, routeTablesElement, 'ROUTELIST', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (routeListSequenceElement !== null && routeListSequenceElement !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < js2xml.getElements(responseDoc, routeListSequenceElement, 'ROUTE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex2 = loweredIndex2 + 1) {
                  var routeListElement = js2xml.getElements(responseDoc, routeListSequenceElement, 'ROUTE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex2];
                  var routeInstance = {};
                  routeTableInstance.routeList.push(routeInstance);
                  
                  var nameElement2 = js2xml.getElement(responseDoc, routeListElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (nameElement2 !== null && nameElement2 !== undefined) {
                    var nameInstance2 = nameElement2;
                    routeInstance.name = nameInstance2;
                  }
                  
                  var addressPrefixElement = js2xml.getElement(responseDoc, routeListElement, 'ADDRESSPREFIX', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (addressPrefixElement !== null && addressPrefixElement !== undefined) {
                    var addressPrefixInstance = addressPrefixElement;
                    routeInstance.addressPrefix = addressPrefixInstance;
                  }
                  
                  var nextHopTypeElement = js2xml.getElement(responseDoc, routeListElement, 'NEXTHOPTYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (nextHopTypeElement !== null && nextHopTypeElement !== undefined) {
                    var nextHopTypeInstance = {};
                    routeInstance.nextHop = nextHopTypeInstance;
                    
                    var typeElement = js2xml.getElement(responseDoc, nextHopTypeElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                    if (typeElement !== null && typeElement !== undefined) {
                      var typeInstance = typeElement;
                      nextHopTypeInstance.type = typeInstance;
                    }
                    
                    var ipAddressElement = js2xml.getElement(responseDoc, nextHopTypeElement, 'IPADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                    if (ipAddressElement !== null && ipAddressElement !== undefined) {
                      var ipAddressInstance = ipAddressElement;
                      nextHopTypeInstance.ipAddress = ipAddressInstance;
                    }
                  }
                  
                  var metricElement = js2xml.getElement(responseDoc, routeListElement, 'METRIC', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (metricElement !== null && metricElement !== undefined && metricElement.length !== 0) {
                    var metricInstance = parseInt(metricElement, 10);
                    routeInstance.metric = metricInstance;
                  }
                  
                  var routeStateElement = js2xml.getElement(responseDoc, routeListElement, 'ROUTESTATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (routeStateElement !== null && routeStateElement !== undefined && routeStateElement.length !== 0) {
                    var routeStateInstance = routeStateElement;
                    routeInstance.state = routeStateInstance;
                  }
                }
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * Remove the route table from the provided subnet in the provided virtual
   * network in this subscription.
   * 
   * @param {string} vnetName The name of the virtual network that contains the
   * provided subnet.
   * 
   * @param {string} subnetName The name of the subnet that the route table
   * will be removed from.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RouteOperations.prototype.removeRouteTableFromSubnet = function(vnetName, subnetName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.routes.beginRemoveRouteTableFromSubnet(vnetName, subnetName, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * Set the specified route for the provided table in this subscription.
   * 
   * @param {string} routeTableName The name of the route table where the
   * provided route will be set.
   * 
   * @param {string} routeName The name of the route that will be set on the
   * provided route table.
   * 
   * @param {SetRouteParameters} parameters The parameters necessary to create
   * a new route table.
   * 
   * @param {string} [parameters.name]
   * 
   * @param {string} [parameters.addressPrefix]
   * 
   * @param {NextHop} [parameters.nextHop]
   * 
   * @param {string} [parameters.nextHop.type] Gets or sets the type of the
   * next hop.
   * 
   * @param {string} [parameters.nextHop.ipAddress] Gets or sets the next hop
   * IP addresses.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RouteOperations.prototype.setRoute = function(routeTableName, routeName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.routes.beginSetRoute(routeTableName, routeName, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  return RouteOperations;
})();

var StaticIPOperations = ( /** @lends StaticIPOperations */ function() {
  /**
   * @class
   * The Network Management API includes operations for managing the static IPs
   * for your subscription.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [NetworkManagementClient] {@link
   * NetworkManagementClient~NetworkManagementClient}.
   * See [staticIPs] {@link
   * NetworkManagementClient~NetworkManagementClient#staticIPs}.
   * Initializes a new instance of the StaticIPOperations class.
   * @constructor
   * 
   * @param {NetworkManagementClient} client Reference to the service client.
   */
  function StaticIPOperations(client) {
    this.client = client;
  }
  
  /**
   * The Check Static IP operation retrieves the details for the availability
   * of static IP addresses for the given virtual network.
   * 
   * @param {string} networkName The name of the virtual network.
   * 
   * @param {string} ipAddress The address of the static IP.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  StaticIPOperations.prototype.check = function(networkName, ipAddress, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (networkName === null || networkName === undefined) {
      return callback(new Error('networkName cannot be null.'));
    }
    if (ipAddress === null || ipAddress === undefined) {
      return callback(new Error('ipAddress 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/networking/';
    url2 = url2 + encodeURIComponent(networkName);
    var queryParameters = [];
    queryParameters.push('op=checkavailability');
    queryParameters.push('address=' + encodeURIComponent(ipAddress));
    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['x-ms-version'] = '2016-03-01';
    
    // 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 = { availableAddresses: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var addressAvailabilityResponseElement = js2xml.getElement(responseDoc, responseDoc, 'ADDRESSAVAILABILITYRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (addressAvailabilityResponseElement !== null && addressAvailabilityResponseElement !== undefined) {
            var isAvailableElement = js2xml.getElement(responseDoc, addressAvailabilityResponseElement, 'ISAVAILABLE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (isAvailableElement !== null && isAvailableElement !== undefined && isAvailableElement.length !== 0) {
              var isAvailableInstance = isAvailableElement === 'true';
              result.isAvailable = isAvailableInstance;
            }
            
            var availableAddressesSequenceElement = js2xml.getElement(responseDoc, addressAvailabilityResponseElement, 'AVAILABLEADDRESSES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (availableAddressesSequenceElement !== null && availableAddressesSequenceElement !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, availableAddressesSequenceElement, 'AVAILABLEADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
                var availableAddressesElement = js2xml.getElements(responseDoc, availableAddressesSequenceElement, 'AVAILABLEADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
                result.availableAddresses.push(availableAddressesElement);
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return StaticIPOperations;
})();

var VirtualIPOperations = ( /** @lends VirtualIPOperations */ function() {
  /**
   * @class
   * The Network Management API includes operations for managing the Virtual
   * IPs for your deployment.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [NetworkManagementClient] {@link
   * NetworkManagementClient~NetworkManagementClient}.
   * See [virtualIPs] {@link
   * NetworkManagementClient~NetworkManagementClient#virtualIPs}.
   * Initializes a new instance of the VirtualIPOperations class.
   * @constructor
   * 
   * @param {NetworkManagementClient} client Reference to the service client.
   */
  function VirtualIPOperations(client) {
    this.client = client;
  }
  
  /**
   * The Add Virtual IP operation adds a logical Virtual IP to the deployment.
   * 
   * @param {string} serviceName The name of the hosted service that contains
   * the given deployment.
   * 
   * @param {string} deploymentName The name of the deployment where the
   * logical Virtual IP is to be added.
   * 
   * @param {string} virtualIPName The name of the logical Virtual IP to be
   * added.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  VirtualIPOperations.prototype.add = function(serviceName, deploymentName, virtualIPName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.virtualIPs.beginAdding(serviceName, deploymentName, virtualIPName, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      if (result.status === 'Succeeded') {
        return callback(null, result);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * The Begin Adding Virtual IP operation adds a logical Virtual IP to the
   * deployment.
   * 
   * @param {string} serviceName The name of the hosted service that contains
   * the given deployment.
   * 
   * @param {string} deploymentName The name of the deployment where the
   * logical Virtual IP is to be added.
   * 
   * @param {string} virtualIPName The name of the logical Virtual IP to be
   * added.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  VirtualIPOperations.prototype.beginAdding = function(serviceName, deploymentName, virtualIPName, 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.'));
    }
    if (deploymentName === null || deploymentName === undefined) {
      return callback(new Error('deploymentName cannot be null.'));
    }
    if (virtualIPName === null || virtualIPName === undefined) {
      return callback(new Error('virtualIPName 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 + '/';
    url2 = url2 + encodeURIComponent(virtualIPName);
    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'] = '2016-03-01';
    
    // 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 Removing Virtual IP operation removes a logical Virtual IP from
   * the deployment.
   * 
   * @param {string} serviceName The name of the hosted service that contains
   * the given deployment.
   * 
   * @param {string} deploymentName The name of the deployment whose logical
   * Virtual IP is to be removed.
   * 
   * @param {string} virtualIPName The name of the logical Virtual IP to be
   * added.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  VirtualIPOperations.prototype.beginRemoving = function(serviceName, deploymentName, virtualIPName, 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.'));
    }
    if (deploymentName === null || deploymentName === undefined) {
      return callback(new Error('deploymentName cannot be null.'));
    }
    if (virtualIPName === null || virtualIPName === undefined) {
      return callback(new Error('virtualIPName 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 + '/virtualIPs/';
    url2 = url2 + encodeURIComponent(virtualIPName);
    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/xml';
    httpRequest.headers['x-ms-version'] = '2016-03-01';
    
    // 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 Remove Virtual IP operation removes a logical Virtual IP from the
   * deployment.
   * 
   * @param {string} serviceName The name of the hosted service that contains
   * the given deployment.
   * 
   * @param {string} deploymentName The name of the deployment whose logical
   * Virtual IP is to be removed.
   * 
   * @param {string} virtualIPName The name of the logical Virtual IP to be
   * removed.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  VirtualIPOperations.prototype.remove = function(serviceName, deploymentName, virtualIPName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.virtualIPs.beginRemoving(serviceName, deploymentName, virtualIPName, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      if (result.status === 'Succeeded') {
        return callback(null, result);
      }
      var delayInSeconds = 30;
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getOperationStatus(result.requestId, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                if (result2.status !== 'Succeeded') {
                  if (result2.error !== null && result2.error !== undefined) {
                    var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                    ex.error = new Error();
                    ex.error.code = result2.error.code;
                    ex.error.message = result2.error.message;
                    return callback(ex);
                  } else {
                    var ex = new Error('');
                    return callback(ex);
                  }
                }
                
                return callback(null, result2);
              } else {
                delayInSeconds = 30;
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  return VirtualIPOperations;
})();
