Skip to content

Commit 8562473

Browse files
Merge pull request #2052 from softlayer/jayasilan-issue2032
--force option for slcli firewall add, firewall cancel command - issue #2032
2 parents 029e87d + a05ee7c commit 8562473

File tree

7 files changed

+67
-20
lines changed

7 files changed

+67
-20
lines changed

SoftLayer/CLI/file/list.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@
6767
default=','.join(DEFAULT_COLUMNS))
6868
@environment.pass_env
6969
def cli(env, sortby, columns, datacenter, username, storage_type, order):
70-
"""List file storage."""
70+
"""List file storage.
71+
72+
Example::
73+
slcli file volume-list -d dal10 --storage-type endurance --sortby capacity_gb
74+
"""
7175
file_manager = SoftLayer.FileStorageManager(env.client)
7276
file_volumes = file_manager.list_file_volumes(datacenter=datacenter,
7377
username=username,

SoftLayer/CLI/file/modify.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import SoftLayer
66
from SoftLayer.CLI import environment
77
from SoftLayer.CLI import exceptions
8+
from SoftLayer.CLI import formatting
89

910

1011
CONTEXT_SETTINGS = {'token_normalize_func': lambda x: x.upper()}
@@ -31,9 +32,19 @@
3132
'be 0.25. If original IOPS/GB for the volume is greater than 0.25, new IOPS/GB for the volume '
3233
'must also be greater than 0.25.]',
3334
type=click.Choice(['0.25', '2', '4', '10']))
35+
@click.option('--force', default=False, is_flag=True, help="Force modify")
3436
@environment.pass_env
35-
def cli(env, volume_id, new_size, new_iops, new_tier):
36-
"""Modify an existing file storage volume."""
37+
def cli(env, volume_id, new_size, new_iops, new_tier, force):
38+
"""Modify an existing file storage volume.
39+
40+
Example::
41+
slcli file volume-modify 12345678 --new-size 1000 --new-iops 400
42+
"""
43+
if not force:
44+
if not (env.skip_confirmations or
45+
formatting.confirm("This action will incur charges on your account. Continue?")):
46+
raise exceptions.CLIAbort('Aborted')
47+
3748
file_manager = SoftLayer.FileStorageManager(env.client)
3849

3950
if new_tier is not None:

SoftLayer/CLI/file/options.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
'add it to the --prices option using location short name, e.g. --prices dal13')
2020
@environment.pass_env
2121
def cli(env, prices, location=None):
22-
"""List all options for ordering a block storage"""
22+
"""List all options for ordering a block storage
23+
24+
Example::
25+
slcli file volume-options
26+
slcli file volume-options --prices dal13
27+
"""
2328

2429
order_manager = SoftLayer.OrderingManager(env.client)
2530
items = order_manager.get_items(PACKAGE_STORAGE)

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/file_tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,3 +820,11 @@ def test_snapshot_get_notification_status(self, status):
820820
def test_volume_options(self):
821821
result = self.run_command(['file', 'volume-options'])
822822
self.assert_no_fail(result)
823+
824+
@mock.patch('SoftLayer.CLI.formatting.confirm')
825+
def test_modify_order_no_force(self, confirm_mock):
826+
confirm_mock.return_value = False
827+
result = self.run_command(['file', 'volume-modify', '102'])
828+
829+
self.assertEqual(2, result.exit_code)
830+
self.assertEqual('Aborted', result.exception.message)

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)