Skip to content

Commit 384d39f

Browse files
Ramkishor ChaladiRamkishor Chaladi
authored andcommitted
added force feature in cancel and duplicate for volume command
1 parent 5405da7 commit 384d39f

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

SoftLayer/CLI/file/cancel.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,21 @@
1616
is_flag=True,
1717
help="Cancels the file storage volume immediately instead "
1818
"of on the billing anniversary")
19+
@click.option('--force', default=False, is_flag=True, help="Force modify")
1920
@environment.pass_env
20-
def cli(env, volume_id, reason, immediate):
21+
def cli(env, volume_id, reason, immediate, force):
2122
"""Cancel an existing file storage volume.
22-
23+
2324
EXAMPLE::
2425
slcli file volume-cancel 12345678 --immediate -f
2526
This command cancels volume with ID 12345678 immediately and without asking for confirmation.
2627
"""
2728

2829
file_storage_manager = SoftLayer.FileStorageManager(env.client)
2930

30-
if not (env.skip_confirmations or formatting.no_going_back(volume_id)):
31-
raise exceptions.CLIAbort('Aborted')
31+
if not force:
32+
if not (env.skip_confirmations or formatting.no_going_back(volume_id)):
33+
raise exceptions.CLIAbort('Aborted.')
3234

3335
cancelled = file_storage_manager.cancel_file_volume(volume_id,
3436
reason, immediate)

SoftLayer/CLI/file/duplicate.py

Lines changed: 9 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()}
@@ -58,12 +59,13 @@
5859
show_default=True,
5960
help='Whether or not this duplicate will be a dependent duplicate'
6061
'of the origin volume.')
62+
@click.option('--force', default=False, is_flag=True, help="Force modify")
6163
@environment.pass_env
6264
def cli(env, origin_volume_id, origin_snapshot_id, duplicate_size,
6365
duplicate_iops, duplicate_tier, duplicate_snapshot_size, billing,
64-
dependent_duplicate):
66+
dependent_duplicate, force):
6567
"""Order a duplicate file storage volume.
66-
68+
6769
EXAMPLE::
6870
slcli file volume-duplicate 12345678
6971
This command shows order a new volume by duplicating the volume with ID 12345678.
@@ -77,6 +79,11 @@ def cli(env, origin_volume_id, origin_snapshot_id, duplicate_size,
7779
if duplicate_tier is not None:
7880
duplicate_tier = float(duplicate_tier)
7981

82+
if not force:
83+
if not (env.skip_confirmations or formatting.confirm("This action will incur charges on your account."
84+
"Continue?")):
85+
raise exceptions.CLIAbort('Aborted.')
86+
8087
try:
8188
order = file_manager.order_duplicate_volume(
8289
origin_volume_id,

SoftLayer/CLI/file/limit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
@environment.pass_env
2020
def cli(env, sortby, datacenter):
2121
"""List number of block storage volumes limit per datacenter.
22-
22+
2323
EXAMPLE:
2424
slcli file volume-limits
2525
This command lists the storage limits per datacenter for this account.

tests/CLI/modules/file_tests.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,3 +850,17 @@ def test_file_snapshot_cancel_force(self, confirm_mock):
850850
result = self.run_command(['file', 'snapshot-cancel', '4917309'])
851851
self.assertEqual(2, result.exit_code)
852852
self.assertEqual('Aborted.', result.exception.message)
853+
854+
@mock.patch('SoftLayer.CLI.formatting.confirm')
855+
def test_file_volume_cancel_force(self, confirm_mock):
856+
confirm_mock.return_value = False
857+
result = self.run_command(['file', 'volume-cancel', '1234'])
858+
self.assertEqual(2, result.exit_code)
859+
self.assertEqual('Aborted.', result.exception.message)
860+
861+
@mock.patch('SoftLayer.CLI.formatting.confirm')
862+
def test_file_volume_duplicate_force(self, confirm_mock):
863+
confirm_mock.return_value = False
864+
result = self.run_command(['file', 'volume-duplicate', '100'])
865+
self.assertEqual(2, result.exit_code)
866+
self.assertEqual('Aborted.', result.exception.message)

0 commit comments

Comments
 (0)