Add service enable/disable helper

This commit is contained in:
up-n-atom
2023-12-30 04:23:09 -05:00
committed by GitHub
parent e67a4db6da
commit 461133a178
2 changed files with 14 additions and 6 deletions
+3 -5
View File
@@ -13,12 +13,10 @@ def _validate_mac_address(ctx: click.Context, param: click.Parameter, value: str
@xmo.cli.command()
@click.option('-m', '--mac-address', callback=_validate_mac_address, prompt='MAC Address')
@click.pass_obj
async def enable_advanced_dmz(client: SagemcomClient, mac_address: str) -> None:
async def enable_advanced_dmz(mac_address: str) -> None:
try:
await client.set_value_by_xpath('Device/Services/BellNetworkCfg/AdvancedDMZ/Enable', False)
await client.set_value_by_xpath('Device/Services/BellNetworkCfg/AdvancedDMZ/AdvancedDMZhost', mac_address)
await client.set_value_by_xpath('Device/Services/BellNetworkCfg/AdvancedDMZ/Enable', True)
async with xmo.flipflop('Device/Services/BellNetworkCfg/AdvancedDMZ/Enable') as client:
await client.set_value_by_xpath('Device/Services/BellNetworkCfg/AdvancedDMZ/AdvancedDMZhost', mac_address)
except Exception as e:
click.echo(e, err=True)
raise click.Abort()
+11 -1
View File
@@ -60,7 +60,6 @@ async def get_value(ctx: click.Context, path: list[str]) -> None:
except Exception as e:
click.echo(e, err=True)
continue
#raise click.Abort()
else:
click.echo(json.dumps(value, indent=2))
@@ -78,3 +77,14 @@ async def set_value(ctx: click.Context, path: str, value: str) -> None:
click.echo(e, err=True)
raise click.Abort()
@asynccontextmanager
async def flipflop(xpath: str) -> None:
if (client := click.get_current_context().find_object(SagemcomClient)) is None:
raise ValueError('client not found')
await client.set_value_by_xpath(xpath, False)
try:
yield client
finally:
await client.set_value_by_xpath(xpath, True)