diff options
Diffstat (limited to 'plugins/modules')
| -rw-r--r-- | plugins/modules/_vyos_interface.py | 70 | ||||
| -rw-r--r-- | plugins/modules/_vyos_l3_interface.py | 62 | ||||
| -rw-r--r-- | plugins/modules/vyos_banner.py | 32 | ||||
| -rw-r--r-- | plugins/modules/vyos_command.py | 27 | ||||
| -rw-r--r-- | plugins/modules/vyos_config.py | 32 | ||||
| -rw-r--r-- | plugins/modules/vyos_facts.py | 17 | ||||
| -rw-r--r-- | plugins/modules/vyos_interfaces.py | 3 | ||||
| -rw-r--r-- | plugins/modules/vyos_l3_interfaces.py | 3 | ||||
| -rw-r--r-- | plugins/modules/vyos_linkagg.py | 74 | ||||
| -rw-r--r-- | plugins/modules/vyos_lldp.py | 14 | ||||
| -rw-r--r-- | plugins/modules/vyos_lldp_interface.py | 37 | ||||
| -rw-r--r-- | plugins/modules/vyos_logging.py | 48 | ||||
| -rw-r--r-- | plugins/modules/vyos_ping.py | 25 | ||||
| -rw-r--r-- | plugins/modules/vyos_static_route.py | 55 | ||||
| -rw-r--r-- | plugins/modules/vyos_system.py | 20 | ||||
| -rw-r--r-- | plugins/modules/vyos_user.py | 49 | ||||
| -rw-r--r-- | plugins/modules/vyos_vlan.py | 78 | 
17 files changed, 351 insertions, 295 deletions
| diff --git a/plugins/modules/_vyos_interface.py b/plugins/modules/_vyos_interface.py index e4b989e8..35b3a2cd 100644 --- a/plugins/modules/_vyos_interface.py +++ b/plugins/modules/_vyos_interface.py @@ -19,10 +19,11 @@  # along with Ansible.  If not, see <http://www.gnu.org/licenses/>.  # -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 63f08732..15668d4b 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 <http://www.gnu.org/licenses/>.  # -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 1f8816ac..7f070994 100644 --- a/plugins/modules/vyos_banner.py +++ b/plugins/modules/vyos_banner.py @@ -19,9 +19,11 @@  # along with Ansible.  If not, see <http://www.gnu.org/licenses/>.  # -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 3570f207..cf08ef67 100644 --- a/plugins/modules/vyos_command.py +++ b/plugins/modules/vyos_command.py @@ -16,10 +16,11 @@  # along with Ansible.  If not, see <http://www.gnu.org/licenses/>.  # -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 7987e148..7f8e71b4 100644 --- a/plugins/modules/vyos_config.py +++ b/plugins/modules/vyos_config.py @@ -16,10 +16,11 @@  # along with Ansible.  If not, see <http://www.gnu.org/licenses/>.  # -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 5c8ac518..27e361d5 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 a78a983d..feef4932 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 c2dd4610..126c6c87 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 71f46ba8..d2ba0032 100644 --- a/plugins/modules/vyos_linkagg.py +++ b/plugins/modules/vyos_linkagg.py @@ -19,10 +19,11 @@  # along with Ansible.  If not, see <http://www.gnu.org/licenses/>.  # -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 fa1ac03a..5e330008 100644 --- a/plugins/modules/vyos_lldp.py +++ b/plugins/modules/vyos_lldp.py @@ -19,10 +19,11 @@  # along with Ansible.  If not, see <http://www.gnu.org/licenses/>.  # -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 86a64e32..aca32249 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 <http://www.gnu.org/licenses/>.  # -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 a94a8bd2..e682e42f 100644 --- a/plugins/modules/vyos_logging.py +++ b/plugins/modules/vyos_logging.py @@ -19,9 +19,11 @@  # along with Ansible.  If not, see <http://www.gnu.org/licenses/>.  # -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 762bc801..f5657ffe 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<tx>\d+) (?:\w+) (?:\w+), (?P<rx>\d+) (?:\w+), (?P<pkt_loss>\d+)% (?:\w+) (?:\w+), (?:\w+) (?P<time>\d+)") +        r"(?P<tx>\d+) (?:\w+) (?:\w+), (?P<rx>\d+) (?:\w+), (?P<pkt_loss>\d+)% (?:\w+) (?:\w+), (?:\w+) (?P<time>\d+)" +    )      rate_err_re = re.compile( -        r"(?P<tx>\d+) (?:\w+) (?:\w+), (?P<rx>\d+) (?:\w+), (?:[+-])(?P<err>\d+) (?:\w+), (?P<pkt_loss>\d+)% (?:\w+) (?:\w+), (?:\w+) (?P<time>\d+)") +        r"(?P<tx>\d+) (?:\w+) (?:\w+), (?P<rx>\d+) (?:\w+), (?:[+-])(?P<err>\d+) (?:\w+), (?P<pkt_loss>\d+)% (?:\w+) (?:\w+), (?:\w+) (?P<time>\d+)" +    )      if rate_re.match(rate_info):          rate = rate_re.match(rate_info) @@ -232,7 +240,8 @@ def parse_rate(rate_info):  def parse_rtt(rtt_info):      rtt_re = re.compile( -        r"rtt (?:.*)=(?:\s*)(?P<min>\d*).(?:\d*)/(?P<avg>\d*).(?:\d*)/(?P<max>\d+).(?:\d*)/(?P<mdev>\d*)") +        r"rtt (?:.*)=(?:\s*)(?P<min>\d*).(?:\d*)/(?P<avg>\d*).(?:\d*)/(?P<max>\d+).(?:\d*)/(?P<mdev>\d*)" +    )      rtt = rtt_re.match(rtt_info)      return rtt.groupdict() diff --git a/plugins/modules/vyos_static_route.py b/plugins/modules/vyos_static_route.py index 3c00bcaf..777706c8 100644 --- a/plugins/modules/vyos_static_route.py +++ b/plugins/modules/vyos_static_route.py @@ -19,10 +19,11 @@  # along with Ansible.  If not, see <http://www.gnu.org/licenses/>.  # -ANSIBLE_METADATA = {'metadata_version': '1.1', -                    'status': ['preview'], -                    'supported_by': 'network'} - +ANSIBLE_METADATA = { +    'metadata_version': '1.1', +    'status': ['preview'], +    'supported_by': 'network' +}  DOCUMENTATION = """  --- @@ -115,7 +116,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 @@ -128,9 +128,11 @@ def spec_to_commands(updates, module):          del w['state']          if state == 'absent' and w in have: -            commands.append('delete protocols static route %s/%s' % (prefix, mask)) +            commands.append('delete protocols static route %s/%s' % +                            (prefix, mask))          elif state == 'present' and w not in have: -            cmd = 'set protocols static route %s/%s next-hop %s' % (prefix, mask, next_hop) +            cmd = 'set protocols static route %s/%s next-hop %s' % ( +                prefix, mask, next_hop)              if admin_distance != 'None':                  cmd += ' distance %s' % (admin_distance)              commands.append(cmd) @@ -158,15 +160,19 @@ def config_to_dict(module):                      admin_distance = None                  if admin_distance is not None: -                    obj.append({'prefix': prefix, -                                'mask': mask, -                                'next_hop': next_hop, -                                'admin_distance': admin_distance}) +                    obj.append({ +                        'prefix': prefix, +                        'mask': mask, +                        'next_hop': next_hop, +                        'admin_distance': admin_distance +                    })                  else: -                    obj.append({'prefix': prefix, -                                'mask': mask, -                                'next_hop': next_hop, -                                'admin_distance': 'None'}) +                    obj.append({ +                        'prefix': prefix, +                        'mask': mask, +                        'next_hop': next_hop, +                        'admin_distance': 'None' +                    })      return obj @@ -215,13 +221,12 @@ def map_params_to_obj(module, required_together=None):  def main():      """ main entry point for module execution      """ -    element_spec = dict( -        prefix=dict(type='str'), -        mask=dict(type='str'), -        next_hop=dict(type='str'), -        admin_distance=dict(type='int'), -        state=dict(default='present', choices=['present', 'absent']) -    ) +    element_spec = dict(prefix=dict(type='str'), +                        mask=dict(type='str'), +                        next_hop=dict(type='str'), +                        admin_distance=dict(type='int'), +                        state=dict(default='present', +                                   choices=['present', 'absent']))      aggregate_spec = deepcopy(element_spec)      aggregate_spec['prefix'] = dict(required=True) @@ -229,9 +234,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_system.py b/plugins/modules/vyos_system.py index 20cf907f..449d142c 100644 --- a/plugins/modules/vyos_system.py +++ b/plugins/modules/vyos_system.py @@ -17,10 +17,11 @@  # along with Ansible.  If not, see <http://www.gnu.org/licenses/>.  # -ANSIBLE_METADATA = {'metadata_version': '1.1', -                    'status': ['preview'], -                    'supported_by': 'network'} - +ANSIBLE_METADATA = { +    'metadata_version': '1.1', +    'status': ['preview'], +    'supported_by': 'network' +}  DOCUMENTATION = """  --- @@ -99,7 +100,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network. \    vyos.vyos import vyos_argument_spec -  def spec_key_to_device_key(key):      device_key = key.replace('_', '-') @@ -154,9 +154,11 @@ def spec_to_commands(want, have):                  commands.append("delete system %s" % device_key)              for config in proposed:                  if state == 'absent' and config in current: -                    commands.append("delete system %s '%s'" % (device_key, config)) +                    commands.append("delete system %s '%s'" % +                                    (device_key, config))                  elif state == 'present' and config not in current: -                    commands.append("set system %s '%s'" % (device_key, config)) +                    commands.append("set system %s '%s'" % +                                    (device_key, config))          else:              if state == 'absent' and current and proposed:                  commands.append('delete system %s' % device_key) @@ -182,7 +184,9 @@ def main():          domain_name=dict(type='str'),          domain_search=dict(type='list'),          name_server=dict(type='list', aliases=['name_servers']), -        state=dict(type='str', default='present', choices=['present', 'absent']), +        state=dict(type='str', +                   default='present', +                   choices=['present', 'absent']),      )      argument_spec.update(vyos_argument_spec) diff --git a/plugins/modules/vyos_user.py b/plugins/modules/vyos_user.py index e670d559..f4fd77d4 100644 --- a/plugins/modules/vyos_user.py +++ b/plugins/modules/vyos_user.py @@ -19,9 +19,11 @@  # along with Ansible.  If not, see <http://www.gnu.org/licenses/>.  # -ANSIBLE_METADATA = {'metadata_version': '1.1', -                    'status': ['preview'], -                    'supported_by': 'network'} +ANSIBLE_METADATA = { +    'metadata_version': '1.1', +    'status': ['preview'], +    'supported_by': 'network' +}  DOCUMENTATION = """  --- @@ -145,10 +147,10 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network. \    vyos.vyos import vyos_argument_spec -  def validate_level(value, module):      if value not in ('admin', 'operator'): -        module.fail_json(msg='level must be either admin or operator, got %s' % value) +        module.fail_json(msg='level must be either admin or operator, got %s' % +                         value)  def spec_to_commands(updates, module): @@ -177,7 +179,9 @@ def spec_to_commands(updates, module):          if needs_update(want, have, 'configured_password'):              if update_password == 'always' or not have: -                add(commands, want, 'authentication plaintext-password %s' % want['configured_password']) +                add( +                    commands, want, 'authentication plaintext-password %s' % +                    want['configured_password'])      return commands @@ -278,17 +282,14 @@ def update_objects(want, have):  def main():      """ main entry point for module execution      """ -    element_spec = dict( -        name=dict(), - -        full_name=dict(), -        level=dict(aliases=['role']), - -        configured_password=dict(no_log=True), -        update_password=dict(default='always', choices=['on_create', 'always']), - -        state=dict(default='present', choices=['present', 'absent']) -    ) +    element_spec = dict(name=dict(), +                        full_name=dict(), +                        level=dict(aliases=['role']), +                        configured_password=dict(no_log=True), +                        update_password=dict(default='always', +                                             choices=['on_create', 'always']), +                        state=dict(default='present', +                                   choices=['present', 'absent']))      aggregate_spec = deepcopy(element_spec)      aggregate_spec['name'] = dict(required=True) @@ -296,10 +297,11 @@ 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, aliases=['users', 'collection']), -        purge=dict(type='bool', default=False) -    ) +    argument_spec = dict(aggregate=dict(type='list', +                                        elements='dict', +                                        options=aggregate_spec, +                                        aliases=['users', 'collection']), +                         purge=dict(type='bool', default=False))      argument_spec.update(element_spec)      argument_spec.update(vyos_argument_spec) @@ -312,9 +314,8 @@ def main():      warnings = list()      if module.params['password'] and not module.params['configured_password']:          warnings.append( -            'The "password" argument is used to authenticate the current connection. ' + -            'To set a user password use "configured_password" instead.' -        ) +            'The "password" argument is used to authenticate the current connection. ' +            + 'To set a user password use "configured_password" instead.')      result = {'changed': False}      if warnings: diff --git a/plugins/modules/vyos_vlan.py b/plugins/modules/vyos_vlan.py index 88ab71b5..5273637d 100644 --- a/plugins/modules/vyos_vlan.py +++ b/plugins/modules/vyos_vlan.py @@ -7,10 +7,11 @@  from __future__ import absolute_import, division, print_function  __metaclass__ = type - -ANSIBLE_METADATA = {'metadata_version': '1.1', -                    'status': ['preview'], -                    'supported_by': 'network'} +ANSIBLE_METADATA = { +    'metadata_version': '1.1', +    'status': ['preview'], +    'supported_by': 'network' +}  DOCUMENTATION = """  --- @@ -129,7 +130,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network. \    vyos.vyos import vyos_argument_spec -  def search_obj_in_list(vlan_id, lst):      obj = list()      for o in lst: @@ -156,17 +156,22 @@ def map_obj_to_commands(updates, module):              if obj_in_have:                  for obj in obj_in_have:                      for i in obj['interfaces']: -                        commands.append('delete interfaces ethernet {0} vif {1}'.format(i, vlan_id)) +                        commands.append( +                            'delete interfaces ethernet {0} vif {1}'.format( +                                i, vlan_id))          elif state == 'present':              if not obj_in_have:                  if w['interfaces'] and w['vlan_id']:                      for i in w['interfaces']: -                        cmd = 'set interfaces ethernet {0} vif {1}'.format(i, vlan_id) +                        cmd = 'set interfaces ethernet {0} vif {1}'.format( +                            i, vlan_id)                          if w['name']: -                            commands.append(cmd + ' description {0}'.format(name)) +                            commands.append(cmd + +                                            ' description {0}'.format(name))                          elif w['address']: -                            commands.append(cmd + ' address {0}'.format(address)) +                            commands.append(cmd + +                                            ' address {0}'.format(address))                          else:                              commands.append(cmd) @@ -175,7 +180,9 @@ def map_obj_to_commands(updates, module):              obj_in_want = search_obj_in_list(h['vlan_id'], want)              if not obj_in_want:                  for i in h['interfaces']: -                    commands.append('delete interfaces ethernet {0} vif {1}'.format(i, h['vlan_id'])) +                    commands.append( +                        'delete interfaces ethernet {0} vif {1}'.format( +                            i, h['vlan_id']))      return commands @@ -200,12 +207,18 @@ def map_params_to_obj(module):              obj.append(d)      else:          obj.append({ -            'vlan_id': str(module.params['vlan_id']), -            'name': module.params['name'], -            'address': module.params['address'], -            'state': module.params['state'], -            'interfaces': module.params['interfaces'], -            'associated_interfaces': module.params['associated_interfaces'] +            'vlan_id': +            str(module.params['vlan_id']), +            'name': +            module.params['name'], +            'address': +            module.params['address'], +            'state': +            module.params['state'], +            'interfaces': +            module.params['interfaces'], +            'associated_interfaces': +            module.params['associated_interfaces']          })      return obj @@ -270,33 +283,34 @@ def check_declarative_intent_params(want, module, result):          if w.get('associated_interfaces') is None:              continue          for i in w['associated_interfaces']: -            if (set(obj_interface) - set(w['associated_interfaces'])) != set([]): -                module.fail_json(msg='Interface {0} not configured on vlan {1}'.format(i, w['vlan_id'])) +            if (set(obj_interface) - set(w['associated_interfaces'])) != set( +                []): +                module.fail_json( +                    msg='Interface {0} not configured on vlan {1}'.format( +                        i, w['vlan_id']))  def main():      """ main entry point for module execution      """ -    element_spec = dict( -        vlan_id=dict(type='int'), -        name=dict(), -        address=dict(), -        interfaces=dict(type='list'), -        associated_interfaces=dict(type='list'), -        delay=dict(default=10, type='int'), -        state=dict(default='present', -                   choices=['present', 'absent']) -    ) +    element_spec = dict(vlan_id=dict(type='int'), +                        name=dict(), +                        address=dict(), +                        interfaces=dict(type='list'), +                        associated_interfaces=dict(type='list'), +                        delay=dict(default=10, type='int'), +                        state=dict(default='present', +                                   choices=['present', 'absent']))      aggregate_spec = deepcopy(element_spec)      # 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), -        purge=dict(default=False, type='bool') -    ) +    argument_spec = dict(aggregate=dict(type='list', +                                        elements='dict', +                                        options=aggregate_spec), +                         purge=dict(default=False, type='bool'))      argument_spec.update(element_spec)      argument_spec.update(vyos_argument_spec) | 
