diff --git a/README.md b/README.md index a6414a5..2119f03 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,21 @@ This program uses the Tenantos API and Tenantos event listener to process Layer ### Installation -Simply use the requirements.txt to install the required libs and you are ready to go. \ No newline at end of file +Simply use the requirements.txt to install the required libs and you are ready to go. + + +### Arguments + +``` +--action {add/del} + add route/delete route + +--server {int} + server-id + +--subnet {int} + related subnet-id + +--ip {str} + ip address(IPv4/IPv6) +``` \ No newline at end of file diff --git a/main.py b/main.py index 07d814b..0eb3f61 100644 --- a/main.py +++ b/main.py @@ -94,7 +94,7 @@ if __name__ == "__main__": ) if af == 4: config_command = [] - config_command = [ f'set routing-instances {VRF} routing-options static route {ip}/32 next-hop {switch["port_name"]}' ] + config_command = [ f'set routing-instances {VRF} routing-options static route {ip}/32 next-hop {switch["port_name"]}.0' ] elif af == 6: config_command = [] cidr = get_cidr(args.subnet) @@ -109,3 +109,27 @@ if __name__ == "__main__": config_command = [ f'set routing-instances {VRF} routing-options static route {ip}/{cidr} next-hop {ptp}' ] switch_connect.send_config_set(config_command) switch_connect.disconnect() + elif args.action == "del": + switch_connect = ConnectHandler( + device_type = "juniper_junos", + host = switch["switch_address"], + username = switch["switch_user"], + password = switch["switch_pass"], + ) + if af == 4: + config_command = [] + config_command = [ f'delete routing-instances {VRF} routing-options static route {ip}/32 next-hop {switch["port_name"]}.0' ] + elif af == 6: + config_command = [] + cidr = get_cidr(args.subnet) + if cidr == 127: + subnet = ipaddress.ip_network(f'{ip}/127') + config_command = [ f'delete interface {switch["port_name"]}.0 family inet6 address {subnet[0]}/127' ] + else: + show_command = [ f'show interfaces {switch["port_name"]}.0 terse | match inet6' ] + show_output = switch_connect.send_command(show_command) + if not show_output.strip(): + ptp = ipaddress.ip_network(f'{re.findall(r'inet6\s+([\da-f:]+)', show_output)}/127')[1] + config_command = [ f'delete routing-instances {VRF} routing-options static route {ip}/{cidr} next-hop {ptp}' ] + switch_connect.send_config_set(config_command) + switch_connect.disconnect() \ No newline at end of file