/*** Generated by streamline 0.10.17 (callbacks) - DO NOT EDIT ***/ var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename, false),__func=__rt.__func,__cb=__rt.__cb,__catch=__rt.__catch,__tryCatch=__rt.__tryCatch,__forIn=__rt.__forIn; var fs = require("fs");















var readableStream = require("readable-stream");
var stream = require("stream");
var __ = require("underscore");
var url = require("url");
var util = require("util");

var azureStorage = require("azure-storage");

var AvailabilitySet = require("./../availabilityset/availabilitySet");
var NetworkNic = require("./networkNic");
var NetworkPublicIP = require("./networkPublicIP");
var profile = require("../../../util/profile");
var StorageUtil = require("../../../util/storage.util");
var startProgress = StorageUtil.startProgress;
var endProgress = StorageUtil.endProgress;
var utils = require("../../../util/utils");
var vmConstants = require("../../../util/vmConstants");
var VirtualMachine = require("./virtualMachine");
var VMImage = require("./vmImage");
var VMExtensionProfile = require("./vmExtensionProfile");
var VMProfile = require("./vmProfile");
var vmShowUtil = require("./vmShowUtil");
var VMStorageProfile = require("./vmStorageProfile");
var blobUtil = require("../../../util/blobUtils");
var AemExtensionUtil = require("./aemExtensionUtil");

var $ = utils.getLocaleString;
var writable = (stream.Writable || readableStream.Writable);
var CHEFPUBLISHER = "Chef.Bootstrap.WindowsAzure";

function WriteStream(options) {
  writable.call(this, options);};


function VMClient(cli, subscription) {
  this.cli = cli;
  this.subscription = subscription;};


