UNPKG

azure-cli

Version:

Microsoft Azure Cross Platform Command Line tool

357 lines (195 loc) 17 kB
/*** Generated by streamline 0.10.17 (callbacks) - DO NOT EDIT ***/ "use strict"; var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename, false),__func=__rt.__func,__cb=__rt.__cb,__tryCatch=__rt.__tryCatch; var util = require("util"); var profile = require("../../../util/profile"); var utils = require("../../../util/utils"); var appserviceplanUtils = require("../webapp/webappUtils"); var $ = utils.getLocaleString; exports.init = function(cli) { var log = cli.output; var tierInfo = ["\n eg:\n F1 (Free), D1 (Shared)","\n B1 (Basic Small), B2 (Basic Medium), B3 (Basic Large)","\n S1 (Standard Small), S2 (Standard Medium), S3 (Standard Large)","\n P1 (Premium Small), P2 (Premium Medium), P3 (Premium Large)\n",]; var appserviceplan = cli.category("appserviceplan").description($("Commands to manage your Azure appserviceplans")); appserviceplan.command("create [resource-group] [name] [location] [sku]").description($("Create an App Service Plan")).usage("[options] <resource-group> <name> <location> <sku>").option("-g --resource-group <resource-group>", $("Name of the resource group")).option("-n --name <name>", $("the name of the App Service Plan to create")).option("-l --location <location>", $("the geographic region to create the App Service Plan, \n locations found at https://azure.microsoft.com/en-us/status/")).option("-k --sku <sku>", $(("sku of the App Service Plan" + tierInfo.toString()))).option("-i --instances <instances>", $("the number of instances in the App Service Plan, Default is 1")).option("-x --islinux <islinux>", $("enables a linux App Service Plan, E.g --islinux true")).option("-s --subscription <subscription>", $("the subscription identifier")).option("-t --tier <tier>", $("to be deprecated, please use --sku option")).execute(function __1(resourceGroup, name, location, sku, options, _) { var subscription, client, numOfInstances, progress, skuInfo, envelope, result, linuxUpper, customOptions; var __frame = { name: "__1", line: 59 }; return __func(_, this, arguments, __1, 5, __frame, function __$__1() { subscription = profile.current.getSubscription(options.subscription); client = appserviceplanUtils.createWebappManagementClient(subscription); if (!resourceGroup) { cli.missingArgument("resource-group"); } ; if (!name) { return _(null, cli.missingArgument("name")); } ; if (!location) { return _(null, cli.missingArgument("location")); } ; if (!sku) { return _(null, cli.missingArgument("sku")); } ; if (("tier" in options)) { skuInfo = translateTier(options.tier); envelope.sku = skuInfo; } ; if (("instances" in options)) { numOfInstances = Number(options.instances); } else { numOfInstances = 1; } ; progress = cli.interaction.progress(util.format($("Creating appserviceplan %s"), name)); skuInfo = translateTier(sku); skuInfo.capacity = numOfInstances; envelope = { location: location, name: name, sku: skuInfo }; return (function __$__1(__then) { if (("islinux" in options)) { linuxUpper = (options.islinux).toUpperCase(); return (function __$__1(__then) { if ((linuxUpper == "TRUE")) { log.info("Checking if this is a supported region"); customOptions = { linuxWorkersEnabled: true }; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__1() { return client.global.getSubscriptionGeoRegions(customOptions, __cb(_, __frame, 43, 35, function ___(__0, __1) { result = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__1() { progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__1() { if ((((result === null) || (result === undefined)) || ((result && (result.length === 0))))) { return _(new Error("No available Linux App Service Regions")); } ; checkRegionForLinux(result, location); envelope.reserved = true; __then(); }); }); } else { __then(); } ; })(__then); } else { __then(); } ; })(function __$__1() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__1() { return client.serverFarms.createOrUpdateServerFarm(resourceGroup, name, envelope, options, __cb(_, __frame, 55, 36, function ___(__0, __2) { result = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__1() { progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__1() { log.info(util.format($("App Service Plan %s has been created"), name)); _(); }); }); }); }); }); appserviceplan.command("delete [resource-group] [name]").description($("Delete an App Service Plan")).usage("[options] <resource-group> <name>").option("-g --resource-group <resource-group>", $("Name of the resource group")).option("-n --name <name>", $("the name of the App Service Plan to delete")).option("-q, --quiet", $("quiet mode, do not ask for delete confirmation")).option("-s --subscription <subscription>", $("the subscription identifier")).execute(function __2(resourceGroup, name, options, _) { var subscription, client, progress, result; var __frame = { name: "__2", line: 128 }; return __func(_, this, arguments, __2, 3, __frame, function __$__2() { subscription = profile.current.getSubscription(options.subscription); client = appserviceplanUtils.createWebappManagementClient(subscription); if (!resourceGroup) { cli.missingArgument("resource-group"); } ; if (!name) { return _(null, cli.missingArgument("name")); } ; return (function __$__2(__then) { if (!options.quiet) { return cli.interaction.confirm(util.format("Delete App Service Plan %s? [y/n] ", name), __cb(_, __frame, 10, 29, function ___(__0, __2) { var __1 = !__2; return (function __$__2(__then) { if (__1) { return _(null); } else { __then(); } ; })(__then); }, true)); } else { __then(); } ; })(function __$__2() { progress = cli.interaction.progress(util.format($("Deleting App Service Plan %s"), name)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__2() { return client.serverFarms.deleteServerFarm(resourceGroup, name, __cb(_, __frame, 17, 36, function ___(__0, __3) { result = __3; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__2() { progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__2() { log.info(util.format($("App Service Plan %s has been deleted"), name)); _(); }); }); }); }); }); appserviceplan.command("list [resource-group]").description($("List your App Service Plans")).usage("[options] <resource-group>").option("-g --resource-group <resource-group>", $("the name of the resource group")).option("-s --subscription <subscription>", $("the subscription identifier")).execute(function __3(resourceGroup, options, _) { var subscription, client, progress, result; var __frame = { name: "__3", line: 157 }; return __func(_, this, arguments, __3, 2, __frame, function __$__3() { if (!resourceGroup) { cli.missingArgument("resource-group"); } ; subscription = profile.current.getSubscription(options.subscription); client = appserviceplanUtils.createWebappManagementClient(subscription); progress = cli.interaction.progress($("Listing App Service Plans")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__3() { return client.serverFarms.getServerFarms(resourceGroup, __cb(_, __frame, 9, 36, function ___(__0, __1) { result = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__3() { progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__3() { cli.interaction.formatOutput(result, function(data) { if (((data !== undefined) && (data.length > 0))) { log.table(data, function(row, item) { row.cell($("Name "), item.name); row.cell($("Location "), item.location); row.cell($("SKU "), item.sku.name); row.cell($("Number Of Workers "), item.sku.capacity); row.cell($("Is Linux "), item.reserved); row.cell($("Worker Size "), translateWorkerSize(item.sku.name)); }); } else { log.info("No app service plans found."); } ; }); _(); }); }); }); }); appserviceplan.command("show [resource-group] [name]").description($("Get an App Service Plan")).usage("[options] <resource-group> <name>").option("-g --resource-group <resource-group>", $("the name of the resource group")).option("-n --name <name>", $("the name of the App Service Plan to show")).option("-s --subscription <subscription>", $("the subscription identifier")).execute(function __4(resourceGroup, name, options, _) { var subscription, client, progress, result; var __frame = { name: "__4", line: 192 }; return __func(_, this, arguments, __4, 3, __frame, function __$__4() { if (!resourceGroup) { cli.missingArgument("resource-group"); } ; if (!name) { return _(null, cli.missingArgument("name")); } ; subscription = profile.current.getSubscription(options.subscription); client = appserviceplanUtils.createWebappManagementClient(subscription); progress = cli.interaction.progress($("Getting App Service Plan")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__4() { return client.serverFarms.getServerFarm(resourceGroup, name, __cb(_, __frame, 12, 36, function ___(__0, __1) { result = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__4() { progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__4() { cli.interaction.formatOutput(result, function(data) { if (!data) { throw new Error((("App Service Plan " + name) + " does not exist! ")); } else { log.data($("App Service Plan Name :"), data.name); log.data($("Location :"), data.location); log.data($("SKU :"), data.sku.name); log.data($("Number of workers :"), data.sku.capacity); log.data($("Is Linux :"), data.reserved); log.data($("Worker Size :"), translateWorkerSize(data.sku.name)); log.data(""); } ; }); _(); }); }); }); }); appserviceplan.command("set [resource-group] [name]").description($("Update App Service Plan Configurations")).usage("[options] <resource-group> <name>").option("-g --resource-group <resource-group>", $("Name of the resource group")).option("-n --name <name>", $("the name of the App Service Plan to update")).option("-k --sku <sku>", $(("sku of the App Service Plan" + tierInfo.toString()))).option("-i --instances <instances>", $("the number of instances in the App Service Plan, Default is 1")).option("-s --subscription <subscription>", $("the subscription identifier")).option("-t --tier <tier>", $("to be deprecated, please use --sku option")).execute(function __5(resourceGroup, name, options, _) { var subscription, client, progress, result, envelope, skuInfo, numOfInstances; var __frame = { name: "__5", line: 232 }; return __func(_, this, arguments, __5, 3, __frame, function __$__5() { subscription = profile.current.getSubscription(options.subscription); client = appserviceplanUtils.createWebappManagementClient(subscription); progress = cli.interaction.progress($("Updating App Service Plan")); if (!resourceGroup) { cli.missingArgument("resource-group"); } ; if (!name) { return _(null, cli.missingArgument("name")); } ; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__5() { return client.serverFarms.getServerFarm(resourceGroup, name, __cb(_, __frame, 12, 36, function ___(__0, __1) { result = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__5() { progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__5() { return (function __$__5(__then) { if (((result === null) || (result === undefined))) { return _(new Error((("App Service Plan " + name) + " does not exist! "))); } else { envelope = { name: name }; skuInfo = result.sku; if (("tier" in options)) { skuInfo = translateTier(options.tier); envelope.sku = skuInfo; } else { if (("sku" in options)) { skuInfo = translateTier(options.sku); envelope.sku = skuInfo; } ; } ; if (("instances" in options)) { numOfInstances = Number(options.instances); skuInfo.capacity = numOfInstances; } ; envelope.location = result.location; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__5() { return client.serverFarms.createOrUpdateServerFarm(resourceGroup, name, envelope, options, __cb(_, __frame, 39, 38, function ___(__0, __2) { result = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__5() { progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__5() { log.info((("App Service Plan " + name) + " has been updated ")); __then(); }); }); } ; })(_); }); }); }); }); function translateWorkerSize(skuName) { var workerSize = skuName.charAt(1); var workerSizeNum = (Number(workerSize) - 1); var workerSizeLiteral = -1; switch (workerSizeNum) { case 0: workerSizeLiteral = "Small"; break; case 1: workerSizeLiteral = "Medium"; break; case 2: workerSizeLiteral = "Large"; break; default: workerSizeLiteral = "Undefined"; }; return workerSizeLiteral; }; function translateTier(tier) { var tierUpper = tier.toUpperCase(); var workerSize = -1; var sku = "invalid"; switch (tierUpper) { case "FREE": case "F1": tier = "F1"; workerSize = 0; break; case "SHARED": case "D1": tier = "D1"; workerSize = 0; break; case "B1": case "B2": case "B3": sku = "Basic"; workerSize = (tier.charAt(1) - 1); break; case "S1": case "S2": case "S3": sku = "Standard"; workerSize = (tier.charAt(1) - 1); break; case "P1": case "P2": case "P3": sku = "Premium"; workerSize = (tier.charAt(1) - 1); break; default: throw new Error(("Invalid sku: " + tier)); }; var skuInfo = { name: tier, tier: sku, family: tier.charAt(0) }; return skuInfo; }; function checkRegionForLinux(result, location) { var locationEdit = (location.replace(/ /g, "")).toUpperCase(); var i; for (i = 0; (i < result.length); i++) { var resultLocationEdit = ((result[i].name).replace(/ /g, "")).toUpperCase(); if ((locationEdit === resultLocationEdit)) { log.info("location OK"); return; } ; }; log.error($("Location not supported :"), location); log.info(""); log.info("List of supported Regions"); log.info("-------------------------"); for (i = 0; (i < result.length); i++) { log.info(result[i].name);; }; log.info(""); throw new Error("Invalid location"); };};