From 5fef78815ae08ed536948db97b7ba92eac55cef3 Mon Sep 17 00:00:00 2001 From: caberos Date: Mon, 21 Mar 2022 12:12:15 -0400 Subject: [PATCH 1/8] When listing datacenters/pods, mark those that are closing soon. --- SoftLayer/CLI/hardware/create_options.py | 30 ++++++++++++++++++++++-- SoftLayer/CLI/virt/create_options.py | 30 ++++++++++++++++++++++-- SoftLayer/managers/network.py | 8 +++---- 3 files changed, 60 insertions(+), 8 deletions(-) diff --git a/SoftLayer/CLI/hardware/create_options.py b/SoftLayer/CLI/hardware/create_options.py index 646d37c09..5a59bf696 100644 --- a/SoftLayer/CLI/hardware/create_options.py +++ b/SoftLayer/CLI/hardware/create_options.py @@ -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() @@ -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]""" + 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") 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) tables.append(_preset_prices_table(options['sizes'], prices)) diff --git a/SoftLayer/CLI/virt/create_options.py b/SoftLayer/CLI/virt/create_options.py index a3ee24314..1db69fe68 100644 --- a/SoftLayer/CLI/virt/create_options.py +++ b/SoftLayer/CLI/virt/create_options.py @@ -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 @@ -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") 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': diff --git a/SoftLayer/managers/network.py b/SoftLayer/managers/network.py index 6638a29d3..6eaabfc44 100644 --- a/SoftLayer/managers/network.py +++ b/SoftLayer/managers/network.py @@ -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): """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() From c690793800ae5ae903eba3de7283dac11cf48e7a Mon Sep 17 00:00:00 2001 From: caberos Date: Tue, 22 Mar 2022 08:26:47 -0400 Subject: [PATCH 2/8] fix the team code review comments --- SoftLayer/CLI/hardware/create_options.py | 27 ++++++------------------ SoftLayer/CLI/virt/create_options.py | 26 ++++++----------------- SoftLayer/managers/network.py | 27 +++++++++++++++++++++--- 3 files changed, 37 insertions(+), 43 deletions(-) diff --git a/SoftLayer/CLI/hardware/create_options.py b/SoftLayer/CLI/hardware/create_options.py index 5a59bf696..556c3af75 100644 --- a/SoftLayer/CLI/hardware/create_options.py +++ b/SoftLayer/CLI/hardware/create_options.py @@ -25,24 +25,12 @@ def cli(env, prices, location=None): 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]""" - pods = network_manager.get_pods(mask=pods_mask, filter=closing_filter) + + pods = network_manager.get_closed_pods() tables = [] # Datacenters - dc_table = formatting.Table(['Datacenter', 'Value', 'note'], 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']: @@ -51,11 +39,10 @@ def cli(env, prices, location=None): 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)]) + 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)) diff --git a/SoftLayer/CLI/virt/create_options.py b/SoftLayer/CLI/virt/create_options.py index 1db69fe68..644e9c900 100644 --- a/SoftLayer/CLI/virt/create_options.py +++ b/SoftLayer/CLI/virt/create_options.py @@ -26,25 +26,12 @@ def cli(env, vsi_type, prices, location=None): 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) + pods = network_manager.get_closed_pods() tables = [] # Datacenters - dc_table = formatting.Table(['Datacenter', 'Value', 'note'], 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']: @@ -53,11 +40,10 @@ def cli(env, vsi_type, prices, location=None): 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)]) + 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': diff --git a/SoftLayer/managers/network.py b/SoftLayer/managers/network.py index 6eaabfc44..0f550ec3d 100644 --- a/SoftLayer/managers/network.py +++ b/SoftLayer/managers/network.py @@ -779,16 +779,17 @@ def cancel_item(self, identifier, cancel_immediately, customer_note, id=identifier) - def get_pods(self, mask=None, filter=None, datacenter=None): + def get_pods(self, datacenter=None): """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', mask=mask, filter=filter) + return self.client.call('SoftLayer_Network_Pod', 'getAllObjects', filter=_filter) def get_list_datacenter(self): """Calls SoftLayer_Location::getDatacenters() @@ -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) From 0567276624979bbee362b5bd00872897c23b8e5b Mon Sep 17 00:00:00 2001 From: caberos Date: Tue, 22 Mar 2022 08:35:27 -0400 Subject: [PATCH 3/8] fix the tox analysis --- SoftLayer/CLI/hardware/create_options.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SoftLayer/CLI/hardware/create_options.py b/SoftLayer/CLI/hardware/create_options.py index 556c3af75..b7183758b 100644 --- a/SoftLayer/CLI/hardware/create_options.py +++ b/SoftLayer/CLI/hardware/create_options.py @@ -25,8 +25,8 @@ def cli(env, prices, location=None): routers = account_manager.get_routers(location=location) network_manager = network.NetworkManager(env.client) - pods = network_manager.get_closed_pods() + tables = [] # Datacenters From 68fa92e770550471045f89b64cf6be7e5a47f977 Mon Sep 17 00:00:00 2001 From: caberos Date: Tue, 22 Mar 2022 08:40:00 -0400 Subject: [PATCH 4/8] fix the tox analysis --- SoftLayer/CLI/hardware/create_options.py | 2 +- SoftLayer/CLI/virt/create_options.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SoftLayer/CLI/hardware/create_options.py b/SoftLayer/CLI/hardware/create_options.py index b7183758b..cf09971da 100644 --- a/SoftLayer/CLI/hardware/create_options.py +++ b/SoftLayer/CLI/hardware/create_options.py @@ -36,7 +36,7 @@ def cli(env, prices, location=None): for location_info in options['locations']: closure = [] for pod in pods: - if ((location_info['key'] in str(pod['name']))): + if location_info['key'] in str(pod['name']): closure.append(pod['name']) notes = '-' diff --git a/SoftLayer/CLI/virt/create_options.py b/SoftLayer/CLI/virt/create_options.py index 644e9c900..ac84eda64 100644 --- a/SoftLayer/CLI/virt/create_options.py +++ b/SoftLayer/CLI/virt/create_options.py @@ -37,7 +37,7 @@ def cli(env, vsi_type, prices, location=None): for location_info in options['locations']: closure = [] for pod in pods: - if ((location_info['key'] in str(pod['name']))): + if location_info['key'] in str(pod['name']): closure.append(pod['name']) notes = '-' From 9083aba4b4884cc2df0dd27e37ae01466854a7d6 Mon Sep 17 00:00:00 2001 From: caberos Date: Wed, 23 Mar 2022 18:28:34 -0400 Subject: [PATCH 5/8] fix the team code review comments --- SoftLayer/CLI/order/package_locations.py | 16 ++++++++++++++-- tests/CLI/modules/order_tests.py | 3 ++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/SoftLayer/CLI/order/package_locations.py b/SoftLayer/CLI/order/package_locations.py index 9f8ffb655..984a7f276 100644 --- a/SoftLayer/CLI/order/package_locations.py +++ b/SoftLayer/CLI/order/package_locations.py @@ -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() @@ -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) diff --git a/tests/CLI/modules/order_tests.py b/tests/CLI/modules/order_tests.py index 0e8878093..a8040bafa 100644 --- a/tests/CLI/modules/order_tests.py +++ b/tests/CLI/modules/order_tests.py @@ -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'} ] print("FUCK") print(result.output) From 3c9cf602a1082b93ca8bc9a4daf05379becd5b84 Mon Sep 17 00:00:00 2001 From: caberos Date: Thu, 24 Mar 2022 08:22:30 -0400 Subject: [PATCH 6/8] fix the team code review comments --- tests/CLI/modules/order_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CLI/modules/order_tests.py b/tests/CLI/modules/order_tests.py index a8040bafa..490362b99 100644 --- a/tests/CLI/modules/order_tests.py +++ b/tests/CLI/modules/order_tests.py @@ -310,7 +310,7 @@ def test_location_list(self): self.assert_no_fail(result) expected_results = [ {'id': 2017603, 'dc': 'wdc07', 'description': 'WDC07 - Washington, DC', - 'keyName': 'WASHINGTON07','note': 'closed soon: wdc07.pod01'} + 'keyName': 'WASHINGTON07', 'note': 'closed soon: wdc07.pod01'} ] print("FUCK") print(result.output) From b8ebc9a625a582843f6f54f1b35d7d34cbee1043 Mon Sep 17 00:00:00 2001 From: caberos Date: Thu, 24 Mar 2022 10:35:25 -0400 Subject: [PATCH 7/8] fix the team code review comments --- SoftLayer/CLI/order/package_locations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SoftLayer/CLI/order/package_locations.py b/SoftLayer/CLI/order/package_locations.py index 984a7f276..2bddbf66f 100644 --- a/SoftLayer/CLI/order/package_locations.py +++ b/SoftLayer/CLI/order/package_locations.py @@ -7,7 +7,7 @@ from SoftLayer.managers import network from SoftLayer.managers import ordering -COLUMNS = ['id', 'dc', 'description', 'keyName', 'note'] +COLUMNS = ['id', 'dc', 'description', 'keyName', 'Note'] @click.command() From 79a16e5cd123c94c55a5a0772dd59272ec681016 Mon Sep 17 00:00:00 2001 From: caberos Date: Thu, 24 Mar 2022 15:38:59 -0400 Subject: [PATCH 8/8] fix the team code review comments --- tests/CLI/modules/order_tests.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/CLI/modules/order_tests.py b/tests/CLI/modules/order_tests.py index 490362b99..be03bbd17 100644 --- a/tests/CLI/modules/order_tests.py +++ b/tests/CLI/modules/order_tests.py @@ -310,10 +310,9 @@ def test_location_list(self): self.assert_no_fail(result) expected_results = [ {'id': 2017603, 'dc': 'wdc07', 'description': 'WDC07 - Washington, DC', - 'keyName': 'WASHINGTON07', 'note': 'closed soon: wdc07.pod01'} + '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):