Skip to content

Added Example and some sub features in slcli file volume-cancel, slcli file volume-duplicate, slcli file volume-limits #2084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions SoftLayer/CLI/file/cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@
is_flag=True,
help="Cancels the file storage volume immediately instead "
"of on the billing anniversary")
@click.option('--force', default=False, is_flag=True, help="Force modify")
@environment.pass_env
def cli(env, volume_id, reason, immediate):
"""Cancel an existing file storage volume."""
def cli(env, volume_id, reason, immediate, force):
"""Cancel an existing file storage volume.

EXAMPLE::
slcli file volume-cancel 12345678 --immediate -f
This command cancels volume with ID 12345678 immediately and without asking for confirmation.
"""

file_storage_manager = SoftLayer.FileStorageManager(env.client)

if not (env.skip_confirmations or formatting.no_going_back(volume_id)):
raise exceptions.CLIAbort('Aborted')
if not force:
if not (env.skip_confirmations or formatting.no_going_back(volume_id)):
raise exceptions.CLIAbort('Aborted.')

cancelled = file_storage_manager.cancel_file_volume(volume_id,
reason, immediate)
Expand Down
16 changes: 14 additions & 2 deletions SoftLayer/CLI/file/duplicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import SoftLayer
from SoftLayer.CLI import environment
from SoftLayer.CLI import exceptions
from SoftLayer.CLI import formatting


CONTEXT_SETTINGS = {'token_normalize_func': lambda x: x.upper()}
Expand Down Expand Up @@ -58,11 +59,17 @@
show_default=True,
help='Whether or not this duplicate will be a dependent duplicate'
'of the origin volume.')
@click.option('--force', default=False, is_flag=True, help="Force modify")
@environment.pass_env
def cli(env, origin_volume_id, origin_snapshot_id, duplicate_size,
duplicate_iops, duplicate_tier, duplicate_snapshot_size, billing,
dependent_duplicate):
"""Order a duplicate file storage volume."""
dependent_duplicate, force):
"""Order a duplicate file storage volume.

EXAMPLE::
slcli file volume-duplicate 12345678
This command shows order a new volume by duplicating the volume with ID 12345678.
"""
file_manager = SoftLayer.FileStorageManager(env.client)

hourly_billing_flag = False
Expand All @@ -72,6 +79,11 @@ def cli(env, origin_volume_id, origin_snapshot_id, duplicate_size,
if duplicate_tier is not None:
duplicate_tier = float(duplicate_tier)

if not force:
if not (env.skip_confirmations or formatting.confirm("This action will incur charges on your account."
"Continue?")):
raise exceptions.CLIAbort('Aborted.')

try:
order = file_manager.order_duplicate_volume(
origin_volume_id,
Expand Down
7 changes: 6 additions & 1 deletion SoftLayer/CLI/file/limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
@click.option('--datacenter', '-d', help='Filter by datacenter')
@environment.pass_env
def cli(env, sortby, datacenter):
"""List number of block storage volumes limit per datacenter."""
"""List number of block storage volumes limit per datacenter.

EXAMPLE:
slcli file volume-limits
This command lists the storage limits per datacenter for this account.
"""
file_manager = SoftLayer.FileStorageManager(env.client)
file_volumes = file_manager.list_file_volume_limit()

Expand Down
14 changes: 14 additions & 0 deletions tests/CLI/modules/file_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,3 +850,17 @@ def test_file_snapshot_cancel_force(self, confirm_mock):
result = self.run_command(['file', 'snapshot-cancel', '4917309'])
self.assertEqual(2, result.exit_code)
self.assertEqual('Aborted.', result.exception.message)

@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_file_volume_cancel_force(self, confirm_mock):
confirm_mock.return_value = False
result = self.run_command(['file', 'volume-cancel', '1234'])
self.assertEqual(2, result.exit_code)
self.assertEqual('Aborted.', result.exception.message)

@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_file_volume_duplicate_force(self, confirm_mock):
confirm_mock.return_value = False
result = self.run_command(['file', 'volume-duplicate', '100'])
self.assertEqual(2, result.exit_code)
self.assertEqual('Aborted.', result.exception.message)