Skip to content

Commit

Permalink
Merge pull request #1597 from caberos/issue1589
Browse files Browse the repository at this point in the history
When listing datacenters/pods, mark those that are closing soon.
  • Loading branch information
allmightyspiff authored Mar 24, 2022
2 parents 2ce632b + 79a16e5 commit 51b594e
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 9 deletions.
17 changes: 15 additions & 2 deletions SoftLayer/CLI/hardware/create_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from SoftLayer.CLI import formatting
from SoftLayer.managers import account
from SoftLayer.managers import hardware
from SoftLayer.managers import network


@click.command()
Expand All @@ -22,14 +23,26 @@ def cli(env, prices, location=None):
account_manager = account.AccountManager(env.client)
options = hardware_manager.get_create_options(location)
routers = account_manager.get_routers(location=location)
network_manager = network.NetworkManager(env.client)

pods = network_manager.get_closed_pods()

tables = []

# Datacenters
dc_table = formatting.Table(['Datacenter', 'Value'], title="Datacenters")
dc_table = formatting.Table(['Datacenter', 'Value', 'Note'], title="Datacenters")
dc_table.sortby = 'Value'
dc_table.align = 'l'
for location_info in options['locations']:
dc_table.add_row([location_info['name'], location_info['key']])
closure = []
for pod in pods:
if location_info['key'] in str(pod['name']):
closure.append(pod['name'])

notes = '-'
if len(closure) > 0:
notes = 'closed soon: %s' % (', '.join(closure))
dc_table.add_row([location_info['name'], location_info['key'], notes])
tables.append(dc_table)

tables.append(_preset_prices_table(options['sizes'], prices))
Expand Down
16 changes: 14 additions & 2 deletions SoftLayer/CLI/order/package_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

from SoftLayer.CLI import environment
from SoftLayer.CLI import formatting
from SoftLayer.managers import network
from SoftLayer.managers import ordering

COLUMNS = ['id', 'dc', 'description', 'keyName']
COLUMNS = ['id', 'dc', 'description', 'keyName', 'Note']


@click.command()
Expand All @@ -18,15 +19,26 @@ def cli(env, package_keyname):
Use the location Key Name to place orders
"""
manager = ordering.OrderingManager(env.client)
network_manager = network.NetworkManager(env.client)

pods = network_manager.get_closed_pods()
table = formatting.Table(COLUMNS)

locations = manager.package_locations(package_keyname)
for region in locations:
for datacenter in region['locations']:
closure = []
for pod in pods:
if datacenter['location']['name'] in str(pod['name']):
closure.append(pod['name'])

notes = '-'
if len(closure) > 0:
notes = 'closed soon: %s' % (', '.join(closure))
table.add_row([
datacenter['location']['id'],
datacenter['location']['name'],
region['description'],
region['keyname']
region['keyname'], notes
])
env.fout(table)
16 changes: 14 additions & 2 deletions SoftLayer/CLI/virt/create_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# :license: MIT, see LICENSE for more details.
# pylint: disable=too-many-statements
import click
from SoftLayer.managers import network

import SoftLayer
from SoftLayer.CLI import environment
Expand All @@ -22,16 +23,27 @@ def cli(env, vsi_type, prices, location=None):
"""Virtual server order options."""

vsi = SoftLayer.VSManager(env.client)
network_manager = network.NetworkManager(env.client)
options = vsi.get_create_options(vsi_type, location)

pods = network_manager.get_closed_pods()

tables = []

# Datacenters
dc_table = formatting.Table(['datacenter', 'Value'], title="Datacenters")
dc_table = formatting.Table(['Datacenter', 'Value', 'Note'], title="Datacenters")
dc_table.sortby = 'Value'
dc_table.align = 'l'
for location_info in options['locations']:
dc_table.add_row([location_info['name'], location_info['key']])
closure = []
for pod in pods:
if location_info['key'] in str(pod['name']):
closure.append(pod['name'])

notes = '-'
if len(closure) > 0:
notes = 'closed soon: %s' % (', '.join(closure))
dc_table.add_row([location_info['name'], location_info['key'], notes])
tables.append(dc_table)

if vsi_type == 'CLOUD_SERVER':
Expand Down
21 changes: 21 additions & 0 deletions SoftLayer/managers/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,7 @@ def get_pods(self, datacenter=None):
returns list of all network pods and their routers.
"""
_filter = None

if datacenter:
_filter = {"datacenterName": {"operation": datacenter}}

Expand All @@ -803,3 +804,23 @@ def get_routers(self, identifier):
returns all routers locations.
"""
return self.client.call('SoftLayer_Location_Datacenter', 'getHardwareRouters', id=identifier)

def get_closed_pods(self):
"""Calls SoftLayer_Network_Pod::getAllObjects()
returns list of all closing network pods.
"""
closing_filter = {
'capabilities': {
'operation': 'in',
'options': [{'name': 'data', 'value': ['CLOSURE_ANNOUNCED']}]
},
'name': {
'operation': 'orderBy',
'options': [{'name': 'sort', 'value': ['DESC']}]
}
}

mask = """mask[name, datacenterLongName, frontendRouterId, capabilities, datacenterId, backendRouterId,
backendRouterName, frontendRouterName]"""
return self.client.call('SoftLayer_Network_Pod', 'getAllObjects', mask=mask, filter=closing_filter)
6 changes: 3 additions & 3 deletions tests/CLI/modules/order_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,10 @@ def test_location_list(self):
result = self.run_command(['order', 'package-locations', 'package'])
self.assert_no_fail(result)
expected_results = [
{'id': 2017603, 'dc': 'wdc07', 'description': 'WDC07 - Washington, DC', 'keyName': 'WASHINGTON07'}
{'id': 2017603, 'dc': 'wdc07', 'description': 'WDC07 - Washington, DC',
'keyName': 'WASHINGTON07', 'Note': 'closed soon: wdc07.pod01'}
]
print("FUCK")
print(result.output)

self.assertEqual(expected_results, json.loads(result.output))

def test_quote_verify(self):
Expand Down

0 comments on commit 51b594e

Please sign in to comment.