Skip to content

Commit

Permalink
BugFix: Update "provider" to work with Ansible2.8 (#245)
Browse files Browse the repository at this point in the history
* BugFix: Update "provider" to work with Ansible2.8

* BugFix: Update "provider" to work with Ansible2.8

* Removed missing_required_lib from ntc_config_command
  • Loading branch information
jmcgill298 authored Aug 13, 2019
1 parent cd317e3 commit 22d8525
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 199 deletions.
59 changes: 38 additions & 21 deletions library/ntc_config_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,16 @@

import os.path
import socket
from netmiko import ConnectHandler
try:
from netmiko import ConnectHandler
HAS_NETMIKO=True
except ImportError:
HAS_NETMIKO=False


from ansible import __version__ as ansible_version
if float(ansible_version[:3]) < 2.4:
raise ImportError("Ansible versions < 2.4 are not supported")


def error_params(platform, command_output):
Expand All @@ -148,38 +157,46 @@ def error_params(platform, command_output):


def main():
connection_argument_spec = dict(
connection=dict(
choices=[
'ssh',
'telnet'
],
default='ssh',
),
platform=dict(required=False, default="cisco_ios"),
host=dict(required=False),
port=dict(required=False),
username=dict(required=False, type='str'),
password=dict(required=False, type='str', no_log=True),
secret=dict(required=False, type='str', no_log=True),
use_keys=dict(required=False, default=False, type='bool'),
key_file=dict(required=False, default=None),
)
base_argument_spec = dict(
commands=dict(required=False, type='list'),
commands_file=dict(required=False),
)
argument_spec = base_argument_spec
argument_spec.update(connection_argument_spec)
argument_spec["provider"] = dict(required=False, type="dict", options=connection_argument_spec)

module = AnsibleModule(
argument_spec=dict(
connection=dict(choices=['ssh', 'telnet'],
default='ssh'),
platform=dict(required=False),
commands=dict(required=False, type='list'),
commands_file=dict(required=False),
host=dict(required=False),
port=dict(required=False),
provider=dict(type='dict', required=False),
username=dict(required=False, type='str'),
password=dict(required=False, type='str', no_log=True),
secret=dict(required=False, type='str', no_log=True),
use_keys=dict(required=False, default=False, type='bool'),
key_file=dict(required=False, default=None, type='str'),
),
argument_spec=argument_spec,
supports_check_mode=False
)

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]))

# allow local params to override provider
for param, pvalue in provider.items():
if module.params.get(param) != False:
module.params[param] = module.params.get(param) or pvalue

if not HAS_NETMIKO:
module.fail_json(msg="This module requires netmiko")

host = module.params['host']
connection = module.params['connection']
platform = module.params['platform']
Expand Down
51 changes: 27 additions & 24 deletions library/ntc_file_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,26 +190,34 @@


def main():
connection_argument_spec = dict(
platform=dict(choices=[PLATFORM_NXAPI, PLATFORM_IOS, PLATFORM_EAPI,
PLATFORM_JUNOS, PLATFORM_F5, PLATFORM_ASA],
required=False),
host=dict(required=False),
port=dict(required=False),
username=dict(required=False, type='str'),
password=dict(required=False, type='str', no_log=True),
secret=dict(required=False, type='str', no_log=True),
use_keys=dict(required=False, default=False, type='bool'),
key_file=dict(required=False, default=None),
global_delay_factor=dict(default=1, required=False, type='int'),
delay_factor=dict(default=1, required=False, type='int'),
transport=dict(required=False, choices=['http', 'https']),
ntc_host=dict(required=False),
ntc_conf_file=dict(required=False),
)
base_argument_spec = dict(
local_file=dict(required=False),
remote_file=dict(required=False),
file_system=dict(required=False),
)
argument_spec = base_argument_spec
argument_spec.update(connection_argument_spec)
argument_spec["provider"] = dict(required=False, type="dict", options=connection_argument_spec)

