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 1 commit
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
30 changes: 28 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,39 @@ 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)

closing_filter = {
'capabilities': {
'operation': 'in',
'options': [{'name': 'data', 'value': ['CLOSURE_ANNOUNCED']}]
},
'name': {
'operation': 'orderBy',
'options': [{'name': 'sort', 'value': ['DESC']}]
}
}

pods_mask = """mask[name, datacenterLongName, frontendRouterId, capabilities, datacenterId, backendRouterId,
backendRouterName, frontendRouterName]"""
caberos marked this conversation as resolved.
Show resolved Hide resolved
pods = network_manager.get_pods(mask=pods_mask, filter=closing_filter)
tables = []

# Datacenters
dc_table = formatting.Table(['Datacenter', 'Value'], title="Datacenters")
dc_table = formatting.Table(['Datacenter', 'Value', 'note'], title="Datacenters")
caberos marked this conversation as resolved.
Show resolved Hide resolved
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'])

if len(closure) == 0:
closure = ''
else:
closure = 'closed soon: %s' % (str(closure))
dc_table.add_row([location_info['name'], location_info['key'], str(closure)])
caberos marked this conversation as resolved.
Show resolved Hide resolved
tables.append(dc_table)

tables.append(_preset_prices_table(options['sizes'], prices))
Expand Down
30 changes: 28 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,41 @@ 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)

closing_filter = {
'capabilities': {
'operation': 'in',
'options': [{'name': 'data', 'value': ['CLOSURE_ANNOUNCED']}]
},
'name': {
'operation': 'orderBy',
'options': [{'name': 'sort', 'value': ['DESC']}]
}
}

pods_mask = """mask[name, datacenterLongName, frontendRouterId, capabilities, datacenterId, backendRouterId,
backendRouterName, frontendRouterName]"""
pods = network_manager.get_pods(mask=pods_mask, filter=closing_filter)

tables = []

# Datacenters
dc_table = formatting.Table(['datacenter', 'Value'], title="Datacenters")
dc_table = formatting.Table(['Datacenter', 'Value', 'note'], title="Datacenters")
caberos marked this conversation as resolved.
Show resolved Hide resolved
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'])

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

if vsi_type == 'CLOUD_SERVER':
Expand Down
8 changes: 4 additions & 4 deletions SoftLayer/managers/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,16 +779,16 @@ def cancel_item(self, identifier, cancel_immediately,
customer_note,
id=identifier)

def get_pods(self, datacenter=None):
def get_pods(self, mask=None, filter=None, datacenter=None):
caberos marked this conversation as resolved.
Show resolved Hide resolved
"""Calls SoftLayer_Network_Pod::getAllObjects()

returns list of all network pods and their routers.
"""
_filter = None

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

return self.client.call('SoftLayer_Network_Pod', 'getAllObjects', filter=_filter)
return self.client.call('SoftLayer_Network_Pod', 'getAllObjects', mask=mask, filter=filter)

def get_list_datacenter(self):
"""Calls SoftLayer_Location::getDatacenters()
Expand Down