Skip to content

Commit b53d039

Browse files
committed
Merge pull request #169 from dbarrosop/master
Added documentation for releasing 0.51
2 parents 2a6b268 + 8ccae3d commit b53d039

File tree

11 files changed

+189
-45
lines changed

11 files changed

+189
-45
lines changed

docs/cli.rst

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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``.

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
# General information about the project.
5050
project = u'NAPALM'
51-
copyright = u'2015, David Barroso'
51+
copyright = u'2016, David Barroso'
5252

5353
# The version info for the project you're documenting, acts as replacement for
5454
# |version| and |release|, also used in various other places throughout the

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ Documentation
4040

4141
tutorials/index
4242
support/index
43+
cli
4344
base

docs/support/ibm.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
IBM Networking Operating System
2-
-------
2+
-------------------------------
33

44
Rollback
55
~~~~~~~~

docs/support/index.rst

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ General support matrix
99
_ EOS JunOS IOS-XR FortiOS IBM NXOS IOS
1010
===================== ========== ============= =========== ============== ============= ============ ============
1111
**Driver Name** eos junos iosxr fortios ibm nxos ios
12-
**Structured data** Yes Yes No No Yes Yes No
13-
**Minimum version** 4.15.0F 12.1 5.1.0 5.2.0 ??? 6.1 ???
12+
**Structured data** Yes Yes No No Yes Yes No
13+
**Minimum version** 4.15.0F 12.1 5.1.0 5.2.0 ??? 6.1 ???
1414
**Backend library** `pyeapi`_ `junos-eznc`_ `pyIOSXR`_ `pyFG`_ `bnclient`_ `pycsco`_ `netmiko`_
1515
**Caveats** :doc:`eos` :doc:`fortios` :doc:`ibm` :doc:`nxos` :doc:`ios`
1616
===================== ========== ============= =========== ============== ============= ============ ============
@@ -33,10 +33,10 @@ Configuration support matrix
3333
===================== ========== ===== ========== ============== ============= ============== ==============
3434
_ EOS JunOS IOS-XR FortiOS IBM NXOS IOS
3535
===================== ========== ===== ========== ============== ============= ============== ==============
36-
**Config. replace** Yes Yes Yes Yes Yes [#c3]_ Yes No
36+
**Config. replace** Yes Yes Yes Yes Yes [#c3]_ Yes Yes
3737
**Config. merge** Yes Yes Yes Yes Yes Yes Yes
3838
**Compare config** Yes Yes Yes [#c1]_ Yes [#c1]_ Yes [#c1]_ Yes [#c4]_ Yes
39-
**Atomic Changes** Yes Yes Yes No [#c2]_ No [#c2]_ Yes/No [#c5]_ No [#c2]_
39+
**Atomic Changes** Yes Yes Yes No [#c2]_ No [#c2]_ Yes/No [#c5]_ Yes
4040
**Rollback** Yes [#c2]_ Yes Yes Yes Yes [#c2]_ Yes/No [#c5]_ Yes
4141
===================== ========== ===== ========== ============== ============= ============== ==============
4242

@@ -56,16 +56,16 @@ Getters support matrix
5656
.. |yes| unicode:: U+02705 .. Yes
5757
.. |no| unicode:: U+0274C .. No
5858

59-
========================== ===== ===== ====== ======= ====== ====== ======
60-
_ EOS JunOS IOS-XR FortiOS IBM NXOS IOS
61-
========================== ===== ===== ====== ======= ====== ====== ======
62-
**get_facts** |yes| |yes| |yes| |yes| |no| |yes| |yes|
63-
**get_interfaces** |yes| |yes| |yes| |yes| |no| |yes| |yes|
64-
**get_lldp_neighbors** |yes| |yes| |yes| |yes| |no| |no| |yes|
65-
**get_bgp_neighbors** |yes| |yes| |yes| |yes| |no| |no| |yes|
66-
**get_environment** |yes| |yes| |yes| |yes| |no| |no| |no|
67-
**get_interface_counters** |yes| |yes| |yes| |yes| |no| |no| |no|
68-
========================== ===== ===== ====== ======= ====== ====== ======
59+
=========================== ===== ===== ====== ======= ====== ====== =====
60+
_ EOS JunOS IOS-XR FortiOS IBM NXOS IOS
61+
=========================== ===== ===== ====== ======= ====== ====== =====
62+
**get_facts** |yes| |yes| |yes| |yes| |no| |yes| |yes|
63+
**get_interfaces** |yes| |yes| |yes| |yes| |no| |yes| |yes|
64+
**get_lldp_neighbors** |yes| |yes| |yes| |yes| |no| |no| |yes|
65+
**get_bgp_neighbors** |yes| |yes| |yes| |yes| |no| |no| |yes|
66+
**get_environment** |yes| |yes| |yes| |yes| |no| |no| |yes|
67+
**get_interfaces_counters** |yes| |yes| |yes| |yes| |no| |no| |yes|
68+
=========================== ===== ===== ====== ======= ====== ====== =====
6969

7070
Caveats
7171
-------
@@ -95,7 +95,7 @@ List of supported optional arguments
9595
____________________________________
9696

9797
* :code:`fortios_vdom` (fortios) - VDOM to connect to.
98-
* :code:`port` (eos, iosxr, junos) - Allows you to specify a port other than the default.
98+
* :code:`port` (eos, iosxr, junos, ios) - Allows you to specify a port other than the default.
9999

100100
Adding optional arguments to NAPALM drivers
101101
___________________________________________

docs/support/nxos.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ _____________
1717

1818
Your device must be running NXOS 6.1. The features ``nxapi`` server ``scp-server`` must be enabled.
1919
On the device and any checkpoint file you push, you must have the lines::
20+
2021
feature scp-server
2122
feature nxapi
2223

@@ -31,7 +32,7 @@ function in the ``napalm.nxos`` driver.
3132
Known gotchas
3233
_____________
3334

34-
- Leaving out a ``shutdown`` or ``no shutdown`` line will cause the switch to toggle the up/down state of an interface, depending on it's current state.
35+
- Leaving out a ``shutdown`` or ``no shutdown`` line will cause the switch to toggle the up/down state of an interface, depending on it's current state.
3536

3637
- ``!#switchport trunk allowed vlan 1-4094`` is required even if the switchport is in ``switchport mode access``. However if ``!#switchport trunk allowed vlan 1-4094`` is included with ``no switchport``, the configuration replacement will fail.
3738

docs/tutorials/context_manager.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Context Manager
2+
===============
3+
4+
In the previous tutorial we used the methods ``open()`` to connect to the device and ``close()`` to disconnect.
5+
Using those methods are useful if you want to do complex or asynchronous code. However, for most situations you should
6+
try to stick with the context manager. It handles opening and closing the session automatically and it's the
7+
pythonic way:
8+
9+
.. code-block:: python
10+
11+
>>> from napalm import get_network_driver
12+
>>> driver = get_network_driver('eos')
13+
>>> with driver('localhost', 'vagrant', 'vagrant', optional_args={'port': 12443}) as device:
14+
... print device.get_facts()
15+
... print device.get_interfaces_counters()
16+
...
17+
{'os_version': u'4.15.2.1F-2759627.41521F', 'uptime': 2010, 'interface_list': [u'Ethernet1', u'Ethernet2', u'Management1'], 'vendor': u'Arista', 'serial_number': u'', 'model': u'vEOS', 'hostname': u'NEWHOSTNAME', 'fqdn': u'NEWHOSTNAME'}
18+
{u'Ethernet2': {'tx_multicast_packets': 1028, 'tx_discards': 0, 'tx_octets': 130744, 'tx_errors': 0, 'rx_octets': 0, 'tx_unicast_packets': 0, 'rx_errors': 0, 'tx_broadcast_packets': 0, 'rx_multicast_packets': 0, 'rx_broadcast_packets': 0, 'rx_discards': 0, 'rx_unicast_packets': 0}, u'Management1': {'tx_multicast_packets': 0, 'tx_discards': 0, 'tx_octets': 99664, 'tx_errors': 0, 'rx_octets': 105000, 'tx_unicast_packets': 773, 'rx_errors': 0, 'tx_broadcast_packets': 0, 'rx_multicast_packets': 0, 'rx_broadcast_packets': 0, 'rx_discards': 0, 'rx_unicast_packets': 0}, u'Ethernet1': {'tx_multicast_packets': 1027, 'tx_discards': 0, 'tx_octets': 130077, 'tx_errors': 0, 'rx_octets': 0, 'tx_unicast_packets': 0, 'rx_errors': 0, 'tx_broadcast_packets': 0, 'rx_multicast_packets': 0, 'rx_broadcast_packets': 0, 'rx_discards': 0, 'rx_unicast_packets': 0}}

docs/tutorials/first_steps_config.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Use the appropriate network driver to connect to the device::
1313
>>> device = driver('192.168.76.10', 'dbarroso', 'this_is_not_a_secure_password')
1414
>>> device.open()
1515

16-
Configurations can be replaced entirely or merged into the existing device config.
16+
Configurations can be replaced entirely or merged into the existing device config.
1717
You can load configuration either from a string or from a file.
1818

1919
Replacing the Configuration
@@ -79,3 +79,9 @@ If for some reason you committed the changes and you want to rollback::
7979

8080
>>> device.rollback()
8181

82+
Disconnecting
83+
-------------
84+
85+
To close the session with the device just do::
86+
87+
>>> device.close()

docs/tutorials/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ Tutorials
55
:maxdepth: 1
66

77
first_steps_config
8+
context_manager

napalm/base.py

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -261,48 +261,51 @@ def get_bgp_neighbors(self):
261261
"""
262262
Returns a dictionary of dictionaries. The keys for the first dictionary will be the vrf (global if no vrf).
263263
The inner dictionary will contain the following data for each vrf:
264-
* router_id
265-
* peers - another dictionary of dictionaries. Outer keys are the IPs of the neighbors. The inner keys are:
266-
* local_as (int)
267-
* remote_as (int)
268-
* remote_id - peer router id
269-
* is_up (True/False)
270-
* is_enabled (True/False)
271-
* description (string)
272-
* uptime (int in seconds)
273-
* address_family (dictionary) - A dictionary of address families available for the neighbor. So far it can
274-
be 'ipv4' or 'ipv6'
275-
* received_prefixes (int)
276-
* accepted_prefixes (int)
277-
* sent_prefixes (int)
264+
265+
* router_id
266+
* peers - another dictionary of dictionaries. Outer keys are the IPs of the neighbors. The inner keys are:
267+
* local_as (int)
268+
* remote_as (int)
269+
* remote_id - peer router id
270+
* is_up (True/False)
271+
* is_enabled (True/False)
272+
* description (string)
273+
* uptime (int in seconds)
274+
* address_family (dictionary) - A dictionary of address families available for the neighbor. So far it can\
275+
be 'ipv4' or 'ipv6'
276+
* received_prefixes (int)
277+
* accepted_prefixes (int)
278+
* sent_prefixes (int)
278279
"""
279280
raise NotImplementedError
280281

281282
def get_environment(self):
282283
"""
283284
Returns a dictionary where:
285+
284286
* fans is a dictionary of dictionaries where the key is the location and the values:
285-
* status (boolean) - True if it's ok, false if it's broken
287+
* status (boolean) - True if it's ok, false if it's broken
286288
* temperature is a dictionary of dictionaries where the key is the location and the values:
287-
* temperature (float) - Temperature in celsius the sensor is reporting.
288-
* is_alert (boolean) - True if the temperature is above the alert threshold
289-
* is_critical (boolean) - True if the temperature is above the critical threshold
289+
* temperature (float) - Temperature in celsius the sensor is reporting.
290+
* is_alert (boolean) - True if the temperature is above the alert threshold
291+
* is_critical (boolean) - True if the temperature is above the critical threshold
290292
* power is a dictionary of dictionaries where the key is the PSU id and the values:
291-
* status (boolean) - True if it's ok, false if it's broken
292-
* capacity (float) - Capacity in W that the power supply can support
293-
* output (float) - Watts drawn by the system
293+
* status (boolean) - True if it's ok, false if it's broken
294+
* capacity (float) - Capacity in W that the power supply can support
295+
* output (float) - Watts drawn by the system
294296
* cpu is a dictionary of dictionaries where the key is the ID and the values
295-
* %usage
297+
* %usage
296298
* memory is a dictionary with:
297-
* available_ram (int) - Total amount of RAM installed in the device
298-
* used_ram (int) - RAM in use in the device
299+
* available_ram (int) - Total amount of RAM installed in the device
300+
* used_ram (int) - RAM in use in the device
299301
"""
300302
raise NotImplementedError
301303

302304
def get_interfaces_counters(self):
303305
"""
304306
Returns a dictionary of dictionaries where the first key is an interface name and the inner dictionary contains
305307
the following keys:
308+
306309
* tx_errors (int)
307310
* rx_errors (int)
308311
* tx_discards (int)
@@ -316,7 +319,7 @@ def get_interfaces_counters(self):
316319
* tx_broadcast_packets (int)
317320
* rx_broadcast_packets (int)
318321
319-
Example:
322+
Example::
320323
321324
{
322325
u'Ethernet2': {

0 commit comments

Comments
 (0)