azure-cli
Version:
Microsoft Azure Cross Platform Command Line tool
388 lines (224 loc) • 23.4 kB
JavaScript
/*** 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; var __ = require("underscore");
var util = require("util");
var utils = require("../../../util/utils");
var $ = utils.getLocaleString;
var tagUtils = require("../tag/tagUtils");
var Subnet = require("./subnet");
var LoadBalancer = require("./loadBalancer");
var Nsg = require("./nsg");
var PublicIp = require("./publicIPAddress.helper");
var resourceUtils = require("../resource/resourceUtils");
function Nic(cli, networkManagementClient) {
this.networkManagementClient = networkManagementClient;
this.subnetCrud = new Subnet(cli, networkManagementClient);
this.loadBalancerCrud = new LoadBalancer(cli, networkManagementClient);
this.nsgCrud = new Nsg(cli, networkManagementClient);
this.publicIpCrud = new PublicIp(cli, networkManagementClient);
this.output = cli.output;
this.interaction = cli.interaction;};
__.extend(Nic.prototype, {
get: function get__1(resourceGroupName, nicName, _) { var self, progress, nic, __this = this; var __frame = { name: "get__1", line: 39 }; return __func(_, this, arguments, get__1, 2, __frame, function __$get__1() { self = __this;
progress = self.interaction.progress(util.format($("Looking up the network interface \"%s\""), nicName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$get__1() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$get__1() {
return self.networkManagementClient.networkInterfaces.get(resourceGroupName, nicName, null, __cb(_, __frame, 4, 63, function ___(__0, __1) { nic = __1;
return _(null, nic); }, true)); }); })(function ___(e, __result) { __catch(function __$get__1() { if (e) {
if ((e.statusCode === 404)) {
return _(null, null); } ;
return _(e); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$get__1() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$get__1() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$get__1() { _(); }); }); }); },
list: function list__2(options, _) { var self, nics, progress, __this = this; var __frame = { name: "list__2", line: 55 }; return __func(_, this, arguments, list__2, 1, __frame, function __$list__2() { self = __this;
nics = null;
progress = self.interaction.progress($("Getting the network interfaces")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$list__2() { return (function __$list__2(__then) {
if (options.resourceGroup) { return (function __$list__2(__then) {
if (options.virtualMachineScaleSetName) { return (function __$list__2(__then) {
if (options.virtualMachineIndex) {
return self.networkManagementClient.networkInterfaces.listVirtualMachineScaleSetVMNetworkInterfaces(options.resourceGroup, options.virtualMachineScaleSetName, options.virtualMachineIndex, __cb(_, __frame, 10, 66, function ___(__0, __1) { nics = __1; __then(); }, true)); } else {
return self.networkManagementClient.networkInterfaces.listVirtualMachineScaleSetNetworkInterfaces(options.resourceGroup, options.virtualMachineScaleSetName, __cb(_, __frame, 12, 66, function ___(__0, __2) { nics = __2; __then(); }, true)); } ; })(__then); } else {
return self.networkManagementClient.networkInterfaces.list(options.resourceGroup, __cb(_, __frame, 15, 64, function ___(__0, __3) { nics = __3; __then(); }, true)); } ; })(__then); } else {
return self.networkManagementClient.networkInterfaces.listAll(__cb(_, __frame, 18, 62, function ___(__0, __4) { nics = __4; __then(); }, true)); } ; })(function __$list__2() { _(null, null, true); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$list__2() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$list__2() {
self.interaction.formatOutput(nics, function(nics) {
if ((nics.length === 0)) {
self.output.warn($("No network interfaces found")); }
else {
self.output.table(nics, function(row, nic) {
row.cell($("Name"), nic.name);
row.cell($("Location"), (nic.location || ""));
var resInfo = resourceUtils.getResourceInformation(nic.id);
row.cell($("Resource group"), resInfo.resourceGroup);
row.cell($("Provisioning state"), nic.provisioningState);
row.cell($("MAC Address"), (nic.macAddress || ""));
row.cell($("IP forwarding"), nic.enableIPForwarding);
row.cell($("Internal DNS name"), (nic.dnsSettings.internalDnsNameLabel || ""));
row.cell($("Internal FQDN"), (nic.dnsSettings.internalFqdn || ""));
if (nic.dnsSettings.internalDomainNameSuffix) {
row.cell($("Internal domain name suffix"), (nic.dnsSettings.internalDomainNameSuffix || "")); } ; }); } ; }); _(); }); }); }); },
show: function show__3(resourceGroupName, nicName, options, _) { var self, nic, __this = this; var __frame = { name: "show__3", line: 101 }; return __func(_, this, arguments, show__3, 3, __frame, function __$show__3() { self = __this;
nic = null; return (function __$show__3(__then) {
if ((options.virtualMachineScaleSetName || options.virtualMachineIndex)) {
if (!((options.virtualMachineScaleSetName && options.virtualMachineIndex))) {
return _(new Error(util.format($("--virtual-machine-scale-set-name and --virtual-machine-index must be specified")))); } ;
return self.getFromScaleSet(resourceGroupName, options.virtualMachineScaleSetName, options.virtualMachineIndex, nicName, __cb(_, __frame, 8, 17, function ___(__0, __1) { nic = __1; __then(); }, true)); } else {
return self.get(resourceGroupName, nicName, __cb(_, __frame, 10, 17, function ___(__0, __2) { nic = __2; __then(); }, true)); } ; })(function __$show__3() {
self._showNic(nic, resourceGroupName, nicName); _(); }); }); },
getFromScaleSet: function getFromScaleSet__4(resourceGroupName, virtualMachineScaleSetName, virtualMachineIndex, nicName, _) { var self, progress, nic, __this = this; var __frame = { name: "getFromScaleSet__4", line: 117 }; return __func(_, this, arguments, getFromScaleSet__4, 4, __frame, function __$getFromScaleSet__4() { self = __this;
progress = self.interaction.progress(util.format($("Looking up the network interface \"%s\" in scale set \"%s\""), nicName, virtualMachineScaleSetName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$getFromScaleSet__4() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$getFromScaleSet__4() {
return self.networkManagementClient.networkInterfaces.getVirtualMachineScaleSetNetworkInterface(resourceGroupName, virtualMachineScaleSetName, virtualMachineIndex, nicName, null, __cb(_, __frame, 4, 63, function ___(__0, __1) { nic = __1;
return _(null, nic); }, true)); }); })(function ___(e, __result) { __catch(function __$getFromScaleSet__4() { if (e) {
if ((e.statusCode === 404)) {
return _(null, null); } ;
return _(e); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$getFromScaleSet__4() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$getFromScaleSet__4() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$getFromScaleSet__4() { _(); }); }); }); },
update: function update__5(resourceGroupName, nicName, nic, _) { var self, progress, __this = this; var __frame = { name: "update__5", line: 133 }; return __func(_, this, arguments, update__5, 3, __frame, function __$update__5() { self = __this;
progress = self.interaction.progress(util.format($("Updating network interface \"%s\""), nicName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$update__5() {
return self.networkManagementClient.networkInterfaces.createOrUpdate(resourceGroupName, nicName, nic, __cb(_, __frame, 4, 59, function ___(__0, __1) { nic = __1;
return _(null, nic); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$update__5() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$update__5() { _(); }); }); }); },
createBackendAddressPool: function createBackendAddressPool__6(resourceGroupName, nicName, ipConfigName, options, _) { var __this = this; var __frame = { name: "createBackendAddressPool__6", line: 147 }; return __func(_, this, arguments, createBackendAddressPool__6, 4, __frame, function __$createBackendAddressPool__6() {
return __this._updateBackendAddressPool(resourceGroupName, nicName, ipConfigName, options, true, __cb(_, __frame, 1, 9, function __$createBackendAddressPool__6() { _(); }, true)); }); },
deleteBackendAddressPool: function deleteBackendAddressPool__7(resourceGroupName, nicName, ipConfigName, options, _) { var __this = this; var __frame = { name: "deleteBackendAddressPool__7", line: 151 }; return __func(_, this, arguments, deleteBackendAddressPool__7, 4, __frame, function __$deleteBackendAddressPool__7() {
return __this._updateBackendAddressPool(resourceGroupName, nicName, ipConfigName, options, false, __cb(_, __frame, 1, 9, function __$deleteBackendAddressPool__7() { _(); }, true)); }); },
createInboundNatRule: function createInboundNatRule__8(resourceGroupName, nicName, ipConfigName, options, _) { var __this = this; var __frame = { name: "createInboundNatRule__8", line: 158 }; return __func(_, this, arguments, createInboundNatRule__8, 4, __frame, function __$createInboundNatRule__8() {
return __this._updateInboundNatRule(resourceGroupName, nicName, ipConfigName, options, true, __cb(_, __frame, 1, 9, function __$createInboundNatRule__8() { _(); }, true)); }); },
deleteInboundNatRule: function deleteInboundNatRule__9(resourceGroupName, nicName, ipConfigName, options, _) { var __this = this; var __frame = { name: "deleteInboundNatRule__9", line: 162 }; return __func(_, this, arguments, deleteInboundNatRule__9, 4, __frame, function __$deleteInboundNatRule__9() {
return __this._updateInboundNatRule(resourceGroupName, nicName, ipConfigName, options, false, __cb(_, __frame, 1, 9, function __$deleteInboundNatRule__9() { _(); }, true)); }); },
_showNic: function(nic, resourceGroupName, nicName) {
var self = this;
self.interaction.formatOutput(nic, function(nic) {
if ((nic === null)) {
self.output.warn(util.format($("A network interface with name \"%s\" not found in the resource group \"%s\""), nicName, resourceGroupName));
return; } ;
self.output.nameValue($("Id"), nic.id);
self.output.nameValue($("Name"), nic.name);
self.output.nameValue($("Type"), nic.type);
self.output.nameValue($("Location"), nic.location);
self.output.nameValue($("Provisioning state"), nic.provisioningState);
self.output.nameValue($("Tags"), tagUtils.getTagsInfo(nic.tags));
self.output.nameValue($("MAC address"), nic.macAddress);
self.output.nameValue($("Internal DNS name label"), nic.dnsSettings.internalDnsNameLabel);
self.output.nameValue($("Internal FQDN"), nic.dnsSettings.internalFqdn);
self.output.nameValue($("Internal domain name suffix"), nic.dnsSettings.internalDomainNameSuffix);
self.output.nameValue($("Enable IP forwarding"), nic.enableIPForwarding);
if (nic.networkSecurityGroup) {
self.output.nameValue($("Network security group"), nic.networkSecurityGroup.id); } ;
if (nic.virtualMachine) {
self.output.nameValue($("Virtual machine"), nic.virtualMachine.id); } ;
self.output.header($("IP configurations"));
nic.ipConfigurations.forEach(function(ipConfig) {
self._showIpConfig(ipConfig, nicName, ipConfig.name);
self.output.data($(""), ""); }); }); },
_showIpConfig: function(ipConfig, nicName, ipConfigName) {
var self = this;
var configIndent = 2;
var subItemsIndent = 4;
self.interaction.formatOutput(ipConfig, function(ipConfig) {
if (((ipConfig === null) || (ipConfig === undefined))) {
self.output.warn(util.format($("IP configuration with name \"%s\" not found in the nic \"%s\""), ipConfigName, nicName));
return; } ;
self.output.nameValue($("Name"), ipConfig.name, configIndent);
self.output.nameValue($("Primary"), ipConfig.primary, configIndent);
self.output.nameValue($("Provisioning state"), ipConfig.provisioningState, configIndent);
self.output.nameValue($("Private IP address"), ipConfig.privateIPAddress, configIndent);
self.output.nameValue($("Private IP version"), ipConfig.privateIPAddressVersion, configIndent);
self.output.nameValue($("Private IP allocation method"), ipConfig.privateIPAllocationMethod, configIndent);
if (ipConfig.publicIPAddress) {
self.output.nameValue($("Public IP address"), ipConfig.publicIPAddress.id, configIndent); } ;
if (ipConfig.subnet) {
self.output.nameValue($("Subnet"), ipConfig.subnet.id, configIndent); } ;
if ((ipConfig.loadBalancerBackendAddressPools && (ipConfig.loadBalancerBackendAddressPools.length > 0))) {
self.output.header($("Load balancer backend address pools"), configIndent);
ipConfig.loadBalancerBackendAddressPools.forEach(function(pool) {
self.output.nameValue($("Id"), pool.id, subItemsIndent); }); } ;
if ((ipConfig.loadBalancerInboundNatRules && (ipConfig.loadBalancerInboundNatRules.length > 0))) {
self.output.header($("Load balancer inbound NAT rules"), configIndent);
ipConfig.loadBalancerInboundNatRules.forEach(function(rule) {
self.output.nameValue($("Id"), rule.id, subItemsIndent); }); } ; }); },
_updateBackendAddressPool: function _updateBackendAddressPool__10(resourceGroupName, nicName, ipConfigName, options, isAdding, _) { var self, nic, ipConfig, poolId, lb, pool, index, __this = this; var __frame = { name: "_updateBackendAddressPool__10", line: 241 }; return __func(_, this, arguments, _updateBackendAddressPool__10, 5, __frame, function __$_updateBackendAddressPool__10() { self = __this;
return self.get(resourceGroupName, nicName, __cb(_, __frame, 3, 19, function ___(__0, __1) { nic = __1;
if (!nic) {
return _(new Error(util.format($("A network interface with name \"%s\" not found in the resource group \"%s\""), nicName, resourceGroupName))); } ;
if (ipConfigName) {
ipConfig = utils.findFirstCaseIgnore(nic.ipConfigurations, { name: ipConfigName });
if (!ipConfig) {
return _(new Error(util.format($("An ip configuration with name \"%s\" not found in the nic \"%s\""), ipConfigName, nicName))); } ; }
else {
ipConfig = nic.ipConfigurations[0];
self.output.warn(util.format($("--ip-config-name not specified, using \"%s\" ip configuration"), ipConfig.name)); } ;
poolId = null;
if (!ipConfig.loadBalancerBackendAddressPools) {
ipConfig.loadBalancerBackendAddressPools = []; } ;
if (((!options.lbAddressPoolId && !options.lbName) && !options.lbAddressPoolName)) {
return _(new Error($("You must specify --lb-address-pool-id or --lb-name, --lb-address-pool-name"))); } ; return (function __$_updateBackendAddressPool__10(__then) {
if (options.lbAddressPoolId) {
if ((options.lbName || options.lbAddressPoolName)) {
self.output.warn("--lb-name parameter, --lb-address-pool-name will be ignored"); } ;
poolId = options.lbAddressPoolId; __then(); } else { return (function __$_updateBackendAddressPool__10(__then) {
if ((options.lbName || options.lbAddressPoolName)) {
if (!options.lbName) {
return _(new Error($("You must specify --lb-name parameter if --lb-address-pool-name is specified"))); } ;
if (!options.lbAddressPoolName) {
return _(new Error($("You must specify --lb-address-pool-name parameter if --lb-name is specified"))); } ;
return self.loadBalancerCrud.get(resourceGroupName, options.lbName, __cb(_, __frame, 42, 37, function ___(__0, __2) { lb = __2;
if (!lb) {
return _(new Error(util.format($("A load balancer with name \"%s\" not found in the resource group \"%s"), options.lbName, resourceGroupName))); } ;
pool = utils.findFirstCaseIgnore(lb.backendAddressPools, { name: options.lbAddressPoolName });
if (!pool) {
return _(new Error(util.format($("A backend address pool with name \"%s\" not found in the load balancer \"%s\" resource group \"%s\""), options.lbAddressPoolName, options.lbName, resourceGroupName))); } ;
poolId = pool.id; __then(); }, true)); } else { __then(); } ; })(__then); } ; })(function __$_updateBackendAddressPool__10() {
if (isAdding) {
if (utils.findFirstCaseIgnore(ipConfig.loadBalancerBackendAddressPools, { id: poolId })) {
return _(new Error(util.format($("Specified backend address pool already attached to NIC \"%s\" in the resource group \"%s\""), nicName, resourceGroupName))); } ;
ipConfig.loadBalancerBackendAddressPools.push({ id: poolId }); }
else {
index = utils.indexOfCaseIgnore(ipConfig.loadBalancerBackendAddressPools, { id: poolId });
if ((index === -1)) {
return _(new Error(util.format($("Backend address pool is not attached to NIC \"%s\" in the resource group \"%s\""), nicName, resourceGroupName))); } ;
ipConfig.loadBalancerBackendAddressPools.splice(index, 1); } ;
return self.update(resourceGroupName, nicName, nic, __cb(_, __frame, 67, 15, function ___(__0, __3) { nic = __3;
self._showNic(nic); _(); }, true)); }); }, true)); }); },
_updateInboundNatRule: function _updateInboundNatRule__11(resourceGroupName, nicName, ipConfigName, options, isAdding, _) { var self, nic, ipConfig, ruleId, lb, rule, index, __this = this; var __frame = { name: "_updateInboundNatRule__11", line: 312 }; return __func(_, this, arguments, _updateInboundNatRule__11, 5, __frame, function __$_updateInboundNatRule__11() { self = __this;
return self.get(resourceGroupName, nicName, __cb(_, __frame, 3, 19, function ___(__0, __1) { nic = __1;
if (!nic) {
return _(new Error(util.format($("A network interface with name \"%s\" not found in the resource group \"%s\""), nicName, resourceGroupName))); } ;
if (ipConfigName) {
ipConfig = utils.findFirstCaseIgnore(nic.ipConfigurations, { name: ipConfigName });
if (!ipConfig) {
return _(new Error(util.format($("An ip configuration with name \"%s\" not found in the nic \"%s\""), ipConfigName, nicName))); } ; }
else {
ipConfig = nic.ipConfigurations[0];
self.output.warn(util.format($("--ip-config-name not specified, using \"%s\" ip configuration"), ipConfig.name)); } ;
ruleId = null;
if (!ipConfig.loadBalancerInboundNatRules) {
ipConfig.loadBalancerInboundNatRules = []; } ;
if (((!options.lbInboundNatRuleId && !options.lbName) && !options.lbInboundNatRuleName)) {
return _(new Error($("You must specify --lb-inbound-nat-rule-id or --lb-name, --lb-inbound-nat-rule-name"))); } ; return (function __$_updateInboundNatRule__11(__then) {
if (options.lbInboundNatRuleId) {
if ((options.lbName || options.lbInboundNatRuleName)) {
self.output.warn("--lb-name, --lb-inbound-nat-rule-name will be ignored"); } ;
ruleId = options.lbInboundNatRuleId; __then(); } else { return (function __$_updateInboundNatRule__11(__then) {
if ((options.lbName || options.lbInboundNatRuleName)) {
if (!options.lbName) {
return _(new Error($("You must specify --lb-name parameter if --lb-inbound-nat-rule-name is specified"))); } ;
if (!options.lbInboundNatRuleName) {
return _(new Error($("You must specify --lb-inbound-nat-rule-name parameter if --lb-name is specified"))); } ;
return self.loadBalancerCrud.get(resourceGroupName, options.lbName, __cb(_, __frame, 42, 37, function ___(__0, __2) { lb = __2;
if (!lb) {
return _(new Error(util.format($("A load balancer with name \"%s\" not found in the resource group \"%s"), options.lbName, resourceGroupName))); } ;
rule = utils.findFirstCaseIgnore(lb.inboundNatRules, { name: options.lbInboundNatRuleName });
if (!rule) {
return _(new Error(util.format($("An inbound NAT rule with name \"%s\" not found in the load balancer \"%s\""), options.lbInboundNatRuleName, options.lbName))); }
else {
ruleId = rule.id; } ; __then(); }, true)); } else { __then(); } ; })(__then); } ; })(function __$_updateInboundNatRule__11() {
if (isAdding) {
if (!utils.findFirstCaseIgnore(ipConfig.loadBalancerInboundNatRules, { id: ruleId })) {
ipConfig.loadBalancerInboundNatRules.push({ id: ruleId }); }
else {
return _(new Error(util.format($("Inbound NAT rule already attached to NIC \"%s\" in the resource group \"%s\""), nicName, resourceGroupName))); } ; }
else {
index = utils.indexOfCaseIgnore(ipConfig.loadBalancerInboundNatRules, { id: ruleId });
if ((index !== -1)) {
ipConfig.loadBalancerInboundNatRules.splice(index, 1); }
else {
return _(new Error(util.format($("Inbound NAT rule is not attached to NIC \"%s\" in the resource group \"%s\""), nicName, resourceGroupName))); } ; } ;
return self.update(resourceGroupName, nicName, nic, __cb(_, __frame, 70, 15, function ___(__0, __3) { nic = __3;
self._showNic(nic); _(); }, true)); }); }, true)); }); }});
module.exports = Nic;