99import socket
1010import time
1111
12- import SoftLayer
1312from SoftLayer .decoration import retry
13+ from SoftLayer .exceptions import SoftLayerError
1414from SoftLayer .managers import ordering
15+ from SoftLayer .managers .ticket import TicketManager
1516from SoftLayer import utils
1617
1718LOGGER = logging .getLogger (__name__ )
@@ -77,19 +78,18 @@ def cancel_hardware(self, hardware_id, reason='unneeded', comment='', immediate=
7778 # Get cancel reason
7879 reasons = self .get_cancellation_reasons ()
7980 cancel_reason = reasons .get (reason , reasons ['unneeded' ])
80- ticket_mgr = SoftLayer . TicketManager (self .client )
81+ ticket_mgr = TicketManager (self .client )
8182 mask = 'mask[id, hourlyBillingFlag, billingItem[id], openCancellationTicket[id], activeTransaction]'
8283 hw_billing = self .get_hardware (hardware_id , mask = mask )
8384
8485 if 'activeTransaction' in hw_billing :
85- raise SoftLayer . SoftLayerError ("Unable to cancel hardware with running transaction" )
86+ raise SoftLayerError ("Unable to cancel hardware with running transaction" )
8687
8788 if 'billingItem' not in hw_billing :
8889 if utils .lookup (hw_billing , 'openCancellationTicket' , 'id' ):
89- raise SoftLayer .SoftLayerError ("Ticket #%s already exists for this server" %
90- hw_billing ['openCancellationTicket' ]['id' ])
91- raise SoftLayer .SoftLayerError ("Cannot locate billing for the server. "
92- "The server may already be cancelled." )
90+ raise SoftLayerError ("Ticket #%s already exists for this server" %
91+ hw_billing ['openCancellationTicket' ]['id' ])
92+ raise SoftLayerError ("Cannot locate billing for the server. The server may already be cancelled." )
9393
9494 billing_id = hw_billing ['billingItem' ]['id' ]
9595
@@ -744,7 +744,7 @@ def _get_extra_price_id(items, key_name, hourly, location):
744744
745745 return price ['id' ]
746746
747- raise SoftLayer . SoftLayerError (
747+ raise SoftLayerError (
748748 "Could not find valid price for extra option, '%s'" % key_name )
749749
750750
@@ -762,7 +762,7 @@ def _get_default_price_id(items, option, hourly, location):
762762 _matches_location (price , location )]):
763763 return price ['id' ]
764764
765- raise SoftLayer . SoftLayerError (
765+ raise SoftLayerError (
766766 "Could not find valid price for '%s' option" % option )
767767
768768
@@ -792,19 +792,16 @@ def _get_bandwidth_price_id(items,
792792
793793 return price ['id' ]
794794
795- raise SoftLayer . SoftLayerError (
795+ raise SoftLayerError (
796796 "Could not find valid price for bandwidth option" )
797797
798798
799799def _get_os_price_id (items , os , location ):
800800 """Returns the price id matching."""
801801
802802 for item in items :
803- if any ([utils .lookup (item ,
804- 'itemCategory' ,
805- 'categoryCode' ) != 'os' ,
806- utils .lookup (item ,
807- 'keyName' ) != os ]):
803+ if any ([utils .lookup (item , 'itemCategory' , 'categoryCode' ) != 'os' ,
804+ utils .lookup (item , 'keyName' ) != os ]):
808805 continue
809806
810807 for price in item ['prices' ]:
@@ -813,17 +810,14 @@ def _get_os_price_id(items, os, location):
813810
814811 return price ['id' ]
815812
816- raise SoftLayer .SoftLayerError ("Could not find valid price for os: '%s'" %
817- os )
813+ raise SoftLayerError ("Could not find valid price for os: '%s'" % os )
818814
819815
820816def _get_port_speed_price_id (items , port_speed , no_public , location ):
821817 """Choose a valid price id for port speed."""
822818
823819 for item in items :
824- if utils .lookup (item ,
825- 'itemCategory' ,
826- 'categoryCode' ) != 'port_speed' :
820+ if utils .lookup (item , 'itemCategory' , 'categoryCode' ) != 'port_speed' :
827821 continue
828822
829823 # 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):
838832
839833 return price ['id' ]
840834
841- raise SoftLayer . SoftLayerError (
835+ raise SoftLayerError (
842836 "Could not find valid price for port speed: '%s'" % port_speed )
843837
844838
@@ -887,7 +881,7 @@ def _get_location(package, location):
887881 if region ['location' ]['location' ]['name' ] == location :
888882 return region
889883
890- raise SoftLayer . SoftLayerError ("Could not find valid location for: '%s'" % location )
884+ raise SoftLayerError ("Could not find valid location for: '%s'" % location )
891885
892886
893887def _get_preset_id (package , size ):
@@ -896,4 +890,4 @@ def _get_preset_id(package, size):
896890 if preset ['keyName' ] == size or preset ['id' ] == size :
897891 return preset ['id' ]
898892
899- raise SoftLayer . SoftLayerError ("Could not find valid size for: '%s'" % size )
893+ raise SoftLayerError ("Could not find valid size for: '%s'" % size )
0 commit comments