-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from napalm-automation/develop
Release 0.7.0
- Loading branch information
Showing
29 changed files
with
542 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
0.7.0 | ||
===== | ||
|
||
- Minor internal improvements | ||
- [#77] Added ``napalm_cli`` module | ||
- Prepend 'napalm_' to NAPALM ansible facts generated by napalm_get_facts module | ||
- Make NAPALM 'get_facts' be directly accessible Ansible facts (e.g. napalm_model) | ||
- Change validate behavior to fail if 'complies' is False | ||
- Create run_tests.sh script to make it easier to run the unit tests | ||
|
||
0.6.1 | ||
===== | ||
|
||
- First official version installable via pypi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
napalm_ansible |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import os | ||
|
||
message = """ | ||
To make sure ansible can make use of the napalm modules you will have | ||
to add the following configurtion to your ansible configureation | ||
file, i.e. `./ansible.cfg`: | ||
[defaults] | ||
library = {path} | ||
For more details on ansible's configuration file visit: | ||
https://docs.ansible.com/ansible/latest/intro_configuration.html | ||
""" | ||
|
||
|
||
def main(): | ||
path = os.path.dirname(__file__) | ||
print(message.format(path=path).strip()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
from ansible.module_utils.basic import AnsibleModule, return_values | ||
|
||
|
||
DOCUMENTATION = ''' | ||
--- | ||
module: napalm_cli | ||
author: "Charlie Allom - based on napalm_ping Jason Edelman (@jedelman8)" | ||
version_added: "2.2" | ||
short_description: "Executes CLI commands and returns response using NAPALM" | ||
description: | ||
- "This module logs into the device, issues a ping request, and returns the response" | ||
requirements: | ||
- napalm | ||
options: | ||
args: | ||
description: | ||
- Keyword arguments to pass to the `cli` method | ||
required: True | ||
''' | ||
|
||
EXAMPLES = ''' | ||
vars: | ||
napalm_provider: | ||
hostname: "{{ inventory_hostname }}" | ||
username: "napalm" | ||
password: "napalm" | ||
dev_os: "eos" | ||
- napalm_cli: | ||
provider: "{{ napalm_provider }}" | ||
args: | ||
commands: | ||
- show version | ||
- show snmp chassis | ||
''' | ||
|
||
RETURN = ''' | ||
changed: | ||
description: ALWAYS RETURNS FALSE | ||
returned: always | ||
type: bool | ||
sample: True | ||
results: | ||
description: string of command output | ||
returned: always | ||
type: dict | ||
sample: | ||
{ | ||
"show snmp chassis": "Chassis: 1234\n", | ||
"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 | ||
} | ||
''' | ||
|
||
try: | ||
from napalm_base import get_network_driver | ||
except ImportError: | ||
napalm_found = False | ||
else: | ||
napalm_found = True | ||
|
||
|
||
def main(): | ||
os_choices = ['eos', 'junos', 'iosxr', 'fortios', | ||
'ios', 'mock', 'nxos', '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), | ||
optional_args=dict(required=False, type='dict', default=None), | ||
args=dict(required=True, type='dict', default=None), | ||
), | ||
supports_check_mode=False | ||
) | ||
|
||
if not napalm_found: | ||
module.fail_json(msg="the python module napalm is required") | ||
|
||
provider = module.params['provider'] or {} | ||
|
||
no_log = ['password', 'secret'] | ||
for param in no_log: | ||
if provider.get(param): | ||
module.no_log_values.update(return_values(provider[param])) | ||
if provider.get('optional_args') and provider['optional_args'].get(param): | ||
module.no_log_values.update(return_values(provider['optional_args'].get(param))) | ||
if module.params.get('optional_args') and module.params['optional_args'].get(param): | ||
module.no_log_values.update(return_values(module.params['optional_args'].get(param))) | ||
|
||
# allow host or hostname | ||
provider['hostname'] = provider.get('hostname', None) or provider.get('host', None) | ||
# allow local params to override provider | ||
for param, pvalue in provider.items(): | ||
if module.params.get(param) is not False: | ||
module.params[param] = module.params.get(param) or pvalue | ||
|
||
hostname = module.params['hostname'] | ||
username = module.params['username'] | ||
dev_os = module.params['dev_os'] | ||
password = module.params['password'] | ||
timeout = module.params['timeout'] | ||
args = module.params['args'] | ||
|
||
argument_check = {'hostname': hostname, 'username': username, | ||
'dev_os': dev_os, 'password': password} | ||
for key, val in argument_check.items(): | ||
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) | ||
device = network_driver(hostname=hostname, | ||
username=username, | ||
password=password, | ||
timeout=timeout, | ||
optional_args=optional_args) | ||
device.open() | ||
except Exception, e: | ||
module.fail_json(msg="cannot connect to device: " + str(e)) | ||
|
||
try: | ||
cli_response = device.cli(**args) | ||
except Exception as e: | ||
module.fail_json(msg="{}".format(e)) | ||
|
||
try: | ||
device.close() | ||
except Exception, e: | ||
module.fail_json(msg="cannot close device connection: " + str(e)) | ||
|
||
module.exit_json(changed=False, results=cli_response) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
File renamed without changes.
Oops, something went wrong.