|
| 1 | +Command Line Tool |
| 2 | +================= |
| 3 | + |
| 4 | +NAPALM ships with a simple CLI tool to help you deploying configuration to your devices directly from the shell. |
| 5 | +It might be convenient for simple bash scripts or provisioning tools that rely on a shell. |
| 6 | + |
| 7 | +The usage is very simple. For example, let's do a dry run (changes will not be applied) and check the changes between |
| 8 | +my current configuration and a new candidate configuration: |
| 9 | + |
| 10 | +.. code-block:: diff |
| 11 | +
|
| 12 | + # cl_napalm_configure --user vagrant --vendor eos --strategy replace --optional_args 'port=12443' --dry-run new_good.conf localhost |
| 13 | + Enter password: |
| 14 | + @@ -2,30 +2,38 @@ |
| 15 | + ! |
| 16 | + ! boot system flash:/vEOS-lab.swi |
| 17 | + ! |
| 18 | + -event-handler dhclient |
| 19 | + - trigger on-boot |
| 20 | + - action bash sudo /mnt/flash/initialize_ma1.sh |
| 21 | + +transceiver qsfp default-mode 4x10G |
| 22 | + ! |
| 23 | + -transceiver qsfp default-mode 4x10G |
| 24 | + +hostname pyeos-unittest-changed |
| 25 | + ! |
| 26 | + spanning-tree mode mstp |
| 27 | + ! |
| 28 | + aaa authorization exec default local |
| 29 | + ! |
| 30 | + -aaa root secret 5 $1$b4KXboe4$yeTwqHOKscsF07WGoOnZ0. |
| 31 | + +no aaa root |
| 32 | + ! |
| 33 | + -username admin privilege 15 role network-admin secret 5 $1$nT3t1LkI$1f.SG5YaRo6h4LlhIKgTK. |
| 34 | + -username vagrant privilege 15 role network-admin secret 5 $1$589CDTZ0$9S4LGAiCpxHCOC17jECxt1 |
| 35 | + +username admin privilege 15 role network-admin secret 5 $1$RT/92Zg9$J8wD1qPAdQBcOhv4fefyt. |
| 36 | + +username vagrant privilege 15 role network-admin secret 5 $1$Lw2STh4k$bPEDVVTY2e7lf.vNlnNEO0 |
| 37 | + ! |
| 38 | + interface Ethernet1 |
| 39 | + ! |
| 40 | + interface Ethernet2 |
| 41 | + + description ble |
| 42 | + ! |
| 43 | + interface Management1 |
| 44 | + ip address 10.0.2.15/24 |
| 45 | + ! |
| 46 | + no ip routing |
| 47 | + ! |
| 48 | + +router bgp 65000 |
| 49 | + + vrf test |
| 50 | + + neighbor 1.1.1.2 remote-as 1 |
| 51 | + + neighbor 1.1.1.2 maximum-routes 12000 |
| 52 | + + ! |
| 53 | + + vrf test2 |
| 54 | + + neighbor 2.2.2.3 remote-as 2 |
| 55 | + + neighbor 2.2.2.3 maximum-routes 12000 |
| 56 | + +! |
| 57 | + management api http-commands |
| 58 | + no shutdown |
| 59 | + ! |
| 60 | + # |
| 61 | +
|
| 62 | +We got the diff back. Now let's try a partial configuration instead. However, this time we will directly apply the |
| 63 | +configuration and we will also be passing the password directly as an argument: |
| 64 | + |
| 65 | +.. code-block:: diff |
| 66 | +
|
| 67 | + # cl_napalm_configure --user vagrant --password vagrant --vendor eos --strategy merge --optional_args 'port=12443' merge_good.conf localhost |
| 68 | + @@ -7,6 +7,8 @@ |
| 69 | + action bash sudo /mnt/flash/initialize_ma1.sh |
| 70 | + ! |
| 71 | + transceiver qsfp default-mode 4x10G |
| 72 | + +! |
| 73 | + +hostname NEWHOSTNAME |
| 74 | + ! |
| 75 | + spanning-tree mode mstp |
| 76 | + ! |
| 77 | + @@ -20,6 +22,7 @@ |
| 78 | + interface Ethernet1 |
| 79 | + ! |
| 80 | + interface Ethernet2 |
| 81 | + + description BLALALAL |
| 82 | + ! |
| 83 | + interface Management1 |
| 84 | + ip address 10.0.2.15/24 |
| 85 | + # |
| 86 | +
|
| 87 | +We got the diff back in the stdout. If we try to run the command we should get an empty string: |
| 88 | + |
| 89 | +.. code-block:: diff |
| 90 | +
|
| 91 | + # cl_napalm_configure --user vagrant --password vagrant --vendor eos --strategy merge --optional_args 'port=12443' merge_good.conf localhost |
| 92 | + # |
| 93 | +
|
| 94 | +Errors are detected as well:: |
| 95 | + |
| 96 | + # cl_napalm_configure --user vagrant --password vagrant --vendor eos --strategy merge --optional_args 'port=12443' merge_typo.conf localhost |
| 97 | + Traceback (most recent call last): |
| 98 | + File "/Users/dbarroso/.virtualenvs/test/bin/cl_napalm_configure", line 9, in <module> |
| 99 | + load_entry_point('napalm==0.50.3', 'console_scripts', 'cl_napalm_configure')() |
| 100 | + File "/Users/dbarroso/.virtualenvs/test/lib/python2.7/site-packages/napalm-0.50.3-py2.7.egg/napalm/clitools/cl_napalm_configure.py", line 139, in main |
| 101 | + args.optional_args, args.config_file, args.dry_run)) |
| 102 | + File "/Users/dbarroso/.virtualenvs/test/lib/python2.7/site-packages/napalm-0.50.3-py2.7.egg/napalm/clitools/cl_napalm_configure.py", line 131, in run |
| 103 | + return diff |
| 104 | + File "/Users/dbarroso/.virtualenvs/test/lib/python2.7/site-packages/napalm-0.50.3-py2.7.egg/napalm/base.py", line 46, in __exit__ |
| 105 | + self.__raise_clean_exception(exc_type, exc_value, exc_traceback) |
| 106 | + File "/Users/dbarroso/.virtualenvs/test/lib/python2.7/site-packages/napalm-0.50.3-py2.7.egg/napalm/clitools/cl_napalm_configure.py", line 119, in run |
| 107 | + strategy_method(filename=config_file) |
| 108 | + File "/Users/dbarroso/.virtualenvs/test/lib/python2.7/site-packages/napalm-0.50.3-py2.7.egg/napalm/eos.py", line 95, in load_merge_candidate |
| 109 | + self._load_config(filename, config, False) |
| 110 | + File "/Users/dbarroso/.virtualenvs/test/lib/python2.7/site-packages/napalm-0.50.3-py2.7.egg/napalm/eos.py", line 89, in _load_config |
| 111 | + raise MergeConfigException(e.message) |
| 112 | + napalm.exceptions.MergeConfigException: Error [1002]: CLI command 5 of 5 'descriptin BLALALAL' failed: invalid command |
| 113 | + |
| 114 | +For more information, run ``cl_napalm_configure --help``. |
0 commit comments