Skip to content

Commit 55108c5

Browse files
caberoscaberos
authored andcommitted
fix the merge conflicts
2 parents cd0195c + 10c6c31 commit 55108c5

10 files changed

Lines changed: 71 additions & 9 deletions

File tree

SoftLayer/CLI/autoscale/delete.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""Delete autoscale."""
2+
# :license: MIT, see LICENSE for more details.
3+
import click
4+
import SoftLayer
5+
6+
from SoftLayer.CLI import environment
7+
from SoftLayer.managers.autoscale import AutoScaleManager
8+
9+
10+
@click.command()
11+
@click.argument('identifier')
12+
@environment.pass_env
13+
def cli(env, identifier):
14+
"""Delete this group and destroy all members of it.
15+
16+
Example: slcli autoscale delete autoscaleId
17+
18+
"""
19+
20+
autoscale = AutoScaleManager(env.client)
21+
22+
try:
23+
autoscale.delete(identifier)
24+
click.secho("%s deleted successfully" % identifier, fg='green')
25+
except SoftLayer.SoftLayerAPIError as ex:
26+
click.secho("Failed to delete %s\n%s" % (identifier, ex), fg='red')

SoftLayer/CLI/autoscale/scale.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ def cli(env, identifier, scale_up, scale_by, amount):
3737

3838
try:
3939
# Check if the first guest has a cancellation date, assume we are removing guests if it is.
40-
cancel_date = result[0]['virtualGuest']['billingItem']['cancellationDate'] or False
40+
status = result[0]['virtualGuest']['status']['keyName'] or False
4141
except (IndexError, KeyError, TypeError):
42-
cancel_date = False
42+
status = False
4343

44-
if cancel_date:
45-
member_table = formatting.Table(['Id', 'Hostname', 'Created'], title="Cancelled Guests")
46-
else:
44+
if status == 'ACTIVE':
4745
member_table = formatting.Table(['Id', 'Hostname', 'Created'], title="Added Guests")
46+
else:
47+
member_table = formatting.Table(['Id', 'Hostname', 'Created'], title="Cancelled Guests")
4848

4949
for guest in result:
5050
real_guest = guest.get('virtualGuest')

SoftLayer/CLI/routes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,8 @@
378378
('autoscale:scale', 'SoftLayer.CLI.autoscale.scale:cli'),
379379
('autoscale:logs', 'SoftLayer.CLI.autoscale.logs:cli'),
380380
('autoscale:tag', 'SoftLayer.CLI.autoscale.tag:cli'),
381-
('autoscale:edit', 'SoftLayer.CLI.autoscale.edit:cli')
381+
('autoscale:edit', 'SoftLayer.CLI.autoscale.edit:cli'),
382+
('autoscale:delete', 'SoftLayer.CLI.autoscale.delete:cli'),
382383
]
383384

384385
ALL_ALIASES = {

SoftLayer/CLI/virt/detail.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,13 @@ def cli(env, identifier, passwords=False, price=False):
6969
table.add_row(['transient', result.get('transientGuestFlag', False)])
7070
table.add_row(['created', result['createDate']])
7171
table.add_row(['modified', result['modifyDate']])
72-
last_transaction = "{} ({})".format(utils.lookup(result, 'lastTransaction', 'transactionGroup', 'name'),
73-
utils.clean_time(utils.lookup(result, 'lastTransaction', 'modifyDate')))
72+
last_transaction = ''
73+
if result.get('lastTransaction'):
74+
last_transaction = "{} ({})".format(utils.lookup(result, 'lastTransaction', 'transactionGroup', 'name'),
75+
utils.clean_time(utils.lookup(result, 'lastTransaction', 'modifyDate')))
7476

7577
table.add_row(['last_transaction', last_transaction])
76-
table.add_row(['billing', 'Hourly' if result['hourlyBillingFlag'] else'Monthly'])
78+
table.add_row(['billing', 'Hourly' if result['hourlyBillingFlag'] else 'Monthly'])
7779
table.add_row(['preset', utils.lookup(result, 'billingItem',
7880
'orderItem',
7981
'preset',

SoftLayer/fixtures/SoftLayer_Scale_Group.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@
455455
]
456456

457457
editObject = True
458+
forceDeleteObject = True
458459

459460
createObject = {
460461
"accountId": 307608,

SoftLayer/managers/autoscale.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,13 @@ def create(self, template):
127127
.. _SoftLayer_Scale_Group: https://sldn.softlayer.com/reference/datatypes/SoftLayer_Scale_Group/
128128
"""
129129
return self.client.call('SoftLayer_Scale_Group', 'createObject', template)
130+
131+
def delete(self, identifier):
132+
"""Calls `SoftLayer_Scale_Group::forceDeleteObject()`_
133+
134+
:param identifier: SoftLayer_Scale_Group id
135+
136+
.. _SoftLayer_Scale_Group::forceDeleteObject():
137+
https://sldn.softlayer.com/reference/services/SoftLayer_Scale_Group/forceDeleteObject/
138+
"""
139+
return self.client.call('SoftLayer_Scale_Group', 'forceDeleteObject', id=identifier)

docs/cli/autoscale.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ For making changes to the triggers or the autoscale group itself, see the `Autos
3434
:prog: autoscale edit
3535
:show-nested:
3636

37+
.. click:: SoftLayer.CLI.autoscale.delete:cli
38+
:prog: autoscale delete
39+
:show-nested:
40+
3741
.. click:: SoftLayer.CLI.autoscale.create:cli
3842
:prog: autoscale create
3943
:show-nested:

tests/CLI/modules/autoscale_tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,7 @@ def test_autoscale_create(self, confirm_mock):
111111
'--disk=25'])
112112
self.assert_no_fail(result)
113113
self.assertEqual(result.exit_code, 0)
114+
115+
def test_autoscale_delete(self):
116+
result = self.run_command(['autoscale', 'delete', '12345'])
117+
self.assert_no_fail(result)

tests/CLI/modules/vs/vs_tests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,3 +947,13 @@ def test_authorize_volume_and_portable_storage_vs(self):
947947
def test_monitoring_vs(self):
948948
result = self.run_command(['vs', 'monitoring', '1234'])
949949
self.assert_no_fail(result)
950+
951+
def test_last_transaction_empty(self):
952+
vg_return = SoftLayer_Virtual_Guest.getObject
953+
transaction = []
954+
955+
vg_return['lastTransaction'] = transaction
956+
mock = self.set_mock('SoftLayer_Virtual_Guest', 'getObject')
957+
mock.return_value = vg_return
958+
result = self.run_command(['vs', 'detail', '100'])
959+
self.assert_no_fail(result)

tests/managers/autoscale_tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,7 @@ def test_create_object(self):
174174
'SoftLayer_Scale_Group',
175175
'createObject',
176176
args=(template,))
177+
178+
def test_delete_object(self):
179+
self.autoscale.delete(12345)
180+
self.assert_called_with('SoftLayer_Scale_Group', 'forceDeleteObject')

0 commit comments

Comments
 (0)