Skip to content

Commit 5fef788

Browse files
caberoscaberos
authored andcommitted
When listing datacenters/pods, mark those that are closing soon.
1 parent 2ce632b commit 5fef788

File tree

3 files changed

+60
-8
lines changed

3 files changed

+60
-8
lines changed

SoftLayer/CLI/hardware/create_options.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from SoftLayer.CLI import formatting
88
from SoftLayer.managers import account
99
from SoftLayer.managers import hardware
10+
from SoftLayer.managers import network
1011

1112

1213
@click.command()
@@ -22,14 +23,39 @@ def cli(env, prices, location=None):
2223
account_manager = account.AccountManager(env.client)
2324
options = hardware_manager.get_create_options(location)
2425
routers = account_manager.get_routers(location=location)
26+
network_manager = network.NetworkManager(env.client)
27+
28+
closing_filter = {
29+
'capabilities': {
30+
'operation': 'in',
31+
'options': [{'name': 'data', 'value': ['CLOSURE_ANNOUNCED']}]
32+
},
33+
'name': {
34+
'operation': 'orderBy',
35+
'options': [{'name': 'sort', 'value': ['DESC']}]
36+
}
37+
}
38+
39+
pods_mask = """mask[name, datacenterLongName, frontendRouterId, capabilities, datacenterId, backendRouterId,
40+
backendRouterName, frontendRouterName]"""
41+
pods = network_manager.get_pods(mask=pods_mask, filter=closing_filter)
2542
tables = []
2643

2744
# Datacenters
28-
dc_table = formatting.Table(['Datacenter', 'Value'], title="Datacenters")
45+
dc_table = formatting.Table(['Datacenter', 'Value', 'note'], title="Datacenters")
2946
dc_table.sortby = 'Value'
3047
dc_table.align = 'l'
3148
for location_info in options['locations']:
32-
dc_table.add_row([location_info['name'], location_info['key']])
49+
closure = []
50+
for pod in pods:
51+
if ((location_info['key'] in str(pod['name']))):
52+
closure.append(pod['name'])
53+
54+
if len(closure) == 0:
55+
closure = ''
56+
else:
57+
closure = 'closed soon: %s' % (str(closure))
58+
dc_table.add_row([location_info['name'], location_info['key'], str(closure)])
3359
tables.append(dc_table)
3460

3561
tables.append(_preset_prices_table(options['sizes'], prices))

SoftLayer/CLI/virt/create_options.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# :license: MIT, see LICENSE for more details.
33
# pylint: disable=too-many-statements
44
import click
5+
from SoftLayer.managers import network
56

67
import SoftLayer
78
from SoftLayer.CLI import environment
@@ -22,16 +23,41 @@ def cli(env, vsi_type, prices, location=None):
2223
"""Virtual server order options."""
2324

2425
vsi = SoftLayer.VSManager(env.client)
26+
network_manager = network.NetworkManager(env.client)
2527
options = vsi.get_create_options(vsi_type, location)
2628

29+
closing_filter = {
30+
'capabilities': {
31+
'operation': 'in',
32+
'options': [{'name': 'data', 'value': ['CLOSURE_ANNOUNCED']}]
33+
},
34+
'name': {
35+
'operation': 'orderBy',
36+
'options': [{'name': 'sort', 'value': ['DESC']}]
37+
}
38+
}
39+
40+
pods_mask = """mask[name, datacenterLongName, frontendRouterId, capabilities, datacenterId, backendRouterId,
41+
backendRouterName, frontendRouterName]"""
42+
pods = network_manager.get_pods(mask=pods_mask, filter=closing_filter)
43+
2744
tables = []
2845

2946
# Datacenters
30-
dc_table = formatting.Table(['datacenter', 'Value'], title="Datacenters")
47+
dc_table = formatting.Table(['Datacenter', 'Value', 'note'], title="Datacenters")
3148
dc_table.sortby = 'Value'
3249
dc_table.align = 'l'
3350
for location_info in options['locations']:
34-
dc_table.add_row([location_info['name'], location_info['key']])
51+
closure = []
52+
for pod in pods:
53+
if ((location_info['key'] in str(pod['name']))):
54+
closure.append(pod['name'])
55+
56+
if len(closure) == 0:
57+
closure = ''
58+
else:
59+
closure = 'closed soon: %s' % (str(closure))
60+
dc_table.add_row([location_info['name'], location_info['key'], str(closure)])
3561
tables.append(dc_table)
3662

3763
if vsi_type == 'CLOUD_SERVER':

SoftLayer/managers/network.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -779,16 +779,16 @@ def cancel_item(self, identifier, cancel_immediately,
779779
customer_note,
780780
id=identifier)
781781

782-
def get_pods(self, datacenter=None):
782+
def get_pods(self, mask=None, filter=None, datacenter=None):
783783
"""Calls SoftLayer_Network_Pod::getAllObjects()
784784
785785
returns list of all network pods and their routers.
786786
"""
787-
_filter = None
787+
788788
if datacenter:
789-
_filter = {"datacenterName": {"operation": datacenter}}
789+
filter = {"datacenterName": {"operation": datacenter}}
790790

791-
return self.client.call('SoftLayer_Network_Pod', 'getAllObjects', filter=_filter)
791+
return self.client.call('SoftLayer_Network_Pod', 'getAllObjects', mask=mask, filter=filter)
792792

793793
def get_list_datacenter(self):
794794
"""Calls SoftLayer_Location::getDatacenters()

0 commit comments

Comments
 (0)