File: cancel.py

package info (click to toggle)
python-softlayer 6.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,508 kB
  • sloc: python: 57,195; makefile: 133; xml: 97; sh: 59
file content (47 lines) | stat: -rw-r--r-- 1,811 bytes parent folder | download
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
40
41
42
43
44
45
46
47
"""Cancel an existing iSCSI account."""
# :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('volume-id')
@click.option('--reason', help="An optional reason for cancellation")
@click.option('--immediate',
              is_flag=True,
              help="Cancels the block storage volume immediately instead "
                   "of on the billing anniversary")
@click.option('--force', default=False, is_flag=True, help="Force cancel block volume without confirmation")
@environment.pass_env
def cli(env, volume_id, reason, immediate, force):
    """Cancel an existing block storage volume.

    Example::
        slcli block volume-cancel 12345678 --immediate -f
        This command cancels volume with ID 12345678 immediately and without asking for confirmation.
"""

    block_storage_manager = SoftLayer.BlockStorageManager(env.client)

    if not force:
        if not (env.skip_confirmations or
                formatting.confirm(f"This will cancel the block volume: {volume_id} and cannot be undone. Continue?")):
            raise exceptions.CLIAbort('Aborted')

    cancelled = block_storage_manager.cancel_block_volume(volume_id,
                                                          reason, immediate)

    if cancelled:
        if immediate:
            click.echo('Block volume with id %s has been marked'
                       ' for immediate cancellation' % volume_id)
        else:
            click.echo('Block volume with id %s has been marked'
                       ' for cancellation' % volume_id)
    else:
        click.echo('Unable to cancel block volume %s' % volume_id)