__.extend(VMClient.prototype, {
  createVM: function createVM__1(resourceGroupName, vmName, location, osType, options, _) { var subscription, params, serviceClients, virtualMachine, vmResult, vmProfile, vmCreateProfile, diagProfile, diagMessage, foundBginfoExt, foundMajorVersion, vmImage, publishers, key1, types, key2, versions, key3, versionTable, bgInfoParams, vmExtensionProfile, vmBgInfoExtension, __this = this; var __frame = { name: "createVM__1", line: 57 }; return __func(_, this, arguments, createVM__1, 5, __frame, function __$createVM__1() {
      subscription = profile.current.getSubscription(__this.subscription);
      params = { };

      params.subscriptionId = subscription.id;
      params.vmName = vmName;
      params.location = location;
      if ((options.imageUrn && (options.imageUrn.indexOf(":") === -1))) {
        options.imageUrn = utils.getImageAliasUrn(options.imageUrn); } ;

      params.imageUrn = options.imageUrn;

      params.vmSize = options.vmSize;

      params.computerName = params.vmName;
      params.adminUsername = options.adminUsername;
      params.adminPassword = options.adminPassword;
      params.osType = osType;
      params.sshPublickeyFile = options.sshPublickeyFile;
      params.generateSshKeys = options.generateSshKeys;
      params.customData = options.customData;

      params.storageAccountName = options.storageAccountName;
      params.storageAccountContainerName = (options.storageAccountContainerName || "vhds");

      params.osDiskType = params.osType;
      params.osDiskCaching = options.osDiskCaching;
      params.osDiskVhd = options.osDiskVhd;

      params.diskEncryptionKeyVaultId = options.diskEncryptionKeyVaultId;
      params.diskEncryptionKeySecretUrl = options.diskEncryptionKeyUrl;
      params.keyEncryptionKeyVaultId = options.keyEncryptionKeyVaultId;
      params.keyEncryptionKeyUrl = options.keyEncryptionKeyUrl;

      params.dataDiskCaching = options.dataDiskCaching;
      params.dataDiskVhd = options.dataDiskVhd;
      params.dataDiskSize = options.dataDiskSize;
      params.newDataDisk = !options.dataDiskExisting;
      params.dataDisks = [];

      params.nicName = options.nicName;
      params.nicId = options.nicId;
      params.nicIds = options.nicIds;
      params.nicNames = options.nicNames;

      params.publicipName = options.publicIpName;
      params.publicipDomainName = options.publicIpDomainName;
      params.publicipIdletimeout = options.publicIpIdletimeout;
      params.publicipAllocationmethod = options.publicIpAllocationMethod;

      params.subnetId = options.subnetId;
      params.vnetName = options.vnetName;
      params.vnetAddressPrefix = options.vnetAddressPrefix;
      params.vnetSubnetName = options.vnetSubnetName;
      params.vnetSubnetAddressprefix = options.vnetSubnetAddressPrefix;

      params.availsetName = options.availsetName;

      params.tags = options.tags;

      params.disableBootDiagnostics = !!(options.disableBootDiagnostics);
      params.enableBootDiagnostics = !(params.disableBootDiagnostics);
      params.enableBootDiagnostics = (options.bootDiagnosticsStorageUri ? true : params.enableBootDiagnostics);
      params.bootDiagnosticsStorageUri = (options.bootDiagnosticsStorageUri ? options.bootDiagnosticsStorageUri : null);

      params.disableBginfoExtension = (options.disableBginfoExtension ? options.disableBginfoExtension : null);

      params.licenseType = options.licenseType;

      if (!utils.stringIsNullOrEmpty(options.planName)) {
        params.plan = {
          name: options.planName,
          publisher: (options.planPublisher ? options.planPublisher : null),
          product: (options.planProduct ? options.planProduct : null),
          promotionCode: (options.planPromotionCode ? options.planPromotionCode : null) }; } ;



      serviceClients = __this._getServiceClients(subscription);
      virtualMachine = new VirtualMachine(__this.cli, serviceClients);
      return virtualMachine.getVM(resourceGroupName, params.vmName, __cb(_, __frame, 80, 34, function ___(__0, __5) { vmResult = __5;
        if (vmResult) {
          return _(new Error(util.format($("A virtual machine with name \"%s\" already exists in the resource group \"%s\""), vmResult.name, resourceGroupName))); } ;


        vmProfile = new VMProfile(__this.cli, resourceGroupName, params, serviceClients);
        return vmProfile.generateVMProfile(__cb(_, __frame, 86, 36, function ___(__0, __6) { vmCreateProfile = __6;

          if ((!options.bootDiagnosticsStorageUri && vmCreateProfile.profile.diagnosticsProfile)) {
            diagProfile = vmCreateProfile.profile.diagnosticsProfile;
            if (((diagProfile.bootDiagnostics && diagProfile.bootDiagnostics.enabled) && diagProfile.bootDiagnostics.storageUri)) {
              diagMessage = util.format($(("The storage URI '%s' will be used for boot diagnostics settings, and it " + "can be overwritten by the parameter input of '--boot-diagnostics-storage-uri'.")), diagProfile.bootDiagnostics.storageUri);



              __this.cli.output.info(diagMessage); } ; } ;



          foundBginfoExt = false;
          foundMajorVersion = (vmConstants.EXTENSIONS.BGINFO_MAJOR_VERSION + ".0"); return (function __$createVM__1(__then) {
            if ((!params.disableBginfoExtension && (osType.toString().toLowerCase() == "windows"))) {

              vmImage = new VMImage(__this.cli, serviceClients);
              return vmImage.getVMImagePublisherList(location, __cb(_, __frame, 104, 31, function ___(__0, __7) { publishers = __7;
                var __1 = __forIn(publishers); var __2 = 0; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$createVM__1() { __more = false; var __13 = (__2 < __1.length); if (__13) { key1 = __1[__2++]; return (function __$createVM__1(__then) {
                        if ((publishers[key1].name === vmConstants.EXTENSIONS.BGINFO_PUBLISHER)) {
                          return vmImage.getVMExtensionImageTypeList(location, publishers[key1].name, __cb(_, __frame, 107, 30, function ___(__0, __8) { types = __8;
                            var __3 = __forIn(types); var __4 = 0; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$createVM__1() { __more = false; var __15 = (__4 < __3.length); if (__15) { key2 = __3[__4++]; return (function __$createVM__1(__then) {
                                    if ((types[key2].name === vmConstants.EXTENSIONS.BGINFO_NAME)) {
                                      return vmImage.getVMExtensionImageVersionList(location, publishers[key1].name, types[key2].name, __cb(_, __frame, 110, 37, function ___(__0, __9) { versions = __9;
                                        if ((versions.length > 0)) {
                                          for (key3 in versions) {

                                            if (utils.stringStartsWith(versions[key3].name, (vmConstants.EXTENSIONS.BGINFO_MAJOR_VERSION + "."))) {
                                              foundBginfoExt = true;
                                              versionTable = versions[key3].name.split(".");
                                              if ((versionTable.length >= 2)) {
                                                foundMajorVersion = ((versionTable[0] + ".") + versionTable[1]); } ;

                                              break; } ; }; } ; return __break(); }, true)); } else { __then(); } ; })(function __$createVM__1() { while (__more) { __loop(); }; __more = true; }); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(__break); }, true)); } else { __then(); } ; })(function __$createVM__1() { while (__more) { __loop(); }; __more = true; }); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(__then); }, true)); } else { __then(); } ; })(function __$createVM__1() {











            return virtualMachine.createOrUpdateVM(resourceGroupName, vmCreateProfile.profile, true, __cb(_, __frame, 132, 19, function __$createVM__1() { return (function __$createVM__1(__then) {


                if (foundBginfoExt) {
                  bgInfoParams = {
                    resourceGroupName: resourceGroupName,
                    osType: osType,
                    location: location,
                    versionFound: true,
                    version: foundMajorVersion };


                  vmExtensionProfile = new VMExtensionProfile(__this.cli, bgInfoParams, serviceClients);
                  vmBgInfoExtension = vmExtensionProfile.generateVMBgInfoExtensionProfile();
                  return virtualMachine.createOrUpdateVMExtension(resourceGroupName, params.vmName, vmBgInfoExtension.profile, true, __cb(_, __frame, 146, 21, __then, true)); } else { __then(); } ; })(_); }, true)); }); }, true)); }, true)); }); },



  getDefaultVmSize: function getDefaultVmSize__2(location, _) { var subscription, serviceClients, virtualMachine, sizeResult, selectedSize, findAndSet, __this = this; var __frame = { name: "getDefaultVmSize__2", line: 207 }; return __func(_, this, arguments, getDefaultVmSize__2, 1, __frame, function __$getDefaultVmSize__2() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      virtualMachine = new VirtualMachine(__this.cli, serviceClients);
      return virtualMachine.getVMSizesByLocationName(location, __cb(_, __frame, 4, 36, function ___(__0, __1) { sizeResult = __1;
        selectedSize = null;
        findAndSet = function(sizeName) {
          for (var i = 0; (i < sizeResult.length); i++) {
            if ((sizeResult[i].name === sizeName)) {
              selectedSize = sizeName; }; }; };


        if ((sizeResult && Array.isArray(sizeResult))) {
          findAndSet("Standard_D1");
          findAndSet("Standard_D1_v2");
          findAndSet("Standard_DS1"); } ;

        return _(null, (selectedSize ? selectedSize : "Standard_A0")); }, true)); }); },


  tryCreatePremiumStorageAccount: function tryCreatePremiumStorageAccount__3(storageManagementClient, location, resourceGroupName, name, _) { var defaultType, createdAccount, stoParams, __this = this; var __frame = { name: "tryCreatePremiumStorageAccount__3", line: 227 }; return __func(_, this, arguments, tryCreatePremiumStorageAccount__3, 4, __frame, function __$tryCreatePremiumStorageAccount__3() {
      defaultType = "Premium_LRS";
      createdAccount = null; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$tryCreatePremiumStorageAccount__3() {

            stoParams = { };
            stoParams.name = name;
            stoParams.location = location;

            stoParams.sku = { name: "Premium_LRS" };
            stoParams.kind = "Storage";
            return storageManagementClient.storageAccounts.create(resourceGroupName, stoParams.name, stoParams, __cb(_, __frame, 10, 63, function ___(__0, __1) { createdAccount = __1; __then(); }, true)); }); })(function ___(err, __result) { __catch(function __$tryCreatePremiumStorageAccount__3() { if (err) {


              if ((((err.code === "AccountTypeNotSupportedInLocation") || (err.code === "StorageAccountAlreadyExists")) || (err.code === "VMScaleSetAllocationError"))) {
                __this.cli.output.warn(util.format($("%s : %s [%s]"), err.code, err.message, defaultType)); } else {

                if ((err.message && utils.stringStartsWith(err.message, "Storage account type Premium_LRS is not supported for VM size"))) {
                  __this.cli.output.warn(util.format($("%s : %s [%s]"), err.code, err.message, defaultType)); }

                 else {
                  return _(err); } ; } ; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$tryCreatePremiumStorageAccount__3() {


          return _(null, createdAccount); }); }); }); },


  quickCreateVM: function quickCreateVM__4(resourceGroupName, vmName, location, osType, imageUrn, adminUsername, adminPassword, options, _) { var subscription, removeAllSpace, hash, resourceNamePrefix, resourceName, params, serviceClients, response, rgList, found, index, rgParams, virtualMachine, vmResult, vmProfile, vmCreateProfile, __this = this; var __frame = { name: "quickCreateVM__4", line: 253 }; return __func(_, this, arguments, quickCreateVM__4, 8, __frame, function __$quickCreateVM__4() {
      subscription = profile.current.getSubscription(__this.subscription);

      removeAllSpace = function(str) {
        return (str.replace(/[\(\)\{\}\[\]\.\,\;\:\"\ ']/g, "").toLowerCase()); };


      hash = utils.getHash((((resourceGroupName + vmName) + location) + imageUrn));

      resourceNamePrefix = ((((removeAllSpace(vmName).slice(0, 5) + "-") + removeAllSpace(location).slice(0, 5)) + "-") + hash);

      resourceName = function(postFix) {
        return ((resourceNamePrefix + "-") + postFix); };


      params = { };

      params.subscriptionId = subscription.id;
      params.vmName = vmName;
      params.location = location;
      if ((imageUrn && (imageUrn.indexOf(":") === -1))) {
        imageUrn = utils.getImageAliasUrn(imageUrn); } ;

      params.imageUrn = imageUrn; return (function __$quickCreateVM__4(_) {


        var __1 = options.vmSize; if (__1) { return _(null, __1); } ; return __this.getDefaultVmSize(location, __cb(_, __frame, 26, 44, _, true)); })(__cb(_, __frame, -252, 17, function ___(__0, __2) { params.vmSize = __2;

        params.computerName = params.vmName;
        params.adminUsername = adminUsername;
        params.adminPassword = adminPassword;
        params.sshPublickeyFile = options.sshPublickeyFile;
        params.osType = osType;

        params.storageAccountName = ((("cli" + hash) + utils.getHash(adminUsername))).substring(0, 24);
        params.storageAccountContainerName = "vhds";

        params.osDiskType = osType;

        params.dataDisks = [];

        params.nicName = resourceName("nic");

        params.publicipName = resourceName("pip");
        params.publicipDomainName = resourceName("pip");

        params.vnetName = resourceName("vnet");
        params.vnetAddressPrefix = "10.0.0.0/16";
        params.vnetSubnetName = resourceName("snet");
        params.vnetSubnetAddressprefix = "10.0.1.0/24";




        params.disableBootDiagnostics = false;
        params.enableBootDiagnostics = true;
        params.bootDiagnosticsStorageUri = null;

        serviceClients = __this._getServiceClients(subscription);

        return serviceClients.resourceManagementClient.resourceGroups.list({ }, __cb(_, __frame, 60, 74, function ___(__0, __3) { response = __3;
          rgList = response.resourceGroups;
          found = false;
          for (index in rgList) {
            if ((rgList[index].name === resourceGroupName)) {
              found = true; } ; }; return (function __$quickCreateVM__4(__then) {



            if ((found === false)) {
              rgParams = { location: location };
              return serviceClients.resourceManagementClient.resourceGroups.createOrUpdate(resourceGroupName, rgParams, __cb(_, __frame, 71, 61, __then, true)); } else { __then(); } ; })(function __$quickCreateVM__4() {


            virtualMachine = new VirtualMachine(__this.cli, serviceClients);
            return virtualMachine.getVM(resourceGroupName, params.vmName, __cb(_, __frame, 75, 34, function ___(__0, __4) { vmResult = __4;
              if (vmResult) {
                return _(new Error(util.format($("A virtual machine with name \"%s\" already exists in the resource group \"%s\""), vmResult.name, resourceGroupName))); } ;


              vmProfile = new VMProfile(__this.cli, resourceGroupName, params, serviceClients);
              return vmProfile.generateVMProfile(__cb(_, __frame, 81, 36, function ___(__0, __5) { vmCreateProfile = __5;
                return virtualMachine.createOrUpdateVM(resourceGroupName, vmCreateProfile.profile, true, __cb(_, __frame, 82, 19, function __$quickCreateVM__4() {

                  return __this.showVM(resourceGroupName, params.vmName, { }, __cb(_, __frame, 84, 9, function __$quickCreateVM__4() { _(); }, true)); }, true)); }, true)); }, true)); }); }, true)); }, true)); }); },


  showVM: function showVM__5(resourceGroupName, name, options, _) { var output, isJson, depth, subscription, serviceClients, dependencies, vmResult, virtualMachine, __this = this; var __frame = { name: "showVM__5", line: 340 }; return __func(_, this, arguments, showVM__5, 3, __frame, function __$showVM__5() {
      output = __this.cli.output;
      isJson = output.format().json;
      depth = 0;
      if (isJson) {
        if (options.depth) {
          if ((options.depth === "full")) {
            depth = -1; }
           else {
            depth = utils.parseInt(options.depth);
            if (isNaN(depth)) {
              return _(new Error($("--depth is an optional parameter but when specified it must be an integer (number of times to recurse) or text \"full\" (idefinite recursion)"))); } ; } ; } ; }



       else {
        if (options.depth) {
          output.warn($("--depth paramater will be ignored when --json option is not specified")); } ; } ;



      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      dependencies = {
        virtualMachine: new VirtualMachine(__this.cli, serviceClients),
        availabilitySet: new AvailabilitySet(__this.cli, serviceClients),
        networkNic: new NetworkNic(__this.cli, serviceClients.networkResourceProviderClient) };


      return dependencies.virtualMachine.getVMByNameExpanded(resourceGroupName, name, depth, { }, dependencies, __cb(_, __frame, 29, 47, function ___(__0, __1) { vmResult = __1; return (function __$showVM__5(__then) {
          if (vmResult) {
            virtualMachine = vmResult; return (function __$showVM__5(__then) {
              if (isJson) {
                output.json(virtualMachine); __then(); } else {

                return __this._populateNics(virtualMachine, subscription, __cb(_, __frame, 35, 30, function ___(__0, __2) { virtualMachine = __2;
                  vmShowUtil.show(virtualMachine, output.data); __then(); }, true)); } ; })(__then); } else {


            if (isJson) {
              output.json({ }); }
             else {
              return _(new Error($("No VMs found"))); } ; __then(); } ; })(_); }, true)); }); },




  listVM: function listVM__6(resourceGroupName, options, _) { var subscription, serviceClients, virtualMachine, vmsResult, output, __this = this; var __frame = { name: "listVM__6", line: 387 }; return __func(_, this, arguments, listVM__6, 2, __frame, function __$listVM__6() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      virtualMachine = new VirtualMachine(__this.cli, serviceClients);

      return virtualMachine.getVMList(resourceGroupName, __cb(_, __frame, 5, 35, function ___(__0, __1) { vmsResult = __1;
        output = __this.cli.output;
        __this.cli.interaction.formatOutput(vmsResult, function(outputData) {
          if ((outputData.length === 0)) {
            output.info($("No VMs found")); }
           else {
            output.table(outputData, function(row, item) {
              row.cell($("ResourceGroupName"), item.resourceGroupName);
              row.cell($("Name"), item.name);
              row.cell($("ProvisioningState"), item.provisioningState);
              row.cell($("PowerState"), (item.powerState ? item.powerState : ""));
              row.cell($("Location"), item.location);
              row.cell($("Size"), item.hardwareProfile.vmSize); }); } ; }); _(); }, true)); }); },





  listIPAddress: function listIPAddress__7(resourceGroupName, options, _) { var subscription, serviceClients, virtualMachine, vmsResult, output, __this = this; var __frame = { name: "listIPAddress__7", line: 410 }; return __func(_, this, arguments, listIPAddress__7, 2, __frame, function __$listIPAddress__7() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      virtualMachine = new VirtualMachine(__this.cli, serviceClients);
      return virtualMachine.getVMList(resourceGroupName, __cb(_, __frame, 4, 35, function ___(__0, __1) { vmsResult = __1;
        i = 0; var __5 = false; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$listIPAddress__7() { __more = false; if (__5) { i++; } else { __5 = true; } ; var __4 = (i < vmsResult.length); if (__4) {

              return __this._populateNics(vmsResult[i], subscription, __cb(_, __frame, 7, 26, function ___(__0, __2) { vmsResult[i] = __2; while (__more) { __loop(); }; __more = true; }, true)); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$listIPAddress__7() {

          output = __this.cli.output;
          __this.cli.interaction.formatOutput(vmsResult, function(outputData) {
            if ((outputData.length === 0)) {
              output.info($("No VMs found")); }

             else {
              output.table(outputData, function(row, item) {
                row.cell($("Resource Group "), item.resourceGroupName);
                row.cell($("Name"), item.name);
                row.cell($("Public IP Address"), utils.getPublicIp(item)); }); } ; }); _(); }); }, true)); }); },





  deleteVM: function deleteVM__8(resourceGroupName, name, options, _) { var subscription, serviceClients, virtualMachine, vmResult, __this = this; var __frame = { name: "deleteVM__8", line: 434 }; return __func(_, this, arguments, deleteVM__8, 3, __frame, function __$deleteVM__8() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      virtualMachine = new VirtualMachine(__this.cli, serviceClients);

      return virtualMachine.getVM(resourceGroupName, name, __cb(_, __frame, 5, 34, function ___(__0, __2) { vmResult = __2;
        if (!vmResult) {
          return _(new Error(util.format($("Virtual machine \"%s\" not found under the resource group \"%s\""), name, resourceGroupName))); } ; return (function __$deleteVM__8(_) {


          var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return __this.cli.interaction.confirm(util.format($("Delete the virtual machine \"%s\"? [y/n] "), name), __cb(_, __frame, 10, 48, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -433, 17, function ___(__0, __3) { return (function __$deleteVM__8(__then) { if (__3) { return _(null); } else { __then(); } ; })(function __$deleteVM__8() {



            return virtualMachine.deleteVM(resourceGroupName, name, __cb(_, __frame, 14, 19, function __$deleteVM__8() { _(); }, true)); }); }, true)); }, true)); }); },


  stopVM: function stopVM__9(resourceGroupName, name, options, _) { var subscription, serviceClients, virtualMachine, vmResult, output, __this = this; var __frame = { name: "stopVM__9", line: 451 }; return __func(_, this, arguments, stopVM__9, 3, __frame, function __$stopVM__9() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      virtualMachine = new VirtualMachine(__this.cli, serviceClients);

      return virtualMachine.getVM(resourceGroupName, name, __cb(_, __frame, 5, 34, function ___(__0, __1) { vmResult = __1;
        if (!vmResult) {
          return _(new Error(util.format($("Virtual machine \"%s\" not found under the resource group \"%s\""), name, resourceGroupName))); } ;


        output = __this.cli.output;
        output.warn($("VM shutdown will not release the compute resources so you will be billed for the compute resources that this Virtual Machine uses."));
        output.info($("To release the compute resources use \"azure vm deallocate\"."));
        return virtualMachine.stopVM(resourceGroupName, name, __cb(_, __frame, 13, 19, function __$stopVM__9() { _(); }, true)); }, true)); }); },


  restartVM: function restartVM__10(resourceGroupName, name, options, _) { var subscription, serviceClients, virtualMachine, vmResult, __this = this; var __frame = { name: "restartVM__10", line: 467 }; return __func(_, this, arguments, restartVM__10, 3, __frame, function __$restartVM__10() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      virtualMachine = new VirtualMachine(__this.cli, serviceClients);

      return virtualMachine.getVM(resourceGroupName, name, __cb(_, __frame, 5, 34, function ___(__0, __1) { vmResult = __1;
        if (!vmResult) {
          return _(new Error(util.format($("Virtual machine \"%s\" not found under the resource group \"%s\""), name, resourceGroupName))); } ;


        return virtualMachine.restartVM(resourceGroupName, name, __cb(_, __frame, 10, 19, function __$restartVM__10() { _(); }, true)); }, true)); }); },


  startVM: function startVM__11(resourceGroupName, name, options, _) { var subscription, serviceClients, virtualMachine, vmResult, __this = this; var __frame = { name: "startVM__11", line: 480 }; return __func(_, this, arguments, startVM__11, 3, __frame, function __$startVM__11() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      virtualMachine = new VirtualMachine(__this.cli, serviceClients);

      return virtualMachine.getVM(resourceGroupName, name, __cb(_, __frame, 5, 34, function ___(__0, __1) { vmResult = __1;
        if (!vmResult) {
          return _(new Error(util.format($("Virtual machine \"%s\" not found under the resource group \"%s\""), name, resourceGroupName))); } ;


        return virtualMachine.startVM(resourceGroupName, name, __cb(_, __frame, 10, 19, function __$startVM__11() { _(); }, true)); }, true)); }); },


  deallocateVM: function deallocateVM__12(resourceGroupName, name, options, _) { var subscription, serviceClients, virtualMachine, vmResult, __this = this; var __frame = { name: "deallocateVM__12", line: 493 }; return __func(_, this, arguments, deallocateVM__12, 3, __frame, function __$deallocateVM__12() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      virtualMachine = new VirtualMachine(__this.cli, serviceClients);

      return virtualMachine.getVM(resourceGroupName, name, __cb(_, __frame, 5, 34, function ___(__0, __1) { vmResult = __1;
        if (!vmResult) {
          return _(new Error(util.format($("Virtual machine \"%s\" not found under the resource group \"%s\""), name, resourceGroupName))); } ;


        return virtualMachine.deallocateVM(resourceGroupName, name, __cb(_, __frame, 10, 19, function __$deallocateVM__12() { _(); }, true)); }, true)); }); },


  captureVM: function captureVM__13(resourceGroupName, name, vhdNamePrefix, options, _) { var subscription, serviceClients, virtualMachine, vmResult, result, __this = this; var __frame = { name: "captureVM__13", line: 506 }; return __func(_, this, arguments, captureVM__13, 4, __frame, function __$captureVM__13() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      virtualMachine = new VirtualMachine(__this.cli, serviceClients);

      return virtualMachine.getVM(resourceGroupName, name, __cb(_, __frame, 5, 34, function ___(__0, __1) { vmResult = __1;
        if (!vmResult) {
          return _(new Error(util.format($("Virtual machine \"%s\" not found under the resource group \"%s\""), name, resourceGroupName))); } ;


        params = {
          destinationContainerName: (options.storageAccountContainerName || "vhds"),
          vhdPrefix: vhdNamePrefix,
          overwriteVhds: (options.overwrite ? true : false) };


        return virtualMachine.captureVM(resourceGroupName, name, params, __cb(_, __frame, 16, 32, function ___(__0, __2) { result = __2;
          if (result.output) {
            if (options.templateFileName) {
              fs.writeFileSync(options.templateFileName, JSON.stringify(result.output, null, 2));
              __this.cli.output.info(util.format($("Saved template to file \"%s\""), options.templateFileName)); }

             else {
              __this.cli.output.json(result.output); } ; } ; _(); }, true)); }, true)); }); },




  generalizeVM: function generalizeVM__14(resourceGroupName, name, options, _) { var subscription, serviceClients, virtualMachine, vmResult, __this = this; var __frame = { name: "generalizeVM__14", line: 534 }; return __func(_, this, arguments, generalizeVM__14, 3, __frame, function __$generalizeVM__14() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      virtualMachine = new VirtualMachine(__this.cli, serviceClients);

      return virtualMachine.getVM(resourceGroupName, name, __cb(_, __frame, 5, 34, function ___(__0, __1) { vmResult = __1;
        if (!vmResult) {
          return _(new Error(util.format($("Virtual machine \"%s\" not found under the resource group \"%s\""), name, resourceGroupName))); } ;


        return virtualMachine.generalizeVM(resourceGroupName, name, __cb(_, __frame, 10, 19, function __$generalizeVM__14() { _(); }, true)); }, true)); }); },


  getInstanceView: function getInstanceView__15(resourceGroupName, name, options, _) { var subscription, serviceClients, virtualMachine, output, instanceViewResult, vmInstanceView, __this = this; var __frame = { name: "getInstanceView__15", line: 547 }; return __func(_, this, arguments, getInstanceView__15, 3, __frame, function __$getInstanceView__15() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      virtualMachine = new VirtualMachine(__this.cli, serviceClients);
      output = __this.cli.output;

      return virtualMachine.getInstanceView(resourceGroupName, name, __cb(_, __frame, 6, 44, function ___(__0, __1) { instanceViewResult = __1;
        if (!instanceViewResult) {
          if (output.format().json) {
            output.json({ }); }
           else {
            output.warn($("No VMs found")); } ; }

         else {
          vmInstanceView = instanceViewResult;
          __this.cli.interaction.formatOutput(vmInstanceView, function() {
            utils.logLineFormat(vmInstanceView, output.data); }); } ; _(); }, true)); }); },




  getSerialOutput: function getSerialOutput__16(resourceGroupName, name, options, _) { var subscription, serviceClients, virtualMachine, output, instanceViewResult, vmResult, instanceView, consoleScreenshotBlobUri, serialConsoleLogBlobUri, result, storageClient, keys, blobService, content, ws, performStorageOperation, operation, storageOptions, maxLen, startPos, strlen, __this = this; var __frame = { name: "getSerialOutput__16", line: 568 }; return __func(_, this, arguments, getSerialOutput__16, 3, __frame, function __$getSerialOutput__16() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      virtualMachine = new VirtualMachine(__this.cli, serviceClients);
      output = __this.cli.output;

      return virtualMachine.getInstanceView(resourceGroupName, name, __cb(_, __frame, 6, 44, function ___(__0, __2) { instanceViewResult = __2; return (function __$getSerialOutput__16(__then) {
          if (!instanceViewResult) {
            if (output.format().json) {
              output.json({ }); }
             else {
              output.warn($("No VMs found")); } ; __then(); } else {


            vmResult = instanceViewResult; return (function __$getSerialOutput__16(__then) {
              if (vmResult) {
                instanceView = vmResult.instanceView;
                if (((instanceView && instanceView.bootDiagnostics) && instanceView.bootDiagnostics.consoleScreenshotBlobUri)) {

                  consoleScreenshotBlobUri = instanceView.bootDiagnostics.consoleScreenshotBlobUri;
                  __this.cli.output.info(util.format($("Console Screenshot Blob Uri:\n%s"), consoleScreenshotBlobUri)); } ; return (function __$getSerialOutput__16(__then) {


                  if (((instanceView && instanceView.bootDiagnostics) && instanceView.bootDiagnostics.serialConsoleLogBlobUri)) {

                    serialConsoleLogBlobUri = instanceView.bootDiagnostics.serialConsoleLogBlobUri;
                    __this.cli.output.info(util.format($("Serial Console Log Blob Uri:\n%s"), serialConsoleLogBlobUri));


                    StorageUtil.init(__this.cli);

                    result = __this._getStorageAccountContainerAndBlobFromUri(serialConsoleLogBlobUri); return (function __$getSerialOutput__16(__then) {
                      if (((result.accountName && result.containerName) && result.blobName)) {
                        storageClient = serviceClients.storageManagementClient;
                        return storageClient.storageAccounts.listKeys(resourceGroupName, result.accountName, __cb(_, __frame, 34, 53, function ___(__0, __3) { keys = __3;
                          blobService = azureStorage.createBlobService(result.accountName, keys.keys[0].value);

                          content = "";
                          util.inherits(WriteStream, writable);
                          WriteStream.prototype._write = function(chunk, encoding, done) {
                            content += chunk.toString();
                            done(); };

                          ws = new WriteStream();

                          performStorageOperation = StorageUtil.performStorageOperation;
                          operation = __this._getStorageBlobOperation(blobService, "getBlobToStream");
                          storageOptions = __this._getStorageBlobOperationDefaultOption(); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$getSerialOutput__16() {


                                return performStorageOperation(operation, __cb(_, __frame, 50, 14, __then, true), result.containerName, result.blobName, ws, storageOptions); }); })(function ___(e, __result) { __catch(function __$getSerialOutput__16() { if (e) {


                                  if (StorageUtil.isNotFoundException(e)) {
                                    __this.cli.output.warn(util.format($("Can not find blob '%s' in container '%s'"), result.blobName, result.containerName)); }

                                   else {
                                    return _(e); } ; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$getSerialOutput__16() {



                              maxLen = ((options.maxLength === null) ? 1000000 : parseInt(options.maxLength, 10));
                              startPos = 0; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$getSerialOutput__16() { __more = false;
                                  var __8 = (startPos < content.length); if (__8) { return (function __$getSerialOutput__16(_) {
                                      var __1 = (startPos > 0); if (!__1) { return _(null, __1); } ; return __this.cli.interaction.confirm("Do you want to view more log?", __cb(_, __frame, 64, 56, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -567, 17, function ___(__0, __4) { return (function __$getSerialOutput__16(__then) { if (__4) { return __break(); } else { __then(); } ; })(function __$getSerialOutput__16() {



                                        strlen = (((startPos + maxLen) < content.length) ? maxLen : (content.length - startPos));
                                        __this.cli.output.info(content.substr(startPos, strlen));
                                        startPos += parseInt(strlen, 10); while (__more) { __loop(); }; __more = true; }); }, true)); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(__then); }); }); }, true)); } else { __then(); } ; })(__then); } else { __then(); } ; })(__then); } else { __then(); } ; })(__then); } ; })(_); }, true)); }); },







  resetVMAccess: function resetVMAccess__17(resourceGroupName, name, options, _) { var subscription, serviceClients, virtualMachine, vmResult, vmExtensionProfile, vmAccessExtension, __this = this; var __frame = { name: "resetVMAccess__17", line: 646 }; return __func(_, this, arguments, resetVMAccess__17, 3, __frame, function __$resetVMAccess__17() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      virtualMachine = new VirtualMachine(__this.cli, serviceClients);

      return virtualMachine.getVM(resourceGroupName, name, __cb(_, __frame, 5, 34, function ___(__0, __1) { vmResult = __1;
        if (!vmResult) {
          return _(new Error(util.format($("Virtual machine \"%s\" not found under the resource group \"%s\""), name, resourceGroupName))); } ;


        options.location = vmResult.location;
        options.osType = vmResult.storageProfile.osDisk.osType;
        options.version = options.extensionVersion;
        vmExtensionProfile = new VMExtensionProfile(__this.cli, options);
        vmAccessExtension = vmExtensionProfile.generateVMAccessExtensionProfile();

        return virtualMachine.createOrUpdateVMExtension(resourceGroupName, name, vmAccessExtension.profile, true, __cb(_, __frame, 16, 19, function __$resetVMAccess__17() { _(); }, true)); }, true)); }); },


  enableDiagVM: function enableDiagVM__18(resourceGroupName, name, options, _) { var subscription, serviceClients, virtualMachine, vmResult, diagParams, vmExtensionProfile, vmDiagExtension, __this = this; var __frame = { name: "enableDiagVM__18", line: 665 }; return __func(_, this, arguments, enableDiagVM__18, 3, __frame, function __$enableDiagVM__18() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      virtualMachine = new VirtualMachine(__this.cli, serviceClients);

      return virtualMachine.getVM(resourceGroupName, name, __cb(_, __frame, 5, 34, function ___(__0, __1) { vmResult = __1;
        if (!vmResult) {
          return _(new Error(util.format($("Virtual machine \"%s\" not found under the resource group \"%s\""), name, resourceGroupName))); } ;


        diagParams = {
          resourceGroupName: resourceGroupName,
          osType: vmResult.storageProfile.osDisk.osType,
          location: vmResult.location,
          version: options.extensionVersion,
          storageAccountName: options.storageAccountName,
          osDiskUri: vmResult.storageProfile.osDisk.vhd.uri,
          configFile: options.configFile,
          vmID: vmResult.id };


        vmExtensionProfile = new VMExtensionProfile(__this.cli, diagParams, serviceClients);
        return vmExtensionProfile.generateVMDiagExtensionProfile(__cb(_, __frame, 22, 45, function ___(__0, __2) { vmDiagExtension = __2;
          return virtualMachine.createOrUpdateVMExtension(resourceGroupName, name, vmDiagExtension.profile, true, __cb(_, __frame, 23, 19, function __$enableDiagVM__18() { _(); }, true)); }, true)); }, true)); }); },


  enableAemVM: function enableAemVM__19(resourceGroupName, name, options, _) { var subscription, serviceClients, virtualMachine, aemExtensionUtil, vmResult, vmStorageAccounts, saProperties, storageAccountsResult, osDiskUri, i, dataDisk, dataDiskUri, vmStorageAccountNames, diagExtension, wadStorageAccountName, diagParams, progress, vmDiagExtensionProfile, aemParams, vmAEMExtensionProfile, vmAEMExtension, __this = this; var __frame = { name: "enableAemVM__19", line: 691 }; return __func(_, this, arguments, enableAemVM__19, 3, __frame, function __$enableAemVM__19() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      virtualMachine = new VirtualMachine(__this.cli, serviceClients);
      aemExtensionUtil = new AemExtensionUtil(__this.cli);

      return virtualMachine.getVM(resourceGroupName, name, __cb(_, __frame, 6, 34, function ___(__0, __2) { vmResult = __2;
        if (!vmResult) {
          return _(new Error(util.format($("Virtual machine \"%s\" not found under the resource group \"%s\""), name, resourceGroupName))); } ;



        vmStorageAccounts = { };


        StorageUtil.init(__this.cli);

        StorageUtil.startProgress($("Getting storage accounts"));
        storageAccountsResult = null; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$enableAemVM__19() {

              return serviceClients.storageManagementClient.storageAccounts.list(__cb(_, __frame, 20, 85, function ___(__0, __3) { storageAccountsResult = __3; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$enableAemVM__19() {

                StorageUtil.endProgress(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$enableAemVM__19() {


            osDiskUri = blobUtil.splitDestinationUri(vmResult.storageProfile.osDisk.vhd.uri);
            return aemExtensionUtil.getStorageAccountProperties(serviceClients, storageAccountsResult, osDiskUri.accountName, __cb(_, __frame, 26, 36, function ___(__0, __4) { saProperties = __4;
              vmStorageAccounts[saProperties.name] = saProperties;


              i = 0; var __13 = false; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$enableAemVM__19() { __more = false; if (__13) { i++; } else { __13 = true; } ; var __12 = (i < vmResult.storageProfile.dataDisks.length); if (__12) {
                    dataDisk = vmResult.storageProfile.dataDisks[i];
                    dataDiskUri = blobUtil.splitDestinationUri(dataDisk.vhd.uri); return (function __$enableAemVM__19(__then) {
                      if (!vmStorageAccounts[dataDiskUri.accountName]) {
                        return aemExtensionUtil.getStorageAccountProperties(serviceClients, storageAccountsResult, dataDiskUri.accountName, __cb(_, __frame, 34, 40, function ___(__0, __5) { saProperties = __5;
                          vmStorageAccounts[saProperties.name] = saProperties; __then(); }, true)); } else { __then(); } ; })(function __$enableAemVM__19() { while (__more) { __loop(); }; __more = true; }); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$enableAemVM__19() {




                vmStorageAccountNames = Object.keys(vmStorageAccounts);
                i = 0; var __16 = false; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$enableAemVM__19() { __more = false; if (__16) { i++; } else { __16 = true; } ; var __15 = (i < vmStorageAccountNames.length); if (__15) {
                      vmStorageAccount = vmStorageAccounts[vmStorageAccountNames[i]]; return (function __$enableAemVM__19(__then) {
                        if ((vmStorageAccount.type === "Standard")) {
                          return aemExtensionUtil.enableStorageAccountAnalytics(vmStorageAccount, __cb(_, __frame, 44, 25, __then, true)); } else { __then(); } ; })(function __$enableAemVM__19() { while (__more) { __loop(); }; __more = true; }); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$enableAemVM__19() {




                  diagExtension = null;
                  if (vmResult.resources) {
                    for (i = 0; (i < vmResult.resources.length); i++) {
                      extension = vmResult.resources[i];
                      if ((((extension.virtualMachineExtensionType === vmConstants.EXTENSIONS.IAAS_DIAG_NAME) && (extension.publisher === vmConstants.EXTENSIONS.IAAS_DIAG_PUBLISHER)) || ((extension.virtualMachineExtensionType === vmConstants.EXTENSIONS.LINUX_DIAG_NAME) && (extension.publisher === vmConstants.EXTENSIONS.LINUX_DIAG_PUBLISHER)))) {

                        diagExtension = extension; } ; }; } ;


                  wadStorageAccountName = null; return (function __$enableAemVM__19(__then) {
                    if (!diagExtension) {
                      __this.cli.output.info(util.format($("Diagnostic extension must be enabled first for Virtual Machine \"%s\"."), name)); return (function __$enableAemVM__19(_) {
                        var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return __this.cli.interaction.confirm($("Install the virtual machine diagnostic extension? [y/n] "), __cb(_, __frame, 61, 50, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -690, 17, function ___(__0, __6) { return (function __$enableAemVM__19(__then) { if (__6) {
                            __this.cli.output.error($("Canceled. Please enable diagnostic extension first.")); return _(null); } else { __then(); } ; })(function __$enableAemVM__19() {



                          wadStorageAccountName = options.diagnosticStorageAccountName;
                          if (!wadStorageAccountName) {

                            for (i = 0; (i < vmStorageAccountNames.length); i++) {
                              vmStorageAccount = vmStorageAccounts[vmStorageAccountNames[i]];
                              if ((vmStorageAccount.type === "Standard")) {
                                wadStorageAccountName = vmStorageAccount.name;
                                break; } ; }; } ;




                          if (!wadStorageAccountName) {
                            __this.cli.output.error($("Can't find a standard storage account for diagnostic extension to use."));
                            __this.cli.output.error($("Please specify one with option -a, --diagnostic-storage-account-name")); return _(null); } ;



                          diagParams = {
                            resourceGroupName: resourceGroupName,
                            osType: vmResult.storageProfile.osDisk.osType,
                            location: vmResult.location,
                            storageAccountName: wadStorageAccountName,
                            vmID: vmResult.id };


                          progress = __this.cli.interaction.progress($("Preparing parameters for diagnostic extension")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$enableAemVM__19() {

                                vmDiagExtensionProfile = new VMExtensionProfile(__this.cli, diagParams, serviceClients);
                                return vmDiagExtensionProfile.generateVMDiagExtensionProfile(__cb(_, __frame, 95, 47, function ___(__0, __7) { diagExtension = __7.profile; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$enableAemVM__19() {

                                  progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$enableAemVM__19() {

                              return virtualMachine.createOrUpdateVMExtension(resourceGroupName, name, diagExtension, true, __cb(_, __frame, 99, 21, __then, true)); }); }); }); }, true)); } else {


                      wadStorageAccountName = options.diagnosticStorageAccountName;
                      if (!wadStorageAccountName) {
                        if (diagExtension.settings) {
                          wadStorageAccountName = (diagExtension.settings.StorageAccount ? diagExtension.settings.StorageAccount : diagExtension.settings.storageAccount); } ;
                        if (!wadStorageAccountName) {
                          __this.cli.output.error($("Can't get storage account name from diagnostic extension settings"));
                          __this.cli.output.error($("Please specify one with option -a, --diagnostic-storage-account-name")); return _(null); } ; } ; __then(); } ; })(function __$enableAemVM__19() { return (function __$enableAemVM__19(__then) {





                      if (!vmStorageAccounts[wadStorageAccountName]) {
                        return aemExtensionUtil.getStorageAccountProperties(serviceClients, storageAccountsResult, wadStorageAccountName, __cb(_, __frame, 115, 38, function ___(__0, __8) { saProperties = __8;
                          vmStorageAccounts[saProperties.name] = saProperties; __then(); }, true)); } else { __then(); } ; })(function __$enableAemVM__19() {


                      aemParams = {
                        resourceGroupName: resourceGroupName,
                        verbose: options.verbose,
                        location: vmResult.location,
                        osType: vmResult.storageProfile.osDisk.osType,
                        vmSize: vmResult.hardwareProfile.vmSize,
                        wadStorageAccount: wadStorageAccountName,
                        osDisk: vmResult.storageProfile.osDisk,
                        dataDisks: vmResult.storageProfile.dataDisks,
                        vmStorageAccounts: vmStorageAccounts };


                      vmAEMExtensionProfile = new VMExtensionProfile(__this.cli, aemParams, serviceClients);
                      vmAEMExtension = vmAEMExtensionProfile.generateVMAemProfile();
                      return virtualMachine.createOrUpdateVMExtension(resourceGroupName, name, vmAEMExtension.profile, true, __cb(_, __frame, 133, 19, function __$enableAemVM__19() { _(); }, true)); }); }); }); }); }, true)); }); }); }, true)); }); },


  setVM: function setVM__20(resourceGroupName, name, options, _) { var subscription, serviceClients, virtualMachine, vmResult, vmProfile, __this = this; var __frame = { name: "setVM__20", line: 827 }; return __func(_, this, arguments, setVM__20, 3, __frame, function __$setVM__20() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      virtualMachine = new VirtualMachine(__this.cli, serviceClients);

      return virtualMachine.getVM(resourceGroupName, name, __cb(_, __frame, 5, 34, function ___(__0, __1) { vmResult = __1;
        if (!vmResult) {
          return _(new Error(util.format($("Virtual machine \"%s\" not found under the resource group \"%s\""), name, resourceGroupName))); } ;



        if (((options.disableBootDiagnostics || options.enableBootDiagnostics) || options.bootDiagnosticsStorageUri)) {
          options.disableBootDiagnostics = !!(options.disableBootDiagnostics);
          options.enableBootDiagnostics = (options.enableBootDiagnostics ? true : ((options.disableBootDiagnostics ? false : true)));
          options.enableBootDiagnostics = (options.bootDiagnosticsStorageUri ? true : options.enableBootDiagnostics);
          options.bootDiagnosticsStorageUri = (options.disableBootDiagnostics ? "" : ((options.bootDiagnosticsStorageUri ? options.bootDiagnosticsStorageUri : null))); }

         else {
          options.disableBootDiagnostics = null;
          options.enableBootDiagnostics = null;
          options.bootDiagnosticsStorageUri = null; } ;


        vmProfile = new VMProfile(__this.cli, resourceGroupName, options, serviceClients);
        return vmProfile.updateVMProfile(vmResult, __cb(_, __frame, 24, 25, function ___(__0, __2) { vmResult = __2;

          return virtualMachine.createOrUpdateVM(resourceGroupName, vmResult, false, __cb(_, __frame, 26, 19, function __$setVM__20() { _(); }, true)); }, true)); }, true)); }); },


  listVMSizesOrLocationVMSizes: function listVMSizesOrLocationVMSizes__21(options, _) { var subscription, serviceClients, virtualMachine, sizeResult, vmResult, output, __this = this; var __frame = { name: "listVMSizesOrLocationVMSizes__21", line: 856 }; return __func(_, this, arguments, listVMSizesOrLocationVMSizes__21, 1, __frame, function __$listVMSizesOrLocationVMSizes__21() {
      if ((options.location && options.vmName)) {
        return _(new Error($("Both --location and --vm-name parameters cannot be specified together."))); } ; return (function __$listVMSizesOrLocationVMSizes__21(__then) {


        if (options.vmName) { return (function __$listVMSizesOrLocationVMSizes__21(__then) {
            if (!options.resourceGroup) {
              return __this.cli.interaction.promptIfNotGiven($("Resource group name: "), options.resourceGroup, __cb(_, __frame, 7, 53, function ___(__0, __1) { options.resourceGroup = __1; __then(); }, true)); } else { __then(); } ; })(__then); } else {

          if (!options.location) {
            return _(new Error($("One of the optional parameter --location or --vm-name is required."))); } ; __then(); } ; })(function __$listVMSizesOrLocationVMSizes__21() {


        subscription = profile.current.getSubscription(__this.subscription);
        serviceClients = __this._getServiceClients(subscription);
        virtualMachine = new VirtualMachine(__this.cli, serviceClients); return (function __$listVMSizesOrLocationVMSizes__21(__then) {


          if (options.vmName) {
            return virtualMachine.getVM(options.resourceGroup, options.vmName, __cb(_, __frame, 19, 36, function ___(__0, __2) { vmResult = __2;
              if (!vmResult) {
                return _(new Error(util.format($("Virtual machine \"%s\" not found under the resource group \"%s\""), options.vmName, options.resourceGroup))); } ;


              return virtualMachine.getVMSizesByVMName(options.resourceGroup, options.vmName, __cb(_, __frame, 24, 34, function ___(__0, __3) { sizeResult = __3; __then(); }, true)); }, true)); } else {

            return virtualMachine.getVMSizesByLocationName(options.location, __cb(_, __frame, 26, 34, function ___(__0, __4) { sizeResult = __4; __then(); }, true)); } ; })(function __$listVMSizesOrLocationVMSizes__21() {


          output = __this.cli.output;
          __this.cli.interaction.formatOutput(sizeResult, function(outputData) {
            if ((outputData.length === 0)) {
              output.info($("No VM size details found")); }
             else {
              output.table(outputData, function(row, item) {
                row.cell($("Name"), item.name);
                row.cell($("CPU Cores"), item.numberOfCores);
                row.cell($("Memory (MB)"), item.memoryInMB);
                row.cell($("Max data-disks"), item.maxDataDiskCount);
                row.cell($("Max data-disk Size (MB)"), item.resourceDiskSizeInMB);
                row.cell($("Max OS-disk Size (MB)"), item.osDiskSizeInMB); }); } ; }); _(); }); }); }); },





  listComputeUsage: function listComputeUsage__22(location, options, _) { var subscription, client, usageResult, output, usages, __this = this; var __frame = { name: "listComputeUsage__22", line: 902 }; return __func(_, this, arguments, listComputeUsage__22, 2, __frame, function __$listComputeUsage__22() {
      subscription = profile.current.getSubscription(__this.subscription);
      client = utils.createComputeManagementClient(subscription);

      return client.usageOperations.list(location, __cb(_, __frame, 4, 45, function ___(__0, __1) { usageResult = __1;
        output = __this.cli.output;
        if ((!usageResult || (usageResult.length === 0))) {
          if (output.format().json) {
            output.json([]); }
           else {
            output.warn($("No compute usage information found")); } ; return _(null); } ;





        usages = usageResult;
        __this.cli.interaction.formatOutput(usages, function(outputData) {
          output.table(outputData, function(row, item) {
            row.cell($("Name"), item.name.localizedValue);
            row.cell($("Unit"), item.unit);
            row.cell($("CurrentValue"), item.currentValue);
            row.cell($("Limit"), item.limit); }); }); _(); }, true)); }); },




  attachNewDataDisk: function attachNewDataDisk__23(resourceGroup, vmName, size, vhdName, options, _) { var subscription, serviceClients, params, virtualMachine, vmResult, vmStorageProfile, newDataDisk, dataDisks, __this = this; var __frame = { name: "attachNewDataDisk__23", line: 929 }; return __func(_, this, arguments, attachNewDataDisk__23, 5, __frame, function __$attachNewDataDisk__23() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);

      params = { };
      params.dataDiskSize = size;
      params.dataDiskCaching = options.hostCaching;
      params.dataDiskVhd = vhdName;
      params.vmName = vmName;
      params.storageAccountName = options.storageAccountName;
      params.storageAccountContainerName = (options.storageAccountContainerName || "vhds");
      params.lun = options.lun;
      params.newDataDisk = true;

      virtualMachine = new VirtualMachine(__this.cli, serviceClients);
      return virtualMachine.getVM(resourceGroup, vmName, __cb(_, __frame, 15, 34, function ___(__0, __1) { vmResult = __1;
        if (!vmResult) {
          return _(new Error(util.format($("Virtual machine \"%s\" not found under the resource group \"%s\""), vmName, resourceGroup))); } ;


        if (!options.storageAccountName) {
          params.osDiskUri = vmResult.storageProfile.osDisk.vhd.uri; }
         else {
          params.location = vmResult.location; } ;


        params.dataDisks = vmResult.storageProfile.dataDisks;
        vmStorageProfile = new VMStorageProfile(__this.cli, resourceGroup, params, serviceClients);
        return vmStorageProfile.generateDataDiskProfile(__cb(_, __frame, 28, 39, function ___(__0, __2) { newDataDisk = __2;
          __this.cli.output.info(util.format($("New data disk location: %s "), newDataDisk.vhd.uri));

          dataDisks = (vmResult.storageProfile.dataDisks || []);
          dataDisks.push(newDataDisk); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$attachNewDataDisk__23() {


                return virtualMachine.createOrUpdateVM(resourceGroup, vmResult, false, __cb(_, __frame, 35, 21, __then, true)); }); })(function ___(err, __result) { __catch(function __$attachNewDataDisk__23() { if (err) {

                  if (((err.code === "InvalidParameter") && (err.message === "The value of parameter 'dataDisk.lun' is invalid."))) {
                    return _(new Error(util.format($("Exceeded the maximum number of data disks that can be attached to a VM with size \"%s\"."), vmResult.hardwareProfile.vmSize))); }
                   else {
                    return _(err); } ; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$attachNewDataDisk__23() { _(); }); }); }, true)); }, true)); }); },




  attachDataDisk: function attachDataDisk__24(resourceGroup, vmName, vhdUrl, options, _) { var subscription, serviceClients, params, virtualMachine, vmResult, vmStorageProfile, newDataDisk, dataDisks, __this = this; var __frame = { name: "attachDataDisk__24", line: 974 }; return __func(_, this, arguments, attachDataDisk__24, 4, __frame, function __$attachDataDisk__24() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);

      params = { };
      params.dataDiskCaching = options.hostCaching;
      params.dataDiskVhd = vhdUrl;
      params.vmName = vmName;
      params.lun = options.lun;
      params.newDataDisk = false;

      virtualMachine = new VirtualMachine(__this.cli, serviceClients);
      return virtualMachine.getVM(resourceGroup, vmName, __cb(_, __frame, 12, 34, function ___(__0, __1) { vmResult = __1;
        if (!vmResult) {
          return _(new Error(util.format($("Virtual machine \"%s\" not found under the resource group \"%s\""), vmName, resourceGroup))); } ;


        params.dataDisks = vmResult.storageProfile.dataDisks;
        vmStorageProfile = new VMStorageProfile(__this.cli, resourceGroup, params, serviceClients);
        return vmStorageProfile.generateDataDiskProfile(__cb(_, __frame, 19, 39, function ___(__0, __2) { newDataDisk = __2;

          dataDisks = (vmResult.storageProfile.dataDisks || []);
          dataDisks.push(newDataDisk); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$attachDataDisk__24() {


                return virtualMachine.createOrUpdateVM(resourceGroup, vmResult, false, __cb(_, __frame, 25, 21, __then, true)); }); })(function ___(err, __result) { __catch(function __$attachDataDisk__24() { if (err) {

                  if (((err.code === "InvalidParameter") && (err.message === "The value of parameter 'dataDisk.lun' is invalid."))) {
                    return _(new Error(util.format($("Exceeded the maximum number of data disks that can be attached to a VM with size \"%s\"."), vmResult.hardwareProfile.vmSize))); }
                   else {
                    return _(err); } ; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$attachDataDisk__24() { _(); }); }); }, true)); }, true)); }); },




  detachDataDisk: function detachDataDisk__25(resourceGroup, vmName, lun, options, _) { var subscription, serviceClients, lunAsInt, virtualMachine, vmResult, vmStorageProfile, __this = this; var __frame = { name: "detachDataDisk__25", line: 1009 }; return __func(_, this, arguments, detachDataDisk__25, 4, __frame, function __$detachDataDisk__25() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);

      lunAsInt = utils.parseInt(lun);
      if (isNaN(lunAsInt)) {
        return _(new Error($("lun must be an integer"))); } ;


      virtualMachine = new VirtualMachine(__this.cli, serviceClients);
      return virtualMachine.getVM(resourceGroup, vmName, __cb(_, __frame, 10, 34, function ___(__0, __1) { vmResult = __1;
        if (!vmResult) {
          return _(new Error(util.format($("Virtual machine \"%s\" not found under the resource group \"%s\""), vmName, resourceGroup))); } ;


        vmStorageProfile = new VMStorageProfile(__this.cli, resourceGroup, { }, serviceClients);
        vmStorageProfile.removeDataDiskByLun(vmResult, lunAsInt);

        return virtualMachine.createOrUpdateVM(resourceGroup, vmResult, false, __cb(_, __frame, 18, 19, function __$detachDataDisk__25() { _(); }, true)); }, true)); }); },


  listDataDisks: function listDataDisks__26(resourceGroup, vmName, options, _) { var subscription, serviceClients, virtualMachine, vmResult, dataDisks, output, __this = this; var __frame = { name: "listDataDisks__26", line: 1030 }; return __func(_, this, arguments, listDataDisks__26, 3, __frame, function __$listDataDisks__26() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);

      virtualMachine = new VirtualMachine(__this.cli, serviceClients);
      return virtualMachine.getVM(resourceGroup, vmName, __cb(_, __frame, 5, 34, function ___(__0, __1) { vmResult = __1;
        if (!vmResult) {
          return _(new Error(util.format($("Virtual machine \"%s\" not found under the resource group \"%s\""), vmName, resourceGroup))); } ;


        dataDisks = vmResult.storageProfile.dataDisks;
        output = __this.cli.output;
        if ((!dataDisks || (dataDisks.length === 0))) {
          if (output.format().json) {
            output.json([]); }
           else {
            output.warn($("No data disks found")); } ; return _(null); } ;





        __this.cli.interaction.formatOutput(dataDisks, function(outputData) {
          output.table(outputData, function(row, item) {
            row.cell($("Name"), item.name);
            row.cell($("Lun"), item.lun);
            row.cell($("DiskSizeGB"), (item.diskSizeGB ? item.diskSizeGB : ""));
            row.cell($("Caching"), item.caching);
            row.cell($("URI"), item.vhd.uri); }); }); _(); }, true)); }); },




  setExtension: function setExtension__27(resourceGroupName, vmName, extensionName, publisherName, version, options, _) { var subscription, serviceClients, virtualMachine, vmResult, __this = this; var __frame = { name: "setExtension__27", line: 1063 }; return __func(_, this, arguments, setExtension__27, 6, __frame, function __$setExtension__27() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      virtualMachine = new VirtualMachine(__this.cli, serviceClients);
      return virtualMachine.getVM(resourceGroupName, vmName, __cb(_, __frame, 4, 34, function ___(__0, __1) { vmResult = __1;
        if (!vmResult) {
          return _(new Error(util.format($("Virtual machine \"%s\" not found under the resource group \"%s\""), vmName, resourceGroupName))); } ;


        virtualMachine = vmResult;
        if ((virtualMachine.storageProfile.osDisk.osType === "Windows")) {
          if ((!virtualMachine.osProfile.windowsConfiguration || !virtualMachine.osProfile.windowsConfiguration.provisionVMAgent)) {
            return _(new Error($("Provision Guest Agent must be enabled on the VM before setting VM Extension."))); } ; } ; return (function __$setExtension__27(__then) {



          if (options.uninstall) {
            return __this._uninstallExtension(resourceGroupName, vmName, extensionName, serviceClients, options, __cb(_, __frame, 17, 11, function __$setExtension__27() { return _(null); }, true)); } else { __then(); } ; })(function __$setExtension__27() {



          options.location = vmResult.location;
          return __this._createOrUpdateExtension(resourceGroupName, vmName, extensionName, publisherName, version, options, serviceClients, __cb(_, __frame, 22, 9, function __$setExtension__27() { _(); }, true)); }); }, true)); }); },


  setChefExtension: function setChefExtension__28(resourceGroupName, vmName, options, _) { var subscription, serviceClients, virtualMachine, vmResult, extensionName, vmImage, versionsResult, versions, ver, __this = this; var __frame = { name: "setChefExtension__28", line: 1088 }; return __func(_, this, arguments, setChefExtension__28, 3, __frame, function __$setChefExtension__28() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription); return (function __$setChefExtension__28(__then) {

        if ((!options.clientPem && !options.validationPem)) {
          return __this.cli.interaction.promptIfNotGiven($("VM Extension validation pem file path: "), options.validationPem, __cb(_, __frame, 5, 51, function ___(__0, __1) { options.validationPem = __1; __then(); }, true)); } else { __then(); } ; })(function __$setChefExtension__28() { return (function __$setChefExtension__28(__then) {


          if (!options.clientConfig) {
            return __this.cli.interaction.promptIfNotGiven($("Chef client config file(i.e client.rb) path: "), options.clientConfig, __cb(_, __frame, 9, 50, function ___(__0, __2) { options.clientConfig = __2; __then(); }, true)); } else { __then(); } ; })(function __$setChefExtension__28() {


          virtualMachine = new VirtualMachine(__this.cli, serviceClients);
          return virtualMachine.getVM(resourceGroupName, vmName, __cb(_, __frame, 13, 34, function ___(__0, __3) { vmResult = __3;
            options.location = vmResult.location;

            extensionName = "";
            if (!vmResult) {
              return _(new Error(util.format($("Virtual machine \"%s\" not found under the resource group \"%s\""), vmName, resourceGroupName))); } ;



            virtualMachine = vmResult;
            if ((virtualMachine.storageProfile.osDisk.osType === "Windows")) {
              extensionName = "ChefClient";
              if ((!virtualMachine.osProfile.windowsConfiguration || !virtualMachine.osProfile.windowsConfiguration.provisionVMAgent)) {
                return _(new Error($("Provision Guest Agent must be enabled on the VM before setting VM Extension."))); } ; }

             else {
              extensionName = "LinuxChefClient"; } ; return (function __$setChefExtension__28(__then) {


              if (options.uninstall) {
                return __this._uninstallExtension(resourceGroupName, vmName, extensionName, serviceClients, options, __cb(_, __frame, 33, 11, function __$setChefExtension__28() { return _(null); }, true)); } else { __then(); } ; })(function __$setChefExtension__28() { return (function __$setChefExtension__28(__then) {




                if (!options.version) {
                  vmImage = new VMImage(__this.cli, serviceClients);
                  return vmImage.getVMExtensionImageVersionList(options.location, CHEFPUBLISHER, extensionName, __cb(_, __frame, 40, 35, function ___(__0, __4) { versionsResult = __4;
                    versions = versionsResult;
                    ver = versions[(versions.length - 1)].name.split(".");
                    options.version = ((ver[0] + ".") + ver[1]); __then(); }, true)); } else { __then(); } ; })(function __$setChefExtension__28() {



                pubConfig = { };
                priConfig = { };

                pubConfig["client_rb"] = fs.readFileSync(options.clientConfig).toString();
                pubConfig["runlist"] = options.runList; return (function __$setChefExtension__28(__then) {
                  if (options.bootstrapOptions) { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$setChefExtension__28() {

                          pubConfig["bootstrap_options"] = JSON.parse(options.bootstrapOptions); __then(); }); })(function ___(er, __result) { __catch(function __$setChefExtension__28() { if (er) {

                            log.error("Bad user input for -j or --bootstrap-options option", er);
                            return _(null, cb(er)); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, __then); }); } else { __then(); } ; })(function __$setChefExtension__28() {



                  if (options.clientPem) {
                    priConfig["client_pem"] = fs.readFileSync(options.clientPem).toString(); }
                   else {
                    priConfig["validation_key"] = fs.readFileSync(options.validationPem).toString(); } ;


                  options.publicConfig = pubConfig;
                  options.privateConfig = priConfig;

                  return __this._createOrUpdateExtension(resourceGroupName, vmName, extensionName, CHEFPUBLISHER, options.version, options, serviceClients, __cb(_, __frame, 70, 9, function __$setChefExtension__28() { _(); }, true)); }); }); }); }, true)); }); }); }); },



  getExtensions: function getExtensions__29(resourceGroup, vmName, options, _) { var subscription, serviceClients, virtualMachine, vmResult, output, __this = this; var __frame = { name: "getExtensions__29", line: 1162 }; return __func(_, this, arguments, getExtensions__29, 3, __frame, function __$getExtensions__29() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);

      virtualMachine = new VirtualMachine(__this.cli, serviceClients);
      return virtualMachine.getVM(resourceGroup, vmName, __cb(_, __frame, 5, 34, function ___(__0, __1) { vmResult = __1;
        if (!vmResult) {
          return _(new Error(util.format($("Virtual machine \"%s\" not found under the resource group \"%s\""), vmName, resourceGroup))); } ;


        output = __this.cli.output;
        if ((!vmResult.resources || (vmResult.resources.length === 0))) {
          if (output.format().json) {
            output.json([]); }
           else {
            output.warn($("No VM extensions found")); } ; return _(null); } ;





        __this.cli.interaction.formatOutput(vmResult.resources, function(outputData) {
          output.table(outputData, function(row, item) {
            row.cell($("Publisher"), item.publisher);
            row.cell($("Name"), item.name);
            row.cell($("Version"), item.typeHandlerVersion);
            row.cell($("State"), item.provisioningState); }); }); _(); }, true)); }); },




  getChefExtension: function getChefExtension__30(resourceGroup, vmName, options, _) { var subscription, serviceClients, virtualMachine, vmResult, output, __this = this; var __frame = { name: "getChefExtension__30", line: 1193 }; return __func(_, this, arguments, getChefExtension__30, 3, __frame, function __$getChefExtension__30() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);

      virtualMachine = new VirtualMachine(__this.cli, serviceClients);
      return virtualMachine.getVM(resourceGroup, vmName, __cb(_, __frame, 5, 34, function ___(__0, __1) { vmResult = __1;
        if (!vmResult) {
          return _(new Error(util.format($("Virtual machine \"%s\" not found under the resource group \"%s\""), vmName, resourceGroup))); } ;


        output = __this.cli.output;
        if ((!vmResult.resources || (vmResult.resources.length === 0))) {
          if (output.format().json) {
            output.json([]); }
           else {
            output.warn($("No VM extensions found")); } ; return _(null); } ;





        __this.cli.interaction.formatOutput(vmResult.resources, function(outputData) {
          var chefextn = outputData.filter(function(obj) {
            return (obj.publisher === CHEFPUBLISHER); });


          output.table(chefextn, function(row, item) {
            row.cell($("Publisher"), item.publisher);
            row.cell($("Name"), item.name);
            row.cell($("Version"), item.typeHandlerVersion);
            row.cell($("State"), item.provisioningState); }); }); _(); }, true)); }); },




  createDockerVM: function createDockerVM__31(resourceGroupName, vmName, location, osType, options, _) { var subscription, serviceClients, dockerExtensionParams, vmExtensionProfile, dockerExtension, virtualMachine, __this = this; var __frame = { name: "createDockerVM__31", line: 1228 }; return __func(_, this, arguments, createDockerVM__31, 5, __frame, function __$createDockerVM__31() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);

      dockerExtensionParams = {
        dockerPort: options.dockerPort,
        dockerCertDir: options.dockerCertDir,
        version: options.dockerExtensionVersion,
        location: location,
        vmName: vmName,
        dockerCertCn: options.dockerCertCn };

      vmExtensionProfile = new VMExtensionProfile(__this.cli, dockerExtensionParams);
      return vmExtensionProfile.generateDockerExtensionProfile(__cb(_, __frame, 13, 45, function ___(__0, __1) { dockerExtension = __1;

        return __this.createVM(resourceGroupName, vmName, location, osType, options, __cb(_, __frame, 15, 9, function __$createDockerVM__31() {
          virtualMachine = new VirtualMachine(__this.cli, serviceClients); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$createDockerVM__31() {

                return virtualMachine.createOrUpdateVMExtension(resourceGroupName, vmName, dockerExtension.profile, true, __cb(_, __frame, 18, 21, __then, true)); }); })(function ___(e, __result) { __catch(function __$createDockerVM__31() { if (e) {

                  return virtualMachine.deleteVM(resourceGroupName, vmName, __cb(_, __frame, 20, 21, function __$createDockerVM__31() {
                    return _(e); }, true)); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$createDockerVM__31() { _(); }); }); }, true)); }, true)); }); },



  listVMImagePublishers: function listVMImagePublishers__32(location, options, _) { var subscription, serviceClients, vmImage, publishersResult, publishers, output, __this = this; var __frame = { name: "listVMImagePublishers__32", line: 1253 }; return __func(_, this, arguments, listVMImagePublishers__32, 2, __frame, function __$listVMImagePublishers__32() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);

      vmImage = new VMImage(__this.cli, serviceClients);
      return vmImage.getVMImagePublisherList(location, __cb(_, __frame, 5, 35, function ___(__0, __1) { publishersResult = __1;

        publishers = publishersResult;
        output = __this.cli.output;
        if ((!publishers || (publishers.length === 0))) {
          if (output.format().json) {
            output.json([]); }
           else {
            output.warn(util.format($("No virtual machine and/or extension image publishers found in the region \"%s\""), location)); } ; return _(null); } ;





        __this.cli.interaction.formatOutput(publishers, function(outputData) {
          output.table(outputData, function(row, item) {
            row.cell($("Publisher"), item.name);
            row.cell($("Location"), item.location); }); }); _(); }, true)); }); },




  listVMImageOffers: function listVMImageOffers__33(location, publisherName, options, _) { var subscription, serviceClients, vmImage, offersResult, offers, output, __this = this; var __frame = { name: "listVMImageOffers__33", line: 1280 }; return __func(_, this, arguments, listVMImageOffers__33, 3, __frame, function __$listVMImageOffers__33() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);

      vmImage = new VMImage(__this.cli, serviceClients);
      return vmImage.getVMImageOffersList(location, publisherName, __cb(_, __frame, 5, 31, function ___(__0, __1) { offersResult = __1;

        offers = offersResult;
        output = __this.cli.output;
        if ((!offers || (offers.length === 0))) {
          if (output.format().json) {
            output.json([]); }
           else {
            output.warn(util.format($("No virtual machine image offers found (publisher: \"%s\" location:\"%s\")"), publisherName, location)); } ; return _(null); } ;





        __this.cli.interaction.formatOutput(offers, function(outputData) {
          output.table(outputData, function(row, item) {
            row.cell($("Publisher"), item.publisher);
            row.cell($("Offer"), item.name);
            row.cell($("Location"), item.location); }); }); _(); }, true)); }); },




  listVMImageSkus: function listVMImageSkus__34(location, publisherName, offer, options, _) { var subscription, serviceClients, vmImage, skuResult, skus, output, __this = this; var __frame = { name: "listVMImageSkus__34", line: 1308 }; return __func(_, this, arguments, listVMImageSkus__34, 4, __frame, function __$listVMImageSkus__34() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);

      vmImage = new VMImage(__this.cli, serviceClients);
      return vmImage.getVMImageSkusList(location, publisherName, offer, __cb(_, __frame, 5, 28, function ___(__0, __1) { skuResult = __1;

        skus = skuResult;
        output = __this.cli.output;
        if ((!skus || (skus.length === 0))) {
          if (output.format().json) {
            output.json([]); }
           else {
            output.warn(util.format($("No virtual machine image skus found (publisher: \"%s\" location:\"%s\" offer:\"%s\")"), publisherName, location, offer)); } ; return _(null); } ;





        __this.cli.interaction.formatOutput(skus, function(outputData) {
          output.table(outputData, function(row, item) {
            row.cell($("Publisher"), item.publisher);
            row.cell($("Offer"), item.offer);
            row.cell($("sku"), item.name);
            row.cell($("Location"), item.location); }); }); _(); }, true)); }); },




  listVMImages: function listVMImages__35(params, options, _) { var subscription, serviceClients, imageFilter, vmImage, imagesResult, images, output, __this = this; var __frame = { name: "listVMImages__35", line: 1337 }; return __func(_, this, arguments, listVMImages__35, 2, __frame, function __$listVMImages__35() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      imageFilter = {
        location: params.location,
        publishername: params.publisher,
        offer: params.offer,
        skus: params.sku };


      vmImage = new VMImage(__this.cli, serviceClients);
      return vmImage.getVMImageList(imageFilter, __cb(_, __frame, 11, 31, function ___(__0, __1) { imagesResult = __1;
        images = imagesResult;
        output = __this.cli.output;
        if ((!images || (images.length === 0))) {
          if (output.format().json) {
            output.json([]); }
           else {
            output.warn($("No virtual machine images found")); } ; return _(null); } ;





        __this.cli.interaction.formatOutput(images, function(outputData) {
          output.table(outputData, function(row, item) {
            row.cell($("Publisher"), item.publisher);
            row.cell($("Offer"), item.offer);
            row.cell($("Sku"), item.skus);
            row.cell($("OS"), item.operatingSystem);
            row.cell($("Version"), item.name);
            row.cell($("Location"), item.location);
            row.cell($("Urn"), item.urn); }); }); _(); }, true)); }); },




  getVMImageDetails: function getVMImageDetails__36(params, options, _) { var subscription, serviceClients, imageFilter, vmImage, imagesResult, images, output, __this = this; var __frame = { name: "getVMImageDetails__36", line: 1374 }; return __func(_, this, arguments, getVMImageDetails__36, 2, __frame, function __$getVMImageDetails__36() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      imageFilter = {
        location: params.location,
        publishername: params.publisher,
        offer: params.offer,
        skus: params.sku,
        version: params.version };


      vmImage = new VMImage(__this.cli, serviceClients);
      return vmImage.getVMImageDetails(imageFilter, __cb(_, __frame, 12, 31, function ___(__0, __1) { imagesResult = __1;
        images = imagesResult;
        output = __this.cli.output;
        if ((!images || (images.length === 0))) {
          output.warn($("No virtual machine images found")); }

         else {
          if (output.format().json) {
            output.json(images); }

           else {
            __this.cli.interaction.formatOutput(images, function(outputData) {
              output.table(outputData, function(row, item) {
                row.cell($("Publisher"), params.publisher);
                row.cell($("Offer"), params.offer);
                row.cell($("Sku"), params.sku);
                row.cell($("OS"), (item.osDiskImage ? item.osDiskImage.operatingSystem : null));
                row.cell($("Version"), item.name);
                row.cell($("Location"), item.location);
                row.cell($("Urn"), ((((((params.publisher + ":") + params.offer) + ":") + params.sku) + ":") + item.name));
                if ((item.dataDiskImages && (item.dataDiskImages.length > 0))) {
                  row.cell($("DataDiskImages"), item.dataDiskImages); } ; }); }); } ; } ; _(); }, true)); }); },







  listVMExtensionImageTypes: function listVMExtensionImageTypes__37(location, publisherName, options, _) { var subscription, serviceClients, vmImage, typesResult, types, output, __this = this; var __frame = { name: "listVMExtensionImageTypes__37", line: 1415 }; return __func(_, this, arguments, listVMExtensionImageTypes__37, 3, __frame, function __$listVMExtensionImageTypes__37() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);

      vmImage = new VMImage(__this.cli, serviceClients);
      return vmImage.getVMExtensionImageTypeList(location, publisherName, __cb(_, __frame, 5, 30, function ___(__0, __1) { typesResult = __1;

        types = typesResult;
        output = __this.cli.output;
        if ((!types || (types.length === 0))) {
          if (output.format().json) {
            output.json([]); }
           else {
            output.warn(util.format($("No virtual machine extension image types found (publisher: \"%s\" location:\"%s\")"), publisherName, location)); } ; return _(null); } ;





        __this.cli.interaction.formatOutput(types, function(outputData) {
          output.table(outputData, function(row, item) {
            row.cell($("Publisher"), item.publisher);
            row.cell($("Type"), item.name);
            row.cell($("Location"), item.location); }); }); _(); }, true)); }); },




  listVMExtensionImageVersions: function listVMExtensionImageVersions__38(location, publisherName, typeName, options, _) { var subscription, serviceClients, vmImage, versionsResult, versions, output, __this = this; var __frame = { name: "listVMExtensionImageVersions__38", line: 1443 }; return __func(_, this, arguments, listVMExtensionImageVersions__38, 4, __frame, function __$listVMExtensionImageVersions__38() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);

      vmImage = new VMImage(__this.cli, serviceClients);
      return vmImage.getVMExtensionImageVersionList(location, publisherName, typeName, __cb(_, __frame, 5, 33, function ___(__0, __1) { versionsResult = __1;

        versions = versionsResult;
        output = __this.cli.output;
        if ((!versions || (versions.length === 0))) {
          if (output.format().json) {
            output.json([]); }
           else {
            output.warn(util.format($("No virtual machine extension image versions found (publisher: \"%s\" type: \"%s\" location:\"%s\")"), publisherName, typeName, location)); } ; return _(null); } ;





        __this.cli.interaction.formatOutput(versions, function(outputData) {
          output.table(outputData, function(row, item) {
            row.cell($("Publisher"), item.publisher);
            row.cell($("Type"), item.typeName);
            row.cell($("Version"), item.name);
            row.cell($("Location"), item.location); }); }); _(); }, true)); }); },




  listVMExtensionImages: function listVMExtensionImages__39(location, publisher, typeName, options, _) { var subscription, serviceClients, vmImageClient, extImagesResult, extImages, output, __this = this; var __frame = { name: "listVMExtensionImages__39", line: 1472 }; return __func(_, this, arguments, listVMExtensionImages__39, 4, __frame, function __$listVMExtensionImages__39() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);

      vmImageClient = new VMImage(__this.cli, serviceClients);
      return vmImageClient.getVMExtensionImageList(location, publisher, typeName, __cb(_, __frame, 5, 40, function ___(__0, __1) { extImagesResult = __1;
        extImages = extImagesResult;
        output = __this.cli.output;
        if ((!extImages || (extImages.length === 0))) {
          if (output.format().json) {
            output.json([]); }
           else {
            output.warn($("No virtual machine extension images found")); } ; return _(null); } ;





        __this.cli.interaction.formatOutput(extImages, function(outputData) {
          output.table(outputData, function(row, item) {
            row.cell($("Publisher"), item.publisher);
            row.cell($("Type"), item.typeName);
            row.cell($("Version"), item.name);
            row.cell($("Location"), item.location); }); }); _(); }, true)); }); },




  getVMExtensionImage: function getVMExtensionImage__40(location, publisherName, typeName, version, options, _) { var subscription, serviceClients, vmImage, imageResult, output, __this = this; var __frame = { name: "getVMExtensionImage__40", line: 1500 }; return __func(_, this, arguments, getVMExtensionImage__40, 5, __frame, function __$getVMExtensionImage__40() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);

      vmImage = new VMImage(__this.cli, serviceClients);
      return vmImage.getVMExtensionImage(location, publisherName, typeName, version, __cb(_, __frame, 5, 30, function ___(__0, __1) { imageResult = __1;

        output = __this.cli.output;
        if (!imageResult) {
          if (output.format().json) {
            output.json([]); }
           else {
            output.warn(util.format($("No virtual machine extension images found (publisher: \"%s\" type: \"%s\" version: \"%s\" location:\"%s\")"), publisherName, typeName, version, location)); } ; return _(null); }




         else {
          output.json(imageResult); } ; _(); }, true)); }); },



  _createOrUpdateExtension: function _createOrUpdateExtension__41(resourceGroupName, vmName, extensionName, publisherName, version, options, serviceClients, _) { var vMExtensionProfile, vmExtension, virtualMachine, __this = this; var __frame = { name: "_createOrUpdateExtension__41", line: 1522 }; return __func(_, this, arguments, _createOrUpdateExtension__41, 7, __frame, function __$_createOrUpdateExtension__41() {
      options.extensionName = extensionName;
      options.publisherName = publisherName;
      options.version = version;

      vMExtensionProfile = new VMExtensionProfile(__this.cli, options);
      vmExtension = vMExtensionProfile.generateExtensionProfile();

      virtualMachine = new VirtualMachine(__this.cli, serviceClients);
      return virtualMachine.createOrUpdateVMExtension(resourceGroupName, vmName, vmExtension.profile, true, __cb(_, __frame, 9, 19, function __$_createOrUpdateExtension__41() { _(); }, true)); }); },


  _uninstallExtension: function _uninstallExtension__42(resourceGroupName, vmName, extensionName, serviceClients, options, _) { var virtualMachine, extension, __this = this; var __frame = { name: "_uninstallExtension__42", line: 1534 }; return __func(_, this, arguments, _uninstallExtension__42, 5, __frame, function __$_uninstallExtension__42() {
      virtualMachine = new VirtualMachine(__this.cli, serviceClients);
      return virtualMachine.getVMExtension(resourceGroupName, vmName, extensionName, __cb(_, __frame, 2, 35, function ___(__0, __2) { extension = __2;
        if (!extension) {
          return _(new Error(util.format($("Extension \"%s\" not found under the virtual machine \"%s\""), extensionName, vmName))); } ; return (function __$_uninstallExtension__42(_) {


          var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return __this.cli.interaction.confirm(util.format($("Uninstall the virtual machine extension \"%s\"? [y/n] "), extensionName), __cb(_, __frame, 7, 48, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -1533, 17, function ___(__0, __3) { return (function __$_uninstallExtension__42(__then) { if (__3) { return _(null); } else { __then(); } ; })(function __$_uninstallExtension__42() {



            return virtualMachine.deleteVMExtension(resourceGroupName, vmName, extensionName, __cb(_, __frame, 11, 19, function __$_uninstallExtension__42() { _(); }, true)); }); }, true)); }, true)); }); },


  _populateNics: function _populateNics__43(virtualMachine, subscription, _) { var networkInterfaces, networkResourceProviderClient, networkNic, networkPublicIP, i, networkInterface, nicInfo, ipConfigurations, ipConfiguration, pubIPInfo, __this = this; var __frame = { name: "_populateNics__43", line: 1548 }; return __func(_, this, arguments, _populateNics__43, 2, __frame, function __$_populateNics__43() {
      if (((!virtualMachine || !virtualMachine.networkProfile) || !virtualMachine.networkProfile.networkInterfaces)) {
        return _(null, virtualMachine); } ;


      networkInterfaces = virtualMachine.networkProfile.networkInterfaces; return (function __$_populateNics__43(__then) {
        if ((networkInterfaces.length > 0)) {
          networkResourceProviderClient = utils.createNetworkManagementClient(subscription);
          networkNic = new NetworkNic(__this.cli, networkResourceProviderClient);
          networkPublicIP = new NetworkPublicIP(__this.cli, networkResourceProviderClient);
          i = 0; var __4 = false; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$_populateNics__43() { __more = false; if (__4) { i++; } else { __4 = true; } ; var __3 = (i < networkInterfaces.length); if (__3) {
                networkInterface = networkInterfaces[i];
                return networkNic.getNICInfoById(networkInterface.id, __cb(_, __frame, 12, 33, function ___(__0, __1) { nicInfo = __1; return (function __$_populateNics__43(__then) {
                    if (nicInfo.profile) {
                      networkInterface.expanded = nicInfo.profile;
                      ipConfigurations = networkInterface.expanded.ipConfigurations; return (function __$_populateNics__43(__then) {
                        if ((ipConfigurations && (ipConfigurations.length > 0))) {

                          ipConfiguration = ipConfigurations[0]; return (function __$_populateNics__43(__then) {
                            if ((ipConfiguration.publicIPAddress && ipConfiguration.publicIPAddress.id)) {
                              return networkPublicIP.getPublicIPInfoById(ipConfiguration.publicIPAddress.id, __cb(_, __frame, 20, 46, function ___(__0, __2) { pubIPInfo = __2;
                                if (pubIPInfo.profile) {
                                  ipConfiguration.publicIPAddress.expanded = pubIPInfo.profile; } ; __then(); }, true)); } else { __then(); } ; })(__then); } else { __then(); } ; })(__then); } else { __then(); } ; })(function __$_populateNics__43() { while (__more) { __loop(); }; __more = true; }); }, true)); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(__then); } else { __then(); } ; })(function __$_populateNics__43() {







        return _(null, virtualMachine); }); }); },


  _getServiceClients: function(subscription) {
    return {
      computeManagementClient: utils.createComputeManagementClient(subscription),
      storageManagementClient: utils.createStorageResourceProviderClient(subscription),
      networkResourceProviderClient: utils.createNetworkManagementClient(subscription),
      resourceManagementClient: utils.createResourceClient(subscription) }; },



  _leftPadTwo: function(n) {
    return ((((n < 10) ? "0" : "")) + n); },


  _toUTC: function(date) {
    return ((((((((((((date.getUTCFullYear() + "-") + this._leftPadTwo(((date.getUTCMonth() + 1)))) + "-") + this._leftPadTwo(date.getUTCDate())) + "T") + this._leftPadTwo(date.getUTCHours())) + ":") + this._leftPadTwo(date.getUTCMinutes())) + ":") + this._leftPadTwo(date.getUTCSeconds())) + "Z")); },







  _getStorageAccountContainerAndBlobFromUri: function(serialConsoleLogBlobUri) {
    var result = {
      accountName: null,
      containerName: null,
      blobName: null };


    var parsedResult = url.parse(serialConsoleLogBlobUri, true);
    var hostName = (parsedResult.host || "");
    var hostSegments = hostName.split(".");
    var containerAndBlobPath = (parsedResult.path || "");
    if (((containerAndBlobPath.length > 0) && (containerAndBlobPath.charAt(0) === "/"))) {
      containerAndBlobPath = containerAndBlobPath.substr(1, (containerAndBlobPath.length - 1)); } ;

    var pathSegments = containerAndBlobPath.split("/");

    if (((hostSegments.length > 0) && (pathSegments.length == 2))) {
      result.accountName = hostSegments[0];
      result.containerName = pathSegments[0];
      result.blobName = pathSegments[1]; } ;

    return result; },


  _getStorageBlobOperation: function(serviceClient, operationName) {
    return StorageUtil.getStorageOperation(serviceClient, StorageUtil.OperationType.Blob, operationName); },


  _getStorageBlobOperationDefaultOption: function() {
    var option = StorageUtil.getStorageOperationDefaultOption();


    option.parallelOperationThreadCount = StorageUtil.threadsInOperation;

    return option; },


  createVMBackup: function createVMBackup__44(resourceGroupName, name, options, _) { var subscription, serviceClients, virtualMachine, vmResult, storageBlobUris, dataDisks, storageSASBlobUris, i, blobUri, result, storageClient, keys, blobService, startDate, expiryDate, sharedAccessPolicy, queryString, uri, params, commandStartTimeUTCTicks, taskId, tag, vmBackupPublicConfig, vmExtensionProfile, azureVmBackupExtension, extResult, __this = this; var __frame = { name: "createVMBackup__44", line: 1640 }; return __func(_, this, arguments, createVMBackup__44, 3, __frame, function __$createVMBackup__44() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      virtualMachine = new VirtualMachine(__this.cli, serviceClients);

      return virtualMachine.getVM(resourceGroupName, name, __cb(_, __frame, 5, 34, function ___(__0, __3) { vmResult = __3;
        if (!vmResult) {
          return _(new Error(util.format($("Virtual machine \"%s\" not found under the resource group \"%s\""), name, resourceGroupName))); } ;



        storageBlobUris = [];
        storageBlobUris.push(vmResult.storageProfile.osDisk.vhd.uri);
        dataDisks = vmResult.storageProfile.dataDisks;
        dataDisks.forEach(function(dataDisk) {
          storageBlobUris.push(dataDisk.vhd.uri); });


        storageSASBlobUris = [];
        var __1 = __forIn(storageBlobUris); var __2 = 0; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$createVMBackup__44() { __more = false; var __7 = (__2 < __1.length); if (__7) { i = __1[__2++];
              blobUri = storageBlobUris[i];
              result = __this._getStorageAccountContainerAndBlobFromUri(blobUri); return (function __$createVMBackup__44(__then) {
                if (((result.accountName && result.containerName) && result.blobName)) {
                  storageClient = serviceClients.storageManagementClient;
                  return storageClient.storageAccounts.listKeys(resourceGroupName, result.accountName, __cb(_, __frame, 24, 53, function ___(__0, __4) { keys = __4;
                    blobService = azureStorage.createBlobService(result.accountName, keys.keys[0].value);
                    startDate = new Date();
                    startDate.setMinutes((startDate.getMinutes() - 2));
                    expiryDate = new Date(startDate);
                    expiryDate.setMinutes((startDate.getMinutes() + 60));
                    sharedAccessPolicy = {
                      Id: null,
                      AccessPolicy: {
                        Permissions: (StorageUtil.BlobPermission.Read + StorageUtil.BlobPermission.Write),
                        Start: __this._toUTC(startDate),
                        Expiry: __this._toUTC(expiryDate) } };


                    queryString = blobService.generateSharedAccessSignature(result.containerName, result.blobName, sharedAccessPolicy);
                    uri = ((blobUri + "?") + queryString);
                    storageSASBlobUris.push(uri); __then(); }, true)); } else {

                  return _(new Error(util.format($("wrong blob uri found %s "), blobUri))); } ; })(function __$createVMBackup__44() { while (__more) { __loop(); }; __more = true; }); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$createVMBackup__44() {


          params = { };

          params.location = vmResult.location;
          params.osType = vmResult.storageProfile.osDisk.osType;
          params.version = options.extensionVersion;

          commandStartTimeUTCTicks = ((((new Date().getTime() * 10000)) + 621355968000000000)).toString();
          params.commandStartTimeUTCTicks = commandStartTimeUTCTicks;
          params.locale = "en-us";
          params.command = "snapshot";
          taskId = utils.uuidGen().toString();
          params.taskId = taskId;
          tag = utils.uuidGen().toString();

          params.objectStr = new Buffer(JSON.stringify({ blobSASUri: storageSASBlobUris })).toString("base64");

          vmBackupPublicConfig = {
            backupMetadata: [{ Key: "vmbackupidentity", Value: taskId },{ Key: "vmbackuptag", Value: tag },] };


          params.pubObjectStr = new Buffer(JSON.stringify(vmBackupPublicConfig)).toString("base64");

          vmExtensionProfile = new VMExtensionProfile(__this.cli, params);
          azureVmBackupExtension = vmExtensionProfile.generateAzureVMBackupExtensionProfile();

          return virtualMachine.createOrUpdateVMExtension(resourceGroupName, name, azureVmBackupExtension.profile, true, __cb(_, __frame, 70, 35, function ___(__0, __5) { extResult = __5;

            if ((!(extResult) || !utils.ignoreCaseEquals(extResult.provisioningState, vmConstants.EXTENSIONS.EXTENSION_PROVISIONING_SUCCEEDED))) {

              return _(new Error(util.format($("call extension %s failed with : %s  "), vmConstants.AZURE_VM_BACKUP_LINUX_EXTENSION_PUBLISHER, extResult.error.message))); } ;

            console.log(util.format($("one snapshot with tag %s is created for this vm."), tag));
            return _(null, true); }, true)); }); }, true)); }); },


  removeVMBackup: function removeVMBackup__45(resourceGroupName, name, options, _) { var subscription, serviceClients, virtualMachine, vmResult, storageBlobUris, dataDisks, i, blobUri, result, storageClient, keys, blobService, operation, storageOptions, blobs, tips, performStorageOperation, j, len, __this = this; var __frame = { name: "removeVMBackup__45", line: 1720 }; return __func(_, this, arguments, removeVMBackup__45, 3, __frame, function __$removeVMBackup__45() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      virtualMachine = new VirtualMachine(__this.cli, serviceClients);
      console.log(("removing the backup with identity:" + options.identity));

      return virtualMachine.getVM(resourceGroupName, name, __cb(_, __frame, 6, 34, function ___(__0, __3) { vmResult = __3;
        if (!vmResult) {
          return _(new Error(util.format($("Virtual machine \"%s\" not found under the resource group \"%s\""), name, resourceGroupName))); } ;


        storageBlobUris = [];
        storageBlobUris.push(vmResult.storageProfile.osDisk.vhd.uri);
        dataDisks = vmResult.storageProfile.dataDisks;
        dataDisks.forEach(function(dataDisk) {
          storageBlobUris.push(dataDisk.vhd.uri); });

        StorageUtil.init(__this.cli);
        var __1 = __forIn(storageBlobUris); var __2 = 0; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$removeVMBackup__45() { __more = false; var __7 = (__2 < __1.length); if (__7) { i = __1[__2++];
              blobUri = storageBlobUris[i];
              result = __this._getStorageAccountContainerAndBlobFromUri(blobUri); return (function __$removeVMBackup__45(__then) {
                if (((result.accountName && result.containerName) && result.blobName)) {
                  storageClient = serviceClients.storageManagementClient;
                  return storageClient.storageAccounts.listKeys(resourceGroupName, result.accountName, __cb(_, __frame, 23, 53, function ___(__0, __4) { keys = __4;
                    blobService = azureStorage.createBlobService(result.accountName, keys.keys[0].value);
                    blobService.listAllBlobs = function(container, options, callback) {
                      StorageUtil.listWithContinuation(blobService.listBlobsSegmentedWithPrefix, blobService, StorageUtil.ListContinuationTokenArgIndex.Blob, container, options.prefix, null, options, callback); };



                    operation = __this._getStorageBlobOperation(blobService, "listAllBlobs");
                    storageOptions = __this._getStorageBlobOperationDefaultOption();
                    storageOptions.include = "snapshots,metadata";
                    blobs = [];
                    tips = util.format($("listing blobs in container %s"), result.containerName);
                    startProgress(tips);
                    performStorageOperation = StorageUtil.performStorageOperation; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$removeVMBackup__45() {

                          return performStorageOperation(operation, __cb(_, __frame, 38, 24, function ___(__0, __5) { blobs = __5; _(null, null, true); }, true), result.containerName, storageOptions); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$removeVMBackup__45() {

                            endProgress(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$removeVMBackup__45() {

                        j = 0; len = blobs.length; var __11 = false; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$removeVMBackup__45() { __more = false; if (__11) { j++; } else { __11 = true; } ; var __10 = (j < len); if (__10) {
                              blob = blobs[j]; return (function __$removeVMBackup__45(__then) {
                                if ((blob.metadata["vmbackuptag"] == options.identity)) {
                                  console.log("the snapshot with the tag found.");
                                  storageOptions = __this._getStorageBlobOperationDefaultOption();
                                  storageOptions.snapshotId = blob.snapshot;
                                  tips = util.format($("Deleting Blob %s in container %s"), blob.name, result.containerName);
                                  operation = __this._getStorageBlobOperation(blobService, "deleteBlob");
                                  startProgress(tips); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$removeVMBackup__45() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$removeVMBackup__45() {

                                              return performStorageOperation(operation, __cb(_, __frame, 52, 24, __then, true), result.containerName, blob.name, storageOptions); }); })(function ___(e, __result) { __catch(function __$removeVMBackup__45() { if (e) {

                                                if (StorageUtil.isNotFoundException(e)) {
                                                  return _(new Error(util.format($("Can not remove blob snapshot '%s' in container '%s'"), blob.name, result.containerName))); }
                                                 else {
                                                  return _(e); } ; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$removeVMBackup__45() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$removeVMBackup__45() {


                                          endProgress(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, __then); }); } else { __then(); } ; })(function __$removeVMBackup__45() { while (__more) { __loop(); }; __more = true; }); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(__then); }); }); }, true)); } else {




                  return _(new Error(util.format($("wrong blob uri found %s "), blobUri))); } ; })(function __$removeVMBackup__45() { while (__more) { __loop(); }; __more = true; }); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(_); }, true)); }); },




  setAzureDiskEncryption: function setAzureDiskEncryption__46(resourceGroupName, name, options, _) { var subscription, serviceClients, virtualMachine, params, vmResult, createResult, vmExtensionProfile, azureDiskEncryptionExtension, result, extensionName, publisherName, getOptions, extensionResult, statusUrl, vmModel, encryptionSettings, __this = this; var __frame = { name: "setAzureDiskEncryption__46", line: 1790 }; return __func(_, this, arguments, setAzureDiskEncryption__46, 3, __frame, function __$setAzureDiskEncryption__46() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      virtualMachine = new VirtualMachine(__this.cli, serviceClients);
      params = { };

      return virtualMachine.getVM(resourceGroupName, name, __cb(_, __frame, 6, 34, function ___(__0, __2) { vmResult = __2;
        if (!vmResult) {
          return _(new Error(util.format($("Virtual machine \"%s\" not found under the resource group \"%s\""), name, resourceGroupName))); } ; return (function __$setAzureDiskEncryption__46(__then) {


          if (utils.ignoreCaseEquals(vmResult.storageProfile.osDisk.osType, "Linux")) {
            return __this.createVMBackup(resourceGroupName, name, options, __cb(_, __frame, 12, 32, function ___(__0, __3) { createResult = __3;
              if (!createResult) {
                return _(new Error($("create backup failed."))); } ; __then(); }, true)); } else { __then(); } ; })(function __$setAzureDiskEncryption__46() {



          if (!utils.ignoreCaseEquals(vmResult.storageProfile.osDisk.osType, "Linux")) {
            if (options.passphrase) {
              return _(new Error($("only Linux support the passphrase specified in parameters."))); } ; }

           else {
            params.passphrase = options.passphrase; } ;


          params.location = vmResult.location;
          params.osType = vmResult.storageProfile.osDisk.osType;
          params.version = options.extensionVersion;
          params.aadClientId = options.aadClientId;
          params.aadClientSecret = options.aadClientSecret;
          params.aadClientCertThumbprint = options.aadClientCertThumbprint;
          params.diskEncryptionKeyVaultUrl = options.diskEncryptionKeyVaultUrl;
          params.diskEncryptionKeyVaultId = options.diskEncryptionKeyVaultId;
          params.keyEncryptionKeyUrl = options.keyEncryptionKeyUrl;
          params.keyEncryptionKeyVaultId = options.keyEncryptionKeyVaultId;
          params.keyEncryptionAlgorithm = options.keyEncryptionAlgorithm;
          params.volumeType = options.volumeType;
          params.sequenceVersion = options.sequenceVersion;
          params.autoUpgradeMinorVersion = !options.disableAutoUpgradeMinorVersion;


          if (!utils.stringIsNullOrEmpty(options.keyEncryptionKeyUrl)) {
            if (utils.stringIsNullOrEmpty(options.keyEncryptionAlgorithm)) {
              params.keyEncryptionAlgorithm = vmConstants.EXTENSIONS.DEFAULT_KEY_ENCRYPTION_ALGORITHM; } ; } ;



          if ((utils.ignoreCaseEquals(params.osType, "Linux") && !utils.ignoreCaseEquals(params.volumeType, "Data"))) {

            return _(new Error($("Enabling encryption is only allowed on Data volumes for Linux VMs."))); } ;



          vmExtensionProfile = new VMExtensionProfile(__this.cli, params);
          azureDiskEncryptionExtension = vmExtensionProfile.generateAzureDiskEncryptionExtensionProfile(); return (function __$setAzureDiskEncryption__46(_) {

            var __1 = !options.quiet; if (!__1) { return _(null, __1); } ;
            return __this.cli.interaction.confirm($("This cmdlet prepares the VM and enables encryption which may reboot the machine and takes 10-15 minutes to finish. Please save your work on the VM before confirming. Do you want to continue? [y/n] "), __cb(_, __frame, 58, 30, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -1789, 17, function ___(__0, __4) { return (function __$setAzureDiskEncryption__46(__then) { if (__4) { return _(null); } else { __then(); } ; })(function __$setAzureDiskEncryption__46() {




              return virtualMachine.createOrUpdateVMExtension(resourceGroupName, name, azureDiskEncryptionExtension.profile, true, __cb(_, __frame, 63, 32, function ___(__0, __5) { result = __5;
                if ((!(result) || !utils.ignoreCaseEquals(result.provisioningState, vmConstants.EXTENSIONS.EXTENSION_PROVISIONING_SUCCEEDED))) {


                  return _(new Error(util.format($("Installing extension failed with : %s  "), result.error.message))); } ;



                extensionName = "";
                publisherName = "";

                if (utils.ignoreCaseEquals(params.osType, "Linux")) {
                  extensionName = vmConstants.EXTENSIONS.AZURE_DISK_ENCRYPTION_LINUX_EXTENSION_NAME;
                  publisherName = vmConstants.EXTENSIONS.AZURE_DISK_ENCRYPTION_LINUX_EXTENSION_PUBLISHER; } else {

                  if (utils.ignoreCaseEquals(params.osType, "Windows")) {
                    extensionName = vmConstants.EXTENSIONS.AZURE_DISK_ENCRYPTION_WINDOWS_EXTENSION_NAME;
                    publisherName = vmConstants.EXTENSIONS.AZURE_DISK_ENCRYPTION_WINDOWS_EXTENSION_PUBLISHER; } ; } ;


                getOptions = { expand: "instanceView" };
                return serviceClients.computeManagementClient.virtualMachineExtensions.get(resourceGroupName, name, extensionName, getOptions, __cb(_, __frame, 84, 90, function ___(__0, __6) { extensionResult = __6;

                  if (((((((!extensionResult || !extensionResult.instanceView) || !extensionResult.instanceView.statuses) || ((extensionResult.instanceView.statuses.length < 1))) || !utils.ignoreCaseEquals(extensionResult.publisher, publisherName)) || !utils.ignoreCaseEquals(extensionResult.virtualMachineExtensionType, extensionName)) || !utils.ignoreCaseEquals(extensionResult.provisioningState, vmConstants.EXTENSIONS.EXTENSION_PROVISIONING_SUCCEEDED))) {







                    return _(new Error(util.format($("Virtual machine \"%s\" extension with successful status not found after installing extension  "), extensionName))); } ;


                  statusUrl = extensionResult.instanceView.statuses[0].message;
                  if (utils.stringIsNullOrEmpty(statusUrl)) {

                    return _(new Error(util.format($("Extension status is empty. It should be valid KeyVault secret URL"), statusUrl))); } ;


                  return virtualMachine.getVM(resourceGroupName, name, __cb(_, __frame, 103, 33, function ___(__0, __7) { vmModel = __7;
                    if ((!vmModel || !vmModel.storageProfile)) {


                      return _(new Error(util.format($("Virtual machine \"%s\" with valid storage profile is not found under the resource group \"%s\""), name, resourceGroupName))); } ;



                    encryptionSettings = {
                      diskEncryptionKey: {
                        sourceVault: {
                          id: options.diskEncryptionKeyVaultId },

                        secretUrl: statusUrl },

                      keyEncryptionKey: null,
                      enabled: true };

                    if ((options.keyEncryptionKeyVaultId || options.keyEncryptionKeyUrl)) {
                      encryptionSettings.keyEncryptionKey = {
                        sourceVault: {
                          id: options.keyEncryptionKeyVaultId },

                        keyUrl: options.keyEncryptionKeyUrl }; } ;




                    vmModel.storageProfile.osDisk.encryptionSettings = encryptionSettings;
                    return virtualMachine.createOrUpdateVM(resourceGroupName, vmModel, false, __cb(_, __frame, 132, 26, _, true)); }, true)); }, true)); }, true)); }); }, true)); }); }, true)); }); },


  showAzureDiskEncryptionStatus: function showAzureDiskEncryptionStatus__47(resourceGroupName, name, options, _) { var subscription, serviceClients, virtualMachine, output, encryptionStatus, extensionStatus, vmModel, extensionName, publisherName, getOptions, isJson, string, __this = this; var __frame = { name: "showAzureDiskEncryptionStatus__47", line: 1925 }; return __func(_, this, arguments, showAzureDiskEncryptionStatus__47, 3, __frame, function __$showAzureDiskEncryptionStatus__47() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      virtualMachine = new VirtualMachine(__this.cli, serviceClients);
      output = __this.cli.output;
      encryptionStatus = {
        osVolumeEncrypted: "NotEncrypted",
        osVolumeEncryptionSettings: null,
        dataVolumesEncrypted: "NotEncrypted" };

      extensionStatus = null;

      return virtualMachine.getVM(resourceGroupName, name, __cb(_, __frame, 12, 33, function ___(__0, __1) { vmModel = __1;
        if (!vmModel) {
          return _(new Error(util.format($("Virtual machine \"%s\" not found under the resource group \"%s\""), name, resourceGroupName))); } ;

        if (utils.ignoreCaseEquals(vmModel.storageProfile.osDisk.osType, "Linux")) {

          encryptionStatus.osVolumeEncrypted = "Unknown"; } ; return (function __$showAzureDiskEncryptionStatus__47(__then) {

          if (vmModel.storageProfile.osDisk.encryptionSettings) {

            encryptionStatus.osVolumeEncryptionSettings = vmModel.storageProfile.osDisk.encryptionSettings;
            if (((encryptionStatus.osVolumeEncryptionSettings.enabled) && (encryptionStatus.osVolumeEncryptionSettings.diskEncryptionKey.secretUrl))) {

              encryptionStatus.osVolumeEncrypted = "Encrypted"; } ;




            extensionName = "";
            publisherName = "";

            if (utils.ignoreCaseEquals(vmModel.storageProfile.osDisk.osType, "Linux")) {
              extensionName = vmConstants.EXTENSIONS.AZURE_DISK_ENCRYPTION_LINUX_EXTENSION_NAME;
              publisherName = vmConstants.EXTENSIONS.AZURE_DISK_ENCRYPTION_LINUX_EXTENSION_PUBLISHER; } else {

              if (utils.ignoreCaseEquals(vmModel.storageProfile.osDisk.osType, "Windows")) {
                extensionName = vmConstants.EXTENSIONS.AZURE_DISK_ENCRYPTION_WINDOWS_EXTENSION_NAME;
                publisherName = vmConstants.EXTENSIONS.AZURE_DISK_ENCRYPTION_WINDOWS_EXTENSION_PUBLISHER; } ; } ; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$showAzureDiskEncryptionStatus__47() {



                  getOptions = { expand: "instanceView" };
                  return serviceClients.computeManagementClient.virtualMachineExtensions.get(resourceGroupName, name, extensionName, getOptions, __cb(_, __frame, 44, 90, function ___(__0, __2) { extensionStatus = __2; __then(); }, true)); }); })(function ___(e, __result) { __catch(function __$showAzureDiskEncryptionStatus__47() { if (e) {


                    extensionStatus = null; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$showAzureDiskEncryptionStatus__47() {


                if (((((extensionStatus) && utils.ignoreCaseEquals(extensionStatus.publisher, publisherName)) && utils.ignoreCaseEquals(extensionStatus.virtualMachineExtensionType, extensionName)) && utils.ignoreCaseEquals(extensionStatus.provisioningState, vmConstants.EXTENSIONS.EXTENSION_PROVISIONING_SUCCEEDED))) {




                  if ((((!extensionStatus.settings.VolumeType || utils.ignoreCaseEquals(extensionStatus.settings.VolumeType, "All")) || utils.ignoreCaseEquals(extensionStatus.settings.VolumeType, "Data")) || (utils.stringIsNullOrEmpty(extensionStatus.settings.VolumeType)))) {




                    if (utils.ignoreCaseEquals(extensionStatus.settings.EncryptionOperation, "EnableEncryption")) {
                      encryptionStatus.dataVolumesEncrypted = "Encrypted"; } ; } ; } ; __then(); }); }); } else { __then(); } ; })(function __$showAzureDiskEncryptionStatus__47() {






          isJson = output.format().json;
          if (isJson) {
            output.json(encryptionStatus); }
           else {
            string = JSON.stringify(encryptionStatus);
            __this.cli.output.info(string); } ;


          return _(null, encryptionStatus); }); }, true)); }); },


  disableAzureDiskEncryption: function disableAzureDiskEncryption__48(resourceGroupName, name, options, _) { var subscription, serviceClients, virtualMachine, params, vmResult, vmExtensionProfile, disableAzureDiskEncryptionExtension, result, extensionName, publisherName, getOptions, extensionResult, statusMsg, vmModel, encryptionSettings, __this = this; var __frame = { name: "disableAzureDiskEncryption__48", line: 2004 }; return __func(_, this, arguments, disableAzureDiskEncryption__48, 3, __frame, function __$disableAzureDiskEncryption__48() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      virtualMachine = new VirtualMachine(__this.cli, serviceClients);
      params = { };

      return virtualMachine.getVM(resourceGroupName, name, __cb(_, __frame, 6, 34, function ___(__0, __2) { vmResult = __2;
        if (!vmResult) {
          return _(new Error(util.format($("Virtual machine \"%s\" not found under the resource group \"%s\""), name, resourceGroupName))); } ;


        params.location = vmResult.location;
        params.osType = vmResult.storageProfile.osDisk.osType;
        params.version = options.extensionVersion;
        params.volumeType = options.volumeType;
        params.sequenceVersion = options.sequenceVersion;
        params.autoUpgradeMinorVersion = !options.disableAutoUpgradeMinorVersion;

        if (utils.ignoreCaseEquals(params.osType, "Linux")) {
          return _(new Error($("Disabling encryption is only supported for Windows virtual machines"))); } ;



        vmExtensionProfile = new VMExtensionProfile(__this.cli, params);
        disableAzureDiskEncryptionExtension = vmExtensionProfile.generateDisableAzureDiskEncryptionExtensionProfile(); return (function __$disableAzureDiskEncryption__48(_) {

          var __1 = !options.quiet; if (!__1) { return _(null, __1); } ;
          return __this.cli.interaction.confirm($("This cmdlet disables encryption on the VM which may reboot the machine. Please save your work on the VM before confirming. Do you want to continue? [y/n] "), __cb(_, __frame, 27, 30, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -2003, 17, function ___(__0, __3) { return (function __$disableAzureDiskEncryption__48(__then) { if (__3) { return _(null); } else { __then(); } ; })(function __$disableAzureDiskEncryption__48() {




            return virtualMachine.createOrUpdateVMExtension(resourceGroupName, name, disableAzureDiskEncryptionExtension.profile, true, __cb(_, __frame, 32, 32, function ___(__0, __4) { result = __4;
              if ((!(result) || !utils.ignoreCaseEquals(result.provisioningState, vmConstants.EXTENSIONS.EXTENSION_PROVISIONING_SUCCEEDED))) {


                return _(new Error(util.format($("Installing extension failed with : %s  "), result.error.message))); } ;



              extensionName = "";
              publisherName = "";

              extensionName = vmConstants.EXTENSIONS.AZURE_DISK_ENCRYPTION_WINDOWS_EXTENSION_NAME;
              publisherName = vmConstants.EXTENSIONS.AZURE_DISK_ENCRYPTION_WINDOWS_EXTENSION_PUBLISHER;

              getOptions = { expand: "instanceView" };
              return serviceClients.computeManagementClient.virtualMachineExtensions.get(resourceGroupName, name, extensionName, getOptions, __cb(_, __frame, 47, 90, function ___(__0, __5) { extensionResult = __5;

                if (((((((!extensionResult || !extensionResult.instanceView) || !extensionResult.instanceView.statuses) || ((extensionResult.instanceView.statuses.length < 1))) || !utils.ignoreCaseEquals(extensionResult.publisher, publisherName)) || !utils.ignoreCaseEquals(extensionResult.virtualMachineExtensionType, extensionName)) || !utils.ignoreCaseEquals(extensionResult.provisioningState, vmConstants.EXTENSIONS.EXTENSION_PROVISIONING_SUCCEEDED))) {







                  return _(new Error(util.format($("Virtual machine \"%s\" extension with successful status not found after installing extension  "), extensionName))); } ;


                statusMsg = extensionResult.instanceView.statuses[0].message;
                if (utils.stringIsNullOrEmpty(statusMsg)) {

                  return _(new Error($("Extension status is empty."))); } ;


                return virtualMachine.getVM(resourceGroupName, name, __cb(_, __frame, 66, 33, function ___(__0, __6) { vmModel = __6;
                  if ((!vmModel || !vmModel.storageProfile)) {


                    return _(new Error(util.format($("Virtual machine \"%s\" with valid storage profile is not found under the resource group \"%s\""), name, resourceGroupName))); } ; return (function __$disableAzureDiskEncryption__48(__then) {



                    if (((utils.ignoreCaseEquals(options.volumeType, "All") || utils.ignoreCaseEquals(options.volumeType, "OS")) || (utils.stringIsNullOrEmpty(options.volumeType)))) {



                      encryptionSettings = {
                        enabled: false };



                      vmModel.storageProfile.osDisk.encryptionSettings = encryptionSettings;
                      return virtualMachine.createOrUpdateVM(resourceGroupName, vmModel, false, __cb(_, __frame, 84, 28, _, true)); } else { __then(); } ; })(_); }, true)); }, true)); }, true)); }); }, true)); }, true)); }); }});






module.exports = VMClient;
