add func: del

This commit is contained in:
arT
2025-08-02 13:01:36 +08:00
parent 3d955c5c80
commit 260b31f271
2 changed files with 43 additions and 2 deletions

View File

@ -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.
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)
```

26
main.py
View File

@ -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()