module = AnsibleModule(
argument_spec=dict(
platform=dict(choices=[PLATFORM_NXAPI, PLATFORM_IOS, PLATFORM_EAPI,
PLATFORM_JUNOS, PLATFORM_F5, PLATFORM_ASA],
required=False),
host=dict(required=False),
username=dict(required=False, type='str'),
provider=dict(required=False, type='dict'),
password=dict(required=False, type='str', no_log=True),
secret=dict(required=False, no_log=True),
transport=dict(required=False, choices=['http', 'https']),
port=dict(required=False, type='int'),
global_delay_factor=dict(default=1, required=False, type='int'),
delay_factor=dict(default=1, required=False, type='int'),
ntc_host=dict(required=False),
ntc_conf_file=dict(required=False),
local_file=dict(required=False),
remote_file=dict(required=False),
file_system=dict(required=False),
),
argument_spec=argument_spec,
mutually_exclusive=[['host', 'ntc_host'],
['ntc_host', 'secret'],
['ntc_host', 'transport'],
Expand All @@ -224,11 +232,6 @@ def main():

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]))

# allow local params to override provider
for param, pvalue in provider.items():
if module.params.get(param) != False:
Expand Down
41 changes: 21 additions & 20 deletions library/ntc_get_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,21 +212,28 @@


def main():
connection_argument_spec = dict(
platform=dict(choices=[PLATFORM_NXAPI, PLATFORM_IOS, PLATFORM_EAPI,
PLATFORM_JUNOS, PLATFORM_F5],
required=False),
host=dict(required=False),
port=dict(required=False),
username=dict(required=False, type='str'),
password=dict(required=False, type='str', no_log=True),
secret=dict(required=False, type='str', no_log=True),
transport=dict(required=False, choices=['http', 'https']),
ntc_host=dict(required=False),
ntc_conf_file=dict(required=False),
)
base_argument_spec = dict(
)
argument_spec = base_argument_spec
argument_spec.update(connection_argument_spec)
argument_spec["provider"] = dict(required=False, type="dict", options=connection_argument_spec)

module = AnsibleModule(
argument_spec=dict(
platform=dict(choices=[PLATFORM_NXAPI, PLATFORM_IOS, PLATFORM_EAPI,
PLATFORM_JUNOS, PLATFORM_F5],
required=False),
host=dict(required=False),
username=dict(required=False, type='str'),
password=dict(required=False, type='str', no_log=True),
secret=dict(required=False, no_log=True),
transport=dict(required=False, choices=['http', 'https']),
port=dict(required=False, type='int'),
provider=dict(type='dict', required=False),
ntc_host=dict(required=False),
ntc_conf_file=dict(required=False),
),
argument_spec=argument_spec,
supports_check_mode=False,
mutually_exclusive=[['host', 'ntc_host'],
['ntc_host', 'secret'],
['ntc_host', 'transport'],
Expand All @@ -236,19 +243,13 @@ def main():
['ntc_conf_file', 'port'],
],
required_one_of=[['host', 'ntc_host', 'provider']],
supports_check_mode=False
)

if not HAS_PYNTC:
module.fail_json(msg='pyntc Python library not found.')

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]))

# allow local params to override provider
for param, pvalue in provider.items():
if module.params.get(param) != False:
Expand Down
71 changes: 35 additions & 36 deletions library/ntc_install_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@

import time # noqa E402

from ansible.module_utils.basic import AnsibleModule, return_values # noqa E402
from ansible.module_utils.basic import AnsibleModule # noqa E402

try:
from pyntc import ntc_device, ntc_device_by_name # noqa E402
Expand Down Expand Up @@ -220,38 +220,42 @@ def already_set(boot_options, system_image_file, kickstart_image_file, **kwargs)


def main():
connection_argument_spec = dict(
platform=dict(choices=[PLATFORM_NXAPI, PLATFORM_IOS, PLATFORM_EAPI,
PLATFORM_F5, PLATFORM_ASA],
required=False),
host=dict(required=False),
port=dict(required=False),
username=dict(required=False, type='str'),
password=dict(required=False, type='str', no_log=True),
secret=dict(required=False, type='str', no_log=True),
transport=dict(required=False, choices=['http', 'https']),
ntc_host=dict(required=False),
ntc_conf_file=dict(required=False),
)
base_argument_spec = dict(
system_image_file=dict(required=True),
kickstart_image_file=dict(required=False),
volume=dict(required=False, type="str"),
reboot=dict(required=False, type="bool", default=False),
)
argument_spec = base_argument_spec
argument_spec.update(connection_argument_spec)
argument_spec["provider"] = dict(required=False, type="dict", options=connection_argument_spec)

