Skip to content

Commit 5f99361

Browse files
Merge pull request #2061 from softlayer/jayasilan-issue2015
Example text and some features for slcli block volume-cancel, slcli block volume-duplicate command #2015
2 parents 0c2ef90 + ca37722 commit 5f99361

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

SoftLayer/CLI/block/cancel.py

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

2329
block_storage_manager = SoftLayer.BlockStorageManager(env.client)
2430

25-
if not (env.skip_confirmations or formatting.no_going_back(volume_id)):
26-
raise exceptions.CLIAbort('Aborted')
31+
if not force:
32+
if not (env.skip_confirmations or
33+
formatting.confirm(f"This will cancel the block volume: {volume_id} and cannot be undone. Continue?")):
34+
raise exceptions.CLIAbort('Aborted')
2735

2836
cancelled = block_storage_manager.cancel_block_volume(volume_id,
2937
reason, immediate)

SoftLayer/CLI/block/duplicate.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@
6464
def cli(env, origin_volume_id, origin_snapshot_id, duplicate_size,
6565
duplicate_iops, duplicate_tier, duplicate_snapshot_size, billing,
6666
dependent_duplicate):
67-
"""Order a duplicate block storage volume."""
67+
"""Order a duplicate block storage volume.
68+
69+
Example::
70+
slcli block volume-duplicate 12345678
71+
This command shows order a new volume by duplicating the volume with ID 12345678.
72+
"""
73+
6874
block_manager = SoftLayer.BlockStorageManager(env.client)
6975

7076
hourly_billing_flag = False

tests/CLI/modules/block_tests.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,3 +978,18 @@ def test_block_duplicate_covert_status(self):
978978

979979
self.assert_no_fail(result)
980980
self.assert_called_with('SoftLayer_Network_Storage', 'getDuplicateConversionStatus')
981+
982+
@mock.patch('SoftLayer.CLI.formatting.confirm')
983+
def test_cancel_block_volume_force(self, confirm_mock):
984+
confirm_mock.return_value = False
985+
result = self.run_command(['block', 'volume-cancel', '12345678', '--immediate', '--force'])
986+
self.assert_no_fail(result)
987+
self.assertEqual('Block volume with id 12345678 has been marked'
988+
' for immediate cancellation\n', result.output)
989+
990+
@mock.patch('SoftLayer.CLI.formatting.confirm')
991+
def test_cancel_block_volume_no_force(self, confirm_mock):
992+
confirm_mock.return_value = False
993+
result = self.run_command(['block', 'volume-cancel', '12345678'])
994+
self.assertEqual(2, result.exit_code)
995+
self.assertEqual('Aborted', result.exception.message)

0 commit comments

Comments
 (0)