Skip to content

Commit 6f2ec6c

Browse files
authored
Merge pull request #119 from napalm-automation/develop
Release 0.9.0
2 parents 822e73e + 80d1c0d commit 6f2ec6c

35 files changed

+398
-141
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,5 @@ tags
6161
*.swp
6262

6363
.compiled
64+
65+
module_docs/

.travis.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ env:
1010

1111
install:
1212
- pip install pylama
13-
- pip install napalm-base
13+
- pip install napalm
1414
- pip install "ansible>=$ANSIBLE_VERSION.0,<$ANSIBLE_VERSION.99"
15+
- pip install -r requirements-dev.txt
16+
- pip install -e .
1517

1618
script:
1719
- pylama
1820
- cd tests
1921
- ./run_tests.sh
2022
- ./test_changelog.sh
2123
- cd ..
24+
- py.test
2225

2326
deploy:
2427
provider: pypi

CHANGELOG.rst

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
develop
22
=====
33

4+
0.9.0
5+
=====
6+
7+
- Fix old napalm_base references
8+
- Various documentation fixes
9+
- Add action plugin to better support command-line arguments
410

511
0.8.0
612
=====

README.md

+27-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ The following modules are currently available:
1515
- ``napalm_translate_yang``
1616
- ``napalm_validate``
1717

