docs: improve readme and add robust lifecycle tests
This commit is contained in:
parent
9c8c771cb1
commit
ce67360c3c
4 changed files with 162 additions and 68 deletions
|
|
@ -96,6 +96,23 @@ def dns_remove_host(config, mac):
|
|||
mgr.remove_host(mac)
|
||||
click.echo(f"Removed host {mac}")
|
||||
|
||||
@dns.command(name='add-dns')
|
||||
@click.argument('domain')
|
||||
@click.argument('ip')
|
||||
@click.pass_obj
|
||||
def dns_add_dns(config, domain, ip):
|
||||
mgr = DNSManager(config)
|
||||
mgr.add_dns(domain, ip)
|
||||
click.echo(f"Added DNS record for {domain} -> {ip}")
|
||||
|
||||
@dns.command(name='remove-dns')
|
||||
@click.argument('domain')
|
||||
@click.pass_obj
|
||||
def dns_remove_dns(config, domain):
|
||||
mgr = DNSManager(config)
|
||||
mgr.remove_dns(domain)
|
||||
click.echo(f"Removed DNS record for {domain}")
|
||||
|
||||
@dns.command(name='list')
|
||||
@click.pass_obj
|
||||
def dns_list(config):
|
||||
|
|
@ -147,6 +164,17 @@ def router():
|
|||
@click.argument('int_port')
|
||||
@click.pass_obj
|
||||
def router_add(config, name, proto, ext_port, int_ip, int_port):
|
||||
import ipaddress
|
||||
# Validate IP and Ports in CLI layer for better error messages
|
||||
try:
|
||||
ipaddress.ip_address(int_ip)
|
||||
except ValueError:
|
||||
raise click.BadParameter(f"Invalid internal IP address: {int_ip}")
|
||||
|
||||
for p in [ext_port, int_port]:
|
||||
if not (1 <= int(p) <= 65535):
|
||||
raise click.BadParameter(f"Port {p} out of range (1-65535)")
|
||||
|
||||
mgr = RouterManager(config)
|
||||
mgr.add_forward(name, proto, ext_port, int_ip, int_port)
|
||||
click.echo(f"Added port forward {name}")
|
||||
|
|
@ -156,8 +184,12 @@ def router_add(config, name, proto, ext_port, int_ip, int_port):
|
|||
@click.pass_obj
|
||||
def router_remove(config, section):
|
||||
mgr = RouterManager(config)
|
||||
mgr.remove_forward(section)
|
||||
click.echo(f"Removed port forward {section}")
|
||||
try:
|
||||
mgr.remove_forward(section)
|
||||
click.echo(f"Removed port forward {section}")
|
||||
except ValueError as e:
|
||||
click.echo(f"Error: {e}", err=True)
|
||||
sys.exit(1)
|
||||
|
||||
@router.command(name='list')
|
||||
@click.pass_obj
|
||||
|
|
|
|||
|
|
@ -33,6 +33,11 @@ class RouterManager:
|
|||
self.run_uci(cmds)
|
||||
|
||||
def remove_forward(self, section_name):
|
||||
# Check existence first
|
||||
res = self.client.run(f"uci get firewall.{section_name}")
|
||||
if res.returncode != 0:
|
||||
raise ValueError(f"Port forward section '{section_name}' not found")
|
||||
|
||||
cmds = f"uci delete firewall.{section_name}; uci commit firewall; /etc/init.d/firewall reload"
|
||||
self.run_uci(cmds)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue