azure-cli
Version:
Microsoft Azure Cross Platform Command Line tool
337 lines (168 loc) • 19.7 kB
JavaScript
/*** 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 webappUtils = require("./webappUtils");
var $ = utils.getLocaleString;
exports.init = function(cli) {
var log = cli.output;
var webapp = cli.category("webapp").description($("Commands to manage your Azure webapps"));
webapp.command("create [resource-group] [name] [location] [plan]").description($("create a web app")).usage("[options] <resource-group> <name> <location> <plan>").option("-g --resource-group <resource-group>", $("Name of the resource group")).option("-n --name <name>", $("the name of the webapp to create")).option("--slot <slot>", $("the name of the slot")).option("-l --location <location>", $("the geographic region to create the webapp, \n locations found at https://azure.microsoft.com/en-us/status/")).option("-p --plan <plan>", $("the name of the app service plan eg: Default1.")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __1(resourceGroup, name, location, plan, options, _) { var subscription, client, progress, siteEnvelope; var __frame = { name: "__1", line: 50 }; return __func(_, this, arguments, __1, 5, __frame, function __$__1() {
if (!resourceGroup) {
cli.missingArgument("resource-group"); } ;
if (!name) {
return _(null, cli.missingArgument("name")); } ;
if (!location) {
return _(null, cli.missingArgument("location")); } ;
if (!plan) {
return _(null, cli.missingArgument("plan")); } ;
subscription = profile.current.getSubscription(options.subscription);
client = webappUtils.createWebappManagementClient(subscription);
progress = cli.interaction.progress(util.format($("Creating webapp %s"), name));
siteEnvelope = {
sitename: name,
serverFarmId: plan,
location: location }; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__1() { return (function __$__1(__then) {
if (options.slot) {
return client.sites.createOrUpdateSiteSlot(resourceGroup, name, siteEnvelope, options.slot, __cb(_, __frame, 23, 23, function __$__1() {
log.info((((("Webapp slot " + name) + "/") + options.slot) + " has been created ")); __then(); }, true)); } else {
return client.sites.createOrUpdateSite(resourceGroup, name, siteEnvelope, __cb(_, __frame, 26, 23, function __$__1() {
log.info((("Webapp " + name) + " has been created")); __then(); }, true)); } ; })(function __$__1() { _(null, null, 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() { _(); }); }); }); });
webapp.command("stop [resource-group] [name]").description($("Stop a web app")).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 webapp to stop")).option("--slot <slot>", $("the name of the slot")).option("-s, --subscription <id>", $("the subscription id")).execute(function __2(resourceGroup, name, options, _) { var subscription, client, progress; var __frame = { name: "__2", line: 91 }; return __func(_, this, arguments, __2, 3, __frame, function __$__2() {
if (!resourceGroup) {
cli.missingArgument("resource-group"); } ;
if (!name) {
return _(null, cli.missingArgument("name")); } ;
subscription = profile.current.getSubscription(options.subscription);
client = webappUtils.createWebappManagementClient(subscription);
progress = cli.interaction.progress(util.format($("Stopping webapp %s"), name)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__2() { return (function __$__2(__then) {
if (options.slot) {
return client.sites.stopSiteSlot(resourceGroup, name, options.slot, __cb(_, __frame, 12, 23, function __$__2() {
log.info((((("Webapp slot " + name) + "/") + options.slot) + " has been stopped ")); __then(); }, true)); } else {
return client.sites.stopSite(resourceGroup, name, __cb(_, __frame, 15, 23, function __$__2() {
log.info((("Webapp " + name) + " has been stopped")); __then(); }, true)); } ; })(function __$__2() { _(null, null, 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() { _(); }); }); }); });
webapp.command("start [resource-group] [name]").description($("Start a web app")).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 webapp to start")).option("--slot <slot>", $("the name of the slot")).option("-s, --subscription <id>", $("the subscription id")).execute(function __3(resourceGroup, name, options, _) { var webSiteSlotName, subscription, client, progress; var __frame = { name: "__3", line: 121 }; return __func(_, this, arguments, __3, 3, __frame, function __$__3() {
if (!resourceGroup) {
cli.missingArgument("resource-group"); } ;
if (!name) {
return _(null, cli.missingArgument("name")); } ;
webSiteSlotName = name;
if (options.slot) {
webSiteSlotName = name.concat("/", options.slot); } ;
subscription = profile.current.getSubscription(options.subscription);
client = webappUtils.createWebappManagementClient(subscription);
progress = cli.interaction.progress(util.format($("Starting webapp %s"), webSiteSlotName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__3() { return (function __$__3(__then) {
if (options.slot) {
return client.sites.startSiteSlot(resourceGroup, name, options.slot, __cb(_, __frame, 16, 23, function __$__3() {
log.info((((("Webapp slot " + name) + "/") + options.slot) + " has been started")); __then(); }, true)); } else {
return client.sites.startSite(resourceGroup, name, __cb(_, __frame, 19, 23, function __$__3() {
log.info((("Webapp " + name) + " has been started")); __then(); }, true)); } ; })(function __$__3() { _(null, null, 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() { _(); }); }); }); });
webapp.command("restart [resource-group] [name]").description($("Stop and then start a web app")).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 webapp to restart")).option("--slot <slot>", $("the name of the slot")).option("-s, --subscription <id>", $("the subscription id")).execute(function __4(resourceGroup, name, options, _) { var webSiteSlotName, subscription, client, progress; var __frame = { name: "__4", line: 155 }; return __func(_, this, arguments, __4, 3, __frame, function __$__4() {
if (!resourceGroup) {
cli.missingArgument("resource-group"); } ;
if (!name) {
return _(null, cli.missingArgument("name")); } ;
webSiteSlotName = name;
if (options.slot) {
webSiteSlotName = name.concat("/", options.slot); } ;
subscription = profile.current.getSubscription(options.subscription);
client = webappUtils.createWebappManagementClient(subscription);
progress = cli.interaction.progress(util.format($("Restarting webapp %s"), name)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__4() { return (function __$__4(__then) {
if (options.slot) {
return client.sites.restartSiteSlot(resourceGroup, name, options.slot, __cb(_, __frame, 16, 23, function __$__4() {
log.info((((("Webapp slot " + name) + "/") + options.slot) + " has been restarted")); __then(); }, true)); } else {
return client.sites.restartSite(resourceGroup, name, __cb(_, __frame, 19, 23, function __$__4() {
log.info((("Webapp " + name) + " has been restarted")); __then(); }, true)); } ; })(function __$__4() { _(null, null, 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() { _(); }); }); }); });
webapp.command("delete [resource-group] [name]").description($("Delete a webapp")).usage("[options] <resource-group> <name>").option("-g --resource-group <resource-group>", $("Name of the resource group")).option("-n --name <name>", $("the name of the webapp to delete")).option("--slot <slot>", $("the name of the slot to be deleted")).option("-q, --quiet", $("quiet mode, do not ask for delete confirmation")).option("-s --subscription <subscription>", $("the subscription identifier")).execute(function __5(resourceGroup, name, options, _) { var subscription, client, progress; var __frame = { name: "__5", line: 190 }; return __func(_, this, arguments, __5, 3, __frame, function __$__5() {
if (!resourceGroup) {
cli.missingArgument("resource-group"); } ;
if (!name) {
return _(null, cli.missingArgument("name")); } ; return (function __$__5(__then) {
if (!options.quiet) { return (function __$__5(__then) {
if (!options.slot) {
return cli.interaction.confirm(util.format("Delete site %s? [y/n] ", name), __cb(_, __frame, 9, 31, function ___(__0, __2) { var __1 = !__2; return (function __$__5(__then) { if (__1) { return _(null); } else { __then(); } ; })(__then); }, true)); } else {
return cli.interaction.confirm(util.format("Delete site %s - %s? [y/n] ", name, options.slot), __cb(_, __frame, 12, 36, function ___(__0, __4) { var __3 = !__4; return (function __$__5(__then) { if (__3) { return _(null); } else { __then(); } ; })(__then); }, true)); } ; })(__then); } else { __then(); } ; })(function __$__5() {
subscription = profile.current.getSubscription(options.subscription);
client = webappUtils.createWebappManagementClient(subscription);
progress = cli.interaction.progress(util.format($("Deleting webapp %s"), name));
options.delProperties = {
deleteMetrics: true,
deleteEmptyServerFarm: false,
deleteAllSlots: true }; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__5() { return (function __$__5(__then) {
if (options.slot) {
return client.sites.deleteSiteSlot(resourceGroup, name, options.slot, options, __cb(_, __frame, 26, 23, function __$__5() {
log.info((((("Webapp slot " + name) + "/") + options.slot) + " has been deleted")); __then(); }, true)); } else {
return client.sites.deleteSite(resourceGroup, name, options, __cb(_, __frame, 29, 23, function __$__5() {
log.info((("Webapp " + name) + " has been deleted")); __then(); }, true)); } ; })(function __$__5() { _(null, null, 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(util.format($("Webapp %s has been deleted"), name)); _(); }); }); }); }); });
webapp.command("list [resource-group]").description($("List your webapps")).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 __6(resourceGroup, options, _) { var subscription, client, progress, result, i, resultSlots, j; var __frame = { name: "__6", line: 233 }; return __func(_, this, arguments, __6, 2, __frame, function __$__6() {
if (!resourceGroup) {
cli.missingArgument("resource-group"); } ;
subscription = profile.current.getSubscription(options.subscription);
client = webappUtils.createWebappManagementClient(subscription);
progress = cli.interaction.progress($("Listing webapps")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__6() {
return client.sites.getSites(resourceGroup, __cb(_, __frame, 9, 30, function ___(__0, __1) { result = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__6() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__6() { return (function __$__6(__then) {
if ((result && (result.length > 0))) {
i = 0; var __5 = false; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$__6() { __more = false; if (__5) { i++; } else { __5 = true; } ; var __4 = (i < result.length); if (__4) {
cli.interaction.formatOutput(result[i], function(data) {
if (!data) {
log.info($("No webapp information available")); }
else {
log.data($(""));
log.data($("Web App Name :"), data.name);
log.data($("Enabled :"), data.enabled);
log.data($("Status :"), data.state);
log.data($("Last Modified :"), data.lastModifiedTimeUtc);
log.data($("Location :"), data.location);
var serverFarmIdArr = (data.serverFarmId).split("/");
var serverFarmId = serverFarmIdArr[(serverFarmIdArr.length - 1)];
log.data($("App Service Plan :"), serverFarmId); } ; });
progress = cli.interaction.progress($("Checking for slots")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__6() {
return client.sites.getSiteSlots(resourceGroup, result[i].name, __cb(_, __frame, 34, 39, function ___(__0, __2) { resultSlots = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__6() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__6() {
if ((resultSlots.length > 0)) {
for (j = 0; (j < resultSlots.length); j++) {
cli.interaction.formatOutput(resultSlots[j], function(data) {
if (!data) {
log.info($("No webapp slot information available")); }
else {
log.data($(" Slot Name :"), data.name);
log.data($(" Enabled :"), data.enabled);
log.data($(" Status :"), data.state);
log.data($(" Last Modified :"), data.lastModifiedTimeUtc);
log.data($("")); } ; }); }; } ; while (__more) { __loop(); }; __more = true; }); }); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(__then); } else { __then(); } ; })(_); }); }); }); });
webapp.command("show [resource-group] [name]").description($("Get an available webapp")).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 webapp to show")).option("--slot <slot>", $("the name of the slot to show")).option("-s --subscription <subscription>", $("the subscription identifier")).execute(function __7(resourceGroup, name, options, _) { var subscription, client, progress, result; var __frame = { name: "__7", line: 297 }; return __func(_, this, arguments, __7, 3, __frame, function __$__7() {
if (!resourceGroup) {
cli.missingArgument("resource-group"); } ;
if (!name) {
return _(null, cli.missingArgument("name")); } ;
subscription = profile.current.getSubscription(options.subscription);
client = webappUtils.createWebappManagementClient(subscription);
progress = cli.interaction.progress($("Getting webapp")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__7() { return (function __$__7(__then) {
if (options.slot) {
return client.sites.getSiteSlot(resourceGroup, name, options.slot, options, __cb(_, __frame, 13, 32, function ___(__0, __1) { result = __1; __then(); }, true)); } else {
return client.sites.getSite(resourceGroup, name, options, __cb(_, __frame, 15, 32, function ___(__0, __2) { result = __2; __then(); }, true)); } ; })(function __$__7() { _(null, null, true); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__7() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__7() {
cli.interaction.formatOutput(result, function(data) {
if (!data) {
log.info($("No webapp information available")); }
else {
log.data($(""));
log.data($("Web App Name :"), data.name);
log.data($("Enabled :"), data.enabled);
log.data($("Status :"), data.state);
log.data($("Last Modified :"), data.lastModifiedTimeUtc);
log.data($("Location :"), data.location);
var serverFarmIdArr = (data.serverFarmId).split("/");
var serverFarmId = serverFarmIdArr[(serverFarmIdArr.length - 1)];
log.data($("App Service Plan :"), serverFarmId);
log.data("");
if ((data.hostNames[0] && (data.hostNames[0].length > 0))) {
log.table(data.hostNames, function(row, s) {
row.cell($("Host Name"), s); }); } ;
log.data(""); } ; }); _(); }); }); }); });};