UNPKG

azure-cli

Version:

Microsoft Azure Cross Platform Command Line tool

798 lines (511 loc) 137 kB
/*** 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, 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()); }; resourceNamePrefix = ((((removeAllSpace(vmName).slice(0, 5) + "-") + removeAllSpace(location).slice(0, 5)) + "-") + utils.getRandomString()); 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, 25, 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.customData = options.customData; params.storageAccountName = (options.storageAccountName ? options.storageAccountName : (("sto" + utils.getRandomString())).substring(0, 24)); params.storageAccountContainerName = "vhds"; params.osDiskType = osType; params.dataDisks = []; params.nicName = resourceName("nic"); params.publicipName = resourceName("pip"); params.publicipDomainName = (options.publicIpDomainName ? options.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, 61, 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, 72, 61, __then, true)); } else { __then(); } ; })(function __$quickCreateVM__4() { virtualMachine = new VirtualMachine(__this.cli, serviceClients); return virtualMachine.getVM(resourceGroupName, params.vmName, __cb(_, __frame, 76, 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, 82, 36, function ___(__0, __5) { vmCreateProfile = __5; return virtualMachine.createOrUpdateVM(resourceGroupName, vmCreateProfile.profile, true, __cb(_, __frame, 83, 19, function __$quickCreateVM__4() { return __this.showVM(resourceGroupName, params.vmName, { }, __cb(_, __frame, 85, 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: 341 }; 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: 388 }; 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: 411 }; 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: 435 }; 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, -434, 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: 452 }; 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: 468 }; 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: 481 }; 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: 494 }; 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: 507 }; 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: 535 }; 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: 548 }; 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: 569 }; 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, url.parse(serialConsoleLogBlobUri).host); 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, -568, 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: 647 }; 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: 666 }; 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: 692 }; 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, -691, 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 (!wadStorageAccountN