Skip to content
This repository has been archived by the owner on Apr 20, 2021. It is now read-only.

Commit

Permalink
linters fix
Browse files Browse the repository at this point in the history
Signed-off-by: Sumit Jaiswal <[email protected]>
  • Loading branch information
justjais committed Jun 28, 2019
1 parent 84b3b21 commit 93d57d8
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 95 deletions.
1 change: 0 additions & 1 deletion library/ios_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,3 @@ def main():

if __name__ == '__main__':
main()

70 changes: 37 additions & 33 deletions library/ios_l3_interface.py
Original file line number Diff line number Diff line change
@@ -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.
#
#
##############################################

"""
Expand All @@ -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:
Expand All @@ -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 <ipv4 address>/<mask>, 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 <ipv4 address>/<mask>,
the mask is number in range 0-32 eg. 192.168.0.1/24.
suboptions:
address:
description:
Expand All @@ -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 <ipv6 address>/<mask>, 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 <ipv6 address>/<mask>,
the mask is number in range 0-128 eg. fd5d:12c9:2201:1::1/64
suboptions:
address:
description:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion module_utils/ios/argspec/facts/facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""


class FactsArgs(object): #pylint: disable=R0903
class FactsArgs(object):
""" The arg spec for the ios facts module
"""

Expand Down
45 changes: 22 additions & 23 deletions module_utils/ios/argspec/l3_interfaces/l3_interfaces.py
Original file line number Diff line number Diff line change
@@ -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))

Expand All @@ -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)
}
}
31 changes: 14 additions & 17 deletions module_utils/ios/argspec/resource/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions module_utils/ios/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
self._connection = Connection(self._module._socket_path)
return self._connection
17 changes: 10 additions & 7 deletions module_utils/ios/config/l3_interfaces/l3_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions module_utils/ios/facts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion module_utils/ios/facts/facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
FACT_SUBSETS = {}


class Facts(FactsArgs, FactsBase): #pylint: disable=R0903
class Facts(FactsArgs, FactsBase):
""" The fact class for ios l3 interface
"""

Expand Down
4 changes: 2 additions & 2 deletions module_utils/ios/facts/l3_interfaces/l3_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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]
Expand Down
Loading

0 comments on commit 93d57d8

Please sign in to comment.