Skip to content

Commit

Permalink
chore: auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Oct 21, 2024
1 parent 78c83ba commit 7416a85
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

from copy import deepcopy

import debugpy

from ansible.module_utils.six import iteritems
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils

Expand All @@ -27,7 +29,7 @@
Vrf_address_familyTemplate,
)

import debugpy

debugpy.listen(3000)
debugpy.wait_for_client()

Expand All @@ -43,41 +45,39 @@ def get_config(self, connection):
"""Get the configuration from the device"""

return connection.get("show running-config | section ^vrf")

def _flatten_config(self, data):
"""Flatten contexts in the vrf address family
running-config for easier parsing.
:param data: string running-config
:returns: flattened running config
"""

dataLines = data.split('\n')
dataLines = data.split("\n")
curData = ""

for line in dataLines:
if "vrf context" in line:
curData = line
elif "address-family" in line:
dataLines[dataLines.index(line)] = curData + ' ' + line
dataLines[dataLines.index(line)] = curData + " " + line

return "\n".join(dataLines)

def _parse_vrf_af(self, data: dict):
"""Parse the vrf address family data
:param data: dict of vrf address family data
:returns: argspec compliant list
"""
if not data:
return {}

vrf_lists = list(data.values())
for item in vrf_lists:
if "address_families" in item:
item["address_families"] = list(item["address_families"].values())
return vrf_lists



def populate_facts(self, connection, ansible_facts, data=None):
"""Populate the facts for Vrf_address_family network resource
Expand All @@ -93,12 +93,13 @@ def populate_facts(self, connection, ansible_facts, data=None):

if not data:
data = self.get_config(connection)

flattened_data = self._flatten_config(data)

# parse native config using the Vrf_address_family template
vrf_address_family_parser = Vrf_address_familyTemplate(
lines=flattened_data.splitlines(), module=self._module
lines=flattened_data.splitlines(),
module=self._module,
)
parsed_data = vrf_address_family_parser.parse()
vrfObjs = self._parse_vrf_af(parsed_data)
Expand All @@ -107,7 +108,9 @@ def populate_facts(self, connection, ansible_facts, data=None):

params = utils.remove_empties(
vrf_address_family_parser.validate_config(
self.argument_spec, {"config": vrfObjs}, redact=True
self.argument_spec,
{"config": vrfObjs},
redact=True,
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
NetworkTemplate,
)


VRF_NAME = "{{ name }}"
UNIQUE_AFI = "{{ 'address_families_'+afi+'_'+safi }}"


class Vrf_address_familyTemplate(NetworkTemplate):
def __init__(self, lines=None, module=None):
super(Vrf_address_familyTemplate, self).__init__(lines=lines, tmplt=self, module=module)
Expand Down Expand Up @@ -80,12 +82,12 @@ def __init__(self, lines=None, module=None):
"threshold": {
"threshold_value": "{{ threshold_value }}",
"reinstall_threshold": "{{ reinstall }}",
}
}
}
},
},
},
},
},
}
},
},
},
{
Expand All @@ -103,7 +105,7 @@ def __init__(self, lines=None, module=None):
"afi": "{{ afi }}",
"safi": "{{ safi }}",
"route_target": [{
"import": "{{ import }}"
"import": "{{ import }}",
}],
},
},
Expand All @@ -125,7 +127,7 @@ def __init__(self, lines=None, module=None):
"afi": "{{ afi }}",
"safi": "{{ safi }}",
"route_target": [{
"export": "{{ export }}"
"export": "{{ export }}",
}],
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ def test_nxos_vrf_address_fam_gathered(self):
address-family ipv4 unicast
vrf context VRF2
address-family ipv6 unicast
"""
""",
)

set_module_args({})
self.module.get_config(self.mock_connection)

self.execute_show_command.assert_called_once_with(self.mock_connection)
self.execute_show_command.assert_called_once_with(self.mock_connection)

0 comments on commit 7416a85

Please sign in to comment.