Assorted pylint fixes

This commit is contained in:
Dag Wieers
2019-02-14 21:02:27 +01:00
committed by Matt Clay
parent 8e0f95951d
commit f9ab9b4d68
65 changed files with 343 additions and 473 deletions

View File

@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc
# Copyright: (c) 2017, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
@@ -187,7 +187,7 @@ def parse_shutdown(configobj, name):
cfg = configobj['interface %s' % name]
cfg = '\n'.join(cfg.children)
match = re.search(r'shutdown', cfg, re.M)
return True if match else False
return bool(match)
def parse_config_argument(configobj, name, arg=None):
@@ -368,7 +368,7 @@ def check_declarative_intent_params(module, want, result):
have_host = []
have_port = []
if have_neighbors is None:
command = {'command': 'show lldp neighbors {}'.format(w['name']), 'output': 'text'}
command = {'command': 'show lldp neighbors {0}'.format(w['name']), 'output': 'text'}
have_neighbors = run_commands(module, [command])
if have_neighbors[0]:

View File

@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc
# Copyright: (c) 2017, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
@@ -170,23 +170,23 @@ def map_obj_to_commands(updates, module):
if state == 'absent' and obj_in_have:
if obj_in_have['ipv4']:
if ipv4:
commands.append('no ip address {}'.format(ipv4))
commands.append('no ip address {0}'.format(ipv4))
else:
commands.append('no ip address')
if obj_in_have['ipv6']:
if ipv6:
commands.append('no ipv6 address {}'.format(ipv6))
commands.append('no ipv6 address {0}'.format(ipv6))
else:
commands.append('no ipv6 address')
elif state == 'present':
if ipv4:
if obj_in_have is None or obj_in_have['ipv4'] is None or ipv4 != obj_in_have['ipv4']:
commands.append('ip address {}'.format(ipv4))
commands.append('ip address {0}'.format(ipv4))
if ipv6:
if obj_in_have is None or obj_in_have['ipv6'] is None or ipv6.lower() != obj_in_have['ipv6'].lower():
commands.append('ipv6 address {}'.format(ipv6))
commands.append('ipv6 address {0}'.format(ipv6))
if commands[-1] == interface:
commands.pop(-1)

View File

