Skip to content

Commit 16d877a

Browse files
Merge pull request #1822 from allmightyspiff/issues1768
Fixes firewall cancel so it can properly do multiVlan firewalls
2 parents 7fdc73a + 74e89fe commit 16d877a

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

SoftLayer/CLI/command.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@
1919

2020

2121
class OptionHighlighter(RegexHighlighter):
22-
"""Provides highlighter regex for the Command help"""
22+
"""Provides highlighter regex for the Command help.
23+
24+
Defined in SoftLayer\\utils.py console_color_themes()
25+
"""
2326
highlights = [
2427
r"(?P<switch>^\-\w)", # single options like -v
2528
r"(?P<option>\-\-[\w\-]+)", # long options like --verbose
2629
r"(?P<default_option>\[[^\]]+\])", # anything between [], usually default options
30+
r"(?P<option_choices>Choices: )",
2731
]
2832

2933

@@ -223,6 +227,11 @@ def format_options(self, ctx, formatter):
223227
if help_record:
224228
help_message = param.get_help_record(ctx)[-1]
225229

230+
# Add Click choices to help message
231+
if isinstance(param.type, click.Choice):
232+
choices = ", ".join(param.type.choices)
233+
help_message += f" Choices: {choices}"
234+
226235
if param.metavar:
227236
options += f" {param.metavar}"
228237
options_table.add_row(opt1, opt2, self.highlighter(help_message))

SoftLayer/CLI/firewall/cancel.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,27 @@
66
import SoftLayer
77
from SoftLayer.CLI import environment
88
from SoftLayer.CLI import exceptions
9-
from SoftLayer.CLI import firewall
109
from SoftLayer.CLI import formatting
1110

1211

1312
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
1413
@click.argument('identifier')
14+
@click.option('--firewall-type', required=True, show_default=True, default='vlan',
15+
type=click.Choice(['vlan', 'server'], case_sensitive=False),
16+
help='Firewall type.')
1517
@environment.pass_env
16-
def cli(env, identifier):
18+
def cli(env, identifier, firewall_type):
1719
"""Cancels a firewall."""
1820

1921
mgr = SoftLayer.FirewallManager(env.client)
20-
firewall_type, firewall_id = firewall.parse_id(identifier)
2122

2223
if not (env.skip_confirmations or
23-
formatting.confirm("This action will cancel a firewall from your "
24-
"account. Continue?")):
24+
formatting.confirm("This action will cancel a firewall from your account. Continue?")):
2525
raise exceptions.CLIAbort('Aborted.')
2626

27-
if firewall_type in ['vs', 'server']:
28-
mgr.cancel_firewall(firewall_id, dedicated=False)
29-
elif firewall_type == 'vlan':
30-
mgr.cancel_firewall(firewall_id, dedicated=True)
27+
if firewall_type == 'server':
28+
mgr.cancel_firewall(identifier, dedicated=False)
3129
else:
32-
raise exceptions.CLIAbort('Unknown firewall type: %s' % firewall_type)
30+
mgr.cancel_firewall(identifier, dedicated=True)
3331

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

SoftLayer/managers/firewall.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,9 @@ def _get_fwl_billing_item(self, firewall_id, dedicated=False):
157157
firewall_service = self.client['Network_Component_Firewall']
158158
firewall = firewall_service.getObject(id=firewall_id, mask=mask)
159159
if firewall is None:
160-
raise exceptions.SoftLayerError(
161-
"Unable to find firewall %d" % firewall_id)
160+
raise exceptions.SoftLayerError(f"Unable to find firewall {firewall_id}")
162161
if firewall.get('billingItem') is None:
163-
raise exceptions.SoftLayerError(
164-
"Unable to find billing item for firewall %d" % firewall_id)
162+
raise exceptions.SoftLayerError(f"Unable to find billing item for firewall {firewall_id}")
165163

166164
return firewall['billingItem']
167165

SoftLayer/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ def console_color_themes(theme):
481481
"default_option": "light_coral",
482482
"option_keyword": "bold dark_cyan",
483483
"args_keyword": "bold green4",
484+
"option_choices": "gold3",
484485
})
485486
)
486487
return Console(theme=Theme(
@@ -497,6 +498,7 @@ def console_color_themes(theme):
497498
"default_option": "light_pink1",
498499
"option_keyword": "bold cyan",
499500
"args_keyword": "bold green",
501+
"option_choices": "gold3",
500502
})
501503
)
502504

0 commit comments

Comments
 (0)