Skip to content

Commit 7641f50

Browse files
caberoscaberos
authored andcommitted
Need a command for slcli object-storage delete <storageId>
1 parent be23dbb commit 7641f50

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""Cancel an existing object-storage account."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
import SoftLayer
7+
from SoftLayer.CLI import environment
8+
from SoftLayer.CLI import exceptions
9+
from SoftLayer.CLI import formatting
10+
11+
12+
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
13+
@click.argument('storage-id')
14+
@click.option('--reason', help="An optional reason for cancellation")
15+
@click.option('--immediate',
16+
is_flag=True,
17+
help="Cancels the object storage immediately instead "
18+
"of on the billing anniversary")
19+
@environment.pass_env
20+
def cli(env, storage_id, reason, immediate):
21+
"""Cancel an existing object storage."""
22+
23+
block_storage_manager = SoftLayer.BlockStorageManager(env.client)
24+
25+
if not (env.skip_confirmations or formatting.no_going_back(storage_id)):
26+
raise exceptions.CLIAbort('Aborted')
27+
28+
cancelled = block_storage_manager.cancel_block_volume(storage_id,
29+
reason, immediate)
30+
31+
if cancelled:
32+
if immediate:
33+
click.echo('Object storage with id %s has been marked'
34+
' for immediate cancellation' % storage_id)
35+
else:
36+
click.echo('Object storage with id %s has been marked'
37+
' for cancellation' % storage_id)
38+
else:
39+
click.echo('Unable to cancel object storage %s' % storage_id)

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@
260260
('object-storage:accounts', 'SoftLayer.CLI.object_storage.list_accounts:cli'),
261261
('object-storage:endpoints', 'SoftLayer.CLI.object_storage.list_endpoints:cli'),
262262
('object-storage:credential', 'SoftLayer.CLI.object_storage.credential:cli'),
263+
('object-storage:cancel', 'SoftLayer.CLI.object_storage.cancel:cli'),
263264

264265
('order', 'SoftLayer.CLI.order'),
265266
('order:category-list', 'SoftLayer.CLI.order.category_list:cli'),

docs/cli/object_storage.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ Object Storage Commands
2828
.. click:: SoftLayer.CLI.object_storage.credential.create:cli
2929
:prog: object-storage credential create
3030
:show-nested:
31+
32+
.. click:: SoftLayer.CLI.object_storage.cancel:cli
33+
:prog: object-storage cancel
34+
:show-nested:

tests/CLI/modules/object_storage_tests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,13 @@ def test_list_credential_by_username(self, resolve_id_mock):
120120
resolve_id_mock.return_value = 100
121121
result = self.run_command(['object-storage', 'credential', 'list', 'test'])
122122
self.assert_no_fail(result)
123+
124+
def test_object_storage_cancel(self):
125+
result = self.run_command([
126+
'--really', 'object-storage', 'cancel', '1234'])
127+
128+
self.assert_no_fail(result)
129+
self.assertEqual('Object storage with id 1234 has been marked'
130+
' for cancellation\n', result.output)
131+
self.assert_called_with('SoftLayer_Billing_Item', 'cancelItem',
132+
args=(False, True, None))

0 commit comments

Comments
 (0)