Skip to content

Commit

Permalink
Merge pull request #139 from napalm-automation/develop
Browse files Browse the repository at this point in the history
Release 0.10.0
  • Loading branch information
ktbyers authored Jul 17, 2018
2 parents a1c4554 + 8d868d3 commit 2afe705
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 81 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ htmlcov/
.cache
nosetests.xml
coverage.xml
.pytest_cache/

# Translations
*.mo
Expand Down
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ language: python

python:
- 2.7
- 3.5
- 3.6

env:
- ANSIBLE_VERSION=2.2
- ANSIBLE_VERSION=2.3
- ANSIBLE_VERSION=2.4
- ANSIBLE_VERSION=2.5
- ANSIBLE_VERSION=2.6

install:
- pip install pylama
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
develop
=====

0.10.0
=====

- Python3 support
- Fix issue with an exception in napalm_install_config

0.9.1
=====

- Fix PIP10 compatibility issue
- Add support for saving `candidate_file` during the config install

0.9.0
Expand Down
1 change: 1 addition & 0 deletions napalm_ansible/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import unicode_literals, print_function
import os
import ansible
from distutils.version import LooseVersion
Expand Down
23 changes: 11 additions & 12 deletions napalm_ansible/modules/napalm_cli.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from __future__ import unicode_literals, print_function
from ansible.module_utils.basic import AnsibleModule, return_values


