From 7b9a33a29007ed302c3001566061e22c514cde64 Mon Sep 17 00:00:00 2001 From: "Bradley A. Thornton" Date: Fri, 9 Aug 2019 10:42:04 -0700 Subject: bt_yapfed --- .../network/vyos/argspec/facts/facts.py | 8 +- .../network/vyos/argspec/interfaces/interfaces.py | 1 - .../vyos/argspec/l3_interfaces/l3_interfaces.py | 2 - .../network/vyos/config/interfaces/interfaces.py | 98 +++++++++++++--------- .../vyos/config/l3_interfaces/l3_interfaces.py | 83 ++++++++++-------- plugins/module_utils/network/vyos/facts/facts.py | 27 +++--- .../network/vyos/facts/interfaces/interfaces.py | 15 ++-- .../vyos/facts/l3_interfaces/l3_interfaces.py | 10 +-- .../module_utils/network/vyos/facts/legacy/base.py | 5 +- plugins/module_utils/network/vyos/utils/utils.py | 1 - plugins/module_utils/network/vyos/vyos.py | 29 ++++--- plugins/modules/_vyos_interface.py | 70 +++++++++------- plugins/modules/_vyos_l3_interface.py | 62 +++++++------- plugins/modules/vyos_banner.py | 32 +++---- plugins/modules/vyos_command.py | 27 +++--- plugins/modules/vyos_config.py | 32 +++---- plugins/modules/vyos_facts.py | 17 ++-- plugins/modules/vyos_interfaces.py | 3 - plugins/modules/vyos_l3_interfaces.py | 3 - plugins/modules/vyos_linkagg.py | 74 +++++++++------- plugins/modules/vyos_lldp.py | 14 ++-- plugins/modules/vyos_lldp_interface.py | 37 ++++---- plugins/modules/vyos_logging.py | 48 ++++++----- plugins/modules/vyos_ping.py | 25 ++++-- plugins/modules/vyos_static_route.py | 55 ++++++------ plugins/modules/vyos_system.py | 20 +++-- plugins/modules/vyos_user.py | 49 +++++------ plugins/modules/vyos_vlan.py | 78 ++++++++++------- 28 files changed, 501 insertions(+), 424 deletions(-) diff --git a/plugins/module_utils/network/vyos/argspec/facts/facts.py b/plugins/module_utils/network/vyos/argspec/facts/facts.py index 456c8bd..84b7135 100644 --- a/plugins/module_utils/network/vyos/argspec/facts/facts.py +++ b/plugins/module_utils/network/vyos/argspec/facts/facts.py @@ -5,7 +5,6 @@ The arg spec for the vyos facts module. """ - from __future__ import absolute_import, division, print_function __metaclass__ = type @@ -13,16 +12,11 @@ __metaclass__ = type class FactsArgs(object): # pylint: disable=R0903 """ The arg spec for the vyos facts module """ - def __init__(self, **kwargs): pass choices = [ - 'all', - 'interfaces', - '!interfaces', - 'l3_interfaces', - '!l3_interfaces' + 'all', 'interfaces', '!interfaces', 'l3_interfaces', '!l3_interfaces' ] argument_spec = { diff --git a/plugins/module_utils/network/vyos/argspec/interfaces/interfaces.py b/plugins/module_utils/network/vyos/argspec/interfaces/interfaces.py index d6ab446..40df125 100644 --- a/plugins/module_utils/network/vyos/argspec/interfaces/interfaces.py +++ b/plugins/module_utils/network/vyos/argspec/interfaces/interfaces.py @@ -30,7 +30,6 @@ __metaclass__ = type class InterfacesArgs(object): # pylint: disable=R0903 """The arg spec for the vyos_interfaces module """ - def __init__(self, **kwargs): pass diff --git a/plugins/module_utils/network/vyos/argspec/l3_interfaces/l3_interfaces.py b/plugins/module_utils/network/vyos/argspec/l3_interfaces/l3_interfaces.py index e5785a8..240f348 100644 --- a/plugins/module_utils/network/vyos/argspec/l3_interfaces/l3_interfaces.py +++ b/plugins/module_utils/network/vyos/argspec/l3_interfaces/l3_interfaces.py @@ -25,7 +25,6 @@ The arg spec for the vyos_l3_interfaces module """ - from __future__ import absolute_import, division, print_function __metaclass__ = type @@ -33,7 +32,6 @@ __metaclass__ = type class L3_interfacesArgs(object): # pylint: disable=R0903 """The arg spec for the vyos_l3_interfaces module """ - def __init__(self, **kwargs): pass diff --git a/plugins/module_utils/network/vyos/config/interfaces/interfaces.py b/plugins/module_utils/network/vyos/config/interfaces/interfaces.py index b17971c..c85b865 100644 --- a/plugins/module_utils/network/vyos/config/interfaces/interfaces.py +++ b/plugins/module_utils/network/vyos/config/interfaces/interfaces.py @@ -12,7 +12,6 @@ created from __future__ import absolute_import, division, print_function __metaclass__ = type - from copy import deepcopy from ansible.module_utils.network.common.cfg.base import ConfigBase from ansible.module_utils.network.common.utils import to_list, dict_diff, remove_empties @@ -24,7 +23,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network. \ vyos.utils.utils import search_obj_in_list, get_interface_type, dict_delete - class Interfaces(ConfigBase): """ The vyos_interfaces class @@ -35,9 +33,7 @@ class Interfaces(ConfigBase): '!min', ] - gather_network_resources = [ - 'interfaces' - ] + gather_network_resources = ['interfaces'] def __init__(self, module): super(Interfaces, self).__init__(module) @@ -48,8 +44,8 @@ class Interfaces(ConfigBase): :rtype: A dictionary :returns: The current configuration as a dictionary """ - facts, _warnings = Facts(self._module).get_facts(self.gather_subset, - self.gather_network_resources) + facts, _warnings = Facts(self._module).get_facts( + self.gather_subset, self.gather_network_resources) interfaces_facts = facts['ansible_network_resources'].get('interfaces') if not interfaces_facts: return [] @@ -118,19 +114,11 @@ class Interfaces(ConfigBase): if not want: for intf in have: commands.extend( - self._state_deleted( - {'name': intf['name']}, - intf - ) - ) + self._state_deleted({'name': intf['name']}, intf)) else: for item in want: obj_in_have = search_obj_in_list(item['name'], have) - commands.extend( - self._state_deleted( - item, obj_in_have - ) - ) + commands.extend(self._state_deleted(item, obj_in_have)) else: for item in want: name = item['name'] @@ -140,18 +128,10 @@ class Interfaces(ConfigBase): obj_in_have = {'name': item['name']} elif state == 'merged': - commands.extend( - self._state_merged( - item, obj_in_have - ) - ) + commands.extend(self._state_merged(item, obj_in_have)) elif state == 'replaced': - commands.extend( - self._state_replaced( - item, obj_in_have - ) - ) + commands.extend(self._state_replaced(item, obj_in_have)) return commands @@ -182,7 +162,8 @@ class Interfaces(ConfigBase): for intf in have: intf_in_want = search_obj_in_list(intf['name'], want) if not intf_in_want: - commands.extend(self._state_deleted({'name': intf['name']}, intf)) + commands.extend( + self._state_deleted({'name': intf['name']}, intf)) for intf in want: intf_in_have = search_obj_in_list(intf['name'], have) @@ -208,18 +189,30 @@ class Interfaces(ConfigBase): if updates: for key, value in iteritems(updates): - commands.append(self._compute_commands(key=key, value=value, interface=want_copy['name'])) + commands.append( + self._compute_commands(key=key, + value=value, + interface=want_copy['name'])) if want_vifs: for want_vif in want_vifs: - have_vif = search_obj_in_list(want_vif['vlan_id'], have_vifs, key='vlan_id') + have_vif = search_obj_in_list(want_vif['vlan_id'], + have_vifs, + key='vlan_id') if not have_vif: - have_vif = {'vlan_id': want_vif['vlan_id'], 'enabled': True} + have_vif = { + 'vlan_id': want_vif['vlan_id'], + 'enabled': True + } vif_updates = dict_diff(have_vif, want_vif) if vif_updates: for key, value in iteritems(vif_updates): - commands.append(self._compute_commands(key=key, value=value, interface=want_copy['name'], vif=want_vif['vlan_id'])) + commands.append( + self._compute_commands(key=key, + value=value, + interface=want_copy['name'], + vif=want_vif['vlan_id'])) return commands @@ -241,27 +234,52 @@ class Interfaces(ConfigBase): for key in dict_delete(have_copy, want_copy).keys(): if key == 'enabled': continue - commands.append(self._compute_commands(key=key, interface=want_copy['name'], remove=True)) + commands.append( + self._compute_commands(key=key, + interface=want_copy['name'], + remove=True)) if have_copy['enabled'] is False: - commands.append(self._compute_commands(key='enabled', value=True, interface=want_copy['name'])) + commands.append( + self._compute_commands(key='enabled', + value=True, + interface=want_copy['name'])) if have_vifs: for have_vif in have_vifs: - want_vif = search_obj_in_list(have_vif['vlan_id'], want_vifs, key='vlan_id') + want_vif = search_obj_in_list(have_vif['vlan_id'], + want_vifs, + key='vlan_id') if not want_vif: - want_vif = {'vlan_id': have_vif['vlan_id'], 'enabled': True} + want_vif = { + 'vlan_id': have_vif['vlan_id'], + 'enabled': True + } for key in dict_delete(have_vif, want_vif).keys(): if key == 'enabled': continue - commands.append(self._compute_commands(key=key, interface=want_copy['name'], vif=want_vif['vlan_id'], remove=True)) + commands.append( + self._compute_commands(key=key, + interface=want_copy['name'], + vif=want_vif['vlan_id'], + remove=True)) if have_vif['enabled'] is False: - commands.append(self._compute_commands(key='enabled', value=True, interface=want_copy['name'], vif=want_vif['vlan_id'])) + commands.append( + self._compute_commands(key='enabled', + value=True, + interface=want_copy['name'], + vif=want_vif['vlan_id'])) return commands - def _compute_commands(self, interface, key, vif=None, value=None, remove=False): - intf_context = 'interfaces {0} {1}'.format(get_interface_type(interface), interface) + def _compute_commands(self, + interface, + key, + vif=None, + value=None, + remove=False): + intf_context = 'interfaces {0} {1}'.format( + get_interface_type(interface), interface) set_cmd = 'set {0}'.format(intf_context) del_cmd = 'delete {0}'.format(intf_context) diff --git a/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py b/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py index 9027c84..7cac4ed 100644 --- a/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py +++ b/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py @@ -14,7 +14,6 @@ created from __future__ import absolute_import, division, print_function __metaclass__ = type - from copy import deepcopy from ansible.module_utils.network.common.cfg.base import ConfigBase from ansible.module_utils.network.common.utils import to_list, remove_empties @@ -26,7 +25,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network. \ vyos.utils.utils import search_obj_in_list, get_interface_type, diff_list_of_dicts - class L3_interfaces(ConfigBase): """ The vyos_l3_interfaces class @@ -50,8 +48,10 @@ class L3_interfaces(ConfigBase): :rtype: A dictionary :returns: The current configuration as a dictionary """ - facts, _warnings = Facts(self._module).get_facts(self.gather_subset, self.gather_network_resources) - l3_interfaces_facts = facts['ansible_network_resources'].get('l3_interfaces') + facts, _warnings = Facts(self._module).get_facts( + self.gather_subset, self.gather_network_resources) + l3_interfaces_facts = facts['ansible_network_resources'].get( + 'l3_interfaces') if not l3_interfaces_facts: return [] return l3_interfaces_facts @@ -120,19 +120,11 @@ class L3_interfaces(ConfigBase): if not want: for intf in have: commands.extend( - self._state_deleted( - {'name': intf['name']}, - intf - ) - ) + self._state_deleted({'name': intf['name']}, intf)) else: for item in want: obj_in_have = search_obj_in_list(item['name'], have) - commands.extend( - self._state_deleted( - item, obj_in_have - ) - ) + commands.extend(self._state_deleted(item, obj_in_have)) else: for item in want: name = item['name'] @@ -142,18 +134,10 @@ class L3_interfaces(ConfigBase): obj_in_have = {'name': item['name']} if state == 'merged': - commands.extend( - self._state_merged( - item, obj_in_have - ) - ) + commands.extend(self._state_merged(item, obj_in_have)) elif state == 'replaced': - commands.extend( - self._state_replaced( - item, obj_in_have - ) - ) + commands.extend(self._state_replaced(item, obj_in_have)) return commands @@ -184,7 +168,8 @@ class L3_interfaces(ConfigBase): for intf in have: intf_in_want = search_obj_in_list(intf['name'], want) if not intf_in_want: - commands.extend(self._state_deleted({'name': intf['name']}, intf)) + commands.extend( + self._state_deleted({'name': intf['name']}, intf)) for intf in want: intf_in_have = search_obj_in_list(intf['name'], have) @@ -208,17 +193,26 @@ class L3_interfaces(ConfigBase): for update in self._get_updates(want_copy, have_copy): for key, value in iteritems(update): - commands.append(self._compute_commands(key=key, value=value, interface=want_copy['name'])) + commands.append( + self._compute_commands(key=key, + value=value, + interface=want_copy['name'])) if want_vifs: for want_vif in want_vifs: - have_vif = search_obj_in_list(want_vif['vlan_id'], have_vifs, key='vlan_id') + have_vif = search_obj_in_list(want_vif['vlan_id'], + have_vifs, + key='vlan_id') if not have_vif: have_vif = {} for update in self._get_updates(want_vif, have_vif): for key, value in iteritems(update): - commands.append(self._compute_commands(key=key, value=value, interface=want_copy['name'], vif=want_vif['vlan_id'])) + commands.append( + self._compute_commands(key=key, + value=value, + interface=want_copy['name'], + vif=want_vif['vlan_id'])) return commands @@ -238,22 +232,39 @@ class L3_interfaces(ConfigBase): for update in self._get_updates(have_copy, want_copy): for key, value in iteritems(update): - commands.append(self._compute_commands(key=key, value=value, interface=want_copy['name'], remove=True)) + commands.append( + self._compute_commands(key=key, + value=value, + interface=want_copy['name'], + remove=True)) if have_vifs: for have_vif in have_vifs: - want_vif = search_obj_in_list(have_vif['vlan_id'], want_vifs, key='vlan_id') + want_vif = search_obj_in_list(have_vif['vlan_id'], + want_vifs, + key='vlan_id') if not want_vif: want_vif = {'vlan_id': have_vif['vlan_id']} for update in self._get_updates(have_vif, want_vif): for key, value in iteritems(update): - commands.append(self._compute_commands(key=key, interface=want_copy['name'], value=value, vif=want_vif['vlan_id'], remove=True)) + commands.append( + self._compute_commands(key=key, + interface=want_copy['name'], + value=value, + vif=want_vif['vlan_id'], + remove=True)) return commands - def _compute_commands(self, interface, key, vif=None, value=None, remove=False): - intf_context = 'interfaces {0} {1}'.format(get_interface_type(interface), interface) + def _compute_commands(self, + interface, + key, + vif=None, + value=None, + remove=False): + intf_context = 'interfaces {0} {1}'.format( + get_interface_type(interface), interface) set_cmd = 'set {0}'.format(intf_context) del_cmd = 'delete {0}'.format(intf_context) @@ -271,7 +282,9 @@ class L3_interfaces(ConfigBase): def _get_updates(self, want, have): updates = [] - updates = diff_list_of_dicts(want.get('ipv4', []), have.get('ipv4', [])) - updates.extend(diff_list_of_dicts(want.get('ipv6', []), have.get('ipv6', []))) + updates = diff_list_of_dicts(want.get('ipv4', []), + have.get('ipv4', [])) + updates.extend( + diff_list_of_dicts(want.get('ipv6', []), have.get('ipv6', []))) return updates diff --git a/plugins/module_utils/network/vyos/facts/facts.py b/plugins/module_utils/network/vyos/facts/facts.py index a065eaf..bcdc54f 100644 --- a/plugins/module_utils/network/vyos/facts/facts.py +++ b/plugins/module_utils/network/vyos/facts/facts.py @@ -27,16 +27,9 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network. \ from ansible.module_utils. \ network.vyos.vyos import run_commands, get_capabilities - -FACT_LEGACY_SUBSETS = dict( - default=Default, - neighbors=Neighbors, - config=Config -) -FACT_RESOURCE_SUBSETS = dict( - interfaces=InterfacesFacts, - l3_interfaces=L3_interfacesFacts -) +FACT_LEGACY_SUBSETS = dict(default=Default, neighbors=Neighbors, config=Config) +FACT_RESOURCE_SUBSETS = dict(interfaces=InterfacesFacts, + l3_interfaces=L3_interfacesFacts) class Facts(FactsBase): @@ -49,7 +42,10 @@ class Facts(FactsBase): def __init__(self, module): super(Facts, self).__init__(module) - def get_facts(self, legacy_facts_type=None, resource_facts_type=None, data=None): + def get_facts(self, + legacy_facts_type=None, + resource_facts_type=None, + data=None): """ Collect the facts for vyos :param legacy_facts_type: List of legacy facts types @@ -58,12 +54,15 @@ class Facts(FactsBase): :rtype: dict :return: the facts gathered """ - netres_choices = FactsArgs.argument_spec['gather_network_resources'].get('choices', []) + netres_choices = FactsArgs.argument_spec[ + 'gather_network_resources'].get('choices', []) if self.VALID_RESOURCE_SUBSETS: - self.get_network_resources_facts(netres_choices, FACT_RESOURCE_SUBSETS, + self.get_network_resources_facts(netres_choices, + FACT_RESOURCE_SUBSETS, resource_facts_type, data) if self.VALID_LEGACY_GATHER_SUBSETS: - self.get_network_legacy_facts(FACT_LEGACY_SUBSETS, legacy_facts_type) + self.get_network_legacy_facts(FACT_LEGACY_SUBSETS, + legacy_facts_type) return self.ansible_facts, self._warnings diff --git a/plugins/module_utils/network/vyos/facts/interfaces/interfaces.py b/plugins/module_utils/network/vyos/facts/interfaces/interfaces.py index cc89e4f..915abaa 100644 --- a/plugins/module_utils/network/vyos/facts/interfaces/interfaces.py +++ b/plugins/module_utils/network/vyos/facts/interfaces/interfaces.py @@ -13,7 +13,6 @@ based on the configuration. from __future__ import absolute_import, division, print_function __metaclass__ = type - from re import findall, M from copy import deepcopy from ansible.module_utils.network.common import utils @@ -21,11 +20,9 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network. \ vyos.argspec.interfaces.interfaces import InterfacesArgs - class InterfacesFacts(object): """ The vyos interfaces fact class """ - def __init__(self, module, subspec='config', options='options'): self._module = module self.argument_spec = InterfacesArgs.argument_spec @@ -52,8 +49,9 @@ class InterfacesFacts(object): data = connection.get_config(flags=['| grep interfaces']) objs = [] - interface_names = findall(r'^set interfaces (?:ethernet|bonding|vti|loopback|vxlan) (?:\'*)(\S+)(?:\'*)', - data, M) + interface_names = findall( + r'^set interfaces (?:ethernet|bonding|vti|loopback|vxlan) (?:\'*)(\S+)(?:\'*)', + data, M) if interface_names: for interface in set(interface_names): intf_regex = r' %s .+$' % interface.strip("'") @@ -65,7 +63,8 @@ class InterfacesFacts(object): facts = {} if objs: facts['interfaces'] = [] - params = utils.validate_config(self.argument_spec, {'config': objs}) + params = utils.validate_config(self.argument_spec, + {'config': objs}) for cfg in params['config']: facts['interfaces'].append(utils.remove_empties(cfg)) @@ -84,8 +83,8 @@ class InterfacesFacts(object): """ vif_conf = '\n'.join(filter(lambda x: ('vif' in x), conf)) eth_conf = '\n'.join(filter(lambda x: ('vif' not in x), conf)) - config = self.parse_attribs( - ['description', 'speed', 'mtu', 'duplex'], eth_conf) + config = self.parse_attribs(['description', 'speed', 'mtu', 'duplex'], + eth_conf) config['vifs'] = self.parse_vifs(vif_conf) return utils.remove_empties(config) diff --git a/plugins/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py b/plugins/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py index 61f635b..c082c5b 100644 --- a/plugins/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py +++ b/plugins/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py @@ -13,7 +13,6 @@ based on the configuration. from __future__ import absolute_import, division, print_function __metaclass__ = type - import re from copy import deepcopy from ansible.module_utils.network.common import utils @@ -23,11 +22,9 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network. \ vyos.argspec.l3_interfaces.l3_interfaces import L3_interfacesArgs - class L3_interfacesFacts(object): """ The vyos l3_interfaces fact class """ - def __init__(self, module, subspec='config', options='options'): self._module = module self.argument_spec = L3_interfacesArgs.argument_spec @@ -55,7 +52,9 @@ class L3_interfacesFacts(object): # operate on a collection of resource x objs = [] - interface_names = re.findall(r'set interfaces (?:ethernet|bonding|vti|vxlan) (?:\'*)(\S+)(?:\'*)', data, re.M) + interface_names = re.findall( + r'set interfaces (?:ethernet|bonding|vti|vxlan) (?:\'*)(\S+)(?:\'*)', + data, re.M) if interface_names: for interface in set(interface_names): intf_regex = r' %s .+$' % interface @@ -69,7 +68,8 @@ class L3_interfacesFacts(object): facts = {} if objs: facts['l3_interfaces'] = [] - params = utils.validate_config(self.argument_spec, {'config': objs}) + params = utils.validate_config(self.argument_spec, + {'config': objs}) for cfg in params['config']: facts['l3_interfaces'].append(utils.remove_empties(cfg)) diff --git a/plugins/module_utils/network/vyos/facts/legacy/base.py b/plugins/module_utils/network/vyos/facts/legacy/base.py index cdf0cce..33d094b 100644 --- a/plugins/module_utils/network/vyos/facts/legacy/base.py +++ b/plugins/module_utils/network/vyos/facts/legacy/base.py @@ -12,7 +12,6 @@ based on the configuration. from __future__ import absolute_import, division, print_function __metaclass__ = type - import platform import re from ansible.module_utils. \ @@ -114,9 +113,7 @@ class Neighbors(LegacyFactsBase): all_neighbors = self.responses[0] if 'LLDP not configured' not in all_neighbors: - neighbors = self.parse( - self.responses[1] - ) + neighbors = self.parse(self.responses[1]) self.facts['neighbors'] = self.parse_neighbors(neighbors) def parse(self, data): diff --git a/plugins/module_utils/network/vyos/utils/utils.py b/plugins/module_utils/network/vyos/utils/utils.py index f59c24f..960d268 100644 --- a/plugins/module_utils/network/vyos/utils/utils.py +++ b/plugins/module_utils/network/vyos/utils/utils.py @@ -5,7 +5,6 @@ # utils - from __future__ import absolute_import, division, print_function __metaclass__ = type diff --git a/plugins/module_utils/network/vyos/vyos.py b/plugins/module_utils/network/vyos/vyos.py index 2aa7b49..ee15101 100644 --- a/plugins/module_utils/network/vyos/vyos.py +++ b/plugins/module_utils/network/vyos/vyos.py @@ -34,14 +34,18 @@ from ansible.module_utils.connection import Connection, ConnectionError _DEVICE_CONFIGS = {} vyos_provider_spec = { - 'host': dict(), - 'port': dict(type='int'), - - 'username': dict(fallback=(env_fallback, ['ANSIBLE_NET_USERNAME'])), - 'password': dict(fallback=(env_fallback, ['ANSIBLE_NET_PASSWORD']), no_log=True), - 'ssh_keyfile': dict(fallback=(env_fallback, ['ANSIBLE_NET_SSH_KEYFILE']), type='path'), - - 'timeout': dict(type='int'), + 'host': + dict(), + 'port': + dict(type='int'), + 'username': + dict(fallback=(env_fallback, ['ANSIBLE_NET_USERNAME'])), + 'password': + dict(fallback=(env_fallback, ['ANSIBLE_NET_PASSWORD']), no_log=True), + 'ssh_keyfile': + dict(fallback=(env_fallback, ['ANSIBLE_NET_SSH_KEYFILE']), type='path'), + 'timeout': + dict(type='int'), } vyos_argument_spec = { 'provider': dict(type='dict', options=vyos_provider_spec), @@ -49,11 +53,9 @@ vyos_argument_spec = { vyos_top_spec = { 'host': dict(removed_in_version=2.9), 'port': dict(removed_in_version=2.9, type='int'), - 'username': dict(removed_in_version=2.9), 'password': dict(removed_in_version=2.9, no_log=True), 'ssh_keyfile': dict(removed_in_version=2.9, type='path'), - 'timeout': dict(removed_in_version=2.9, type='int'), } vyos_argument_spec.update(vyos_top_spec) @@ -110,7 +112,8 @@ def get_config(module, flags=None, format=None): def run_commands(module, commands, check_rc=True): connection = get_connection(module) try: - response = connection.run_commands(commands=commands, check_rc=check_rc) + response = connection.run_commands(commands=commands, + check_rc=check_rc) except ConnectionError as exc: module.fail_json(msg=to_text(exc, errors='surrogate_then_replace')) return response @@ -120,7 +123,9 @@ def load_config(module, commands, commit=False, comment=None): connection = get_connection(module) try: - response = connection.edit_config(candidate=commands, commit=commit, comment=comment) + response = connection.edit_config(candidate=commands, + commit=commit, + comment=comment) except ConnectionError as exc: module.fail_json(msg=to_text(exc, errors='surrogate_then_replace')) diff --git a/plugins/modules/_vyos_interface.py b/plugins/modules/_vyos_interface.py index e4b989e..35b3a2c 100644 --- a/plugins/modules/_vyos_interface.py +++ b/plugins/modules/_vyos_interface.py @@ -19,10 +19,11 @@ # along with Ansible. If not, see . # -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['deprecated'], - 'supported_by': 'network'} - +ANSIBLE_METADATA = { + 'metadata_version': '1.1', + 'status': ['deprecated'], + 'supported_by': 'network' +} DOCUMENTATION = """ --- @@ -181,7 +182,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network. \ vyos.vyos import vyos_argument_spec - def search_obj_in_list(name, lst): for o in lst: if o['name'] == name: @@ -214,7 +214,8 @@ def map_obj_to_commands(updates): if value and value != obj_in_have.get(item): if item == 'description': value = "\'" + str(value) + "\'" - commands.append(set_interface + ' ' + item + ' ' + str(value)) + commands.append(set_interface + ' ' + item + ' ' + + str(value)) if disable and not obj_in_have.get('disable', False): commands.append(set_interface + ' disable') @@ -227,7 +228,8 @@ def map_obj_to_commands(updates): if value: if item == 'description': value = "\'" + str(value) + "\'" - commands.append(set_interface + ' ' + item + ' ' + str(value)) + commands.append(set_interface + ' ' + item + ' ' + + str(value)) if disable: commands.append(set_interface + ' disable') @@ -330,23 +332,31 @@ def check_declarative_intent_params(module, want, result): command = 'show interfaces ethernet %s' % w['name'] rc, out, err = exec_command(module, command) if rc != 0: - module.fail_json(msg=to_text(err, errors='surrogate_then_replace'), command=command, rc=rc) + module.fail_json(msg=to_text(err, errors='surrogate_then_replace'), + command=command, + rc=rc) if want_state in ('up', 'down'): match = re.search(r'%s (\w+)' % 'state', out, re.M) have_state = None if match: have_state = match.group(1) - if have_state is None or not conditional(want_state, have_state.strip().lower()): + if have_state is None or not conditional( + want_state, + have_state.strip().lower()): failed_conditions.append('state ' + 'eq(%s)' % want_state) if want_neighbors: have_host = [] have_port = [] if have_neighbors is None: - rc, have_neighbors, err = exec_command(module, 'show lldp neighbors detail') + rc, have_neighbors, err = exec_command( + module, 'show lldp neighbors detail') if rc != 0: - module.fail_json(msg=to_text(err, errors='surrogate_then_replace'), command=command, rc=rc) + module.fail_json(msg=to_text( + err, errors='surrogate_then_replace'), + command=command, + rc=rc) if have_neighbors: lines = have_neighbors.strip().split('Interface: ') @@ -372,23 +382,21 @@ def check_declarative_intent_params(module, want, result): def main(): """ main entry point for module execution """ - neighbors_spec = dict( - host=dict(), - port=dict() - ) - - element_spec = dict( - name=dict(), - description=dict(), - speed=dict(), - mtu=dict(type='int'), - duplex=dict(choices=['full', 'half', 'auto']), - enabled=dict(default=True, type='bool'), - neighbors=dict(type='list', elements='dict', options=neighbors_spec), - delay=dict(default=10, type='int'), - state=dict(default='present', - choices=['present', 'absent', 'up', 'down']) - ) + neighbors_spec = dict(host=dict(), port=dict()) + + element_spec = dict(name=dict(), + description=dict(), + speed=dict(), + mtu=dict(type='int'), + duplex=dict(choices=['full', 'half', 'auto']), + enabled=dict(default=True, type='bool'), + neighbors=dict(type='list', + elements='dict', + options=neighbors_spec), + delay=dict(default=10, type='int'), + state=dict(default='present', + choices=['present', 'absent', 'up', + 'down'])) aggregate_spec = deepcopy(element_spec) aggregate_spec['name'] = dict(required=True) @@ -396,9 +404,9 @@ def main(): # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) - argument_spec = dict( - aggregate=dict(type='list', elements='dict', options=aggregate_spec), - ) + argument_spec = dict(aggregate=dict(type='list', + elements='dict', + options=aggregate_spec), ) argument_spec.update(element_spec) argument_spec.update(vyos_argument_spec) diff --git a/plugins/modules/_vyos_l3_interface.py b/plugins/modules/_vyos_l3_interface.py index 63f0873..15668d4 100644 --- a/plugins/modules/_vyos_l3_interface.py +++ b/plugins/modules/_vyos_l3_interface.py @@ -19,10 +19,11 @@ # along with Ansible. If not, see . # -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['deprecated'], - 'supported_by': 'network'} - +ANSIBLE_METADATA = { + 'metadata_version': '1.1', + 'status': ['deprecated'], + 'supported_by': 'network' +} DOCUMENTATION = """ --- @@ -108,7 +109,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network. \ vyos.vyos import vyos_argument_spec - def is_ipv4(value): if value: address = value.split('/') @@ -150,34 +150,44 @@ def map_obj_to_commands(updates, module): obj_in_have = search_obj_in_list(name, have) if state == 'absent' and obj_in_have: - if not ipv4 and not ipv6 and (obj_in_have['ipv4'] or obj_in_have['ipv6']): + if not ipv4 and not ipv6 and (obj_in_have['ipv4'] + or obj_in_have['ipv6']): if name == "lo": commands.append('delete interfaces loopback lo address') else: - commands.append('delete interfaces ethernet ' + name + ' address') + commands.append('delete interfaces ethernet ' + name + + ' address') else: if ipv4 and ipv4 in obj_in_have['ipv4']: if name == "lo": - commands.append('delete interfaces loopback lo address ' + ipv4) + commands.append( + 'delete interfaces loopback lo address ' + ipv4) else: - commands.append('delete interfaces ethernet ' + name + ' address ' + ipv4) + commands.append('delete interfaces ethernet ' + name + + ' address ' + ipv4) if ipv6 and ipv6 in obj_in_have['ipv6']: if name == "lo": - commands.append('delete interfaces loopback lo address ' + ipv6) + commands.append( + 'delete interfaces loopback lo address ' + ipv6) else: - commands.append('delete interfaces ethernet ' + name + ' address ' + ipv6) + commands.append('delete interfaces ethernet ' + name + + ' address ' + ipv6) elif (state == 'present' and obj_in_have): if ipv4 and ipv4 not in obj_in_have['ipv4']: if name == "lo": - commands.append('set interfaces loopback lo address ' + ipv4) + commands.append('set interfaces loopback lo address ' + + ipv4) else: - commands.append('set interfaces ethernet ' + name + ' address ' + ipv4) + commands.append('set interfaces ethernet ' + name + + ' address ' + ipv4) if ipv6 and ipv6 not in obj_in_have['ipv6']: if name == "lo": - commands.append('set interfaces loopback lo address ' + ipv6) + commands.append('set interfaces loopback lo address ' + + ipv6) else: - commands.append('set interfaces ethernet ' + name + ' address ' + ipv6) + commands.append('set interfaces ethernet ' + name + + ' address ' + ipv6) return commands @@ -208,9 +218,7 @@ def map_config_to_obj(module): elif is_ipv6(value): ipv6.append(value) - obj.append({'name': name, - 'ipv4': ipv4, - 'ipv6': ipv6}) + obj.append({'name': name, 'ipv4': ipv4, 'ipv6': ipv6}) return obj @@ -240,13 +248,11 @@ def map_params_to_obj(module): def main(): """ main entry point for module execution """ - element_spec = dict( - name=dict(), - ipv4=dict(), - ipv6=dict(), - state=dict(default='present', - choices=['present', 'absent']) - ) + element_spec = dict(name=dict(), + ipv4=dict(), + ipv6=dict(), + state=dict(default='present', + choices=['present', 'absent'])) aggregate_spec = deepcopy(element_spec) aggregate_spec['name'] = dict(required=True) @@ -254,9 +260,9 @@ def main(): # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) - argument_spec = dict( - aggregate=dict(type='list', elements='dict', options=aggregate_spec), - ) + argument_spec = dict(aggregate=dict(type='list', + elements='dict', + options=aggregate_spec), ) argument_spec.update(element_spec) argument_spec.update(vyos_argument_spec) diff --git a/plugins/modules/vyos_banner.py b/plugins/modules/vyos_banner.py index 1f8816a..7f07099 100644 --- a/plugins/modules/vyos_banner.py +++ b/plugins/modules/vyos_banner.py @@ -19,9 +19,11 @@ # along with Ansible. If not, see . # -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'network'} +ANSIBLE_METADATA = { + 'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'network' +} DOCUMENTATION = """ --- @@ -93,19 +95,21 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network. \ vyos.vyos import vyos_argument_spec - def spec_to_commands(updates, module): commands = list() want, have = updates state = module.params['state'] if state == 'absent': - if have.get('state') != 'absent' or (have.get('state') != 'absent' and - 'text' in have.keys() and have['text']): - commands.append('delete system login banner %s' % module.params['banner']) + if have.get('state') != 'absent' or (have.get('state') != 'absent' + and 'text' in have.keys() + and have['text']): + commands.append('delete system login banner %s' % + module.params['banner']) elif state == 'present': - if want['text'] and want['text'].encode().decode('unicode_escape') != have.get('text'): + if want['text'] and want['text'].encode().decode( + 'unicode_escape') != have.get('text'): banner_cmd = 'set system login banner %s ' % module.params['banner'] banner_cmd += want['text'].strip() commands.append(banner_cmd) @@ -144,15 +148,15 @@ def map_params_to_obj(module): def main(): """ main entry point for module execution """ - argument_spec = dict( - banner=dict(required=True, choices=['pre-login', 'post-login']), - text=dict(), - state=dict(default='present', choices=['present', 'absent']) - ) + argument_spec = dict(banner=dict(required=True, + choices=['pre-login', 'post-login']), + text=dict(), + state=dict(default='present', + choices=['present', 'absent'])) argument_spec.update(vyos_argument_spec) - required_if = [('state', 'present', ('text',))] + required_if = [('state', 'present', ('text', ))] module = AnsibleModule(argument_spec=argument_spec, required_if=required_if, diff --git a/plugins/modules/vyos_command.py b/plugins/modules/vyos_command.py index 3570f20..cf08ef6 100644 --- a/plugins/modules/vyos_command.py +++ b/plugins/modules/vyos_command.py @@ -16,10 +16,11 @@ # along with Ansible. If not, see . # -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'network'} - +ANSIBLE_METADATA = { + 'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'network' +} DOCUMENTATION = """ --- @@ -149,7 +150,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network. \ vyos.vyos import vyos_argument_spec - def parse_commands(module, warnings): commands = transform_commands(module) @@ -158,23 +158,18 @@ def parse_commands(module, warnings): if not item['command'].startswith('show'): warnings.append( 'Only show commands are supported when using check mode, not ' - 'executing %s' % item['command'] - ) + 'executing %s' % item['command']) commands.remove(item) return commands def main(): - spec = dict( - commands=dict(type='list', required=True), - - wait_for=dict(type='list', aliases=['waitfor']), - match=dict(default='all', choices=['all', 'any']), - - retries=dict(default=10, type='int'), - interval=dict(default=1, type='int') - ) + spec = dict(commands=dict(type='list', required=True), + wait_for=dict(type='list', aliases=['waitfor']), + match=dict(default='all', choices=['all', 'any']), + retries=dict(default=10, type='int'), + interval=dict(default=1, type='int')) spec.update(vyos_argument_spec) diff --git a/plugins/modules/vyos_config.py b/plugins/modules/vyos_config.py index 7987e14..7f8e71b 100644 --- a/plugins/modules/vyos_config.py +++ b/plugins/modules/vyos_config.py @@ -16,10 +16,11 @@ # along with Ansible. If not, see . # -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'network'} - +ANSIBLE_METADATA = { + 'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'network' +} DOCUMENTATION = """ --- @@ -193,8 +194,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network. \ from ansible_collections.vyos.vyos.plugins.module_utils.network. \ vyos.vyos import vyos_argument_spec, get_connection - - DEFAULT_COMMENT = 'configured by vyos_config' CONFIG_FILTERS = [ @@ -268,7 +267,9 @@ def run(module, result): # create loadable config that includes only the configuration updates connection = get_connection(module) try: - response = connection.get_diff(candidate=candidate, running=config, diff_match=module.params['match']) + response = connection.get_diff(candidate=candidate, + running=config, + diff_match=module.params['match']) except ConnectionError as exc: module.fail_json(msg=to_text(exc, errors='surrogate_then_replace')) @@ -295,20 +296,13 @@ def run(module, result): def main(): - backup_spec = dict( - filename=dict(), - dir_path=dict(type='path') - ) + backup_spec = dict(filename=dict(), dir_path=dict(type='path')) argument_spec = dict( src=dict(type='path'), lines=dict(type='list'), - match=dict(default='line', choices=['line', 'none']), - comment=dict(default=DEFAULT_COMMENT), - config=dict(), - backup=dict(type='bool', default=False), backup_options=dict(type='dict', options=backup_spec), save=dict(type='bool', default=False), @@ -318,11 +312,9 @@ def main(): mutually_exclusive = [('lines', 'src')] - module = AnsibleModule( - argument_spec=argument_spec, - mutually_exclusive=mutually_exclusive, - supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, + mutually_exclusive=mutually_exclusive, + supports_check_mode=True) warnings = list() diff --git a/plugins/modules/vyos_facts.py b/plugins/modules/vyos_facts.py index 5c8ac51..27e361d 100644 --- a/plugins/modules/vyos_facts.py +++ b/plugins/modules/vyos_facts.py @@ -7,11 +7,11 @@ The module file for vyos_facts """ - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': [u'preview'], - 'supported_by': 'network'} - +ANSIBLE_METADATA = { + 'metadata_version': '1.1', + 'status': [u'preview'], + 'supported_by': 'network' +} DOCUMENTATION = """ --- @@ -145,7 +145,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network. \ vyos.vyos import vyos_argument_spec - def main(): """ Main entry point for module execution @@ -159,8 +158,10 @@ def main(): module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) - warnings = ['default value for `gather_subset` ' - 'will be changed to `min` from `!config` v2.11 onwards'] + warnings = [ + 'default value for `gather_subset` ' + 'will be changed to `min` from `!config` v2.11 onwards' + ] result = Facts(module).get_facts() diff --git a/plugins/modules/vyos_interfaces.py b/plugins/modules/vyos_interfaces.py index a78a983..feef493 100644 --- a/plugins/modules/vyos_interfaces.py +++ b/plugins/modules/vyos_interfaces.py @@ -21,7 +21,6 @@ # builder template. # ############################################# - """ The module file for vyos_interfaces """ @@ -853,7 +852,6 @@ commands: - 'set interfaces ethernet eth2 vif 100 description VIF 100' """ - from ansible.module_utils.basic import AnsibleModule from ansible_collections.vyos.vyos.plugins.module_utils.network. \ vyos.argspec.interfaces.interfaces import InterfacesArgs @@ -862,7 +860,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network. \ vyos.config.interfaces.interfaces import Interfaces - def main(): """ Main entry point for module execution diff --git a/plugins/modules/vyos_l3_interfaces.py b/plugins/modules/vyos_l3_interfaces.py index c2dd461..126c6c8 100644 --- a/plugins/modules/vyos_l3_interfaces.py +++ b/plugins/modules/vyos_l3_interfaces.py @@ -21,7 +21,6 @@ # builder template. # ############################################# - """ The module file for vyos_l3_interfaces """ @@ -349,7 +348,6 @@ commands: sample: ['set interfaces ethernet eth1 192.0.2.14/2', 'set interfaces ethernet eth3 vif 101 address 198.51.100.130/25'] """ - from ansible.module_utils.basic import AnsibleModule from ansible_collections.vyos.vyos.plugins.module_utils.network. \ vyos.argspec.l3_interfaces.l3_interfaces import L3_interfacesArgs @@ -358,7 +356,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network. \ vyos.config.l3_interfaces.l3_interfaces import L3_interfaces - def main(): """ Main entry point for module execution diff --git a/plugins/modules/vyos_linkagg.py b/plugins/modules/vyos_linkagg.py index 71f46ba..d2ba003 100644 --- a/plugins/modules/vyos_linkagg.py +++ b/plugins/modules/vyos_linkagg.py @@ -19,10 +19,11 @@ # along with Ansible. If not, see . # -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'network'} - +ANSIBLE_METADATA = { + 'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'network' +} DOCUMENTATION = """ --- @@ -107,7 +108,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network. \ vyos.vyos import vyos_argument_spec - def search_obj_in_list(name, lst): for o in lst: if o['name'] == name: @@ -135,30 +135,39 @@ def map_obj_to_commands(updates, module): if state == 'absent': if obj_in_have: for m in obj_in_have['members']: - commands.append('delete interfaces ethernet ' + m + ' bond-group') + commands.append('delete interfaces ethernet ' + m + + ' bond-group') commands.append('delete interfaces bonding ' + name) else: if not obj_in_have: - commands.append('set interfaces bonding ' + name + ' mode ' + mode) + commands.append('set interfaces bonding ' + name + ' mode ' + + mode) for m in members: - commands.append('set interfaces ethernet ' + m + ' bond-group ' + name) + commands.append('set interfaces ethernet ' + m + + ' bond-group ' + name) if state == 'down': - commands.append('set interfaces bonding ' + name + ' disable') + commands.append('set interfaces bonding ' + name + + ' disable') else: if mode != obj_in_have['mode']: - commands.append('set interfaces bonding ' + name + ' mode ' + mode) + commands.append('set interfaces bonding ' + name + + ' mode ' + mode) - missing_members = list(set(members) - set(obj_in_have['members'])) + missing_members = list( + set(members) - set(obj_in_have['members'])) for m in missing_members: - commands.append('set interfaces ethernet ' + m + ' bond-group ' + name) + commands.append('set interfaces ethernet ' + m + + ' bond-group ' + name) if state == 'down' and obj_in_have['state'] == 'up': - commands.append('set interfaces bonding ' + name + ' disable') + commands.append('set interfaces bonding ' + name + + ' disable') elif state == 'up' and obj_in_have['state'] == 'down': - commands.append('delete interfaces bonding ' + name + ' disable') + commands.append('delete interfaces bonding ' + name + + ' disable') return commands @@ -181,10 +190,12 @@ def map_config_to_obj(module): else: members = [] - obj.append({'name': name, - 'mode': mode, - 'members': members, - 'state': state}) + obj.append({ + 'name': name, + 'mode': mode, + 'members': members, + 'state': state + }) return obj @@ -213,16 +224,17 @@ def map_params_to_obj(module): def main(): """ main entry point for module execution """ - element_spec = dict( - name=dict(), - mode=dict(choices=['802.3ad', 'active-backup', 'broadcast', - 'round-robin', 'transmit-load-balance', - 'adaptive-load-balance', 'xor-hash', 'on'], - default='802.3ad'), - members=dict(type='list'), - state=dict(default='present', - choices=['present', 'absent', 'up', 'down']) - ) + element_spec = dict(name=dict(), + mode=dict(choices=[ + '802.3ad', 'active-backup', 'broadcast', + 'round-robin', 'transmit-load-balance', + 'adaptive-load-balance', 'xor-hash', 'on' + ], + default='802.3ad'), + members=dict(type='list'), + state=dict(default='present', + choices=['present', 'absent', 'up', + 'down'])) aggregate_spec = deepcopy(element_spec) aggregate_spec['name'] = dict(required=True) @@ -230,9 +242,9 @@ def main(): # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) - argument_spec = dict( - aggregate=dict(type='list', elements='dict', options=aggregate_spec), - ) + argument_spec = dict(aggregate=dict(type='list', + elements='dict', + options=aggregate_spec), ) argument_spec.update(element_spec) argument_spec.update(vyos_argument_spec) diff --git a/plugins/modules/vyos_lldp.py b/plugins/modules/vyos_lldp.py index fa1ac03..5e33000 100644 --- a/plugins/modules/vyos_lldp.py +++ b/plugins/modules/vyos_lldp.py @@ -19,10 +19,11 @@ # along with Ansible. If not, see . # -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'network'} - +ANSIBLE_METADATA = { + 'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'network' +} DOCUMENTATION = """ --- @@ -70,7 +71,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network. \ vyos.vyos import vyos_argument_spec - def has_lldp(module): config = get_config(module).splitlines() @@ -86,9 +86,7 @@ def main(): argument_spec = dict( interfaces=dict(type='list'), state=dict(default='present', - choices=['present', 'absent', - 'enabled', 'disabled']) - ) + choices=['present', 'absent', 'enabled', 'disabled'])) argument_spec.update(vyos_argument_spec) diff --git a/plugins/modules/vyos_lldp_interface.py b/plugins/modules/vyos_lldp_interface.py index 86a64e3..aca3224 100644 --- a/plugins/modules/vyos_lldp_interface.py +++ b/plugins/modules/vyos_lldp_interface.py @@ -19,10 +19,11 @@ # along with Ansible. If not, see . # -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'network'} - +ANSIBLE_METADATA = { + 'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'network' +} DOCUMENTATION = """ --- @@ -100,7 +101,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network. \ vyos.vyos import vyos_argument_spec - def search_obj_in_list(name, lst): for o in lst: if o['name'] == name: @@ -124,14 +124,18 @@ def map_obj_to_commands(updates, module): elif state in ('present', 'enabled'): if not obj_in_have: commands.append('set service lldp interface ' + name) - elif obj_in_have and obj_in_have['state'] == 'disabled' and state == 'enabled': - commands.append('delete service lldp interface ' + name + ' disable') + elif obj_in_have and obj_in_have[ + 'state'] == 'disabled' and state == 'enabled': + commands.append('delete service lldp interface ' + name + + ' disable') elif state == 'disabled': if not obj_in_have: commands.append('set service lldp interface ' + name) - commands.append('set service lldp interface ' + name + ' disable') + commands.append('set service lldp interface ' + name + + ' disable') elif obj_in_have and obj_in_have['state'] != 'disabled': - commands.append('set service lldp interface ' + name + ' disable') + commands.append('set service lldp interface ' + name + + ' disable') return commands @@ -171,7 +175,10 @@ def map_params_to_obj(module): obj.append(item.copy()) else: - obj.append({'name': module.params['name'], 'state': module.params['state']}) + obj.append({ + 'name': module.params['name'], + 'state': module.params['state'] + }) return obj @@ -182,9 +189,7 @@ def main(): element_spec = dict( name=dict(), state=dict(default='present', - choices=['present', 'absent', - 'enabled', 'disabled']) - ) + choices=['present', 'absent', 'enabled', 'disabled'])) aggregate_spec = deepcopy(element_spec) aggregate_spec['name'] = dict(required=True) @@ -192,9 +197,9 @@ def main(): # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) - argument_spec = dict( - aggregate=dict(type='list', elements='dict', options=aggregate_spec), - ) + argument_spec = dict(aggregate=dict(type='list', + elements='dict', + options=aggregate_spec), ) argument_spec.update(element_spec) argument_spec.update(vyos_argument_spec) diff --git a/plugins/modules/vyos_logging.py b/plugins/modules/vyos_logging.py index a94a8bd..e682e42 100644 --- a/plugins/modules/vyos_logging.py +++ b/plugins/modules/vyos_logging.py @@ -19,9 +19,11 @@ # along with Ansible. If not, see . # -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'network'} +ANSIBLE_METADATA = { + 'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'network' +} DOCUMENTATION = """ --- @@ -117,7 +119,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network. \ vyos.vyos import vyos_argument_spec - def spec_to_commands(updates, module): commands = list() want, have = updates @@ -132,18 +133,22 @@ def spec_to_commands(updates, module): if state == 'absent' and w in have: if w['name']: - commands.append('delete system syslog {0} {1} facility {2} level {3}'.format( - dest, name, facility, level)) + commands.append( + 'delete system syslog {0} {1} facility {2} level {3}'. + format(dest, name, facility, level)) else: - commands.append('delete system syslog {0} facility {1} level {2}'.format( - dest, facility, level)) + commands.append( + 'delete system syslog {0} facility {1} level {2}'.format( + dest, facility, level)) elif state == 'present' and w not in have: if w['name']: - commands.append('set system syslog {0} {1} facility {2} level {3}'.format( - dest, name, facility, level)) + commands.append( + 'set system syslog {0} {1} facility {2} level {3}'.format( + dest, name, facility, level)) else: - commands.append('set system syslog {0} facility {1} level {2}'.format( - dest, facility, level)) + commands.append( + 'set system syslog {0} facility {1} level {2}'.format( + dest, facility, level)) return commands @@ -175,10 +180,12 @@ def config_to_dict(module): match = re.search(r'level (\S+)', line, re.M) level = match.group(1).strip("'") - obj.append({'dest': dest, - 'name': name, - 'facility': facility, - 'level': level}) + obj.append({ + 'dest': dest, + 'name': name, + 'facility': facility, + 'level': level + }) return obj @@ -215,7 +222,8 @@ def main(): """ main entry point for module execution """ element_spec = dict( - dest=dict(type='str', choices=['console', 'file', 'global', 'host', 'user']), + dest=dict(type='str', + choices=['console', 'file', 'global', 'host', 'user']), name=dict(type='str'), facility=dict(type='str'), level=dict(type='str'), @@ -227,9 +235,9 @@ def main(): # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) - argument_spec = dict( - aggregate=dict(type='list', elements='dict', options=aggregate_spec), - ) + argument_spec = dict(aggregate=dict(type='list', + elements='dict', + options=aggregate_spec), ) argument_spec.update(element_spec) diff --git a/plugins/modules/vyos_ping.py b/plugins/modules/vyos_ping.py index 762bc80..f5657ff 100644 --- a/plugins/modules/vyos_ping.py +++ b/plugins/modules/vyos_ping.py @@ -22,9 +22,11 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} +ANSIBLE_METADATA = { + 'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'community' +} DOCUMENTATION = """ --- @@ -149,7 +151,9 @@ def main(): ttl=dict(type='int'), size=dict(type='int'), interval=dict(type='int'), - state=dict(type="str", choices=["absent", "present"], default="present"), + state=dict(type="str", + choices=["absent", "present"], + default="present"), ) argument_spec.update(vyos_argument_spec) @@ -169,7 +173,9 @@ def main(): if warnings: results["warnings"] = warnings - results["commands"] = [build_ping(dest, count, size, interval, source, ttl)] + results["commands"] = [ + build_ping(dest, count, size, interval, source, ttl) + ] ping_results = run_commands(module, commands=results["commands"]) ping_results_list = ping_results[0].split("\n") @@ -218,9 +224,11 @@ def build_ping(dest, count, size=None, interval=None, source=None, ttl=None): def parse_rate(rate_info): rate_re = re.compile( - r"(?P\d+) (?:\w+) (?:\w+), (?P\d+) (?:\w+), (?P\d+)% (?:\w+) (?:\w+), (?:\w+) (?P