@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc
# Copyright: (c) 2017, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
@@ -141,10 +141,10 @@ def map_obj_to_commands(updates, module):
if state == 'absent':
if obj_in_have:
commands.append('no interface port-channel {}'.format(group))
commands.append('no interface port-channel {0}'.format(group))
elif state == 'present':
cmd = ['interface port-channel {}'.format(group),
cmd = ['interface port-channel {0}'.format(group),
'end']
if not obj_in_have:
if not group:
@@ -152,11 +152,11 @@ def map_obj_to_commands(updates, module):
commands.extend(cmd)
if min_links != 'None':
commands.append('port-channel min-links {}'.format(min_links))
commands.append('port-channel min-links {0}'.format(min_links))
if members:
for m in members:
commands.append('interface {}'.format(m))
commands.append('interface {0}'.format(m))
commands.append('channel-group {0} mode {1}'.format(group, mode))
else:
@@ -164,27 +164,27 @@ def map_obj_to_commands(updates, module):
if 'members' not in obj_in_have.keys():
for m in members:
commands.extend(cmd)
commands.append('interface {}'.format(m))
commands.append('interface {0}'.format(m))
commands.append('channel-group {0} mode {1}'.format(group, mode))
elif set(members) != set(obj_in_have['members']):
missing_members = list(set(members) - set(obj_in_have['members']))
for m in missing_members:
commands.extend(cmd)
commands.append('interface {}'.format(m))
commands.append('interface {0}'.format(m))
commands.append('channel-group {0} mode {1}'.format(group, mode))
superfluous_members = list(set(obj_in_have['members']) - set(members))
for m in superfluous_members:
commands.extend(cmd)
commands.append('interface {}'.format(m))
commands.append('no channel-group {}'.format(group))
commands.append('interface {0}'.format(m))
commands.append('no channel-group {0}'.format(group))
if purge:
for h in have:
obj_in_want = search_obj_in_list(h['group'], want)
if not obj_in_want:
commands.append('no interface port-channel {}'.format(h['group']))
commands.append('no interface port-channel {0}'.format(h['group']))
return commands
@@ -221,9 +221,9 @@ def parse_mode(group, member, config):
mode = None
for line in config.strip().split('!'):
match_int = re.findall(r'interface {}\\b'.format(member), line, re.M)
match_int = re.findall(r'interface {0}\\b'.format(member), line, re.M)
if match_int:
match = re.search(r'channel-group {} mode (\S+)'.format(group), line, re.M)
match = re.search(r'channel-group {0} mode (\S+)'.format(group), line, re.M)
if match:
mode = match.group(1)
@@ -234,7 +234,7 @@ def parse_members(group, config):
members = []
for line in config.strip().split('!'):
match_group = re.findall(r'channel-group {} mode'.format(group), line, re.M)
match_group = re.findall(r'channel-group {0} mode'.format(group), line, re.M)
if match_group:
match = re.search(r'interface (\S+)', line, re.M)
if match:
@@ -263,7 +263,7 @@ def parse_min_links(group, config):
min_links = ''
for line in config.strip().split('!'):
match_pc = re.findall(r'interface Port-Channel{}\\b'.format(group), line, re.M)
match_pc = re.findall(r'interface Port-Channel{0}\\b'.format(group), line, re.M)
if match_pc:
match = re.search(r'port-channel min-links (\S+)', line, re.M)
if match:

View File

@@ -1,23 +1,9 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc
#
# This file is part of Ansible by Red Hat
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright: (c) 2017, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
@@ -152,16 +138,16 @@ def map_obj_to_commands(updates, module):
if state == 'absent' and w in have:
if dest:
if dest == 'host':
commands.append('no logging host {}'.format(name))
commands.append('no logging host {0}'.format(name))
elif dest in DEST_GROUP:
commands.append('no logging {}'.format(dest))
commands.append('no logging {0}'.format(dest))
else:
module.fail_json(msg='dest must be among console, monitor, buffered, host, on')
if facility:
commands.append('no logging facility {}'.format(facility))
commands.append('no logging facility {0}'.format(facility))
if state == 'present' and w not in have:
if facility:
@@ -175,10 +161,10 @@ def map_obj_to_commands(updates, module):
present = True
if not present:
commands.append('logging facility {}'.format(facility))
commands.append('logging facility {0}'.format(facility))
if dest == 'host':
commands.append('logging host {}'.format(name))
commands.append('logging host {0}'.format(name))
elif dest == 'on':
commands.append('logging on')
@@ -203,14 +189,14 @@ def map_obj_to_commands(updates, module):
if not present:
if size and level:
commands.append('logging buffered {} {}'.format(size, level))
commands.append('logging buffered {0} {1}'.format(size, level))
else:
commands.append('logging buffered {}'.format(size))
commands.append('logging buffered {0}'.format(size))
else:
dest_cmd = 'logging {}'.format(dest)
dest_cmd = 'logging {0}'.format(dest)
if level:
dest_cmd += ' {}'.format(level)
dest_cmd += ' {0}'.format(level)
commands.append(dest_cmd)
@@ -268,7 +254,7 @@ def parse_level(line, dest):
match = re.search(r'logging buffered (?:\d+) (\S+)', line, re.M)
else:
match = re.search(r'logging {} (\S+)'.format(dest), line, re.M)
match = re.search(r'logging {0} (\S+)'.format(dest), line, re.M)
if match:
if match.group(1) in LEVEL_GROUP:

View File

@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc
# Copyright: (c) 2017, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
@@ -224,7 +224,7 @@ def main():
if address and prefix:
if '/' not in address or not validate_ip_address(address.split('/')[0]):
module.fail_json(msg='{} is not a valid IP address'.format(address))
module.fail_json(msg='{0} is not a valid IP address'.format(address))
if not validate_prefix(prefix):
module.fail_json(msg='Length of prefix should be between 0 and 32 bits')