Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 8 additions & 8 deletions SoftLayer/managers/dedicated_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

:license: MIT, see License for more details.
"""

import logging
import SoftLayer

from SoftLayer.exceptions import SoftLayerAPIError
from SoftLayer.exceptions import SoftLayerError
from SoftLayer.managers import ordering
from SoftLayer import utils

Expand Down Expand Up @@ -395,7 +395,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."""
Expand Down Expand Up @@ -426,7 +426,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."""
Expand All @@ -435,7 +435,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."""
Expand Down Expand Up @@ -495,7 +495,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."""
Expand All @@ -508,7 +508,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."""
Expand All @@ -524,7 +524,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
40 changes: 17 additions & 23 deletions SoftLayer/managers/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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']

Expand Down Expand Up @@ -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)


Expand All @@ -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)


Expand Down Expand Up @@ -792,19 +792,16 @@ def _get_bandwidth_price_id(items,

return price['id']

raise SoftLayer.SoftLayerError(
raise SoftLayerError(
"Could not find valid price for bandwidth option")


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']:
Expand All @@ -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
Expand All @@ -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)


Expand Down Expand Up @@ -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):
Expand All @@ -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)
4 changes: 2 additions & 2 deletions SoftLayer/managers/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

:license: MIT, see LICENSE for more details.
"""
import SoftLayer
from SoftLayer.API import BaseClient
from SoftLayer import consts
from SoftLayer import exceptions
from SoftLayer import transports
Expand Down Expand Up @@ -66,7 +66,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

Expand Down
4 changes: 2 additions & 2 deletions SoftLayer/managers/vs_capacity.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"""

import logging
import SoftLayer

from SoftLayer.exceptions import SoftLayerError
from SoftLayer.managers import ordering
from SoftLayer.managers.vs import VSManager
from SoftLayer import utils
Expand Down Expand Up @@ -144,7 +144,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']
Expand Down