module = AnsibleModule(
argument_spec=dict(
platform=dict(
choices=[PLATFORM_NXAPI, PLATFORM_IOS, PLATFORM_EAPI, PLATFORM_F5, PLATFORM_ASA],
required=False,
),
host=dict(required=False),
username=dict(required=False, type="str"),
password=dict(required=False, type="str", no_log=True),
secret=dict(required=False, no_log=True),
transport=dict(required=False, choices=["http", "https"]),
port=dict(required=False, type="int"),
provider=dict(type="dict", required=False),
ntc_host=dict(required=False),
ntc_conf_file=dict(required=False),
system_image_file=dict(required=True),
kickstart_image_file=dict(required=False),
volume=dict(required=False, type="str"),
reboot=dict(required=False, type="bool", default=False),
),
mutually_exclusive=[
["host", "ntc_host"],
["ntc_host", "secret"],
["ntc_host", "transport"],
["ntc_host", "port"],
["ntc_conf_file", "secret"],
["ntc_conf_file", "transport"],
["ntc_conf_file", "port"],
],
required_one_of=[["host", "ntc_host", "provider"]],
argument_spec=argument_spec,
mutually_exclusive=[['host', 'ntc_host'],
['ntc_host', 'secret'],
['ntc_host', 'transport'],
['ntc_host', 'port'],
['ntc_conf_file', 'secret'],
['ntc_conf_file', 'transport'],
['ntc_conf_file', 'port'],
],
required_one_of=[['host', 'ntc_host', 'provider']],
required_if=[["platform", PLATFORM_F5, ["volume"]]],
supports_check_mode=True,
supports_check_mode=True
)

if not HAS_PYNTC:
Expand All @@ -265,11 +269,6 @@ def main():

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]))

# allow local params to override provider
for param, pvalue in provider.items():
# TODO: Figure out exactly the purpose of this and correct truthiness or noneness
Expand Down
47 changes: 24 additions & 23 deletions library/ntc_reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,25 +211,31 @@ def check_device(module, username, password, host, timeout, kwargs):


def main():
connection_argument_spec = dict(
platform=dict(choices=[PLATFORM_NXAPI, PLATFORM_IOS, PLATFORM_EAPI,
PLATFORM_JUNOS, PLATFORM_F5, PLATFORM_ASA],
required=False),
host=dict(required=False),
port=dict(required=False),
username=dict(required=False, type='str'),
password=dict(required=False, type='str', no_log=True),
secret=dict(required=False, type='str', no_log=True),
transport=dict(required=False, choices=['http', 'https']),
ntc_host=dict(required=False),
ntc_conf_file=dict(required=False),
)
base_argument_spec = dict(
confirm=dict(required=False, default=True, type='bool'),
timer=dict(requred=False, type='int'),
timeout=dict(required=False, type='int', default=240),
volume=dict(required=False, type='str'),
)
argument_spec = base_argument_spec
argument_spec.update(connection_argument_spec)
argument_spec["provider"] = dict(required=False, type="dict", options=connection_argument_spec)

module = AnsibleModule(
argument_spec=dict(
platform=dict(choices=[PLATFORM_NXAPI, PLATFORM_IOS, PLATFORM_EAPI,
PLATFORM_JUNOS, PLATFORM_F5, PLATFORM_ASA],
required=False),
host=dict(required=False),
username=dict(required=False, type='str'),
provider=dict(required=False, type='dict'),
password=dict(required=False, type='str', no_log=True),
secret=dict(required=False, no_log=True),
transport=dict(required=False, choices=['http', 'https']),
port=dict(required=False, type='int'),
ntc_host=dict(required=False),
ntc_conf_file=dict(required=False),
confirm=dict(required=False, default=False, type='bool'),
timer=dict(requred=False, type='int'),
timeout=dict(required=False, type='int', default=240),
volume=dict(required=False, type='str'),
),
argument_spec=argument_spec,
mutually_exclusive=[['host', 'ntc_host'],
['ntc_host', 'secret'],
['ntc_host', 'transport'],
Expand All @@ -248,11 +254,6 @@ def main():

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]))

# allow local params to override provider
for param, pvalue in provider.items():
if module.params.get(param) != False:
Expand Down
Loading

0 comments on commit 22d8525

Please sign in to comment.