Skip to content

Commit 51b594e

Browse files
Merge pull request #1597 from caberos/issue1589
When listing datacenters/pods, mark those that are closing soon.
2 parents 2ce632b + 79a16e5 commit 51b594e

File tree

5 files changed

+67
-9
lines changed

5 files changed

+67
-9
lines changed

SoftLayer/CLI/hardware/create_options.py

Lines changed: 15 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,26 @@ 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+
pods = network_manager.get_closed_pods()
29+
2530
tables = []
2631

2732
# Datacenters
28-
dc_table = formatting.Table(['Datacenter', 'Value'], title="Datacenters")
33+
dc_table = formatting.Table(['Datacenter', 'Value', 'Note'], title="Datacenters")
2934
dc_table.sortby = 'Value'
3035
dc_table.align = 'l'
3136
for location_info in options['locations']:
32-
dc_table.add_row([location_info['name'], location_info['key']])
37+
closure = []
38+
for pod in pods:
39+
if location_info['key'] in str(pod['name']):
40+
closure.append(pod['name'])
41+
42+
notes = '-'
43+
if len(closure) > 0:
44+
notes = 'closed soon: %s' % (', '.join(closure))
45+
dc_table.add_row([location_info['name'], location_info['key'], notes])
3346
tables.append(dc_table)
3447

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

SoftLayer/CLI/order/package_locations.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
from SoftLayer.CLI import environment
66
from SoftLayer.CLI import formatting
7+
from SoftLayer.managers import network
78
from SoftLayer.managers import ordering
89

9-
COLUMNS = ['id', 'dc', 'description', 'keyName']
10+
COLUMNS = ['id', 'dc', 'description', 'keyName', 'Note']
1011

1112

1213
@click.command()
@@ -18,15 +19,26 @@ def cli(env, package_keyname):
1819
Use the location Key Name to place orders
1920
"""
2021
manager = ordering.OrderingManager(env.client)
22+
network_manager = network.NetworkManager(env.client)
23+
24+
pods = network_manager.get_closed_pods()
2125
table = formatting.Table(COLUMNS)
2226

2327
locations = manager.package_locations(package_keyname)
2428
for region in locations:
2529
for datacenter in region['locations']:
30+
closure = []
31+
for pod in pods:
32+
if datacenter['location']['name'] in str(pod['name']):
33+
closure.append(pod['name'])
34+
35+
notes = '-'
36+
if len(closure) > 0:
37+
notes = 'closed soon: %s' % (', '.join(closure))
2638
table.add_row([
2739
datacenter['location']['id'],
2840
datacenter['location']['name'],
2941
region['description'],
30-
region['keyname']
42+
region['keyname'], notes
3143
])
3244
env.fout(table)

SoftLayer/CLI/virt/create_options.py

Lines changed: 14 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,27 @@ 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+
pods = network_manager.get_closed_pods()
30+
2731
tables = []
2832

2933
# Datacenters
30-
dc_table = formatting.Table(['datacenter', 'Value'], title="Datacenters")
34+
dc_table = formatting.Table(['Datacenter', 'Value', 'Note'], title="Datacenters")
3135
dc_table.sortby = 'Value'
3236
dc_table.align = 'l'
3337
for location_info in options['locations']:
34-
dc_table.add_row([location_info['name'], location_info['key']])
38+
closure = []
39+
for pod in pods:
40+
if location_info['key'] in str(pod['name']):
41+
closure.append(pod['name'])
42+
43+
notes = '-'
44+
if len(closure) > 0:
45+
notes = 'closed soon: %s' % (', '.join(closure))
46+
dc_table.add_row([location_info['name'], location_info['key'], notes])
3547
tables.append(dc_table)
3648

3749
if vsi_type == 'CLOUD_SERVER':

SoftLayer/managers/network.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,7 @@ def get_pods(self, datacenter=None):
785785
returns list of all network pods and their routers.
786786
"""
787787
_filter = None
788+
788789
if datacenter:
789790
_filter = {"datacenterName": {"operation": datacenter}}
790791

@@ -803,3 +804,23 @@ def get_routers(self, identifier):
803804
returns all routers locations.
804805
"""
805806
return self.client.call('SoftLayer_Location_Datacenter', 'getHardwareRouters', id=identifier)
807+
808+
def get_closed_pods(self):
809+
"""Calls SoftLayer_Network_Pod::getAllObjects()
810+
811+
returns list of all closing network pods.
812+
"""
813+
closing_filter = {
814+
'capabilities': {
815+
'operation': 'in',
816+
'options': [{'name': 'data', 'value': ['CLOSURE_ANNOUNCED']}]
817+
},
818+
'name': {
819+
'operation': 'orderBy',
820+
'options': [{'name': 'sort', 'value': ['DESC']}]
821+
}
822+
}
823+
824+
mask = """mask[name, datacenterLongName, frontendRouterId, capabilities, datacenterId, backendRouterId,
825+
backendRouterName, frontendRouterName]"""
826+
return self.client.call('SoftLayer_Network_Pod', 'getAllObjects', mask=mask, filter=closing_filter)

tests/CLI/modules/order_tests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,10 @@ def test_location_list(self):
309309
result = self.run_command(['order', 'package-locations', 'package'])
310310
self.assert_no_fail(result)
311311
expected_results = [
312-
{'id': 2017603, 'dc': 'wdc07', 'description': 'WDC07 - Washington, DC', 'keyName': 'WASHINGTON07'}
312+
{'id': 2017603, 'dc': 'wdc07', 'description': 'WDC07 - Washington, DC',
313+
'keyName': 'WASHINGTON07', 'Note': 'closed soon: wdc07.pod01'}
313314
]
314-
print("FUCK")
315-
print(result.output)
315+
316316
self.assertEqual(expected_results, json.loads(result.output))
317317

318318
def test_quote_verify(self):

0 commit comments

Comments
 (0)