From f4cc2a1fc2e050a50672b8d8dadf48c50a18610c Mon Sep 17 00:00:00 2001 From: JayasilanJibm Date: Tue, 22 Aug 2023 16:33:32 +0530 Subject: [PATCH] #2042 slcli ipsec cancel, ipsec list, loadbal cancel command missing feature fix --- SoftLayer/CLI/loadbal/order.py | 8 +++++++- SoftLayer/CLI/vpn/ipsec/cancel.py | 10 +++++++++- SoftLayer/CLI/vpn/ipsec/list.py | 6 +++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/SoftLayer/CLI/loadbal/order.py b/SoftLayer/CLI/loadbal/order.py index 532bd3ba4..9fe7cf446 100644 --- a/SoftLayer/CLI/loadbal/order.py +++ b/SoftLayer/CLI/loadbal/order.py @@ -153,13 +153,19 @@ def order_options(env, datacenter): @click.command(cls=SoftLayer.CLI.command.SLCommand, ) @click.argument('identifier') +@click.option('--force', default=False, is_flag=True, help="Force cancel LBaaS Instance without confirmation") @environment.pass_env -def cancel(env, identifier): +def cancel(env, identifier, force): """Cancels a LBaaS instance""" mgr = SoftLayer.LoadBalancerManager(env.client) uuid, _ = mgr.get_lbaas_uuid_id(identifier) + if not force: + if not (env.skip_confirmations or + formatting.confirm("This will cancel the LBaaS Instance and cannot be undone. Continue?")): + raise exceptions.CLIAbort('Aborted') + try: mgr.cancel_lbaas(uuid) click.secho(f"LB {identifier} canceled succesfully.", fg='green') diff --git a/SoftLayer/CLI/vpn/ipsec/cancel.py b/SoftLayer/CLI/vpn/ipsec/cancel.py index 660069913..05688a106 100644 --- a/SoftLayer/CLI/vpn/ipsec/cancel.py +++ b/SoftLayer/CLI/vpn/ipsec/cancel.py @@ -5,6 +5,8 @@ import SoftLayer from SoftLayer.CLI import environment +from SoftLayer.CLI import exceptions +from SoftLayer.CLI import formatting @click.command(cls=SoftLayer.CLI.command.SLCommand, ) @@ -15,8 +17,9 @@ help="Cancels the service immediately (instead of on the billing anniversary)") @click.option('--reason', help="An optional cancellation reason. See cancel-reasons for a list of available options") +@click.option('--force', default=False, is_flag=True, help="Force cancel ipsec vpn without confirmation") @environment.pass_env -def cli(env, identifier, immediate, reason): +def cli(env, identifier, immediate, reason, force): """Cancel a IPSEC VPN tunnel context.""" manager = SoftLayer.IPSECManager(env.client) @@ -25,6 +28,11 @@ def cli(env, identifier, immediate, reason): if 'billingItem' not in context: raise SoftLayer.SoftLayerError("Cannot locate billing. May already be cancelled.") + if not force: + if not (env.skip_confirmations or + formatting.confirm("This will cancel the Ipsec Vpn and cannot be undone. Continue?")): + raise exceptions.CLIAbort('Aborted') + result = manager.cancel_item(context['billingItem']['id'], immediate, reason) if result: diff --git a/SoftLayer/CLI/vpn/ipsec/list.py b/SoftLayer/CLI/vpn/ipsec/list.py index a9f8c7034..652bd8330 100644 --- a/SoftLayer/CLI/vpn/ipsec/list.py +++ b/SoftLayer/CLI/vpn/ipsec/list.py @@ -9,8 +9,10 @@ @click.command(cls=SoftLayer.CLI.command.SLCommand, ) +@click.option('--sortby', help='Column to sort by', + default='created') @environment.pass_env -def cli(env): +def cli(env, sortby): """List IPSec VPN tunnel contexts""" manager = SoftLayer.IPSECManager(env.client) contexts = manager.get_tunnel_contexts() @@ -21,6 +23,8 @@ def cli(env): 'internal peer IP address', 'remote peer IP address', 'created']) + table.sortby = sortby + for context in contexts: table.add_row([context.get('id', ''), context.get('name', ''),