Skip to content

Commit c3938a2

Browse files
Merge pull request #2083 from ramkishor-ch/issue_2026
added example in order, partners and cancel in file, added force and unit test cases in order, cancel commands.
2 parents 5798373 + 16b32cf commit c3938a2

File tree

4 files changed

+69
-8
lines changed

4 files changed

+69
-8
lines changed

SoftLayer/CLI/file/replication/order.py

Lines changed: 30 additions & 3 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
from SoftLayer.CLI import helpers
910
from SoftLayer import utils
1011

@@ -27,21 +28,47 @@
2728
help='Endurance Storage Tier (IOPS per GB) of the primary'
2829
' volume for which a replicant is ordered [optional]',
2930
type=click.Choice(['0.25', '2', '4', '10']))
31+
@click.option('--iops', '-i', type=int,
32+
help='Performance Storage IOPs, between 100 and 6000 in multiples of 100,'
33+
'if no IOPS value is specified, the IOPS value of the original volume will be used',
34+
)
35+
@click.option('--force', default=False, is_flag=True, help="Force cancel block volume without confirmation")
3036
@environment.pass_env
31-
def cli(env, volume_id, snapshot_schedule, location, tier):
32-
"""Order a file storage replica volume."""
37+
def cli(env, volume_id, snapshot_schedule, location, tier, iops, force):
38+
"""Order a file storage replica volume.
39+
40+
Example::
41+
slcli file replica-order 12345678 -s DAILY -d dal09 --tier 4 --os-type LINUX
42+
This command orders a replica for volume with ID 12345678, which performs DAILY
43+
replication, is located at dal09, tier level is 4, OS type is Linux.
44+
"""
3345
file_manager = SoftLayer.FileStorageManager(env.client)
3446
file_volume_id = helpers.resolve_id(file_manager.resolve_ids, volume_id, 'File Storage')
3547

3648
if tier is not None:
3749
tier = float(tier)
3850

51+
if iops is not None:
52+
if iops < 100 or iops > 6000:
53+
raise exceptions.CLIHalt("-i|--iops must be between 100 and 6000, inclusive. "
54+
"Run 'slcli block volume-options' to check available options.")
55+
56+
if iops % 100 != 0:
57+
raise exceptions.CLIHalt("-i|--iops must be a multiple of 100. "
58+
"Run 'slcli block volume-options' to check available options.")
59+
60+
if not force:
61+
if not (env.skip_confirmations or
62+
formatting.confirm(f"This will Order a file storage replica volume: {volume_id} "
63+
"and cannot be undone. Continue?")):
64+
raise exceptions.CLIAbort('Aborted.')
65+
3966
try:
4067
order = file_manager.order_replicant_volume(
4168
file_volume_id,
4269
snapshot_schedule=snapshot_schedule,
4370
location=location,
44-
tier=tier,
71+
tier=tier, iops=iops,
4572
)
4673
except ValueError as ex:
4774
raise exceptions.ArgumentError(str(ex))

SoftLayer/CLI/file/replication/partners.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
default=','.join(DEFAULT_COLUMNS))
2222
@environment.pass_env
2323
def cli(env, columns, sortby, volume_id):
24-
"""List existing replicant volumes for a file volume."""
24+
"""List existing replicant volumes for a file volume.
25+
26+
Example::
27+
slcli file replica-partners 12345678
28+
This command lists existing replicant volumes for block volume with ID 12345678.
29+
"""
2530
file_storage_manager = SoftLayer.FileStorageManager(env.client)
2631

2732
legal_volumes = file_storage_manager.get_replication_partners(

SoftLayer/CLI/file/snapshot/cancel.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,21 @@
1616
is_flag=True,
1717
help="Cancels the snapshot space 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 existing snapshot space for a given volume."""
21+
def cli(env, volume_id, reason, immediate, force):
22+
"""Cancel existing snapshot space for a given volume.
23+
24+
Example::
25+
slcli file snapshot-cancel 12345678 --immediate -f
26+
This command cancels snapshot with ID 12345678 immediately without asking for confirmation.
27+
"""
2228

2329
file_storage_manager = SoftLayer.FileStorageManager(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 formatting.no_going_back(volume_id)):
33+
raise exceptions.CLIAbort('Aborted.')
2734

2835
cancelled = file_storage_manager.cancel_snapshot_space(
2936
volume_id, reason, immediate)

tests/CLI/modules/file_tests.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,3 +828,25 @@ def test_modify_order_no_force(self, confirm_mock):
828828

829829
self.assertEqual(2, result.exit_code)
830830
self.assertEqual('Aborted', result.exception.message)
831+
832+
def test_file_replica_order_iops(self):
833+
result_1 = self.run_command(['file', 'replica-order', '4917309', '-s', 'HOURLY', '-l', 'dal09', '-i', '121'])
834+
self.assertEqual("-i|--iops must be a multiple of 100. "
835+
"Run 'slcli block volume-options' to check available options.\n", result_1.output)
836+
result_2 = self.run_command(['file', 'replica-order', '4917309', '-s', 'HOURLY', '-l', 'dal09', '-i', '90'])
837+
self.assertEqual("-i|--iops must be between 100 and 6000, inclusive. "
838+
"Run 'slcli block volume-options' to check available options.\n", result_2.output)
839+
840+
@mock.patch('SoftLayer.CLI.formatting.confirm')
841+
def test_file_replica_order_force(self, confirm_mock):
842+
confirm_mock.return_value = False
843+
result = self.run_command(['file', 'replica-order', '4917309', '-s', 'HOURLY', '-l', 'dal09'])
844+
self.assertEqual(2, result.exit_code)
845+
self.assertEqual('Aborted.', result.exception.message)
846+
847+
@mock.patch('SoftLayer.CLI.formatting.confirm')
848+
def test_file_snapshot_cancel_force(self, confirm_mock):
849+
confirm_mock.return_value = False
850+
result = self.run_command(['file', 'snapshot-cancel', '4917309'])
851+
self.assertEqual(2, result.exit_code)
852+
self.assertEqual('Aborted.', result.exception.message)

0 commit comments

Comments
 (0)