diff --git a/library/ios_facts.py b/library/ios_facts.py index 47cfa0c..b87568a 100644 --- a/library/ios_facts.py +++ b/library/ios_facts.py @@ -110,4 +110,3 @@ def main(): if __name__ == '__main__': main() - diff --git a/library/ios_l3_interface.py b/library/ios_l3_interface.py index 338ad85..78794e7 100644 --- a/library/ios_l3_interface.py +++ b/library/ios_l3_interface.py @@ -1,26 +1,25 @@ #!/usr/bin/python # -*- coding: utf-8 -*- # Copyright 2019 Red Hat Inc. -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) ############################################## -################# WARNING #################### -############################################## -### -### This file is auto generated by the resource -### module builder playbook. -### -### Do not edit this file manually. -### -### Changes to this file will be over written -### by the resource module builder. -### -### Changes should be made in the model used to -### generate this file or in the resource module -### builder template. -### -############################################## -############################################## +# WARNING +# +# This file is auto generated by the resource +# module builder playbook. +# +# Do not edit this file manually. +# +# Changes to this file will be over written +# by the resource module builder. +# +# Changes should be made in the model used to +# generate this file or in the resource module +# builder template. +# +# ############################################## """ @@ -46,7 +45,9 @@ module: ios_l3_interfaces version_added: 2.9 short_description: Manage Layer-3 interface on Cisco IOS devices. - description: This module provides declarative management of Layer-3 interface on Cisco IOS devices. + description: + - This module provides declarative management of Layer-3 interface + on Cisco IOS devices. author: Sumit Jaiswal (@justjais) options: config: @@ -56,14 +57,15 @@ suboptions: name: description: - - Full name of the interface excluding any logical unit number, i.e. GigabitEthernet0/1. + - Full name of the interface excluding any logical unit number, + i.e. GigabitEthernet0/1. type: str required: True ipv4: description: - - IPv4 address to be set for the Layer-3 interface mentioned in I(name) option. - The address format is /, the mask is number in range 0-32 - eg. 192.168.0.1/24 + - IPv4 address to be set for the Layer-3 interface mentioned in + I(name) option. The address format is /, + the mask is number in range 0-32 eg. 192.168.0.1/24. suboptions: address: description: @@ -75,19 +77,21 @@ type: bool dhcp_client: description: - - Configures and specifies client-id to use over DHCP ip. Note, This option shall - work only when dhcp is configured as IP. + - Configures and specifies client-id to use over DHCP ip. + Note, This option shall work only when dhcp is configured + as IP. type: str dhcp_hostname: description: - - Configures and specifies value for hostname option over DHCP ip. Note, This option shall - work only when dhcp is configured as IP. + - Configures and specifies value for hostname option over + DHCP ip. Note, This option shall work only when dhcp is + configured as IP. type: str ipv6: description: - - IPv6 address to be set for the Layer-3 interface mentioned in I(name) option. - The address format is /, the mask is number in range 0-128 - eg. fd5d:12c9:2201:1::1/64 + - IPv6 address to be set for the Layer-3 interface mentioned in + I(name) option. The address format is /, + the mask is number in range 0-128 eg. fd5d:12c9:2201:1::1/64 suboptions: address: description: @@ -133,11 +137,11 @@ ios_l3_interfaces: config: - name: GigabitEthernet0/1 - ipv4: + ipv4: - address: 192.168.0.1/24 secondary: True - name: GigabitEthernet0/2 - ipv4: + ipv4: - address: 192.168.0.2/24 - name: GigabitEthernet0/3 ipv6: @@ -199,7 +203,7 @@ ipv4: - address: 192.168.2.0/24 - name: GigabitEthernet0/3 - ipv4: + ipv4: - address: dhcp dhcp_client: 2 dhcp_hostname: test.com diff --git a/module_utils/ios/argspec/facts/facts.py b/module_utils/ios/argspec/facts/facts.py index d05fa7f..0bee97b 100644 --- a/module_utils/ios/argspec/facts/facts.py +++ b/module_utils/ios/argspec/facts/facts.py @@ -7,7 +7,7 @@ """ -class FactsArgs(object): #pylint: disable=R0903 +class FactsArgs(object): """ The arg spec for the ios facts module """ diff --git a/module_utils/ios/argspec/l3_interfaces/l3_interfaces.py b/module_utils/ios/argspec/l3_interfaces/l3_interfaces.py index dfc40a0..b129fc4 100644 --- a/module_utils/ios/argspec/l3_interfaces/l3_interfaces.py +++ b/module_utils/ios/argspec/l3_interfaces/l3_interfaces.py @@ -1,38 +1,37 @@ #!/usr/bin/python # -*- coding: utf-8 -*- # Copyright 2019 Red Hat Inc. -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +# ############################################# -################# WARNING #################### -############################################## -### -### This file is auto generated by the resource -### module builder playbook. -### -### Do not edit this file manually. -### -### Changes to this file will be over written -### by the resource module builder. -### -### Changes should be made in the model used to -### generate this file or in the resource module -### builder template. -### -############################################## -############################################## +# WARNING +# +# This file is auto generated by the resource +# module builder playbook. +# +# Do not edit this file manually. +# +# Changes to this file will be over written +# by the resource module builder. +# +# Changes should be made in the model used to +# generate this file or in the resource module +# builder template. +# ############################################## """ The arg spec for the ios_l3_interfaces module """ + class L3_InterfacesArgs(object): def __init__(self, **kwargs): pass ipv4addr_spec = dict(address=dict(type=str), - secondary=dict(type=bool), + secondary=dict(type=bool, default=True), dhcp_client=dict(type=str), dhcp_hostname=dict(type=str)) @@ -42,11 +41,11 @@ def __init__(self, **kwargs): config_spec = { 'name': dict(type='str', required=True), - 'ipv4':dict(type='list', elements='dict', options=ipv4addr_spec), - 'ipv6':dict(type='list', elements='dict', options=ipv6addr_spec) + 'ipv4': dict(type='list', elements='dict', options=ipv4addr_spec), + 'ipv6': dict(type='list', elements='dict', options=ipv6addr_spec) } argument_spec = { 'state': dict(default='merged', choices=['merged', 'replaced', 'overridden', 'deleted']), 'config': dict(type='list', elements='dict', options=config_spec) - } \ No newline at end of file + } diff --git a/module_utils/ios/argspec/resource/resource.py b/module_utils/ios/argspec/resource/resource.py index 0734995..2395fcc 100644 --- a/module_utils/ios/argspec/resource/resource.py +++ b/module_utils/ios/argspec/resource/resource.py @@ -4,23 +4,20 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) ############################################# -################# WARNING #################### -############################################## -### -### This file is auto generated by the resource -### module builder playbook. -### -### Do not edit this file manually. -### -### Changes to this file will be over written -### by the resource module builder. -### -### Changes should be made in the model used to -### generate this file or in the resource module -### builder template. -### -############################################## -############################################## +# WARNING +# +# This file is auto generated by the resource +# module builder playbook. +# +# Do not edit this file manually. +# +# Changes to this file will be over written +# by the resource module builder. +# +# Changes should be made in the model used to +# generate this file or in the resource module +# builder template. +# ############################################## """ The arg spec for the ios_l3_interfaces module diff --git a/module_utils/ios/config/base.py b/module_utils/ios/config/base.py index 7e3e468..f3f6638 100644 --- a/module_utils/ios/config/base.py +++ b/module_utils/ios/config/base.py @@ -8,7 +8,8 @@ from ansible.module_utils.connection import Connection -class ConfigBase(object): #pylint: disable=R0205,R0903 + +class ConfigBase(object): """ The base class for all ios resource modules """ _connection = None @@ -20,5 +21,5 @@ def __init__(self, module): def _get_connection(self): if self._connection: return self._connection - self._connection = Connection(self._module._socket_path) #pylint: disable=W0212 - return self._connection \ No newline at end of file + self._connection = Connection(self._module._socket_path) + return self._connection diff --git a/module_utils/ios/config/l3_interfaces/l3_interfaces.py b/module_utils/ios/config/l3_interfaces/l3_interfaces.py index 1b71dfd..63dfab4 100644 --- a/module_utils/ios/config/l3_interfaces/l3_interfaces.py +++ b/module_utils/ios/config/l3_interfaces/l3_interfaces.py @@ -11,13 +11,13 @@ """ from ansible.module_utils.network.common.utils import to_list -from ansible.module_utils.network.common.utils import is_netmask, is_masklen, to_netmask, to_masklen +from ansible.module_utils.network.common.utils import is_masklen, to_netmask from ansible.module_utils.six import iteritems from ansible.module_utils.ios.argspec.l3_interfaces.l3_interfaces import L3_InterfacesArgs from ansible.module_utils.ios.config.base import ConfigBase from ansible.module_utils.ios.facts.facts import Facts -import q + class L3_Interfaces(ConfigBase, L3_InterfacesArgs): """ @@ -296,7 +296,8 @@ def set_interface(**kwargs): ip_addr_want = L3_Interfaces.validate_n_expand_ipv4(module, each) each['address'] = ip_addr_want - want_ipv4 = set(tuple({k:v for k,v in iteritems(address) if v is not None}.items()) for address in want.get("ipv4") or []) + want_ipv4 = set(tuple({k: v for k, v in iteritems(address) if v is not None}.items()) + for address in want.get("ipv4") or []) have_ipv4 = set(tuple(address.items()) for address in have.get("ipv4") or []) diff = want_ipv4 - have_ipv4 for address in diff: @@ -307,17 +308,19 @@ def set_interface(**kwargs): cmd += " secondary" elif address.get('address') == 'dhcp': if address.get('dhcp_client') and address.get('dhcp_hostname'): - cmd = "ip address dhcp client-id GigabitEthernet 0/{} hostname {}".format\ - (address.get('dhcp_client'),address.get('dhcp_hostname')) + cmd = "ip address dhcp client-id GigabitEthernet 0/{} hostname {}".\ + format(address.get('dhcp_client'), address.get('dhcp_hostname')) elif address.get('dhcp_client') and not address.get('dhcp_hostname'): - cmd = "ip address dhcp client-id GigabitEthernet 0/{}".format(address.get('dhcp_client')) + cmd = "ip address dhcp client-id GigabitEthernet 0/{}".\ + format(address.get('dhcp_client')) elif not address.get('dhcp_client') and address.get('dhcp_hostname'): cmd = "ip address dhcp hostname {}".format(address.get('dhcp_client')) L3_Interfaces._add_command_to_interface(interface, cmd, commands) # To handle L3 IPV6 configuration - want_ipv6 = set(tuple({k:v for k,v in iteritems(address) if v is not None}.items()) for address in want.get("ipv6") or []) + want_ipv6 = set(tuple({k: v for k, v in iteritems(address) if v is not None}.items()) + for address in want.get("ipv6") or []) have_ipv6 = set(tuple(address.items()) for address in have.get("ipv6") or []) diff = want_ipv6 - have_ipv6 for address in diff: diff --git a/module_utils/ios/facts/base.py b/module_utils/ios/facts/base.py index 48f6210..895dd49 100644 --- a/module_utils/ios/facts/base.py +++ b/module_utils/ios/facts/base.py @@ -12,7 +12,7 @@ from ansible.module_utils.six import iteritems -class FactsBase(object): #pylint: disable=R0205 +class FactsBase(object): """ The ios facts base class """ @@ -102,5 +102,5 @@ def generate_final_config(cfg_dict): for key, val in iteritems(cfg_dict): if val: - final_cfg.update({key:val}) + final_cfg.update({key: val}) return final_cfg diff --git a/module_utils/ios/facts/facts.py b/module_utils/ios/facts/facts.py index 90c9f3b..ae222b7 100644 --- a/module_utils/ios/facts/facts.py +++ b/module_utils/ios/facts/facts.py @@ -20,7 +20,7 @@ FACT_SUBSETS = {} -class Facts(FactsArgs, FactsBase): #pylint: disable=R0903 +class Facts(FactsArgs, FactsBase): """ The fact class for ios l3 interface """ diff --git a/module_utils/ios/facts/l3_interfaces/l3_interfaces.py b/module_utils/ios/facts/l3_interfaces/l3_interfaces.py index 4b33d1f..b37f393 100644 --- a/module_utils/ios/facts/l3_interfaces/l3_interfaces.py +++ b/module_utils/ios/facts/l3_interfaces/l3_interfaces.py @@ -14,7 +14,7 @@ from ansible.module_utils.ios.facts.base import FactsBase from ansible.module_utils.ios.utils.utils import get_interface_type, normalize_interface -import q + class L3_interfacesFacts(FactsBase): """ The ios l3 interfaces fact class @@ -54,7 +54,6 @@ def render_config(self, spec, conf): :rtype: dictionary :returns: The generated config """ - import q config = deepcopy(spec) match = re.search(r'^(\S+)', conf) intf = match.group(1) @@ -70,6 +69,7 @@ def render_config(self, spec, conf): each_ipv4 = dict() if 'secondary' not in each and 'dhcp' not in each: each_ipv4['address'] = each + each_ipv4['secondary'] = False elif 'secondary' in each: each_ipv4['secondary'] = True each_ipv4['address'] = each.split(' secondary')[0] diff --git a/module_utils/ios/facts/resource/resource.py b/module_utils/ios/facts/resource/resource.py index b6bbcda..5898b42 100644 --- a/module_utils/ios/facts/resource/resource.py +++ b/module_utils/ios/facts/resource/resource.py @@ -11,6 +11,7 @@ from copy import deepcopy from ansible.module_utils.ios.facts.base import FactsBase + class Facts(FactsBase): """ The {{ network_os }} {{ resource }} fact class """ @@ -23,16 +24,16 @@ def populate_facts(self, module, connection, data=None): :rtype: dictionary :returns: facts """ - if module: #just for linting purposes + if module: pass - if connection: #just for linting purposes + if connection: pass if not data: - data = "foo" # connection.get('show running-config | section ^interface') + data = "foo" # operate on a collection of resource x - config = [data] # data.split('interface ') + config = [data] objs = [] for conf in config: if conf: diff --git a/module_utils/ios/utils/utils.py b/module_utils/ios/utils/utils.py index 4cffe84..040639d 100644 --- a/module_utils/ios/utils/utils.py +++ b/module_utils/ios/utils/utils.py @@ -96,4 +96,4 @@ def get_interface_type(interface): elif interface.upper().startswith('HU'): return 'HundredGigE' else: - return 'unknown' \ No newline at end of file + return 'unknown' diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..0637ba7 --- /dev/null +++ b/tox.ini @@ -0,0 +1,7 @@ +[flake8] +# These are ignored intentionally; +# please don't submit patches that solely correct them or enable them. +ignore = E501,E125,E129,E402 +show-source = True +exclude = .venv,.tox,dist,doc,build,*.egg +max-line-length = 100