-
Notifications
You must be signed in to change notification settings - Fork 195
Expand file tree
/
Copy pathcancel.py
More file actions
39 lines (30 loc) · 1.43 KB
/
cancel.py
File metadata and controls
39 lines (30 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""Cancel an IPSec service."""
# :license: MIT, see LICENSE for more details.
import click
import SoftLayer
from SoftLayer.CLI import environment
from SoftLayer.CLI import exceptions
from SoftLayer.CLI import formatting
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
@click.argument('identifier')
@click.option('--immediate',
is_flag=True,
default=False,
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, force):
"""Cancel a IPSEC VPN tunnel context."""
manager = SoftLayer.IPSECManager(env.client)
context = manager.get_tunnel_context(identifier, mask='billingItem')
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:
env.fout(f"Ipsec {identifier} was cancelled.")