Skip to content

Commit

Permalink
Merge pull request #159 from napalm-automation/develop
Browse files Browse the repository at this point in the history
napalm-ansible release 1.0.0
  • Loading branch information
ktbyers authored Jun 3, 2019
2 parents 2afe705 + 853fd94 commit eebc2a6
Show file tree
Hide file tree
Showing 17 changed files with 114 additions and 79 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ python:
- 3.6

env:
- ANSIBLE_VERSION=2.3
- ANSIBLE_VERSION=2.4
- ANSIBLE_VERSION=2.5
- ANSIBLE_VERSION=2.6
- ANSIBLE_VERSION=2.7
- ANSIBLE_VERSION=2.8

install:
- pip install pylama
- pip install napalm
- pip install -r requirements.txt
- pip install "ansible>=$ANSIBLE_VERSION.0,<$ANSIBLE_VERSION.99"
- pip install -r requirements-dev.txt
- pip install -e .
Expand Down
10 changes: 9 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
develop
1.0.0
=====

- Add support for ansible_network_os
- Fix minor documentation errors
- Expand filenames for `*_file` parameters
- Fix Ansible 2.8 backwards incompatible changes
- Removing support of legacy napalm_base
- Changing napalm_cli to cli_results; napalm_ping to ping_results
- Use yaml safe_load for tests

0.10.0
=====

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Example to get compliance report
validation_file: validate.yml
```

Example to use default connection paramters:
Example to use default connection parameters:
```
- name: get facts from device
napalm_get_facts:
Expand Down
22 changes: 11 additions & 11 deletions napalm_ansible/modules/napalm_cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
from __future__ import unicode_literals, print_function
from ansible.module_utils.basic import AnsibleModule, return_values
from ansible.module_utils.basic import AnsibleModule


# FIX for Ansible 2.8 moving this function and making it private
# greatly simplified for napalm-ansible's use
def return_values(obj):
""" Return native stringified values from datastructures.
For use with removing sensitive values pre-jsonification."""
yield str(obj)


DOCUMENTATION = '''
Expand Down Expand Up @@ -87,15 +96,6 @@
except ImportError:
pass

# Legacy for pre-reunification napalm (remove in future)
if not napalm_found:
try:
from napalm_base import get_network_driver # noqa
from napalm_base import ModuleImportError # noqa
napalm_found = True
except ImportError:
pass


def main():
module = AnsibleModule(
Expand Down Expand Up @@ -175,7 +175,7 @@ def main():
except Exception as e:
module.fail_json(msg="cannot close device connection: " + str(e))

module.exit_json(changed=False, results=cli_response)
module.exit_json(changed=False, cli_results=cli_response)


if __name__ == '__main__':
Expand Down
24 changes: 12 additions & 12 deletions napalm_ansible/modules/napalm_get_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
This file is part of Ansible
Ansible is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Ansible is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Expand All @@ -17,7 +17,16 @@
along with Ansible. If not, see <http://www.gnu.org/licenses/>.
"""
from __future__ import unicode_literals, print_function
from ansible.module_utils.basic import AnsibleModule, return_values
from ansible.module_utils.basic import AnsibleModule


# FIX for Ansible 2.8 moving this function and making it private
# greatly simplified for napalm-ansible's use
def return_values(obj):
""" Return native stringified values from datastructures.
For use with removing sensitive values pre-jsonification."""
yield str(obj)


DOCUMENTATION = '''
Expand Down Expand Up @@ -145,15 +154,6 @@
except ImportError:
pass

# Legacy for pre-reunification napalm (remove in future)
if not napalm_found:
try:
from napalm_base import get_network_driver # noqa
from napalm_base import ModuleImportError # noqa
napalm_found = True
except ImportError:
pass


