Skip to content

Commit

Permalink
fixes error messages and logic for L3 interfaces and VRFs
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiapuziowong committed Aug 22, 2019
1 parent 95b3fbe commit a9d0f28
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 125 deletions.
2 changes: 1 addition & 1 deletion library/aoscx_l3_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def main():
aruba_ansible_module, interface_name, acl_name, acl_type,
acl_direction)

if vrf is not None:
if vrf is not None and vrf != "default":
aruba_ansible_module = l3_interface.update_interface_vrf_details_from_l3(aruba_ansible_module, vrf, interface_name) # NOQA

if interface_qos_rate is not None:
Expand Down
106 changes: 0 additions & 106 deletions library/aroscx_vrf_interface.py

This file was deleted.

39 changes: 29 additions & 10 deletions module_utils/aoscx_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def create_l2_interface(self, aruba_ansible_module, interface_name):
}
aruba_ansible_module = port.update_port_fields(aruba_ansible_module, interface_name, port_fields)
else:
aruba_ansible_module.module.fail_json(msg="Interface {} is currently an L3 interface".format(interface_name))
aruba_ansible_module.module.fail_json(msg="Interface {} is currently an L3 interface. Delete interface then configure as L2.".format(interface_name))

return aruba_ansible_module

Expand Down Expand Up @@ -219,7 +219,7 @@ def update_interface_vlan_details(self, aruba_ansible_module, interface_name, vl
interface = L2_Interface()

if not interface.check_if_l2_interface_possible(aruba_ansible_module, interface_name):
aruba_ansible_module.module.fail_json(msg="Interface {} is configured as an L3 interface\nDelete interface then configure as L2.".format(interface_name))
aruba_ansible_module.module.fail_json(msg="Interface {} is configured as an L3 interface. Delete interface then configure as L2.".format(interface_name))
if not port.check_port_exists(aruba_ansible_module, interface_name):
aruba_ansible_module.module.fail_json(msg="Interface {} is not configured".format(interface_name))

Expand Down Expand Up @@ -259,11 +259,11 @@ def create_l3_interface(self, aruba_ansible_module, interface_name):
encoded_interface_name = interface_name.replace("/", "%2F")
interfaces = [encoded_interface_name]
port_fields = {
"interfaces" : interfaces
"interfaces": interfaces
}
aruba_ansible_module = port.update_port_fields(aruba_ansible_module, interface_name, port_fields)
else:
aruba_ansible_module.module.fail_json("Interface {} is currently an L2 interface".format(interface_name))
aruba_ansible_module.module.fail_json("Interface {} is currently an L2 interface. Delete interface then configure as L3.".format(interface_name))

return aruba_ansible_module

Expand All @@ -277,11 +277,12 @@ def delete_l3_interface(self, aruba_ansible_module, interface_name):
def check_if_l3_interface_possible(self, aruba_ansible_module, interface_name):
port = Port()
if port.check_port_exists(aruba_ansible_module, interface_name):
result = port.get_port_field_values(aruba_ansible_module, interface_name, ['vlan_tag', 'vrf'])
if result.has_key('vrf'):
result = port.get_port_field_values(aruba_ansible_module, interface_name, ['vrf', 'routing'])
if 'vrf' in result.keys():
return True
if result.has_key('vlan_tag'):
return False
if 'routing' in result.keys():
if result['routing'] is False:
return False
else:
return True
else:
Expand All @@ -293,13 +294,22 @@ def update_interface_vrf_details_from_l3(self, aruba_ansible_module, vrf_name, i
if not port.check_port_exists(aruba_ansible_module, interface_name):
aruba_ansible_module.module.fail_json(msg="Interface {} is not configured".format(interface_name))

result = port.get_port_field_values(aruba_ansible_module,
interface_name,
['vrf'])
if 'vrf' in result.keys():
if result['vrf'] != "" and result['vrf'] != vrf_name:
aruba_ansible_module.module.fail_json(
msg=("Interface {} is attached to VRF {}. Delete interface and recreate with VRF {}".format(
interface_name, result['vrf'], vrf_name)))

if not vrf.check_vrf_exists(aruba_ansible_module, vrf_name):
if vrf_name != "default":
aruba_ansible_module.module.fail_json(msg="VRF {} does not exist".format(vrf_name))
aruba_ansible_module = vrf.create_vrf(aruba_ansible_module, vrf_name)

port_field = {
"vrf" : vrf_name
"vrf": vrf_name
}

aruba_ansible_module = port.update_port_fields(aruba_ansible_module, interface_name, port_field)
Expand All @@ -312,13 +322,22 @@ def update_interface_vrf_details_from_vrf(self, aruba_ansible_module, vrf_name,
if not port.check_port_exists(aruba_ansible_module, interface_name):
aruba_ansible_module.module.fail_json(msg="Interface {} is not configured".format(interface_name))

result = port.get_port_field_values(aruba_ansible_module,
interface_name,
['vrf'])
if 'vrf' in result.keys():
if result['vrf'] != "" and result['vrf'] != vrf_name:
aruba_ansible_module.module.fail_json(
msg=("Interface {} is attached to VRF {}. Delete interface and recreate with VRF {}".format(
interface_name, result['vrf'], vrf_name)))

if not vrf.check_vrf_exists(aruba_ansible_module, vrf_name):
if vrf_name != "default":
aruba_ansible_module.module.fail_json(msg="VRF {} does not exist".format(vrf_name))
aruba_ansible_module = vrf.create_vrf(aruba_ansible_module, vrf_name)

port_field = {
"vrf" : vrf_name
"vrf": vrf_name
}

aruba_ansible_module = port.update_port_fields(aruba_ansible_module, interface_name, port_field)
Expand Down
13 changes: 5 additions & 8 deletions module_utils/aoscx_vrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,23 @@ def create_vrf(self, aruba_ansible_module, vrf_name):
return aruba_ansible_module

def delete_vrf(self, aruba_ansible_module, vrf_name):

error = ("VRF {} is attached to {}\nInterface must be deleted and "
error = ("VRF {} is attached to {}. Interface must be deleted and "
"created under new VRF before VRF can "
"be deleted.".format(vrf_name,
encoded_port_name.replace.replace('%2F',
'/')))

"be deleted.")
if not self.check_vrf_exists(aruba_ansible_module, vrf_name):
aruba_ansible_module.warnings.append(
"VRF {} is not configured".format(vrf_name))
return aruba_ansible_module

# Remove the ipv4 and restore the VRF to the default VRF
# Throw error if VRF is attached to an interface
if aruba_ansible_module.running_config.has_key('Port'):
port_dict = aruba_ansible_module.running_config['Port']
for encoded_port_name in port_dict.keys():
temp_port_dict = port_dict[encoded_port_name]
if 'vrf' in temp_port_dict.keys():
if temp_port_dict['vrf'] == vrf_name:
aruba_ansible_module.module.fail_json(msg=error)
aruba_ansible_module.module.fail_json(msg=error.format(vrf_name,
encoded_port_name.replace('%2F', '/')))

aruba_ansible_module.running_config['System']['vrfs'].pop(vrf_name)
return aruba_ansible_module
Expand Down

0 comments on commit a9d0f28

Please sign in to comment.