def update_interface_vrf_details_from_l3(self, aruba_ansible_module, vrf_name, interface_name, update_type="insert"): port = Port() vrf = VRF() 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} aruba_ansible_module = port.update_port_fields(aruba_ansible_module, interface_name, port_field) return aruba_ansible_module
def update_interface_ip_helper_address(self, aruba_ansible_module, vrf_name, interface_name, ip_helper_address): vrf = VRF() if vrf_name is not None: vrf_name = 'default' if not vrf.check_vrf_exists(aruba_ansible_module, vrf_name): if vrf_name == 'default': aruba_ansible_module = vrf.create_vrf(aruba_ansible_module, vrf_name) else: aruba_ansible_module.module.fail_json( msg="VRF {vrf} is not " "configured" "".format(vrf=vrf_name)) # NOQA if 'DHCP_Relay' not in aruba_ansible_module.running_config.keys(): aruba_ansible_module.running_config['DHCP_Relay'] = {} encoded_interface_name = interface_name.replace("/", "%2F") index = '{vrf}/{int}'.format(vrf=vrf_name, int=encoded_interface_name) if index not in aruba_ansible_module.running_config["DHCP_Relay"].keys( ): # NOQA aruba_ansible_module.running_config["DHCP_Relay"][index] = {} if "ipv4_ucast_server" not in aruba_ansible_module.running_config[ "DHCP_Relay"][index].keys(): # NOQA aruba_ansible_module.running_config["DHCP_Relay"][index][ "ipv4_ucast_server"] = [] # NOQA aruba_ansible_module.running_config["DHCP_Relay"][index][ "port"] = encoded_interface_name # NOQA aruba_ansible_module.running_config["DHCP_Relay"][index][ "vrf"] = vrf_name # NOQA for item in ip_helper_address: aruba_ansible_module.running_config["DHCP_Relay"][index][ "ipv4_ucast_server"].append(item) # NOQA aruba_ansible_module.running_config["DHCP_Relay"][index][ "ipv4_ucast_server"].sort() # NOQA return aruba_ansible_module
def update_interface_vrf_details_from_vrf(self, aruba_ansible_module, vrf_name, interface_name, update_type="insert"): port = Port() vrf = VRF() if not port.check_port_exists(aruba_ansible_module, interface_name): aruba_ansible_module.module.fail_json( msg="Interface {int} is not " "configured" "".format(int=interface_name) # NOQA ) 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 {int} is attached to VRF {vrf}. " "Delete interface" " and recreate with VRF " "{vrf_name}".format(int=interface_name, vrf=result['vrf'], vrf_name=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 {vrf} does not " "exist" "".format(vrf=vrf_name)) # NOQA aruba_ansible_module = vrf.create_vrf(aruba_ansible_module, vrf_name) port_field = {"vrf": vrf_name} aruba_ansible_module = port.update_port_fields(aruba_ansible_module, interface_name, port_field) try: aruba_ansible_module = port.delete_port_fields( aruba_ansible_module, interface_name, ['ip4_address']) # NOQA aruba_ansible_module = port.delete_port_fields( aruba_ansible_module, interface_name, ['ip6_address']) # NOQA except Exception: pass return aruba_ansible_module
def update_interface_ip_helper_address(self, aruba_ansible_module, vrf_name, interface_name, ip_helper_address): vrf = VRF() if vrf_name is not None: vrf_name = 'default' if not vrf.check_vrf_exists(aruba_ansible_module, vrf_name): if vrf_name == 'default': aruba_ansible_module = vrf.create_vrf(aruba_ansible_module, vrf_name) else: aruba_ansible_module.module.fail_json( msg="VRF {} is not comfigured".format(vrf_name)) if not aruba_ansible_module.running_config.has_key('DHCP_Relay'): aruba_ansible_module.running_config['DHCP_Relay'] = {} encoded_interface_name = interface_name.replace("/", "%2F") index = '{}/{}'.format(vrf_name, encoded_interface_name) if not aruba_ansible_module.running_config["DHCP_Relay"].has_key( index): aruba_ansible_module.running_config["DHCP_Relay"][index] = {} if not aruba_ansible_module.running_config["DHCP_Relay"][ index].has_key("ipv4_ucast_server"): aruba_ansible_module.running_config["DHCP_Relay"][index][ "ipv4_ucast_server"] = [] aruba_ansible_module.running_config["DHCP_Relay"][index][ "port"] = encoded_interface_name aruba_ansible_module.running_config["DHCP_Relay"][index][ "vrf"] = vrf_name for item in ip_helper_address: aruba_ansible_module.running_config["DHCP_Relay"][index][ "ipv4_ucast_server"].append(item) aruba_ansible_module.running_config["DHCP_Relay"][index][ "ipv4_ucast_server"].sort() return aruba_ansible_module
def update_interface_vrf_details_from_l3(self, aruba_ansible_module, vrf_name, interface_name, update_type="insert"): port = Port() vrf = VRF() 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)) 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 } aruba_ansible_module = port.update_port_fields(aruba_ansible_module, interface_name, port_field) return aruba_ansible_module
def main(): module_args = dict(name=dict(type='str', required=True), state=dict(default='create', choices=['create', 'delete'])) aruba_ansible_module = ArubaAnsibleModule(module_args) vrf_name = aruba_ansible_module.module.params['name'] state = aruba_ansible_module.module.params['state'] vrf = VRF() if state == 'create': aruba_ansible_module = vrf.create_vrf(aruba_ansible_module, vrf_name) if state == 'delete': aruba_ansible_module = vrf.delete_vrf(aruba_ansible_module, vrf_name) aruba_ansible_module.update_switch_config()
def main(): module_args = dict(vrf_name=dict(type='str', required=False, default='default'), destination_address_prefix=dict(type='str', required=True), type=dict(type='str', default='forward', choices=['forward', 'blackhole', 'reject']), distance=dict(type='int', default=1), next_hop_interface=dict(type='str', default=None), next_hop_ip_address=dict(type='str', default=None), state=dict(default='create', choices=['create', 'delete'])) aruba_ansible_module = ArubaAnsibleModule(module_args) vrf_name = aruba_ansible_module.module.params['vrf_name'] prefix = aruba_ansible_module.module.params['destination_address_prefix'] route_type = aruba_ansible_module.module.params['type'] distance = aruba_ansible_module.module.params['distance'] next_hop_interface = aruba_ansible_module.module.params['next_hop_interface'] # NOQA next_hop_ip_address = aruba_ansible_module.module.params['next_hop_ip_address'] # NOQA state = aruba_ansible_module.module.params['state'] vrf = VRF() if vrf_name is None: vrf_name = 'default' if not vrf.check_vrf_exists(aruba_ansible_module, vrf_name): if vrf_name == 'default' and state == 'create': aruba_ansible_module = vrf.create_vrf(aruba_ansible_module, vrf_name) else: aruba_ansible_module.module.fail_json(msg="VRF {} is not " "configured" "".format(vrf_name)) encoded_prefix = prefix.replace("/", "%2F") index = vrf_name + '/' + encoded_prefix if (state == 'create') or (state == 'update'): address_family = 'ipv6' if ':' in prefix else 'ipv4' if not aruba_ansible_module.running_config['System']['vrfs'][vrf_name].has_key('Static_Route'): # NOQA aruba_ansible_module.running_config['System']['vrfs'][vrf_name]['Static_Route'] = {} # NOQA if not aruba_ansible_module.running_config['System']['vrfs'][vrf_name]['Static_Route'].has_key(index): # NOQA aruba_ansible_module.running_config['System']['vrfs'][vrf_name]['Static_Route'][index] = {} # NOQA if address_family is not None: aruba_ansible_module.running_config['System']['vrfs'][vrf_name]['Static_Route'][index]["address_family"] = address_family # NOQA if prefix is not None: aruba_ansible_module.running_config['System']['vrfs'][vrf_name]['Static_Route'][index]["prefix"] = prefix # NOQA if route_type is not None: aruba_ansible_module.running_config['System']['vrfs'][vrf_name]['Static_Route'][index]["type"] = route_type # NOQA if route_type == 'forward': if not aruba_ansible_module.running_config['System']['vrfs'][vrf_name]['Static_Route'][index].has_key('static_nexthops'): # NOQA aruba_ansible_module.running_config['System']['vrfs'][vrf_name]['Static_Route'][index]['static_nexthops'] = {"0": {"bfd_enable": False, "distance": distance}} # NOQA if next_hop_interface is not None: encoded_interface = next_hop_interface.replace('/', '%2F') aruba_ansible_module.running_config['System']['vrfs'][vrf_name]['Static_Route'][index]['static_nexthops']["0"]["port"] = encoded_interface # NOQA if next_hop_ip_address is not None: aruba_ansible_module.running_config['System']['vrfs'][vrf_name]['Static_Route'][index]['static_nexthops']["0"]["ip_address"] = next_hop_ip_address # NOQA if state == 'delete': if not aruba_ansible_module.running_config['System']['vrfs'][vrf_name].has_key('Static_Route'): # NOQA aruba_ansible_module.warnings.append("Static route for destination {} and does not exist in VRF{}".format(prefix, vrf_name)) # NOQA elif not aruba_ansible_module.running_config['System']['vrfs'][vrf_name]['Static_Route'].has_key(index): # NOQA aruba_ansible_module.warnings.append("Static route for destination {} and does not exist in VRF{}".format(prefix, vrf_name)) # NOQA else: aruba_ansible_module.running_config['System']['vrfs'][vrf_name]['Static_Route'].pop(index) # NOQA aruba_ansible_module.update_switch_config()