Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When listing datacenters/pods, mark those that are closing soon. #1597

Merged
merged 8 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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']
caberos marked this conversation as resolved.
Show resolved Hide resolved


@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)
3 changes: 2 additions & 1 deletion tests/CLI/modules/order_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ 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'}
caberos marked this conversation as resolved.
Show resolved Hide resolved
]
print("FUCK")
print(result.output)
Expand Down