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 (33 lines) | stat: -rw-r--r-- 1,194 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
"""Cancels a firewall."""
# :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('--firewall-type', required=True, show_default=True, default='vlan',
              type=click.Choice(['vlan', 'server'], case_sensitive=False),
              help='Firewall type.')
@click.option('-f', '--force',  default=False, is_flag=True, help="Force cancel firewall of the server")
@environment.pass_env
def cli(env, identifier, firewall_type, force):
    """Cancels a firewall."""

    mgr = SoftLayer.FirewallManager(env.client)
    if not force:
        if not (env.skip_confirmations or
                formatting.confirm("This action will cancel a firewall from your account. Continue?")):
            raise exceptions.CLIAbort('Aborted.')

    if firewall_type == 'server':
        mgr.cancel_firewall(identifier, dedicated=False)
    else:
        mgr.cancel_firewall(identifier, dedicated=True)

    env.fout('Firewall with id %s is being cancelled!' % identifier)