Add service enable/disable helper
This commit is contained in:
+3
-5
@@ -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
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user