def main():
module = AnsibleModule(
Expand Down
29 changes: 19 additions & 10 deletions napalm_ansible/modules/napalm_install_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@
along with Ansible. If not, see <http://www.gnu.org/licenses/>.
"""
from __future__ import unicode_literals, print_function
from ansible.module_utils.basic import AnsibleModule, return_values
import os.path
from ansible.module_utils.basic import AnsibleModule


# FIX for Ansible 2.8 moving this function and making it private
# greatly simplified for napalm-ansible's use
def return_values(obj):
""" Return native stringified values from datastructures.
For use with removing sensitive values pre-jsonification."""
yield str(obj)


DOCUMENTATION = '''
Expand Down Expand Up @@ -165,15 +175,6 @@
except ImportError:
pass

# Legacy for pre-reunification napalm (remove in future)
if not napalm_found:
try:
from napalm_base import get_network_driver # noqa
from napalm_base import ModuleImportError # noqa
napalm_found = True
except ImportError:
pass


def save_to_file(content, filename):
with open(filename, 'w') as f:
Expand Down Expand Up @@ -236,6 +237,14 @@ def main():
get_diffs = module.params['get_diffs']
archive_file = module.params['archive_file']
candidate_file = module.params['candidate_file']
if config_file:
config_file = os.path.expanduser(os.path.expandvars(config_file))
if diff_file:
diff_file = os.path.expanduser(os.path.expandvars(diff_file))
if archive_file:
archive_file = os.path.expanduser(os.path.expandvars(archive_file))
if candidate_file:
candidate_file = os.path.expanduser(os.path.expandvars(candidate_file))

argument_check = {'hostname': hostname, 'username': username, 'dev_os': dev_os}
for key, val in argument_check.items():
Expand Down
20 changes: 10 additions & 10 deletions napalm_ansible/modules/napalm_parse_yang.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
along with Ansible. If not, see <http://www.gnu.org/licenses/>.
"""
from __future__ import unicode_literals, print_function
from ansible.module_utils.basic import AnsibleModule, return_values
from ansible.module_utils.basic import AnsibleModule
import json

napalm_found = False
Expand All @@ -28,21 +28,21 @@
except ImportError:
pass

# Legacy for pre-reunification napalm (remove in future)
if not napalm_found:
try:
from napalm_base import get_network_driver # noqa
from napalm_base import ModuleImportError # noqa
napalm_found = True
except ImportError:
pass

try:
import napalm_yang
except ImportError:
napalm_yang = None


# FIX for Ansible 2.8 moving this function and making it private
# greatly simplified for napalm-ansible's use
def return_values(obj):
""" Return native stringified values from datastructures.
For use with removing sensitive values pre-jsonification."""
yield str(obj)


DOCUMENTATION = '''
---
module: napalm_parse_yang
Expand Down
22 changes: 11 additions & 11 deletions napalm_ansible/modules/napalm_ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@
along with Ansible. If not, see <http://www.gnu.org/licenses/>.
"""
from __future__ import unicode_literals, print_function
from ansible.module_utils.basic import AnsibleModule, return_values
from ansible.module_utils.basic import AnsibleModule


# FIX for Ansible 2.8 moving this function and making it private
# greatly simplified for napalm-ansible's use
def return_values(obj):
""" Return native stringified values from datastructures.
For use with removing sensitive values pre-jsonification."""
yield str(obj)


DOCUMENTATION = '''
Expand Down Expand Up @@ -136,15 +145,6 @@
except ImportError:
pass

# Legacy for pre-reunification napalm (remove in future)
if not napalm_found:
try:
from napalm_base import get_network_driver # noqa
from napalm_base import ModuleImportError # noqa
napalm_found = True
except ImportError:
pass


def main():
module = AnsibleModule(
Expand Down Expand Up @@ -236,7 +236,7 @@ def main():
except Exception as e:
module.fail_json(msg="cannot close device connection: " + str(e))

module.exit_json(changed=False, results=ping_response)
module.exit_json(changed=False, ping_results=ping_response)


if __name__ == '__main__':
Expand Down
20 changes: 10 additions & 10 deletions napalm_ansible/modules/napalm_validate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import unicode_literals, print_function
from ansible.module_utils.basic import AnsibleModule, return_values
from ansible.module_utils.basic import AnsibleModule

napalm_found = False
try:
Expand All @@ -9,21 +9,21 @@
except ImportError:
pass

# Legacy for pre-reunification napalm (remove in future)
if not napalm_found:
try:
from napalm_base import get_network_driver # noqa
from napalm_base import ModuleImportError # noqa
napalm_found = True
except ImportError:
pass

try:
import napalm_yang
except ImportError:
napalm_yang = None


# FIX for Ansible 2.8 moving this function and making it private
# greatly simplified for napalm-ansible's use
def return_values(obj):
""" Return native stringified values from datastructures.
For use with removing sensitive values pre-jsonification."""
yield str(obj)


DOCUMENTATION = '''
---
module: napalm_validate
Expand Down
3 changes: 3 additions & 0 deletions napalm_ansible/plugins/action/napalm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def run(self, tmp=None, task_vars=None):
# Timeout can't be passed via command-line as Ansible defaults to a 10 second timeout
provider['timeout'] = provider.get('timeout', 60)

if hasattr(pc, 'network_os'):
provider['dev_os'] = provider.get('dev_os', pc.network_os)

self._task.args['provider'] = provider

result = super(ActionModule, self).run(tmp, task_vars)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
napalm
six
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name="napalm-ansible",
version='0.10.0',
version='1.0.0',
packages=find_packages(exclude=("test*", "library")),
author="David Barroso, Kirk Byers, Mircea Ulinic",
author_email="[email protected], [email protected]",
Expand Down
4 changes: 2 additions & 2 deletions tests/napalm_cli/multiple_commands.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
register: result
- assert:
that:
- "{{ result.results['show version']|length > 10 }}"
- "{{ result.results['show interfaces']|length > 10 }}"
- "{{ result.cli_results['show version']|length > 10 }}"
- "{{ result.cli_results['show interfaces']|length > 10 }}"
13 changes: 13 additions & 0 deletions tests/napalm_connection/connection_ansible_network_os.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- name: Get facts
hosts: all
connection: local # code is run locally
gather_facts: no # don't gather facts
tasks:
- block:
- name: get facts from device
napalm_get_facts: # NAPALM plugin
optional_args:
path: "{{ playbook_dir }}/mocked"
profile: "{{ profile }}"
filter: ['facts']
2 changes: 1 addition & 1 deletion tests/napalm_connection/hosts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[all]
dummy os=mock profile=[eos] password=vagrant
dummy os=mock profile=[eos] password=vagrant ansible_network_os=mock

[all:vars]
ansible_python_interpreter="/usr/bin/env python"
1 change: 1 addition & 0 deletions tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -e
ansible-playbook -i napalm_connection/hosts napalm_connection/connection_info_missing.yaml
ansible-playbook -i napalm_connection/hosts napalm_connection/connection_info_in_vars.yaml
ansible-playbook -i napalm_connection/hosts napalm_connection/connection_info_in_args.yaml -u vagrant
ansible-playbook -i napalm_connection/hosts napalm_connection/connection_ansible_network_os.yaml -u vagrant
ANSIBLE_REMOTE_USER=vagrant ansible-playbook -i napalm_connection/hosts napalm_connection/connection_info_in_env.yaml

ansible-playbook -i napalm_install_config/hosts -l "*.dry_run.*" napalm_install_config/config.yaml -C
Expand Down
Loading

0 comments on commit eebc2a6

Please sign in to comment.