mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 14:40:19 -07:00
Update slxos_vlan for new SLX-OS versions, linting fixes (#52956)
This commit is contained in:
parent
4ea09d4d96
commit
b92d81cc01
32 changed files with 58 additions and 80 deletions
|
@ -221,13 +221,10 @@ backup_path:
|
|||
|
||||
"""
|
||||
import re
|
||||
import time
|
||||
|
||||
from ansible.module_utils.network.exos.exos import run_commands, get_config, load_config
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.network.common.parsing import Conditional
|
||||
from ansible.module_utils.network.common.config import NetworkConfig, dumps
|
||||
from ansible.module_utils.six import iteritems
|
||||
from ansible.module_utils._text import to_text
|
||||
|
||||
__metaclass__ = type
|
||||
|
|
|
@ -310,7 +310,6 @@ class Interfaces(FactsBase):
|
|||
return facts
|
||||
|
||||
def populate_interface_descriptions(self, data):
|
||||
facts = dict()
|
||||
for elem in data:
|
||||
if 'show_ports_description' not in elem:
|
||||
continue
|
||||
|
@ -444,7 +443,7 @@ def main():
|
|||
|
||||
warnings = list()
|
||||
|
||||
module.exit_json(ansible_facts=ansible_facts)
|
||||
module.exit_json(ansible_facts=ansible_facts, warnings=warnings)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -180,8 +180,7 @@ backup_path:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.network.ironware.ironware import ironware_argument_spec, check_args
|
||||
from ansible.module_utils.network.ironware.ironware import get_config, load_config, run_commands
|
||||
from ansible.module_utils.network.common.config import NetworkConfig, dumps, ConfigLine
|
||||
from ansible.module_utils._text import to_native
|
||||
from ansible.module_utils.network.common.config import NetworkConfig, dumps
|
||||
|
||||
|
||||
def get_candidate(module):
|
||||
|
@ -281,8 +280,6 @@ def main():
|
|||
|
||||
check_args(module)
|
||||
|
||||
config = None
|
||||
|
||||
if module.params['backup']:
|
||||
result['__backup__'] = get_config(module)
|
||||
|
||||
|
|
|
@ -138,7 +138,6 @@ from ansible.module_utils.network.ironware.ironware import run_commands
|
|||
from ansible.module_utils.network.ironware.ironware import ironware_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.six import iteritems
|
||||
from ansible.module_utils.six.moves import zip
|
||||
|
||||
|
||||
class FactsBase(object):
|
||||
|
@ -320,14 +319,14 @@ class MPLS(FactsBase):
|
|||
facts = list()
|
||||
regex = r'End-point[0-9 ]*: +(?P<tagged>tagged|untagged) +(vlan +(?P<vlan>[0-9]+) +)?(inner- vlan +(?P<innervlan>[0-9]+) +)?(?P<port>e [0-9/]+|--)'
|
||||
matches = re.finditer(regex, data, re.IGNORECASE | re.DOTALL)
|
||||
for n, match in enumerate(matches):
|
||||
for match in matches:
|
||||
f = match.groupdict()
|
||||
f['type'] = 'local'
|
||||
facts.append(f)
|
||||
|
||||
regex = r'Vll-Peer +: +(?P<vllpeer>[0-9\.]+).*Tunnel LSP +: +(?P<lsp>\S+)'
|
||||
matches = re.finditer(regex, data, re.IGNORECASE | re.DOTALL)
|
||||
for n, match in enumerate(matches):
|
||||
for match in matches:
|
||||
f = match.groupdict()
|
||||
f['type'] = 'remote'
|
||||
facts.append(f)
|
||||
|
@ -343,14 +342,14 @@ class MPLS(FactsBase):
|
|||
facts = list()
|
||||
regex = r'Vlan (?P<vlanid>[0-9]+)\s(?: +(?:L2.*)\s| +Tagged: (?P<tagged>.+)+\s| +Untagged: (?P<untagged>.+)\s)*'
|
||||
matches = re.finditer(regex, data, re.IGNORECASE)
|
||||
for n, match in enumerate(matches):
|
||||
for match in matches:
|
||||
f = match.groupdict()
|
||||
f['type'] = 'local'
|
||||
facts.append(f)
|
||||
|
||||
regex = r'Peer address: (?P<vllpeer>[0-9\.]+)'
|
||||
matches = re.finditer(regex, data, re.IGNORECASE)
|
||||
for n, match in enumerate(matches):
|
||||
for match in matches:
|
||||
f = match.groupdict()
|
||||
f['type'] = 'remote'
|
||||
facts.append(f)
|
||||
|
|
|
@ -281,7 +281,7 @@ class Interfaces(FactsBase):
|
|||
primary_address = addresses = []
|
||||
primary_address = re.findall(r'Primary Internet Address is (\S+)', value, re.M)
|
||||
addresses = re.findall(r'Secondary Internet Address is (\S+)', value, re.M)
|
||||
if len(primary_address) == 0:
|
||||
if not primary_address:
|
||||
continue
|
||||
addresses.append(primary_address[0])
|
||||
for address in addresses:
|
||||
|
@ -311,7 +311,7 @@ class Interfaces(FactsBase):
|
|||
def parse_neighbors(self, neighbors):
|
||||
facts = dict()
|
||||
lines = neighbors.split('Local Interface: ')
|
||||
if len(lines) == 0:
|
||||
if not lines:
|
||||
return facts
|
||||
for line in lines:
|
||||
match = re.search(r'(\w+ \S+)\s+\(Local Int.+?\)[\s\S]+Remote Interface: (\S+.+?) \(Remote Int.+?\)[\s\S]+System Name: (\S+)', line, re.M)
|
||||
|
@ -452,7 +452,7 @@ def main():
|
|||
|
||||
warnings = list()
|
||||
|
||||
module.exit_json(ansible_facts=ansible_facts)
|
||||
module.exit_json(ansible_facts=ansible_facts, warnings=warnings)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -254,14 +254,10 @@ backup_path:
|
|||
type: str
|
||||
sample: /playbooks/ansible/backup/slxos_config.2018-02-12@18:26:34
|
||||
"""
|
||||
import re
|
||||
import time
|
||||
|
||||
from ansible.module_utils.network.slxos.slxos import run_commands, get_config, load_config
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.network.common.parsing import Conditional
|
||||
from ansible.module_utils.network.common.config import NetworkConfig, dumps
|
||||
from ansible.module_utils.six import iteritems
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
|
|
|
@ -279,7 +279,7 @@ class Interfaces(FactsBase):
|
|||
primary_address = addresses = []
|
||||
primary_address = re.findall(r'Primary Internet Address is (\S+)', value, re.M)
|
||||
addresses = re.findall(r'Secondary Internet Address is (\S+)', value, re.M)
|
||||
if len(primary_address) == 0:
|
||||
if not primary_address:
|
||||
continue
|
||||
addresses.append(primary_address[0])
|
||||
for address in addresses:
|
||||
|
@ -309,7 +309,7 @@ class Interfaces(FactsBase):
|
|||
def parse_neighbors(self, neighbors):
|
||||
facts = dict()
|
||||
lines = neighbors.split('Local Interface: ')
|
||||
if len(lines) == 0:
|
||||
if not lines:
|
||||
return facts
|
||||
for line in lines:
|
||||
match = re.search(r'(\w+ \S+)\s+\(Local Int.+?\)[\s\S]+Remote Interface: (\S+.+?) \(Remote Int.+?\)[\s\S]+System Name: (\S+)', line, re.M)
|
||||
|
@ -450,7 +450,7 @@ def main():
|
|||
|
||||
warnings = list()
|
||||
|
||||
module.exit_json(ansible_facts=ansible_facts)
|
||||
module.exit_json(ansible_facts=ansible_facts, warnings=warnings)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -35,7 +35,7 @@ description:
|
|||
- This module provides declarative management of VLANs
|
||||
on Extreme SLX-OS network devices.
|
||||
notes:
|
||||
- Tested against SLX-OS 17s.1.02
|
||||
- Tested against SLX-OS 18r.1.00
|
||||
options:
|
||||
name:
|
||||
description:
|
||||
|
@ -105,7 +105,6 @@ from ansible.module_utils.network.slxos.slxos import load_config, run_commands
|
|||
|
||||
|
||||
def search_obj_in_list(vlan_id, lst):
|
||||
obj = list()
|
||||
for o in lst:
|
||||
if o['vlan_id'] == vlan_id:
|
||||
return o
|
||||
|
@ -217,16 +216,16 @@ def map_config_to_obj(module):
|
|||
obj = {}
|
||||
|
||||
for l in lines:
|
||||
splitted_line = re.split(r'([0-9]+)? +(\S.{14})? +(ACTIVE|INACTIVE\(.+?\))? +(Eth .+?|Po .+?)\([ut]\)\s*$', l.rstrip())
|
||||
splitted_line = re.split(r'([0-9]+)? +(\S.{14})? +(ACTIVE|INACTIVE\(.+?\))?.*(Eth .+?|Po .+?|Tu .+?)\([ut]\).*$', l.rstrip())
|
||||
if len(splitted_line) == 1:
|
||||
# Handle situation where VLAN is configured, but has no associated ports
|
||||
inactive = re.match(r'([0-9]+)? +(\S.{14}) +INACTIVE\(no member port\)$', l.rstrip())
|
||||
inactive = re.match(r'([0-9]+)? +(\S.{14}) +INACTIVE\(no member port\).*$', l.rstrip())
|
||||
if inactive:
|
||||
splitted_line = ['', inactive.groups()[0], inactive.groups()[1], '', '']
|
||||
else:
|
||||
continue
|
||||
|
||||
splitted_line[4] = splitted_line[4].replace('Eth', 'Ethernet').replace('Po', 'Port-channel')
|
||||
splitted_line[4] = splitted_line[4].replace('Eth', 'Ethernet').replace('Po', 'Port-channel').replace('Tu', 'Tunnel')
|
||||
|
||||
if splitted_line[1] is None:
|
||||
obj['interfaces'].append(splitted_line[4])
|
||||
|
|
|
@ -311,7 +311,7 @@ class Interfaces(FactsBase):
|
|||
def populate_ipv6_interfaces(self, data):
|
||||
addresses = re.split(r'-{3,}', data)[1].lstrip()
|
||||
for line in addresses.split('\n'):
|
||||
if len(line) == 0:
|
||||
if not line:
|
||||
break
|
||||
|
||||
match = re.match(r'^([\da-f:]+)/(\d+)\s+([CV])-(\d+)\s+.+$', line)
|
||||
|
@ -350,7 +350,7 @@ class Interfaces(FactsBase):
|
|||
def parse_neighbors(self, neighbors):
|
||||
facts = dict()
|
||||
lines = neighbors.split('Port: ')
|
||||
if len(lines) == 0:
|
||||
if not lines:
|
||||
return facts
|
||||
for line in lines:
|
||||
match = re.search(r'^(\w.*?)\s+Index.*IfName\s+(\w.*)$\s+SysName\s+:\s(\S+)', line, (re.M | re.S))
|
||||
|
@ -368,7 +368,7 @@ class Interfaces(FactsBase):
|
|||
parsed = dict()
|
||||
interfaces = re.split(r'-{3,}', data)[1].lstrip()
|
||||
for line in interfaces.split('\n'):
|
||||
if len(line) == 0:
|
||||
if not line or re.match('^All', line):
|
||||
break
|
||||
else:
|
||||
match = re.split(r'^(\S+)\s+', line)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue