Skip to content

Commit b2a396e

Browse files
J JayasilanJ Jayasilan
authored andcommitted
--force option for slcli firewall add, firewall cancel command
1 parent cd58715 commit b2a396e

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

SoftLayer/CLI/firewall/add.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@
1111

1212
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
1313
@click.argument('target')
14-
@click.option('--firewall-type',
15-
type=click.Choice(['vs', 'vlan', 'server']),
16-
help='Firewall type',
17-
required=True)
18-
@click.option('-ha', '--high-availability',
19-
is_flag=True,
20-
help='High available firewall option')
14+
@click.option('--firewall-type', type=click.Choice(['vs', 'vlan', 'server']), help='Firewall type', required=True)
15+
@click.option("-h", '--high-availability', is_flag=True, help='High available firewall option')
16+
@click.option('-f', '--force', default=False, is_flag=True, help="Force addition of firewall to the server")
2117
@environment.pass_env
22-
def cli(env, target, firewall_type, high_availability):
18+
def cli(env, target, firewall_type, high_availability, force):
2319
"""Create new firewall.
2420
2521
TARGET: Id of the server the firewall will protect
@@ -43,8 +39,9 @@ def cli(env, target, firewall_type, high_availability):
4339
click.echo("Price: $%s monthly" % pkg[0]['prices'][0]['recurringFee'])
4440
click.echo("******************")
4541

46-
if not formatting.confirm("This action will incur charges on your account. Continue?"):
47-
raise exceptions.CLIAbort('Aborted.')
42+
if not force:
43+
if not formatting.confirm("This action will incur charges on your account. Continue?"):
44+
raise exceptions.CLIAbort('Aborted.')
4845

4946
if firewall_type == 'vlan':
5047
mgr.add_vlan_firewall(target, ha_enabled=high_availability)

SoftLayer/CLI/firewall/cancel.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@
1414
@click.option('--firewall-type', required=True, show_default=True, default='vlan',
1515
type=click.Choice(['vlan', 'server'], case_sensitive=False),
1616
help='Firewall type.')
17+
@click.option('-f', '--force', default=False, is_flag=True, help="Force cancel firewall of the server")
1718
@environment.pass_env
18-
def cli(env, identifier, firewall_type):
19+
def cli(env, identifier, firewall_type, force):
1920
"""Cancels a firewall."""
2021

2122
mgr = SoftLayer.FirewallManager(env.client)
22-
23-
if not (env.skip_confirmations or
24-
formatting.confirm("This action will cancel a firewall from your account. Continue?")):
25-
raise exceptions.CLIAbort('Aborted.')
23+
if not force:
24+
if not (env.skip_confirmations or
25+
formatting.confirm("This action will cancel a firewall from your account. Continue?")):
26+
raise exceptions.CLIAbort('Aborted.')
2627

2728
if firewall_type == 'server':
2829
mgr.cancel_firewall(identifier, dedicated=False)

tests/CLI/modules/firewall_tests.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_list_firewalls(self):
2121
@mock.patch('SoftLayer.CLI.formatting.confirm')
2222
def test_add_vs(self, confirm_mock):
2323
confirm_mock.return_value = True
24-
result = self.run_command(['firewall', 'add', '1000', '--firewall-type=vlan', '-ha'])
24+
result = self.run_command(['firewall', 'add', '1000', '--firewall-type=vlan', '-h'])
2525
self.assert_no_fail(result)
2626
self.assertIn("Firewall is being created!", result.output)
2727

@@ -158,3 +158,24 @@ def test_edit(self, confirm_mock):
158158
def test_monitoring(self):
159159
result = self.run_command(['firewall', 'monitoring', '123456'])
160160
print(result.output)
161+
162+
@mock.patch('SoftLayer.CLI.formatting.confirm')
163+
def test_add_firewall_force(self, confirm_mock):
164+
confirm_mock.return_value = False
165+
result = self.run_command(['firewall', 'add', '1000', '--firewall-type=vlan', '-h', '--force'])
166+
self.assert_no_fail(result)
167+
self.assertIn("Firewall is being created!", result.output)
168+
169+
@mock.patch('SoftLayer.CLI.formatting.confirm')
170+
def test_add_firewall_no_force(self, confirm_mock):
171+
confirm_mock.return_value = False
172+
result = self.run_command(['firewall', 'add', '1000', '--firewall-type=vlan', '-h'])
173+
self.assertEqual(2, result.exit_code)
174+
175+
@mock.patch('SoftLayer.CLI.formatting.confirm')
176+
def test_cancel_firewall_no_force(self, confirm_mock):
177+
confirm_mock.return_value = False
178+
result = self.run_command(['firewall', 'cancel', 'vlan:1234'])
179+
self.assertEqual(2, result.exit_code)
180+
print(result.output)
181+
self.assertEqual('Aborted.', result.exception.message)

0 commit comments

Comments
 (0)