18+
Actions
19+
=======
20+
21+
Actions will only work with Ansible version 2.3 or greater.
22+
They provides default parameters for the hostname, username, password and timeout paramters.
23+
* hostname is set to the first of provider {{ hostname }}, provider {{ host }}, play-context remote_addr.
24+
* username is set to the first of provider {{ username }}, play-context connection_user.
25+
* password is set to the first of provider {{ password }}, play-context password (-k argument).
26+
* timeout is set to the provider {{ timeout }}, or else defaults to 60 seconds (can't be passed via command-line).
27+
1828
Install
1929
=======
2030

@@ -32,20 +42,27 @@ Once you have installed ``napalm-ansible`` run the command ``napalm-ansible`` an
3242
```
3343
$ napalm-ansible
3444
To make sure ansible can make use of the napalm modules you will have
35-
to add the following configurtion to your ansible configureation
45+
to add the following configuration to your ansible configuration
3646
file, i.e. `./ansible.cfg`:
3747
3848
[defaults]
3949
library = /Users/dbarroso/workspace/napalm/napalm-ansible/napalm_ansible
50+
action_plugins = /Users/dbarroso/workspace/napalm/napalm-ansible/action_plugins
4051
4152
For more details on ansible's configuration file visit:
4253
https://docs.ansible.com/ansible/latest/intro_configuration.html
4354
```
4455

56+
Dependencies
57+
=======
58+
* [napalm](https://github.com/napalm-automation/napalm) 2.3.0 or later
59+
* [ansible](https://github.com/ansible/ansible) 2.2.0.0 or later
60+
61+
4562
Examples
4663
=======
4764

48-
Example to retreive facts from a device
65+
Example to retrieve facts from a device
4966
```
5067
- name: get facts from device
5168
napalm_get_facts:
@@ -87,3 +104,11 @@ Example to get compliance report
87104
dev_os: "{{ dev_os }}"
88105
validation_file: validate.yml
89106
```
107+
108+
Example to use default connection paramters:
109+
```
110+
- name: get facts from device
111+
napalm_get_facts:
112+
dev_os: "{{ os }}"
113+
filter: facts,interfaces,bgp_neighbors
114+
```

library

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
napalm_ansible
1+
napalm_ansible/modules

napalm_ansible/__init__.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import os
2+
import ansible
3+
from distutils.version import LooseVersion
24

35
message = """
4-
To make sure ansible can make use of the napalm modules you will have
5-
to add the following configurtion to your ansible configureation
6-
file, i.e. `./ansible.cfg`:
6+
To ensure Ansible can use the NAPALM modules you will have
7+
to add the following configurtion to your Ansible configuration
8+
file (ansible.cfg):
79
810
[defaults]
9-
library = {path}
11+
library = {path}/modules
12+
{action_plugins}
1013
1114
For more details on ansible's configuration file visit:
1215
https://docs.ansible.com/ansible/latest/intro_configuration.html
@@ -15,4 +18,9 @@
1518

1619
def main():
1720
path = os.path.dirname(__file__)
18-
print(message.format(path=path).strip())
21+
if LooseVersion(ansible.__version__) < LooseVersion('2.3.0.0'):
22+
action_plugins = ""
23+
else:
24+
action_plugins = "action_plugins = {path}/plugins/action".format(path=path)
25+
26+
print(message.format(path=path, action_plugins=action_plugins).strip())

napalm_ansible/modules/__init__.py

Whitespace-only changes.

napalm_ansible/napalm_cli.py renamed to napalm_ansible/modules/napalm_cli.py

+37-8
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,50 @@
1212
requirements:
1313
- napalm
1414
options:
15-
args:
15+
hostname:
16+
description:
17+
- IP or FQDN of the device you want to connect to
18+
required: False
19+
username:
20+
description:
21+
- Username
22+
required: False
23+
password:
24+
description:
25+
- Password
26+
required: False
27+
args:
1628
description:
1729
- Keyword arguments to pass to the `cli` method
1830
required: True
31+
dev_os:
32+
description:
33+
- OS of the device
34+
required: False
35+
choices: ['eos', 'junos', 'iosxr', 'fortios', 'ios', 'mock', 'nxos', 'nxos_ssh', 'panos',
36+
'vyos']
37+
provider:
38+
description:
39+
- Dictionary which acts as a collection of arguments used to define the characteristics
40+
of how to connect to the device.
41+
Note - hostname, username, password and dev_os must be defined in either provider
42+
or local param
43+
Note - local param takes precedence, e.g. hostname is preferred to provider['hostname']
44+
required: False
45+
1946
'''
2047

2148
EXAMPLES = '''
22-
vars:
23-
napalm_provider:
49+
- napalm_cli:
2450
hostname: "{{ inventory_hostname }}"
2551
username: "napalm"
2652
password: "napalm"
2753
dev_os: "eos"
54+
args:
55+
commands:
56+
- show version
57+
- show snmp chassis
58+
2859
- napalm_cli:
2960
provider: "{{ napalm_provider }}"
3061
args:
@@ -43,11 +74,10 @@
4374
description: string of command output
4475
returned: always
4576
type: dict
46-
sample:
47-
{
77+
sample: '{
4878
"show snmp chassis": "Chassis: 1234\n",
4979
"show version": "Arista vEOS\nHardware version: \nSerial number: \nSystem MAC address: 0800.27c3.5f28\n\nSoftware image version: 4.17.5M\nArchitecture: i386\nInternal build version: 4.17.5M-4414219.4175M\nInternal build ID: d02143c6-e42b-4fc3-99b6-97063bddb6b8\n\nUptime: 1 hour and 21 minutes\nTotal memory: 1893416 kB\nFree memory: 956488 kB\n\n" # noqa
50-
}
80+
}'
5181
'''
5282

5383
napalm_found = False
@@ -111,8 +141,7 @@ def main():
111141
timeout = module.params['timeout']
112142
args = module.params['args']
113143

114-
argument_check = {'hostname': hostname, 'username': username,
115-
'dev_os': dev_os, 'password': password}
144+
argument_check = {'hostname': hostname, 'username': username, 'dev_os': dev_os}
116145
for key, val in argument_check.items():
117146
if val is None:
118147
module.fail_json(msg=str(key) + " is required")

napalm_ansible/napalm_diff_yang.py renamed to napalm_ansible/modules/napalm_diff_yang.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,20 @@
5454
'''
5555

5656
EXAMPLES = '''
57-
napalm_diff_yang:
58-
first: "{{ candidate.yang_model }}"
59-
second: "{{ running_config.yang_model }}"
60-
models:
61-
- models.openconfig_interfaces
62-
register: diff
57+
- napalm_diff_yang:
58+
first: "{{ candidate.yang_model }}"
59+
second: "{{ running_config.yang_model }}"
60+
models:
61+
- models.openconfig_interfaces
62+
register: diff
6363
'''
6464

6565
RETURN = '''
6666
diff:
6767
description: "Same output as the method napalm_yang.utils.diff"
6868
returned: always
6969
type: dict
70-
sample: {
70+
sample: '{
7171
"interfaces": {
7272
"interface": {
7373
"both": {
@@ -81,7 +81,7 @@
8181
}
8282
}
8383
}
84-
}
84+
}'
8585
'''
8686

8787

napalm_ansible/napalm_get_facts.py renamed to napalm_ansible/modules/napalm_get_facts.py

+25-33
Original file line numberDiff line numberDiff line change
@@ -68,54 +68,47 @@
6868
default: None
6969
ignore_notimplemented:
7070
description:
71-
- Ignores NotImplementedError for filters which aren't supported by the driver. Returns
72-
invalid filters in a list called: not_implemented
71+
- "Ignores NotImplementedError for filters which aren't supported by the driver. Returns
72+
invalid filters in a list called: not_implemented"
7373
required: False
7474
default: False
7575
choices: [True, False]
7676
filter:
7777
description:
78-
- A list of facts to retreive from a device and provided though C(ansible_facts)
78+
- "A list of facts to retreive from a device and provided though C(ansible_facts)
7979
The list of facts available are maintained at:
8080
http://napalm.readthedocs.io/en/latest/support/
81-
Note- not all getters are implemented on all supported device types
81+
Note- not all getters are implemented on all supported device types"
8282
required: False
8383
default: ['facts']
8484
args:
8585
description:
8686
- dictionary of kwargs arguments to pass to the filter. The outer key is the name of
8787
the getter (same as the filter)
88-
requited: False
88+
required: False
8989
default: None
9090
'''
9191

9292
EXAMPLES = '''
93-
94-
vars:
95-
ios_provider:
96-
hostname: "{{ inventory_hostname }}"
97-
username: "napalm"
98-
password: "napalm"
99-
dev_os: "ios"
100-
101-
- name: get facts from device
102-
napalm_get_facts:
103-
hostname={{ inventory_hostname }}
104-
username={{ user }}
105-
dev_os={{ os }}
106-
password={{ passwd }}
107-
filter=['facts']
108-
register: result
109-
110-
- name: print data
111-
debug: var=result
112-
113-
- name: Getters
114-
napalm_get_facts:
115-
provider: "{{ ios_provider }}"
116-
filter:
117-
- "lldp_neighbors_detail"
118-
- "interfaces"
93+
- name: get facts from device
94+
napalm_get_facts:
95+
hostname: '{{ inventory_hostname }}'
96+
username: '{{ user }}'
97+
dev_os: '{{ os }}'
98+
password: '{{ passwd }}'
99+
filter: ['facts']
100+
register: result
101+
102+
- name: print data
103+
debug:
104+
var: result
105+
106+
- name: Getters
107+
napalm_get_facts:
108+
provider: "{{ ios_provider }}"
109+
filter:
110+
- "lldp_neighbors_detail"
111+
- "interfaces"
119112
120113
- name: get facts from device
121114
napalm_get_facts:
@@ -212,8 +205,7 @@ def main():
212205
ignore_notimplemented = module.params['ignore_notimplemented']
213206
implementation_errors = []
214207

215-
argument_check = {'hostname': hostname, 'username': username,
216-
'dev_os': dev_os, 'password': password}
208+
argument_check = {'hostname': hostname, 'username': username, 'dev_os': dev_os}
217209
for key, val in argument_check.items():
218210
if val is None:
219211
module.fail_json(msg=str(key) + " is required")

0 commit comments

Comments
 (0)