From 47574a40f1a8bb47bde475e7dea21de5deab27b2 Mon Sep 17 00:00:00 2001 From: Christopher Gallo Date: Tue, 28 Apr 2020 16:23:44 -0500 Subject: [PATCH 1/2] fixing pylint 2.5.0 new errors --- SoftLayer/managers/dedicated_host.py | 15 ++++++----- SoftLayer/managers/hardware.py | 40 ++++++++++++---------------- SoftLayer/managers/metadata.py | 5 ++-- SoftLayer/managers/vs_capacity.py | 5 ++-- 4 files changed, 31 insertions(+), 34 deletions(-) diff --git a/SoftLayer/managers/dedicated_host.py b/SoftLayer/managers/dedicated_host.py index 86258416b..24cb3f300 100644 --- a/SoftLayer/managers/dedicated_host.py +++ b/SoftLayer/managers/dedicated_host.py @@ -7,8 +7,9 @@ """ import logging -import SoftLayer +from SoftLayer.exceptions import SoftLayerAPIError +from SoftLayer.exceptions import SoftLayerError from SoftLayer.managers import ordering from SoftLayer import utils @@ -395,7 +396,7 @@ def _get_location(self, regions, datacenter): if region['location']['location']['name'] == datacenter: return region - raise SoftLayer.SoftLayerError("Could not find valid location for: '%s'" % datacenter) + raise SoftLayerError("Could not find valid location for: '%s'" % datacenter) def get_create_options(self): """Returns valid options for ordering a dedicated host.""" @@ -426,7 +427,7 @@ def _get_price(self, package): if not price.get('locationGroupId'): return price['id'] - raise SoftLayer.SoftLayerError("Could not find valid price") + raise SoftLayerError("Could not find valid price") def _get_item(self, package, flavor): """Returns the item for ordering a dedicated host.""" @@ -435,7 +436,7 @@ def _get_item(self, package, flavor): if item['keyName'] == flavor: return item - raise SoftLayer.SoftLayerError("Could not find valid item for: '%s'" % flavor) + raise SoftLayerError("Could not find valid item for: '%s'" % flavor) def _get_backend_router(self, locations, item): """Returns valid router options for ordering a dedicated host.""" @@ -495,7 +496,7 @@ def _get_backend_router(self, locations, item): routers = self.host.getAvailableRouters(host, mask=mask) return routers - raise SoftLayer.SoftLayerError("Could not find available routers") + raise SoftLayerError("Could not find available routers") def _get_default_router(self, routers, router_name=None): """Returns the default router for ordering a dedicated host.""" @@ -508,7 +509,7 @@ def _get_default_router(self, routers, router_name=None): if router['hostname'] == router_name: return router['id'] - raise SoftLayer.SoftLayerError("Could not find valid default router") + raise SoftLayerError("Could not find valid default router") def get_router_options(self, datacenter=None, flavor=None): """Returns available backend routers for the dedicated host.""" @@ -524,7 +525,7 @@ def _delete_guest(self, guest_id): msg = 'Cancelled' try: self.guest.deleteObject(id=guest_id) - except SoftLayer.SoftLayerAPIError as e: + except SoftLayerAPIError as e: msg = 'Exception: ' + e.faultString return msg diff --git a/SoftLayer/managers/hardware.py b/SoftLayer/managers/hardware.py index 99ab45b9c..9d7cbf3f8 100644 --- a/SoftLayer/managers/hardware.py +++ b/SoftLayer/managers/hardware.py @@ -9,9 +9,10 @@ import socket import time -import SoftLayer from SoftLayer.decoration import retry +from SoftLayer.exceptions import SoftLayerError from SoftLayer.managers import ordering +from SoftLayer.managers.ticket import TicketManager from SoftLayer import utils LOGGER = logging.getLogger(__name__) @@ -77,19 +78,18 @@ def cancel_hardware(self, hardware_id, reason='unneeded', comment='', immediate= # Get cancel reason reasons = self.get_cancellation_reasons() cancel_reason = reasons.get(reason, reasons['unneeded']) - ticket_mgr = SoftLayer.TicketManager(self.client) + ticket_mgr = TicketManager(self.client) mask = 'mask[id, hourlyBillingFlag, billingItem[id], openCancellationTicket[id], activeTransaction]' hw_billing = self.get_hardware(hardware_id, mask=mask) if 'activeTransaction' in hw_billing: - raise SoftLayer.SoftLayerError("Unable to cancel hardware with running transaction") + raise SoftLayerError("Unable to cancel hardware with running transaction") if 'billingItem' not in hw_billing: if utils.lookup(hw_billing, 'openCancellationTicket', 'id'): - raise SoftLayer.SoftLayerError("Ticket #%s already exists for this server" % - hw_billing['openCancellationTicket']['id']) - raise SoftLayer.SoftLayerError("Cannot locate billing for the server. " - "The server may already be cancelled.") + raise SoftLayerError("Ticket #%s already exists for this server" % + hw_billing['openCancellationTicket']['id']) + raise SoftLayerError("Cannot locate billing for the server. The server may already be cancelled.") billing_id = hw_billing['billingItem']['id'] @@ -744,7 +744,7 @@ def _get_extra_price_id(items, key_name, hourly, location): return price['id'] - raise SoftLayer.SoftLayerError( + raise SoftLayerError( "Could not find valid price for extra option, '%s'" % key_name) @@ -762,7 +762,7 @@ def _get_default_price_id(items, option, hourly, location): _matches_location(price, location)]): return price['id'] - raise SoftLayer.SoftLayerError( + raise SoftLayerError( "Could not find valid price for '%s' option" % option) @@ -792,7 +792,7 @@ def _get_bandwidth_price_id(items, return price['id'] - raise SoftLayer.SoftLayerError( + raise SoftLayerError( "Could not find valid price for bandwidth option") @@ -800,11 +800,8 @@ def _get_os_price_id(items, os, location): """Returns the price id matching.""" for item in items: - if any([utils.lookup(item, - 'itemCategory', - 'categoryCode') != 'os', - utils.lookup(item, - 'keyName') != os]): + if any([utils.lookup(item, 'itemCategory', 'categoryCode') != 'os', + utils.lookup(item, 'keyName') != os]): continue for price in item['prices']: @@ -813,17 +810,14 @@ def _get_os_price_id(items, os, location): return price['id'] - raise SoftLayer.SoftLayerError("Could not find valid price for os: '%s'" % - os) + raise SoftLayerError("Could not find valid price for os: '%s'" % os) def _get_port_speed_price_id(items, port_speed, no_public, location): """Choose a valid price id for port speed.""" for item in items: - if utils.lookup(item, - 'itemCategory', - 'categoryCode') != 'port_speed': + if utils.lookup(item, 'itemCategory', 'categoryCode') != 'port_speed': continue # Check for correct capacity and if the item matches private only @@ -838,7 +832,7 @@ def _get_port_speed_price_id(items, port_speed, no_public, location): return price['id'] - raise SoftLayer.SoftLayerError( + raise SoftLayerError( "Could not find valid price for port speed: '%s'" % port_speed) @@ -887,7 +881,7 @@ def _get_location(package, location): if region['location']['location']['name'] == location: return region - raise SoftLayer.SoftLayerError("Could not find valid location for: '%s'" % location) + raise SoftLayerError("Could not find valid location for: '%s'" % location) def _get_preset_id(package, size): @@ -896,4 +890,4 @@ def _get_preset_id(package, size): if preset['keyName'] == size or preset['id'] == size: return preset['id'] - raise SoftLayer.SoftLayerError("Could not find valid size for: '%s'" % size) + raise SoftLayerError("Could not find valid size for: '%s'" % size) diff --git a/SoftLayer/managers/metadata.py b/SoftLayer/managers/metadata.py index cdc021515..603ff23aa 100644 --- a/SoftLayer/managers/metadata.py +++ b/SoftLayer/managers/metadata.py @@ -5,7 +5,8 @@ :license: MIT, see LICENSE for more details. """ -import SoftLayer +# import SoftLayer +from SoftLayer.API import BaseClient from SoftLayer import consts from SoftLayer import exceptions from SoftLayer import transports @@ -66,7 +67,7 @@ def __init__(self, client=None, timeout=5): timeout=timeout, endpoint_url=consts.API_PRIVATE_ENDPOINT_REST, ) - client = SoftLayer.BaseClient(transport=transport) + client = BaseClient(transport=transport) self.client = client diff --git a/SoftLayer/managers/vs_capacity.py b/SoftLayer/managers/vs_capacity.py index c2be6a615..453d51b7f 100644 --- a/SoftLayer/managers/vs_capacity.py +++ b/SoftLayer/managers/vs_capacity.py @@ -7,8 +7,9 @@ """ import logging -import SoftLayer +# import SoftLayer +from SoftLayer.exceptions import SoftLayerError from SoftLayer.managers import ordering from SoftLayer.managers.vs import VSManager from SoftLayer import utils @@ -144,7 +145,7 @@ def create_guest(self, capacity_id, test, guest_object): capacity_flavor = capacity['instances'][0]['billingItem']['item']['keyName'] flavor = _flavor_string(capacity_flavor, guest_object['primary_disk']) except KeyError: - raise SoftLayer.SoftLayerError("Unable to find capacity Flavor.") + raise SoftLayerError("Unable to find capacity Flavor.") guest_object['flavor'] = flavor guest_object['datacenter'] = capacity['backendRouter']['datacenter']['name'] From 2d6155aa646dc991ec8a3d7b55718677d739cf71 Mon Sep 17 00:00:00 2001 From: Christopher Gallo Date: Tue, 28 Apr 2020 16:25:11 -0500 Subject: [PATCH 2/2] removing dead imports --- SoftLayer/managers/dedicated_host.py | 1 - SoftLayer/managers/metadata.py | 1 - SoftLayer/managers/vs_capacity.py | 1 - 3 files changed, 3 deletions(-) diff --git a/SoftLayer/managers/dedicated_host.py b/SoftLayer/managers/dedicated_host.py index 24cb3f300..89246da28 100644 --- a/SoftLayer/managers/dedicated_host.py +++ b/SoftLayer/managers/dedicated_host.py @@ -5,7 +5,6 @@ :license: MIT, see License for more details. """ - import logging from SoftLayer.exceptions import SoftLayerAPIError diff --git a/SoftLayer/managers/metadata.py b/SoftLayer/managers/metadata.py index 603ff23aa..13f350add 100644 --- a/SoftLayer/managers/metadata.py +++ b/SoftLayer/managers/metadata.py @@ -5,7 +5,6 @@ :license: MIT, see LICENSE for more details. """ -# import SoftLayer from SoftLayer.API import BaseClient from SoftLayer import consts from SoftLayer import exceptions diff --git a/SoftLayer/managers/vs_capacity.py b/SoftLayer/managers/vs_capacity.py index 453d51b7f..3f6574f12 100644 --- a/SoftLayer/managers/vs_capacity.py +++ b/SoftLayer/managers/vs_capacity.py @@ -7,7 +7,6 @@ """ import logging -# import SoftLayer from SoftLayer.exceptions import SoftLayerError from SoftLayer.managers import ordering