UNPKG

azure-cli

Version:

Microsoft Azure Cross Platform Command Line tool

382 lines (174 loc) 25.8 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,__catch=__rt.__catch,__tryCatch=__rt.__tryCatch; var generatorUtils = require("../../../util/generatorUtils"); var tagUtils = require("../tag/tagUtils"); var util = require("util"); var profile = require("../../../util/profile"); var utils = require("../../../util/utils"); var $ = utils.getLocaleString; exports.init = function(cli) { var network = cli.category("network").description($("Commands to manage network resources")); var virtualNetworks = network.category("vnet").description($("Commands to manage virtual networks")); var defaultAddressPrefixes = "10.0.0.0/8"; virtualNetworks.command("create [resource-group] [name] [location]").description($("Create a virtual network")).usage("[options] <resource-group> <name> <location>").option("-g, --resource-group <resource-group>", $("the name of the resource group")).option("-n, --name <name>", $("the name of the virtual network")).option("-l, --location <location>", $("the location")).option("-a, --address-prefixes [address-prefixes]", $(("a list of address blocks reserved for" + "\n this virtual network in CIDR notation"))).option("-d, --dns-servers [dns-servers]", $("the list of DNS servers IP addresses")).option("--enable-ddos-protection [enable-ddos-protection]", $(("indicates if DDoS protection is enabled" + "\n for all the protected resources in a Virtual Network"))).option("--enable-vm-protection [enable-vm-protection]", $(("indicates if Vm protection is enabled" + "\n for all the subnets in a Virtual Network"))).option("-t, --tags [tags]", $("the list of tags.\n Can be multiple. In the format of \"name=value\".\n Name is required and value is optional.\n For example, -t \"tag1=value1;tag2\"")).option("-s, --subscription <subscription>", $("the subscription identifier")).execute(function __1(resourceGroup, name, location, options, _) { var useDefaults, subscription, networkManagementClient, virtualNetwork, progress, parameters; var __frame = { name: "__1", line: 55 }; return __func(_, this, arguments, __1, 4, __frame, function __$__1() { useDefaults = true; return cli.interaction.promptIfNotGiven($("resource group : "), resourceGroup, __cb(_, __frame, 2, 38, function ___(__0, __1) { resourceGroup = __1; return cli.interaction.promptIfNotGiven($("name : "), name, __cb(_, __frame, 3, 29, function ___(__0, __2) { name = __2; return cli.interaction.promptIfNotGiven($("location : "), location, __cb(_, __frame, 4, 41, function ___(__0, __3) { options.location = __3; subscription = profile.current.getSubscription(options.subscription); networkManagementClient = utils.createNetworkManagementClient(subscription); progress = cli.interaction.progress(util.format($("Looking up the virtual network \"%s\""), name)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__1() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__1() { return networkManagementClient.virtualNetworks.get(resourceGroup, name, null, __cb(_, __frame, 12, 65, function ___(__0, __4) { virtualNetwork = __4; __then(); }, true)); }); })(function ___(e, __result) { __catch(function __$__1() { if (e) { if ((e.statusCode === 404)) { virtualNetwork = null; } else { return _(e); } ; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, 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() { if (virtualNetwork) { return _(new Error(util.format($("virtual network with name \"%s\" already exists in the resource group \"%s\""), name, resourceGroup))); } ; parameters = { }; if (options.location) { parameters.location = options.location; } ; if (!parameters.addressSpace) { parameters.addressSpace = { }; } ; if (options.addressPrefixes) { parameters.addressSpace.addressPrefixes = []; parameters.addressSpace.addressPrefixes = parameters.addressSpace.addressPrefixes.concat(generatorUtils.splitStringByCharacter(options.addressPrefixes, ",")); } else { if (useDefaults) { parameters.addressSpace.addressPrefixes = [defaultAddressPrefixes,]; } ; } ; if (!parameters.dhcpOptions) { parameters.dhcpOptions = { }; } ; if (options.dnsServers) { parameters.dhcpOptions.dnsServers = []; parameters.dhcpOptions.dnsServers = parameters.dhcpOptions.dnsServers.concat(generatorUtils.splitStringByCharacter(options.dnsServers, ",")); } ; if (options.enableDdosProtection) { parameters.enableDdosProtection = utils.parseBool(options.enableDdosProtection); } ; if (options.enableVmProtection) { parameters.enableVmProtection = utils.parseBool(options.enableVmProtection); } ; if ((options.tags && utils.argHasValue(options.tags))) { tagUtils.appendTags(parameters, options); } ; generatorUtils.removeEmptyObjects(parameters); progress = cli.interaction.progress(util.format($("Creating virtual network \"%s\""), name)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__1() { return networkManagementClient.virtualNetworks.createOrUpdate(resourceGroup, name, parameters, __cb(_, __frame, 65, 65, function ___(__0, __5) { virtualNetwork = __5; _(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() { cli.interaction.formatOutput(virtualNetwork, generatorUtils.traverse); _(); }); }); }); }); }, true)); }, true)); }, true)); }); }); virtualNetworks.command("set [resource-group] [name]").description($("Update a virtual network")).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 virtual network")).option("-a, --address-prefixes [address-prefixes]", $(("a list of address blocks reserved for" + "\n this virtual network in CIDR notation"))).option("-d, --dns-servers [dns-servers]", $("the list of DNS servers IP addresses")).option("--enable-ddos-protection [enable-ddos-protection]", $(("indicates if DDoS protection is enabled" + "\n for all the protected resources in a Virtual Network"))).option("--enable-vm-protection [enable-vm-protection]", $(("indicates if Vm protection is enabled" + "\n for all the subnets in a Virtual Network"))).option("-t, --tags [tags]", $("the list of tags.\n Can be multiple. In the format of \"name=value\".\n Name is required and value is optional.\n For example, -t \"tag1=value1;tag2\"")).option("-s, --subscription <subscription>", $("the subscription identifier")).execute(function __2(resourceGroup, name, options, _) { var useDefaults, subscription, networkManagementClient, virtualNetwork, progress, parameters; var __frame = { name: "__2", line: 142 }; return __func(_, this, arguments, __2, 3, __frame, function __$__2() { useDefaults = false; return cli.interaction.promptIfNotGiven($("resource group : "), resourceGroup, __cb(_, __frame, 2, 38, function ___(__0, __1) { resourceGroup = __1; return cli.interaction.promptIfNotGiven($("name : "), name, __cb(_, __frame, 3, 29, function ___(__0, __2) { name = __2; subscription = profile.current.getSubscription(options.subscription); networkManagementClient = utils.createNetworkManagementClient(subscription); progress = cli.interaction.progress(util.format($("Looking up the virtual network \"%s\""), name)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__2() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__2() { return networkManagementClient.virtualNetworks.get(resourceGroup, name, null, __cb(_, __frame, 11, 65, function ___(__0, __3) { virtualNetwork = __3; __then(); }, true)); }); })(function ___(e, __result) { __catch(function __$__2() { if (e) { if ((e.statusCode === 404)) { virtualNetwork = null; } else { return _(e); } ; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, 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() { if (!virtualNetwork) { return _(new Error(util.format($("virtual network with name \"%s\" not found in the resource group \"%s\""), name, resourceGroup))); } ; parameters = virtualNetwork; if (!parameters.addressSpace) { parameters.addressSpace = { }; } ; if (options.addressPrefixes) { if (((virtualNetwork && virtualNetwork.addressSpace) && virtualNetwork.addressSpace.addressPrefixes)) { parameters.addressSpace.addressPrefixes = virtualNetwork.addressSpace.addressPrefixes; } else { parameters.addressSpace.addressPrefixes = []; } ; parameters.addressSpace.addressPrefixes = parameters.addressSpace.addressPrefixes.concat(generatorUtils.splitStringByCharacter(options.addressPrefixes, ",")); } else { if (useDefaults) { parameters.addressSpace.addressPrefixes = [defaultAddressPrefixes,]; } ; } ; if (!parameters.dhcpOptions) { parameters.dhcpOptions = { }; } ; if (options.dnsServers) { if (!utils.argHasValue(options.dnsServers)) { delete parameters.dhcpOptions.dnsServers; } else { if (((virtualNetwork && virtualNetwork.dhcpOptions) && virtualNetwork.dhcpOptions.dnsServers)) { parameters.dhcpOptions.dnsServers = virtualNetwork.dhcpOptions.dnsServers; } else { parameters.dhcpOptions.dnsServers = []; } ; parameters.dhcpOptions.dnsServers = parameters.dhcpOptions.dnsServers.concat(generatorUtils.splitStringByCharacter(options.dnsServers, ",")); } ; } ; if (options.enableDdosProtection) { parameters.enableDdosProtection = utils.parseBool(options.enableDdosProtection); } ; if (options.enableVmProtection) { parameters.enableVmProtection = utils.parseBool(options.enableVmProtection); } ; if ((options.tags && utils.argHasValue(options.tags))) { tagUtils.appendTags(parameters, options); } ; generatorUtils.removeEmptyObjects(parameters); progress = cli.interaction.progress(util.format($("Updating virtual network \"%s\""), name)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__2() { return networkManagementClient.virtualNetworks.createOrUpdate(resourceGroup, name, parameters, __cb(_, __frame, 72, 65, function ___(__0, __4) { virtualNetwork = __4; _(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() { cli.interaction.formatOutput(virtualNetwork, generatorUtils.traverse); _(); }); }); }); }); }, true)); }, true)); }); }); virtualNetworks.command("delete [resource-group] [name]").description($("Delete a virtual network")).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 virtual network")).option("-q, --quiet", $("quiet mode, do not ask for delete confirmation")).option("-s, --subscription <subscription>", $("the subscription identifier")).execute(function __3(resourceGroup, name, options, _) { var subscription, networkManagementClient, virtualNetwork, progress; var __frame = { name: "__3", line: 229 }; return __func(_, this, arguments, __3, 3, __frame, function __$__3() { return cli.interaction.promptIfNotGiven($("resource group : "), resourceGroup, __cb(_, __frame, 1, 38, function ___(__0, __2) { resourceGroup = __2; return cli.interaction.promptIfNotGiven($("name : "), name, __cb(_, __frame, 2, 29, function ___(__0, __3) { name = __3; subscription = profile.current.getSubscription(options.subscription); networkManagementClient = utils.createNetworkManagementClient(subscription); progress = cli.interaction.progress(util.format($("Looking up the virtual network \"%s\""), name)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__3() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__3() { return networkManagementClient.virtualNetworks.get(resourceGroup, name, null, __cb(_, __frame, 10, 65, function ___(__0, __4) { virtualNetwork = __4; __then(); }, true)); }); })(function ___(e, __result) { __catch(function __$__3() { if (e) { if ((e.statusCode === 404)) { virtualNetwork = null; } else { return _(e); } ; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, 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() { if (!virtualNetwork) { return _(new Error(util.format($("virtual network with name \"%s\" not found in the resource group \"%s\""), name, resourceGroup))); } ; return (function __$__3(_) { var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return cli.interaction.confirm(util.format($("Delete virtual network \"%s\"? [y/n] "), name), __cb(_, __frame, 25, 45, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -228, 17, function ___(__0, __5) { return (function __$__3(__then) { if (__5) { cli.output.info(util.format($("virtual network \"%s\" was not deleted and still exists in the resource group \"%s\""), name, resourceGroup)); return _(null); } else { __then(); } ; })(function __$__3() { progress = cli.interaction.progress(util.format($("Deleting virtual network \"%s\""), name)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__3() { return networkManagementClient.virtualNetworks.deleteMethod(resourceGroup, name, __cb(_, __frame, 32, 65, function ___(__0, __6) { virtualNetwork = __6; cli.output.info(util.format($("virtual network \"%s\" was successfully deleted from resource group \"%s\""), name, resourceGroup)); _(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() { _(); }); }); }); }, true)); }); }); }, true)); }, true)); }); }); virtualNetworks.command("show [resource-group] [name]").description($("Show a virtual network")).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 virtual network")).option("-s, --subscription <subscription>", $("the subscription identifier")).execute(function __4(resourceGroup, name, options, _) { var subscription, networkManagementClient, virtualNetwork, progress; var __frame = { name: "__4", line: 274 }; return __func(_, this, arguments, __4, 3, __frame, function __$__4() { return cli.interaction.promptIfNotGiven($("resource group : "), resourceGroup, __cb(_, __frame, 1, 38, function ___(__0, __1) { resourceGroup = __1; return cli.interaction.promptIfNotGiven($("name : "), name, __cb(_, __frame, 2, 29, function ___(__0, __2) { name = __2; subscription = profile.current.getSubscription(options.subscription); networkManagementClient = utils.createNetworkManagementClient(subscription); progress = cli.interaction.progress(util.format($("Looking up the virtual network \"%s\""), name)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__4() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__4() { return networkManagementClient.virtualNetworks.get(resourceGroup, name, null, __cb(_, __frame, 10, 65, function ___(__0, __3) { virtualNetwork = __3; __then(); }, true)); }); })(function ___(e, __result) { __catch(function __$__4() { if (e) { if ((e.statusCode === 404)) { virtualNetwork = null; } else { return _(e); } ; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, 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() { if (!virtualNetwork) { cli.output.warn(util.format($("virtual network with name \"%s\" not found in the resource group \"%s\""), name, resourceGroup)); } ; cli.interaction.formatOutput(virtualNetwork, generatorUtils.traverse); _(); }); }); }, true)); }, true)); }); }); virtualNetworks.command("list [resource-group]").description($("List virtual networks")).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 __5(resourceGroup, options, _) { var subscription, networkManagementClient, virtualNetwork, progress; var __frame = { name: "__5", line: 307 }; return __func(_, this, arguments, __5, 2, __frame, function __$__5() { options.resourceGroup = resourceGroup; subscription = profile.current.getSubscription(options.subscription); networkManagementClient = utils.createNetworkManagementClient(subscription); virtualNetwork = null; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__5() { return (function __$__5(__then) { if ((typeof networkManagementClient.virtualNetworks.listAll != "function")) { return cli.interaction.promptIfNotGiven($("resource-group : "), resourceGroup, __cb(_, __frame, 9, 42, function ___(__0, __1) { resourceGroup = __1; progress = cli.interaction.progress($("Getting the virtual networks")); return networkManagementClient.virtualNetworks.list(resourceGroup, __cb(_, __frame, 11, 67, function ___(__0, __2) { virtualNetwork = __2; __then(); }, true)); }, true)); } else { return (function __$__5(__then) { if (options.resourceGroup) { progress = cli.interaction.progress($("Getting the virtual networks")); return networkManagementClient.virtualNetworks.list(resourceGroup, __cb(_, __frame, 15, 69, function ___(__0, __3) { virtualNetwork = __3; __then(); }, true)); } else { progress = cli.interaction.progress($("Getting the virtual networks")); return networkManagementClient.virtualNetworks.listAll(__cb(_, __frame, 18, 69, function ___(__0, __4) { virtualNetwork = __4; __then(); }, true)); } ; })(__then); } ; })(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() { cli.interaction.formatOutput(virtualNetwork, function(virtualNetwork) { if ((!virtualNetwork || (virtualNetwork.length === 0))) { cli.output.warn($("No virtual networks found")); } else { cli.output.table(virtualNetwork, function(row, item) { generatorUtils.showTableRow(row, item); }); } ; }); _(); }); }); }); }); virtualNetworks.command("usage [resource-group] [name]").description($("Perform list usage operation on a virtual network")).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 virtual network")).option("-s, --subscription <subscription>", $("the subscription identifier")).execute(function __6(resourceGroup, name, options, _) { var subscription, networkManagementClient, virtualNetwork, progress; var __frame = { name: "__6", line: 349 }; return __func(_, this, arguments, __6, 3, __frame, function __$__6() { return cli.interaction.promptIfNotGiven($("resource group : "), resourceGroup, __cb(_, __frame, 1, 38, function ___(__0, __1) { resourceGroup = __1; return cli.interaction.promptIfNotGiven($("name : "), name, __cb(_, __frame, 2, 29, function ___(__0, __2) { name = __2; subscription = profile.current.getSubscription(options.subscription); networkManagementClient = utils.createNetworkManagementClient(subscription); progress = cli.interaction.progress(util.format($("Looking up the virtual network \"%s\""), name)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__6() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__6() { return networkManagementClient.virtualNetworks.get(resourceGroup, name, null, __cb(_, __frame, 11, 65, function ___(__0, __3) { virtualNetwork = __3; __then(); }, true)); }); })(function ___(e, __result) { __catch(function __$__6() { if (e) { if ((e.statusCode === 404)) { virtualNetwork = null; } else { return _(e); } ; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__6() { _(null, null, 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 (!virtualNetwork) { return _(new Error(util.format($("a virtual network with name \"%s\" not found in the resource group \"%s\""), name, resourceGroup))); } ; progress = cli.interaction.progress(util.format($("Performing list usage operation on a virtual network \"%s\""), name)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__6() { return networkManagementClient.virtualNetworks.listUsage(resourceGroup, name, __cb(_, __frame, 27, 65, function ___(__0, __4) { virtualNetwork = __4; _(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(virtualNetwork, generatorUtils.traverse); _(); }); }); }); }); }, true)); }, true)); }); });};