/*** 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 validation = require("../../../util/validation");
var $ = utils.getLocaleString;
var constants = require("./constants");
var resourceUtils = require("../resource/resourceUtils");
var tagUtils = require("../tag/tagUtils");
var VNetUtil = require("../../../util/vnet.util");

function ExpressRoute(cli, networkManagementClient) {
  this.networkManagementClient = networkManagementClient;
  this.output = cli.output;
  this.interaction = cli.interaction;
  this.vnetUtil = new VNetUtil();};


__.extend(ExpressRoute.prototype, {




  createCircuit: function createCircuit__1(resourceGroupName, circuitName, options, _) { var self, parameters, circuit, progress, __this = this; var __frame = { name: "createCircuit__1", line: 38 }; return __func(_, this, arguments, createCircuit__1, 3, __frame, function __$createCircuit__1() { self = __this;


      parameters = {
        name: circuitName,
        location: options.location,
        sku: { },
        serviceProviderProperties: {
          serviceProviderName: options.serviceProviderName,
          peeringLocation: options.peeringLocation } };



      parameters = self._parseCircuit(parameters, options, true);

      return self.getCircuit(resourceGroupName, circuitName, __cb(_, __frame, 15, 23, function ___(__0, __1) { circuit = __1;
        if (circuit) {
          return _(new Error(util.format($("An express route circuit with name \"%s\" already exists in the resource group \"%s\""), circuitName, resourceGroupName))); } ;


        progress = self.interaction.progress(util.format($("Creating express route circuit \"%s\""), circuitName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$createCircuit__1() {

              return self.networkManagementClient.expressRouteCircuits.createOrUpdate(resourceGroupName, circuitName, parameters, __cb(_, __frame, 22, 66, function ___(__0, __2) { circuit = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$createCircuit__1() {

                progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$createCircuit__1() {

            self._showCircuit(circuit, resourceGroupName, circuitName); _(); }); }); }, true)); }); },


  setCircuit: function setCircuit__2(resourceGroupName, circuitName, options, _) { var self, circuit, progress, __this = this; var __frame = { name: "setCircuit__2", line: 67 }; return __func(_, this, arguments, setCircuit__2, 3, __frame, function __$setCircuit__2() { self = __this;


      return self.getCircuit(resourceGroupName, circuitName, __cb(_, __frame, 3, 23, function ___(__0, __1) { circuit = __1;
        if (!circuit) {
          return _(new Error(util.format($("A express route circuit with name \"%s\" not found in the resource group \"%s\""), circuitName, resourceGroupName))); } ;


        circuit = self._parseCircuit(circuit, options, false);

        progress = self.interaction.progress(util.format($("Updating express route circuit \"%s\""), circuitName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$setCircuit__2() {

              return self.networkManagementClient.expressRouteCircuits.createOrUpdate(resourceGroupName, circuitName, circuit, __cb(_, __frame, 12, 66, function ___(__0, __2) { circuit = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$setCircuit__2() {

                progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$setCircuit__2() {

            self._showCircuit(circuit, resourceGroupName, circuitName); _(); }); }); }, true)); }); },


  listCircuits: function listCircuits__3(options, _) { var self, progress, circuits, __this = this; var __frame = { name: "listCircuits__3", line: 86 }; return __func(_, this, arguments, listCircuits__3, 1, __frame, function __$listCircuits__3() { self = __this;


      progress = self.interaction.progress($("Looking up express route circuits"));
      circuits = null; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$listCircuits__3() { return (function __$listCircuits__3(__then) {


              if (options.resourceGroup) {
                return self.networkManagementClient.expressRouteCircuits.list(options.resourceGroup, __cb(_, __frame, 8, 69, function ___(__0, __1) { circuits = __1; __then(); }, true)); } else {

                return self.networkManagementClient.expressRouteCircuits.listAll(__cb(_, __frame, 10, 69, function ___(__0, __2) { circuits = __2; __then(); }, true)); } ; })(function __$listCircuits__3() { _(null, null, true); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$listCircuits__3() {


              progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$listCircuits__3() {


          self.interaction.formatOutput(circuits, function(circuits) {
            if ((circuits.length === 0)) {
              self.output.warn($("No express route circuits found")); }
             else {
              self.output.table(circuits, function(row, circuit) {
                row.cell($("Name"), circuit.name);
                row.cell($("Location"), circuit.location);
                var resInfo = resourceUtils.getResourceInformation(circuit.id);
                row.cell($("Resource group"), resInfo.resourceGroup);
                row.cell($("Provisioning state"), circuit.provisioningState);
                row.cell($("Provider name"), circuit.serviceProviderProperties.serviceProviderName);
                row.cell($("Peering location"), circuit.serviceProviderProperties.peeringLocation);
                row.cell($("Bandwidth, Mbps"), circuit.serviceProviderProperties.bandwidthInMbps);
                row.cell($("Circuit state"), circuit.circuitProvisioningState);
                row.cell($("SKU"), circuit.sku.name); }); } ; }); _(); }); }); }); },





  showCircuit: function showCircuit__4(resourceGroupName, circuitName, options, _) { var self, circuit, __this = this; var __frame = { name: "showCircuit__4", line: 122 }; return __func(_, this, arguments, showCircuit__4, 3, __frame, function __$showCircuit__4() { self = __this;


      return self.getCircuit(resourceGroupName, circuitName, __cb(_, __frame, 3, 23, function ___(__0, __1) { circuit = __1;
        self._showCircuit(circuit, resourceGroupName, circuitName); _(); }, true)); }); },


  deleteCircuit: function deleteCircuit__5(resourceGroupName, circuitName, options, _) { var self, circuit, progress, __this = this; var __frame = { name: "deleteCircuit__5", line: 129 }; return __func(_, this, arguments, deleteCircuit__5, 3, __frame, function __$deleteCircuit__5() { self = __this;


      return self.getCircuit(resourceGroupName, circuitName, __cb(_, __frame, 3, 23, function ___(__0, __2) { circuit = __2;
        if (!circuit) {
          return _(new Error(util.format($("An express route circuit with name \"%s\" not found in the resource group \"%s\""), circuitName, resourceGroupName))); } ; return (function __$deleteCircuit__5(_) {


          var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return self.interaction.confirm(util.format($("Delete express route circuit \"%s\"? [y/n] "), circuitName), __cb(_, __frame, 8, 44, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -128, 17, function ___(__0, __3) { return (function __$deleteCircuit__5(__then) { if (__3) { return _(null); } else { __then(); } ; })(function __$deleteCircuit__5() {



            progress = self.interaction.progress(util.format($("Deleting express route circuit \"%s\""), circuitName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$deleteCircuit__5() {

                  return self.networkManagementClient.expressRouteCircuits.deleteMethod(resourceGroupName, circuitName, __cb(_, __frame, 14, 56, function __$deleteCircuit__5() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$deleteCircuit__5() {

                    progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$deleteCircuit__5() { _(); }); }); }); }, true)); }, true)); }); },



  getCircuit: function getCircuit__6(resourceGroupName, circuitName, _) { var self, progress, circuit, __this = this; var __frame = { name: "getCircuit__6", line: 149 }; return __func(_, this, arguments, getCircuit__6, 2, __frame, function __$getCircuit__6() { self = __this;

      progress = self.interaction.progress(util.format($("Looking up the express route circuit \"%s\""), circuitName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$getCircuit__6() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$getCircuit__6() {

                  return self.networkManagementClient.expressRouteCircuits.get(resourceGroupName, circuitName, null, __cb(_, __frame, 4, 70, function ___(__0, __1) { circuit = __1;
                    return _(null, circuit); }, true)); }); })(function ___(e, __result) { __catch(function __$getCircuit__6() { if (e) {

                    if ((e.statusCode === 404)) {
                      return _(null, null); } ;

                    return _(e); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$getCircuit__6() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$getCircuit__6() {

              progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$getCircuit__6() { _(); }); }); }); },






  listProviders: function listProviders__7(options, _) { var self, progress, providers, __this = this; var __frame = { name: "listProviders__7", line: 168 }; return __func(_, this, arguments, listProviders__7, 1, __frame, function __$listProviders__7() { self = __this;


      progress = self.interaction.progress($("Looking up express route service providers"));
      providers = null; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$listProviders__7() {


            return self.networkManagementClient.expressRouteServiceProviders.list(__cb(_, __frame, 7, 76, function ___(__0, __1) { providers = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$listProviders__7() {

              progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$listProviders__7() {


          self.interaction.formatOutput(providers, function(providers) {
            if ((providers.length === 0)) {
              self.output.warn($("No express route service providers found")); }
             else {
              self.output.table(providers, function(row, provider) {
                row.cell($("Name"), provider.name);
                var bandwidths = provider.bandwidthsOffered.map(function(b) {
                  return b.offerName; });

                row.cell($("Bandwidths offered"), bandwidths);
                row.cell($("Peering locations"), provider.peeringLocations.join()); }); } ; }); _(); }); }); }); },








  createPeering: function createPeering__8(resourceGroupName, circuitName, peeringName, options, _) { var self, circuit, peering, progress, createdPeering, __this = this; var __frame = { name: "createPeering__8", line: 199 }; return __func(_, this, arguments, createPeering__8, 4, __frame, function __$createPeering__8() { self = __this;

      return self.getCircuit(resourceGroupName, circuitName, __cb(_, __frame, 2, 23, function ___(__0, __1) { circuit = __1;
        if (!circuit) {
          return _(new Error(util.format($("An express route circuit with name \"%s\" not found in the resource group \"%s\""), circuitName, resourceGroupName))); } ;

        return self.getPeering(resourceGroupName, circuitName, peeringName, options, __cb(_, __frame, 6, 23, function ___(__0, __2) { peering = __2;
          if (peering) {
            return _(new Error(util.format($("An express route circuit peering with name \"%s\" already exists in circuit \"%s\" in the resource group \"%s\""), peeringName, circuitName, resourceGroupName))); } ;



          peering = {
            name: peeringName };

          peering = self._parseCircuitPeering(peering, options, true, circuit.sku.tier);

          progress = self.interaction.progress(util.format($("Creating express route peering \"%s\" in circuit \"%s\""), peeringName, circuitName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$createPeering__8() {


                return self.networkManagementClient.expressRouteCircuitPeerings.createOrUpdate(resourceGroupName, circuitName, peeringName, peering, options, __cb(_, __frame, 20, 80, function ___(__0, __3) { createdPeering = __3; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$createPeering__8() {


                  progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$createPeering__8() {

              self._showPeering(createdPeering); _(); }); }); }, true)); }, true)); }); },


  getPeering: function getPeering__9(resourceGroupName, circuitName, peeringName, options, _) { var self, progress, peering, __this = this; var __frame = { name: "getPeering__9", line: 227 }; return __func(_, this, arguments, getPeering__9, 4, __frame, function __$getPeering__9() { self = __this;

      progress = self.interaction.progress(util.format($("Looking up the express route circuit \"%s\" peering \"%s\""), circuitName, peeringName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$getPeering__9() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$getPeering__9() {

                  return self.networkManagementClient.expressRouteCircuitPeerings.get(resourceGroupName, circuitName, peeringName, options, __cb(_, __frame, 4, 77, function ___(__0, __1) { peering = __1;
                    return _(null, peering); }, true)); }); })(function ___(e, __result) { __catch(function __$getPeering__9() { if (e) {

                    if ((e.statusCode === 404)) {
                      return _(null, null); } ;

                    return _(e); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$getPeering__9() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$getPeering__9() {

              progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$getPeering__9() { _(); }); }); }); },



  setPeering: function setPeering__10(resourceGroupName, circuitName, peeringName, options, _) { var self, circuit, peering, progress, updatedPeering, __this = this; var __frame = { name: "setPeering__10", line: 243 }; return __func(_, this, arguments, setPeering__10, 4, __frame, function __$setPeering__10() { self = __this;

      return self.getCircuit(resourceGroupName, circuitName, __cb(_, __frame, 2, 23, function ___(__0, __1) { circuit = __1;
        if (!circuit) {
          return _(new Error(util.format($("An express route circuit with name \"%s\" not found in the resource group \"%s\""), circuitName, resourceGroupName))); } ;

        return self.getPeering(resourceGroupName, circuitName, peeringName, options, __cb(_, __frame, 6, 23, function ___(__0, __2) { peering = __2;
          if (!peering) {
            self.output.warn(util.format($("An express route circuit peering with name \"%s\" not found in circuit \"%s\" in the resource group \"%s\""), peeringName, circuitName, resourceGroupName)); } ;

          peering = self._parseCircuitPeering(peering, options, false);
          delete peering.state;
          progress = self.interaction.progress(util.format($("Setting express route peering \"%s\" in circuit \"%s\""), peeringName, circuitName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$setPeering__10() {


                return self.networkManagementClient.expressRouteCircuitPeerings.createOrUpdate(resourceGroupName, circuitName, peeringName, peering, options, __cb(_, __frame, 15, 80, function ___(__0, __3) { updatedPeering = __3; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$setPeering__10() {

                  progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$setPeering__10() {

              self._showPeering(updatedPeering); _(); }); }); }, true)); }, true)); }); },


  showPeering: function showPeering__11(resourceGroupName, circuitName, peeringName, options, _) { var self, peering, __this = this; var __frame = { name: "showPeering__11", line: 265 }; return __func(_, this, arguments, showPeering__11, 4, __frame, function __$showPeering__11() { self = __this;

      return self.getPeering(resourceGroupName, circuitName, peeringName, options, __cb(_, __frame, 2, 23, function ___(__0, __1) { peering = __1;
        if (!peering) {
          self.output.warn(util.format($("An express route circuit peering with name \"%s\" not found in the circuit \"%s\" in resource group \"%s\""), peeringName, circuitName, resourceGroupName)); return _(null); } ;


        self._showPeering(peering); _(); }, true)); }); },


  listPeering: function listPeering__12(resourceGroupName, circuitName, options, _) { var self, progress, peerings, circuit, __this = this; var __frame = { name: "listPeering__12", line: 275 }; return __func(_, this, arguments, listPeering__12, 3, __frame, function __$listPeering__12() { self = __this;

      progress = self.interaction.progress($("Getting the express route circuit peerings")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$listPeering__12() {



            return self.getCircuit(resourceGroupName, circuitName, __cb(_, __frame, 6, 25, function ___(__0, __1) { circuit = __1;
              if (!circuit) {
                return _(new Error(util.format($("An express route circuit with name \"%s\" not found in the resource group \"%s\""), circuitName, resourceGroupName))); } ;

              peerings = circuit.peerings; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$listPeering__12() {

              progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$listPeering__12() {


          self.interaction.formatOutput(peerings, function(peerings) {
            if ((!peerings || (peerings.length === 0))) {
              self.output.warn($("No express route peerings found")); }
             else {
              self.output.table(peerings, function(row, peering) {
                row.cell($("Name"), peering.name);
                row.cell($("Provisioning State"), peering.provisioningState);
                row.cell($("Peering Type"), peering.peeringType);
                row.cell($("State"), peering.state);
                row.cell($("Vlan Id"), peering.vlanId); }); } ; }); _(); }); }); }); },





  deletePeering: function deletePeering__13(resourceGroupName, circuitName, peeringName, options, _) { var self, peering, progress, __this = this; var __frame = { name: "deletePeering__13", line: 305 }; return __func(_, this, arguments, deletePeering__13, 4, __frame, function __$deletePeering__13() { self = __this;


      return self.getPeering(resourceGroupName, circuitName, peeringName, options, __cb(_, __frame, 3, 23, function ___(__0, __2) { peering = __2;
        if (!peering) {
          self.output.warn(util.format($("An express route circuit peering with name \"%s\" not found in the circuit \"%s\" in resource group \"%s\""), peeringName, circuitName, resourceGroupName)); return _(null); } ; return (function __$deletePeering__13(_) {



          var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return self.interaction.confirm(util.format($("Delete express route circuit peering \"%s\" from circuit \"%s\"? [y/n] "), peeringName, circuitName), __cb(_, __frame, 9, 44, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -304, 17, function ___(__0, __3) { return (function __$deletePeering__13(__then) { if (__3) { return _(null); } else { __then(); } ; })(function __$deletePeering__13() {



            progress = self.interaction.progress(util.format($("Deleting express route circuit peering \"%s\""), peeringName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$deletePeering__13() {

                  return self.networkManagementClient.expressRouteCircuitPeerings.deleteMethod(resourceGroupName, circuitName, peeringName, __cb(_, __frame, 15, 63, function __$deletePeering__13() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$deletePeering__13() {

                    progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$deletePeering__13() { _(); }); }); }); }, true)); }, true)); }); },






  createAuthorization: function createAuthorization__14(resourceGroupName, circuitName, authName, options, _) { var self, circuit, circuitAuth, progress, circuitAuthorization, __this = this; var __frame = { name: "createAuthorization__14", line: 329 }; return __func(_, this, arguments, createAuthorization__14, 4, __frame, function __$createAuthorization__14() { self = __this;


      return self.getCircuit(resourceGroupName, circuitName, __cb(_, __frame, 3, 23, function ___(__0, __1) { circuit = __1;
        if (!circuit) {
          return _(new Error(util.format($("An express route circuit with name \"%s\" not found in the resource group \"%s\""), circuitName, resourceGroupName))); } ;


        return self.getAuthorization(resourceGroupName, circuitName, authName, __cb(_, __frame, 8, 27, function ___(__0, __2) { circuitAuth = __2;
          if (circuitAuth) {
            return _(new Error(util.format($("An express route circuit authorization with name \"%s\" already exists in circuit \"%s\" in the resource group \"%s\""), authName, circuitName, resourceGroupName))); } ;


          circuitAuth = {
            name: authName };

          if (options.key) {
            circuitAuth.authorizationKey = options.key.toString("base64"); } ;


          progress = self.interaction.progress(util.format($("Creating express route circuit authorization \"%s\" in circuit \"%s\""), authName, circuitName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$createAuthorization__14() {


                return self.networkManagementClient.expressRouteCircuitAuthorizations.createOrUpdate(resourceGroupName, circuitName, authName, circuitAuth, __cb(_, __frame, 23, 92, function ___(__0, __3) { circuitAuthorization = __3; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$createAuthorization__14() {

                  progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$createAuthorization__14() {

              self._showCircuitAuthorization(circuitAuthorization, resourceGroupName, circuitName); _(); }); }); }, true)); }, true)); }); },


  setAuthorization: function setAuthorization__15(resourceGroupName, circuitName, authName, options, _) { var self, circuit, circuitAuth, progress, circuitAuthorization, __this = this; var __frame = { name: "setAuthorization__15", line: 359 }; return __func(_, this, arguments, setAuthorization__15, 4, __frame, function __$setAuthorization__15() { self = __this;


      return self.getCircuit(resourceGroupName, circuitName, __cb(_, __frame, 3, 23, function ___(__0, __1) { circuit = __1;
        if (!circuit) {
          return _(new Error(util.format($("An express route circuit with name \"%s\" not found in the resource group \"%s\""), circuitName, resourceGroupName))); } ;


        return self.getAuthorization(resourceGroupName, circuitName, authName, __cb(_, __frame, 8, 27, function ___(__0, __2) { circuitAuth = __2;
          if (!circuitAuth) {
            return _(new Error(util.format($("An express route circuit authorization with name \"%s\" not found in circuit \"%s\" in the resource group \"%s\""), authName, circuitName, resourceGroupName))); } ;


          if (options.key) {
            circuitAuth.authorizationKey = options.key.toString("base64"); } ;


          progress = self.interaction.progress(util.format($("Setting express route circuit authorization \"%s\"in circuit \"%s\""), authName, circuitName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$setAuthorization__15() {


                return self.networkManagementClient.expressRouteCircuitAuthorizations.createOrUpdate(resourceGroupName, circuitName, authName, circuitAuth, __cb(_, __frame, 20, 92, function ___(__0, __3) { circuitAuthorization = __3; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$setAuthorization__15() {

                  progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$setAuthorization__15() {


              self._showCircuitAuthorization(circuitAuthorization, resourceGroupName, circuitName); _(); }); }); }, true)); }, true)); }); },


  showAuthorization: function showAuthorization__16(resourceGroupName, circuitName, authName, options, _) { var self, circuit, circuitAuth, __this = this; var __frame = { name: "showAuthorization__16", line: 387 }; return __func(_, this, arguments, showAuthorization__16, 4, __frame, function __$showAuthorization__16() { self = __this;


      return self.getCircuit(resourceGroupName, circuitName, __cb(_, __frame, 3, 23, function ___(__0, __1) { circuit = __1;
        if (!circuit) {
          return _(new Error(util.format($("An express route circuit with name \"%s\" not found in the resource group \"%s\""), circuitName, resourceGroupName))); } ;


        return self.getAuthorization(resourceGroupName, circuitName, authName, __cb(_, __frame, 8, 27, function ___(__0, __2) { circuitAuth = __2;
          self._showCircuitAuthorization(circuitAuth, resourceGroupName, circuitName); _(); }, true)); }, true)); }); },


  deleteAuthorization: function deleteAuthorization__17(resourceGroupName, circuitName, authName, options, _) { var self, circuit, circuitAuth, progress, __this = this; var __frame = { name: "deleteAuthorization__17", line: 399 }; return __func(_, this, arguments, deleteAuthorization__17, 4, __frame, function __$deleteAuthorization__17() { self = __this;

      return self.getCircuit(resourceGroupName, circuitName, __cb(_, __frame, 2, 23, function ___(__0, __2) { circuit = __2;
        if (!circuit) {
          return _(new Error(util.format($("An express route circuit with name \"%s\" not found in the resource group \"%s\""), circuitName, resourceGroupName))); } ;

        return self.getAuthorization(resourceGroupName, circuitName, authName, __cb(_, __frame, 6, 27, function ___(__0, __3) { circuitAuth = __3;
          if (!circuitAuth) {
            return _(new Error(util.format($("An express route circuit authorization with name \"%s\" not found in the circuit \"%s\" in resource group \"%s\""), authName, circuitName, resourceGroupName))); } ; return (function __$deleteAuthorization__17(_) {


            var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return self.interaction.confirm(util.format($("Delete express route circuit authorization \"%s\" in circuit \"%s\"? [y/n] "), authName, circuitName), __cb(_, __frame, 11, 44, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -398, 17, function ___(__0, __4) { return (function __$deleteAuthorization__17(__then) { if (__4) { return _(null); } else { __then(); } ; })(function __$deleteAuthorization__17() {



              progress = self.interaction.progress(util.format($("Deleting express route circuit authorization \"%s\" in circuit \"%s\""), authName, circuitName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$deleteAuthorization__17() {

                    return self.networkManagementClient.expressRouteCircuitAuthorizations.deleteMethod(resourceGroupName, circuitName, authName, null, __cb(_, __frame, 17, 69, function __$deleteAuthorization__17() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$deleteAuthorization__17() {

                      progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$deleteAuthorization__17() { _(); }); }); }); }, true)); }, true)); }, true)); }); },



  listAuthorization: function listAuthorization__18(resourceGroupName, circuitName, options, _) { var self, circuit, progress, circuits, __this = this; var __frame = { name: "listAuthorization__18", line: 422 }; return __func(_, this, arguments, listAuthorization__18, 3, __frame, function __$listAuthorization__18() { self = __this;

      return self.getCircuit(resourceGroupName, circuitName, __cb(_, __frame, 2, 23, function ___(__0, __1) { circuit = __1;
        if (!circuit) {
          return _(new Error(util.format($("An express route circuit with name \"%s\" not found in the resource group \"%s\""), circuitName, resourceGroupName))); } ;


        progress = self.interaction.progress($("Getting the express route circuit authorizations"));
        circuits = null; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$listAuthorization__18() {

              return self.networkManagementClient.expressRouteCircuitAuthorizations.list(resourceGroupName, circuitName, __cb(_, __frame, 10, 80, function ___(__0, __2) { circuits = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$listAuthorization__18() {

                progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$listAuthorization__18() {

            self.interaction.formatOutput(circuits, function(circuits) {
              if ((circuits.length === 0)) {
                self.output.warn($("No express route circuit authorizations found")); }
               else {
                self.output.table(circuits, function(row, circuitAuth) {
                  row.cell($("Name"), circuitAuth.name);
                  row.cell($("Use status"), circuitAuth.authorizationUseStatus);
                  row.cell($("Provisioning state"), circuitAuth.provisioningState); }); } ; }); _(); }); }); }, true)); }); },





  getAuthorization: function getAuthorization__19(resourceGroupName, circuitName, authName, _) { var self, progress, circuit, __this = this; var __frame = { name: "getAuthorization__19", line: 449 }; return __func(_, this, arguments, getAuthorization__19, 3, __frame, function __$getAuthorization__19() { self = __this;

      progress = self.interaction.progress(util.format($("Looking up the express route circuit authorization \"%s\" in circuit \"%s\""), authName, circuitName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$getAuthorization__19() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$getAuthorization__19() {

                  return self.networkManagementClient.expressRouteCircuitAuthorizations.get(resourceGroupName, circuitName, authName, null, __cb(_, __frame, 4, 83, function ___(__0, __1) { circuit = __1;
                    return _(null, circuit); }, true)); }); })(function ___(e, __result) { __catch(function __$getAuthorization__19() { if (e) {

                    if ((e.statusCode === 404)) {
                      return _(null, null); } ;

                    return _(e); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$getAuthorization__19() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$getAuthorization__19() {

              progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$getAuthorization__19() { _(); }); }); }); },






  _parseCircuit: function(circuit, options, useDefaults) {
    var self = this;

    if (options.bandwidthInMbps) {
      circuit.serviceProviderProperties.bandwidthInMbps = validation.isInt(options.bandwidthInMbps, { }, "--bandwidth-in-mbps"); }
     else if (useDefaults) {
      circuit.serviceProviderProperties.bandwidthInMbps = utils.takeDefault(self.output, constants.expressRoute.defBandwidthInMbps, "--bandwidth-in-mbps"); }  ;


    if (options.skuTier) {
      circuit.sku.tier = validation.isIn(options.skuTier, constants.expressRoute.tier, "--sku-tier"); }
     else if (useDefaults) {
      circuit.sku.tier = utils.takeDefault(self.output, constants.expressRoute.tier[0], "--sku-tier"); }  ;


    if (options.skuFamily) {
      circuit.sku.family = validation.isIn(options.skuFamily, constants.expressRoute.family, "--sku-family"); }
     else if (useDefaults) {
      circuit.sku.family = utils.takeDefault(self.output, constants.expressRoute.family[0], "--sku-family"); }  ;


    if ((circuit.sku.tier && circuit.sku.family)) {
      circuit.sku.name = ((circuit.sku.tier + "_") + circuit.sku.family); } ;


    if (options.tags) {
      if (utils.argHasValue(options.tags)) {
        tagUtils.appendTags(circuit, options); }
       else {
        circuit.tags = { }; } ; } ;



    return circuit; },


  _showCircuit: function(circuit, resourceGroupName, circuitName) {
    var self = this;

    self.interaction.formatOutput(circuit, function(circuit) {
      if ((circuit === null)) {
        self.output.warn(util.format($("An express route circuit with name \"%s\" not found in the resource group \"%s\""), circuitName, resourceGroupName));
        return; } ;


      self.output.nameValue($("Id"), circuit.id);
      self.output.nameValue($("Name"), circuit.name);
      self.output.nameValue($("Type"), circuit.type);
      self.output.nameValue($("Location"), circuit.location);
      self.output.nameValue($("Provisioning state"), circuit.provisioningState);
      self.output.nameValue($("Tags"), tagUtils.getTagsInfo(circuit.tags));
      self.output.nameValue($("Circuit provisioning state"), circuit.circuitProvisioningState);
      self.output.nameValue($("Service Key"), circuit.serviceKey);

      self.output.header($("Service provider"));
      self.output.nameValue($("Name"), circuit.serviceProviderProperties.serviceProviderName, 2);
      self.output.nameValue($("Provisioning state"), circuit.serviceProviderProvisioningState, 2);
      self.output.nameValue($("Peering location"), circuit.serviceProviderProperties.peeringLocation, 2);
      self.output.nameValue($("Bandwidth in Mbps"), circuit.serviceProviderProperties.bandwidthInMbps, 2);

      self.output.header($("SKU"));
      self.output.nameValue($("Name"), circuit.sku.name, 2);
      self.output.nameValue($("Tier"), circuit.sku.tier, 2);
      self.output.nameValue($("Family"), circuit.sku.family, 2); }); },



  _parseCircuitPeering: function(peering, options, useDefaults, skuTier) {
    var self = this;
    peering.properties = { };
    if (options.type) {
      peering.peeringType = utils.verifyParamExistsInCollection(constants.expressRoute.peering.type, options.type, "--type");
      if (((peering.peeringType === constants.expressRoute.peering.premiumType) && (skuTier !== constants.expressRoute.tier[1]))) {
        self.output.warn(util.format($("Express route circuit sku tier must be \"%s\" to add \"%s\""), (constants.expressRoute.tier[1] && constants.expressRoute.peering.premiumType))); } ; }


     else {
      if (useDefaults) {
        peering.peeringType = constants.expressRoute.peering.type[0];
        self.output.warn(util.format($("Using default peering type: %s"), peering.peeringType)); } ; } ;



    if (options.azureAsn) {
      peering.azureASN = parseInt(options.azureAsn); } ;


    if (options.peerAsn) {
      peering.peerASN = parseInt(options.peerAsn); } ;


    if (options.primaryAddressPrefix) {
      self._validateAddressPrefix(options.primaryAddressPrefix);
      peering.primaryPeerAddressPrefix = options.primaryAddressPrefix; } ;


    if (options.secondaryAddressPrefix) {
      self._validateAddressPrefix(options.secondaryAddressPrefix);
      peering.secondaryPeerAddressPrefix = options.secondaryAddressPrefix; } ;


    if (options.primaryAzurePort) {
      peering.primaryAzurePort = options.primaryAzurePort; } ;


    if (options.secondaryPeerAddressPrefix) {
      peering.secondaryPeerAddressPrefix = options.secondaryPeerAddressPrefix; } ;


    if (options.sharedKey) {
      peering.sharedKey = options.sharedKey; } ;


    if (options.vlanId) {
      peering.vlanId = parseInt(options.vlanId); } ;


    if ((peering.peeringType.toLowerCase() !== "microsoftpeering")) {
      return peering; } ;


    if (useDefaults) {
      peering.microsoftPeeringConfig = { }; } ;


    if (options.msAdvertisedPublicPrefixes) {
      var addressPrefixes = options.msAdvertisedPublicPrefixes.split(",");

      peering.microsoftPeeringConfig.advertisedPublicPrefixes = [];
      addressPrefixes.forEach(function(prefix) {
        prefix = prefix.trim();
        self._validateAddressPrefix(prefix);
        peering.microsoftPeeringConfig.advertisedPublicPrefixes.push(prefix); }); } ;



    if (options.msAdvertisedPublicPrefixState) {
      peering.microsoftPeeringConfig.advertisedPublicPrefixesState = utils.verifyParamExistsInCollection(constants.expressRoute.peering.publicPrefixState, options.msAdvertisedPublicPrefixState, "--ms-advertised-public-prefix-state"); }

     else {
      if (useDefaults) {
        peering.microsoftPeeringConfig.advertisedPublicPrefixesState = constants.expressRoute.peering.publicPrefixState[0];
        self.output.warn(util.format($("Using default peering config: %s"), peering.microsoftPeeringConfig.advertisedPublicPrefixesState)); } ; } ;



    if (options.msCustomerAsn) {
      peering.microsoftPeeringConfig.customerASN = parseInt(options.msCustomerAsn); } ;


    if (options.msRoutingRegistryName) {
      peering.microsoftPeeringConfig.routingRegistryName = utils.verifyParamExistsInCollection(constants.expressRoute.peering.registryName, options.msRoutingRegistryName, "--ms-routing-registry-name"); }

     else {
      if (useDefaults) {
        peering.microsoftPeeringConfig.routingRegistryName = constants.expressRoute.peering.registryName[0];
        self.output.warn(util.format($("Using default peering routing registry name: %s"), peering.microsoftPeeringConfig.routingRegistryName)); } ; } ;


    return peering; },


  _validateAddressPrefix: function(addressPrefix) {
    var self = this;

    if (utils.stringIsNullOrEmpty(addressPrefix)) {
      throw new Error($("address prefix parameter must not be null or empty string")); } ;


    var ipValidationResult = self.vnetUtil.parseIPv4Cidr(addressPrefix);
    if (ipValidationResult.error) {
      throw new Error($(ipValidationResult.error)); } ;

    if ((ipValidationResult.cidr === null)) {
      throw new Error($("The --address-prefix must be in cidr format (---.---.---.---/cidr)")); } ; },



  _showPeering: function(peering) {
    var self = this;
    self.interaction.formatOutput(peering, function(peering) {
      if ((peering === null)) {
        self.output.warn(util.format($("An express route circuit peering with name \"%s\" not found in the circuit \"%s\" in resource group \"%s\""), peeringName, circuitName, resourceGroupName)); }
       else {
        var resourceInfo = resourceUtils.getResourceInformation(peering.id);
        self.output.nameValue($("Name"), peering.name);
        self.output.nameValue($("Id"), peering.id);
        self.output.nameValue($("Type"), resourceInfo.resourceType);
        self.output.nameValue($("Etag"), peering.etag);

        var indent = 2;
        self.output.header($("Properties"));
        self.output.nameValue($("Provisioning State"), peering.provisioningState, indent);
        self.output.nameValue($("Peering Type"), peering.peeringType, indent);
        self.output.nameValue($("Peer ASN"), peering.peerASN, indent);
        self.output.nameValue($("Primary Peer Address Prefix"), peering.primaryPeerAddressPrefix, indent);
        self.output.nameValue($("Secondary Peer Address Prefix"), peering.secondaryPeerAddressPrefix, indent);
        self.output.nameValue($("Primary Azure Port"), peering.primaryAzurePort, indent);
        self.output.nameValue($("Secondary Azure Port"), peering.secondaryAzurePort, indent);
        self.output.nameValue($("State"), peering.state, indent);
        self.output.nameValue($("Azure ASN"), peering.azureASN, indent);
        self.output.nameValue($("Shared Key"), peering.sharedKey, indent);
        self.output.nameValue($("Vlan Id"), peering.vlanId, indent);

        if (peering.microsoftPeeringConfig) {
          self.output.header($("Microsoft Peering Config"), indent);
          indent += 2;
          self.output.header($("Advertised Public Prefixes"), indent);
          self.output.list(peering.microsoftPeeringConfig.advertisedPublicPrefixes, (indent + 2));
          self.output.nameValue($("Advertised Public Prefix State"), peering.microsoftPeeringConfig.advertisedPublicPrefixesState, indent);
          self.output.nameValue($("Customer Asn"), peering.microsoftPeeringConfig.customerASN, indent);
          self.output.nameValue($("Routing Registry Name"), peering.microsoftPeeringConfig.routingRegistryName, indent); } ; } ; }); },





  _showCircuitAuthorization: function(circuitAuth, resourceGroupName, circuitName) {
    var self = this;

    self.interaction.formatOutput(circuitAuth, function(circuitAuth) {
      if ((circuitAuth === null)) {
        self.output.warn(util.format($("An express route circuit authorization with name \"%s\" not found in the circuit \"%s\" in resource group \"%s\""), name, circuitName, resourceGroupName));
        return; } ;


      var resourceInfo = resourceUtils.getResourceInformation(circuitAuth.id);
      self.output.nameValue($("Id"), circuitAuth.id);
      self.output.nameValue($("Name"), circuitAuth.name);
      self.output.nameValue($("Type"), resourceInfo.resourceType);
      self.output.nameValue($("Use status"), circuitAuth.authorizationUseStatus);
      self.output.nameValue($("Authorization Key"), circuitAuth.authorizationKey);
      self.output.nameValue($("Provisioning state"), circuitAuth.provisioningState); }); }});




module.exports = ExpressRoute;