DOCUMENTATION = '''
---
module: napalm_cli
author: "Charlie Allom - based on napalm_ping Jason Edelman (@jedelman8)"
author: "Charlie Allom"
version_added: "2.2"
short_description: "Executes CLI commands and returns response using NAPALM"
short_description: "Executes network device CLI commands and returns response using NAPALM"
description:
- "This module logs into the device, issues a ping request, and returns the response"
- "Executes network device CLI commands and returns response using NAPALM"
requirements:
- napalm
options:
Expand All @@ -32,8 +33,6 @@
description:
- OS of the device
required: False
choices: ['eos', 'junos', 'iosxr', 'fortios', 'ios', 'mock', 'nxos', 'nxos_ssh', 'panos',
'vyos']
provider:
description:
- Dictionary which acts as a collection of arguments used to define the characteristics
Expand Down Expand Up @@ -83,6 +82,7 @@
napalm_found = False
try:
from napalm import get_network_driver
from napalm.base import ModuleImportError
napalm_found = True
except ImportError:
pass
Expand All @@ -91,22 +91,21 @@
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():
os_choices = ['eos', 'junos', 'iosxr', 'fortios',
'ios', 'mock', 'nxos', 'nxos_ssh', 'panos', 'vyos', 'ros']
module = AnsibleModule(
argument_spec=dict(
hostname=dict(type='str', required=False, aliases=['host']),
username=dict(type='str', required=False),
password=dict(type='str', required=False, no_log=True),
provider=dict(type='dict', required=False),
timeout=dict(type='int', required=False, default=60),
dev_os=dict(type='str', required=False, choices=os_choices),
dev_os=dict(type='str', required=False),
optional_args=dict(required=False, type='dict', default=None),
args=dict(required=True, type='dict', default=None),
),
Expand Down Expand Up @@ -146,17 +145,17 @@ def main():
if val is None:
module.fail_json(msg=str(key) + " is required")

# use checks outside of ansible defined checks, since params come can come from provider
if dev_os not in os_choices:
module.fail_json(msg="dev_os is not set to " + str(os_choices))

if module.params['optional_args'] is None:
optional_args = {}
else:
optional_args = module.params['optional_args']

try:
network_driver = get_network_driver(dev_os)
except ModuleImportError as e:
module.fail_json(msg="Failed to import napalm driver: " + str(e))

try:
device = network_driver(hostname=hostname,
username=username,
password=password,
Expand Down
2 changes: 1 addition & 1 deletion napalm_ansible/modules/napalm_diff_yang.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
(c) 2017 David Barroso <[email protected]>
Expand All @@ -19,6 +18,7 @@
You should have received a copy of the GNU General Public License
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

try:
Expand Down
18 changes: 8 additions & 10 deletions napalm_ansible/modules/napalm_get_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU General Public License
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


Expand Down Expand Up @@ -46,8 +47,6 @@
description:
- OS of the device
required: False
choices: ['eos', 'junos', 'iosxr', 'fortios', 'ios', 'mock', 'nxos', 'nxos_ssh', 'panos',
'vyos']
provider:
description:
- Dictionary which acts as a collection of arguments used to define the characteristics
Expand Down Expand Up @@ -141,6 +140,7 @@
napalm_found = False
try:
from napalm import get_network_driver
from napalm.base import ModuleImportError
napalm_found = True
except ImportError:
pass
Expand All @@ -149,21 +149,20 @@
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():
os_choices = ['eos', 'junos', 'iosxr', 'fortios', 'ios', 'mock', 'nxos', 'nxos_ssh', 'panos',
'vyos', 'ros']
module = AnsibleModule(
argument_spec=dict(
hostname=dict(type='str', required=False, aliases=['host']),
username=dict(type='str', required=False),
password=dict(type='str', required=False, no_log=True),
provider=dict(type='dict', required=False),
dev_os=dict(type='str', required=False, choices=os_choices),
dev_os=dict(type='str', required=False),
timeout=dict(type='int', required=False, default=60),
ignore_notimplemented=dict(type='bool', required=False, default=False),
args=dict(type='dict', required=False, default=None),
Expand Down Expand Up @@ -210,18 +209,17 @@ def main():
if val is None:
module.fail_json(msg=str(key) + " is required")

# use checks outside of ansible defined checks, since params come can come from provider
if dev_os not in os_choices:
module.fail_json(msg="dev_os is not set to " + str(os_choices))

if module.params['optional_args'] is None:
optional_args = {}
else:
optional_args = module.params['optional_args']

# open device connection
try:
network_driver = get_network_driver(dev_os)
except ModuleImportError as e:
module.fail_json(msg="Failed to import napalm driver: " + str(e))

try:
device = network_driver(hostname=hostname,
username=username,
password=password,
Expand Down
26 changes: 11 additions & 15 deletions napalm_ansible/modules/napalm_install_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
You should have received a copy of the GNU General Public License
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


Expand Down Expand Up @@ -56,8 +57,6 @@
description:
- OS of the device
required: False
choices: ['eos', 'junos', 'iosxr', 'fortios', 'ios', 'mock', 'nxos', 'nxos_ssh', 'panos',
'vyos']
timeout:
description:
- Time in seconds to wait for the device to respond
Expand Down Expand Up @@ -161,6 +160,7 @@
napalm_found = False
try:
from napalm import get_network_driver
from napalm.base import ModuleImportError
napalm_found = True
except ImportError:
pass
Expand All @@ -169,22 +169,18 @@
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):
f = open(filename, 'w')
try:
with open(filename, 'w') as f:
f.write(content)
finally:
f.close()


def main():
os_choices = ['eos', 'junos', 'iosxr', 'fortios', 'ios', 'mock', 'nxos',
'nxos_ssh', 'panos', 'vyos', 'ros']
module = AnsibleModule(
argument_spec=dict(
hostname=dict(type='str', required=False, aliases=['host']),
Expand All @@ -195,7 +191,7 @@ def main():
optional_args=dict(required=False, type='dict', default=None),
config_file=dict(type='str', required=False),
config=dict(type='str', required=False),
dev_os=dict(type='str', required=False, choices=os_choices),
dev_os=dict(type='str', required=False),
commit_changes=dict(type='bool', required=True),
replace_config=dict(type='bool', required=False, default=False),
diff_file=dict(type='str', required=False, default=None),
Expand Down Expand Up @@ -246,17 +242,17 @@ def main():
if val is None:
module.fail_json(msg=str(key) + " is required")

# use checks outside of ansible defined checks, since params come can come from provider
if dev_os not in os_choices:
module.fail_json(msg="dev_os is not set to " + str(os_choices))

if module.params['optional_args'] is None:
optional_args = {}
else:
optional_args = module.params['optional_args']

try:
network_driver = get_network_driver(dev_os)
except ModuleImportError as e:
module.fail_json(msg="Failed to import napalm driver: " + str(e))

try:
device = network_driver(hostname=hostname,
username=username,
password=password,
Expand Down Expand Up @@ -290,7 +286,7 @@ def main():

try:
if get_diffs:
diff = device.compare_config().encode('utf-8')
diff = device.compare_config()
changed = len(diff) > 0
else:
changed = True
Expand All @@ -304,7 +300,7 @@ def main():
if candidate_file is not None:
running_config = device.get_config(retrieve="candidate")["candidate"]
save_to_file(running_config, candidate_file)
except Exception, e:
except Exception as e:
module.fail_json(msg="cannot retrieve running config:" + str(e))

try:
Expand Down
Loading

0 comments on commit 2afe705

Please sign in to comment.