Skip to content

Commit

Permalink
Merge pull request #105 from napalm-automation/develop
Browse files Browse the repository at this point in the history
NAPALM-Ansible Release 0.8.0
  • Loading branch information
ktbyers authored Nov 14, 2017
2 parents 8bff2a7 + f4718fd commit 822e73e
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 43 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
0.7.2 (develop)
develop
=====

0.7.1

0.8.0
=====

- Fix import so that reunified napalm gets tried first
- Fix except statements to that they are compatible with Python3

0.7.2
=====

- Add support for ``nxos_ssh`` driver
Expand Down
20 changes: 14 additions & 6 deletions napalm_ansible/napalm_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,20 @@
}
'''

napalm_found = False
try:
from napalm_base import get_network_driver
except ImportError:
napalm_found = False
else:
from napalm import get_network_driver
napalm_found = True
except ImportError:
pass

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


def main():
Expand Down Expand Up @@ -126,7 +134,7 @@ def main():
timeout=timeout,
optional_args=optional_args)
device.open()
except Exception, e:
except Exception as e:
module.fail_json(msg="cannot connect to device: " + str(e))

try:
Expand All @@ -136,7 +144,7 @@ def main():

try:
device.close()
except Exception, e:
except Exception as e:
module.fail_json(msg="cannot close device connection: " + str(e))

module.exit_json(changed=False, results=cli_response)
Expand Down
22 changes: 15 additions & 7 deletions napalm_ansible/napalm_get_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,20 @@
type: dict
'''

napalm_found = False
try:
from napalm_base import get_network_driver
except ImportError:
napalm_found = False
else:
from napalm import get_network_driver
napalm_found = True
except ImportError:
pass

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


def main():
Expand Down Expand Up @@ -228,7 +236,7 @@ def main():
timeout=timeout,
optional_args=optional_args)
device.open()
except Exception, e:
except Exception as e:
module.fail_json(msg="cannot connect to device: " + str(e))

# retreive data from device
Expand All @@ -252,13 +260,13 @@ def main():
module.fail_json(
msg="The filter {} is not supported in napalm-{} [get_{}()]".format(
getter, dev_os, getter))
except Exception, e:
except Exception as e:
module.fail_json(msg="[{}] cannot retrieve device data: ".format(getter) + str(e))

# close device connection
try:
device.close()
except Exception, e:
except Exception as e:
module.fail_json(msg="cannot close device connection: " + str(e))

new_facts = {}
Expand Down
28 changes: 18 additions & 10 deletions napalm_ansible/napalm_install_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,20 @@
sample: "[edit system]\n- host-name lab-testing;\n+ host-name lab;"
'''

napalm_found = False
try:
from napalm_base import get_network_driver
except ImportError:
napalm_found = False
else:
from napalm import get_network_driver
napalm_found = True
except ImportError:
pass

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


def save_to_file(content, filename):
Expand Down Expand Up @@ -256,14 +264,14 @@ def main():
timeout=timeout,
optional_args=optional_args)
device.open()
except Exception, e:
except Exception as e:
module.fail_json(msg="cannot connect to device: " + str(e))

try:
if archive_file is not None:
running_config = device.get_config(retrieve="running")["running"]
save_to_file(running_config, archive_file)
except Exception, e:
except Exception as e:
module.fail_json(msg="cannot retrieve running config:" + str(e))

try:
Expand All @@ -278,7 +286,7 @@ def main():
else:
module.fail_json(
msg="You have to specify either config or config_file")
except Exception, e:
except Exception as e:
module.fail_json(msg="cannot load config: " + str(e))

try:
Expand All @@ -290,7 +298,7 @@ def main():
diff = None
if diff_file is not None and get_diffs:
save_to_file(diff, diff_file)
except Exception, e:
except Exception as e:
module.fail_json(msg="cannot diff config: " + str(e))

try:
Expand All @@ -299,12 +307,12 @@ def main():
else:
if changed:
device.commit_config()
except Exception, e:
except Exception as e:
module.fail_json(msg="cannot install config: " + str(e))

try:
device.close()
except Exception, e:
except Exception as e:
module.fail_json(msg="cannot close device connection: " + str(e))

module.exit_json(changed=changed, msg=diff)
Expand Down
22 changes: 15 additions & 7 deletions napalm_ansible/napalm_parse_yang.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@

import json


napalm_found = False
try:
from napalm_base import get_network_driver
napalm_base = True
from napalm import get_network_driver
napalm_found = True
except ImportError:
napalm_base = None
pass

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

try:
import napalm_yang
Expand Down Expand Up @@ -230,7 +238,7 @@ def parse_from_device(module, os_choices):
timeout=timeout,
optional_args=optional_args)
device.open()
except Exception, e:
except Exception as e:
module.fail_json(msg="cannot connect to device: {}".format(e))

root = get_root_object(models)
Expand All @@ -244,7 +252,7 @@ def parse_from_device(module, os_choices):
# close device connection
try:
device.close()
except Exception, e:
except Exception as e:
module.fail_json(msg="cannot close device connection: {}".format(e))

return root
Expand Down Expand Up @@ -272,7 +280,7 @@ def main():
supports_check_mode=True
)

if not napalm_base:
if not napalm_found:
module.fail_json(msg="the python module napalm is required")
if not napalm_yang:
module.fail_json(msg="the python module napalm-yang is required")
Expand Down
20 changes: 14 additions & 6 deletions napalm_ansible/napalm_ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,20 @@
{"error": "connect: Network is unreachable\n"}}
'''

napalm_found = False
try:
from napalm_base import get_network_driver
except ImportError:
napalm_found = False
else:
from napalm import get_network_driver
napalm_found = True
except ImportError:
pass

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


def main():
Expand Down Expand Up @@ -217,14 +225,14 @@ def main():
timeout=timeout,
optional_args=optional_args)
device.open()
except Exception, e:
except Exception as e:
module.fail_json(msg="cannot connect to device: " + str(e))

ping_response = device.ping(destination, **ping_optional_args)

try:
device.close()
except Exception, e:
except Exception as e:
module.fail_json(msg="cannot close device connection: " + str(e))

module.exit_json(changed=False, results=ping_response)
Expand Down
17 changes: 13 additions & 4 deletions napalm_ansible/napalm_validate.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
from ansible.module_utils.basic import AnsibleModule, return_values

napalm_found = False
try:
from napalm_base import get_network_driver
napalm_base = True
from napalm import get_network_driver
napalm_found = True
except ImportError:
napalm_base = None
pass

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

try:
import napalm_yang
Expand Down Expand Up @@ -220,7 +229,7 @@ def main():
),
supports_check_mode=False
)
if not napalm_base:
if not napalm_found:
module.fail_json(msg="the python module napalm is required")

if module.params["models"]:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setup(
name="napalm-ansible",
version='0.7.2',
version='0.8.0',
packages=["napalm_ansible"],
author="David Barroso, Kirk Byers, Mircea Ulinic",
author_email="dbarrosop@dravetech.com, ktbyers@twb-tech.com",
Expand Down

0 comments on commit 822e73e

Please sign in to comment.