azure-cli
Version:
Microsoft Azure Cross Platform Command Line tool
290 lines (135 loc) • 15.6 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")).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, webSiteSlotName, progress, parameters, result; var __frame = { name: "__1", line: 50 }; return __func(_, this, arguments, __1, 5, __frame, function __$__1() {
subscription = profile.current.getSubscription(options.subscription);
client = webappUtils.createWebappManagementClient(subscription);
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")); } ;
webSiteSlotName = name;
if (Boolean(options.slot)) {
webSiteSlotName = name.concat("/", options.slot); } ;
progress = cli.interaction.progress(util.format($("Creating webapp %s"), webSiteSlotName));
parameters = {
webSite: {
name: webSiteSlotName,
location: location,
properties: {
serverFarm: plan } } }; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__1() {
return client.webSites.createOrUpdate(resourceGroup, name, options.slot, parameters, __cb(_, __frame, 31, 33, 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() {
log.info((("Webapp " + webSiteSlotName) + " has been created ")); _(); }); }); }); });
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, result, webSiteSlotName; var __frame = { name: "__2", line: 94 }; return __func(_, this, arguments, __2, 3, __frame, function __$__2() {
subscription = profile.current.getSubscription(options.subscription);
client = webappUtils.createWebappManagementClient(subscription);
if (!resourceGroup) {
cli.missingArgument("resource-group"); } ;
if (!name) {
return _(null, cli.missingArgument("name")); } ;
progress = cli.interaction.progress(util.format($("Stopping webapp %s"), name)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__2() {
return client.webSites.stop(resourceGroup, name, options.slot, __cb(_, __frame, 12, 33, function ___(__0, __1) { result = __1; _(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() {
webSiteSlotName = name;
if (Boolean(options.slot)) {
webSiteSlotName = name.concat("/", options.slot); } ;
log.info((("Webapp " + webSiteSlotName) + " has been stopped ")); _(); }); }); }); });
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 subscription, client, webSiteSlotName, progress, result; var __frame = { name: "__3", line: 124 }; return __func(_, this, arguments, __3, 3, __frame, function __$__3() {
subscription = profile.current.getSubscription(options.subscription);
client = webappUtils.createWebappManagementClient(subscription);
if (!resourceGroup) {
cli.missingArgument("resource-group"); } ;
if (!name) {
return _(null, cli.missingArgument("name")); } ;
webSiteSlotName = name;
if (Boolean(options.slot)) {
webSiteSlotName = name.concat("/", options.slot); } ;
progress = cli.interaction.progress(util.format($("Starting webapp %s"), webSiteSlotName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__3() {
return client.webSites.start(resourceGroup, name, options.slot, __cb(_, __frame, 16, 33, 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() {
log.info((("Webapp " + webSiteSlotName) + " has been started ")); _(); }); }); }); });
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 subscription, client, webSiteSlotName, progress, result; var __frame = { name: "__4", line: 153 }; return __func(_, this, arguments, __4, 3, __frame, function __$__4() {
subscription = profile.current.getSubscription(options.subscription);
client = webappUtils.createWebappManagementClient(subscription);
if (!resourceGroup) {
cli.missingArgument("resource-group"); } ;
if (!name) {
return _(null, cli.missingArgument("name")); } ;
webSiteSlotName = name;
if (Boolean(options.slot)) {
webSiteSlotName = name.concat("/", options.slot); } ;
progress = cli.interaction.progress(util.format($("Restarting webapp %s"), name)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__4() {
return client.webSites.restart(resourceGroup, name, options.slot, __cb(_, __frame, 16, 33, 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() {
log.info((("Webapp " + webSiteSlotName) + " has been restarted ")); _(); }); }); }); });
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, delProperties, result; var __frame = { name: "__5", line: 183 }; return __func(_, this, arguments, __5, 3, __frame, function __$__5() {
subscription = profile.current.getSubscription(options.subscription);
client = webappUtils.createWebappManagementClient(subscription);
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, 11, 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 in slot %s? [y/n] ", name, options.slot), __cb(_, __frame, 14, 36, function ___(__0, __4) { var __3 = !__4; return (function __$__5(__then) { if (__3) { return _(null); } else { __then(); } ; })(__then); }, true)); } ; })(__then); } else { __then(); } ; })(function __$__5() {
progress = cli.interaction.progress(util.format($("Deleting webapp %s"), name));
delProperties = {
deleteMetrics: true,
deleteEmptyServerFarm: false,
deleteAllSlots: true }; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__5() {
return client.webSites.deleteMethod(resourceGroup, name, options.slot, delProperties, __cb(_, __frame, 26, 33, function ___(__0, __5) { result = __5; _(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(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, name, result; var __frame = { name: "__6", line: 221 }; 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.webSites.list(resourceGroup, name, __cb(_, __frame, 10, 33, 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() {
cli.interaction.formatOutput(result.webSites, function(data) {
if ((data.length > 0)) {
log.table(data, function(row, item) {
row.cell($("Name "), item.name);
row.cell($("Status "), item.properties.state);
row.cell($("Location "), item.location);
row.cell($("SKU "), item.properties.sku);
row.cell($("URL "), item.properties.hostNames); }); }
else {
log.info(util.format($("No web apps found."))); } ; }); _(); }); }); }); });
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, getProp, result; var __frame = { name: "__7", line: 257 }; 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 client.webSites.get(resourceGroup, name, options.slot, getProp, __cb(_, __frame, 13, 33, function ___(__0, __1) { result = __1; _(null, null, true); }, 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($("Web app Name :"), data.webSite.name);
log.data($("SKU :"), data.webSite.properties.sku);
log.data($("Enabled :"), data.webSite.properties.enabled);
log.data($("Last Modified :"), data.webSite.properties.lastModifiedTimeUtc);
log.data($("Location :"), data.webSite.location);
log.data("");
if ((data.webSite.properties.hostNames[0] && (data.webSite.properties.hostNames[0].length > 0))) {
log.table(data.webSite.properties.hostNames, function(row, s) {
row.cell($("Host Name"), s); }); } ;
log.data(""); } ; }); _(); }); }); }); });};