1010 USER_AGENT
1111from SoftLayer .transport import make_xml_rpc_api_call
1212from SoftLayer .exceptions import SoftLayerError
13+ from SoftLayer .deprecated import DeprecatedClientMixin
1314import os
1415
16+
1517__all__ = ['Client' , 'BasicAuthentication' , 'TokenAuthentication' ,
1618 'API_PUBLIC_ENDPOINT' , 'API_PRIVATE_ENDPOINT' ]
1719
@@ -69,7 +71,7 @@ def __repr__(self):
6971 return "<BasicAuthentication: %s>" % (self .username )
7072
7173
72- class Client (object ):
74+ class Client (DeprecatedClientMixin , object ):
7375 """ A SoftLayer API client.
7476
7577 :param service_name: the name of the SoftLayer API service to query
@@ -84,7 +86,6 @@ class Client(object):
8486 Set this to API_PRIVATE_ENDPOINT to connect via SoftLayer's private
8587 network.
8688 :param integer timeout: timeout for API requests
87- :param boolean verbose: prints details about every HTTP request if true
8889 :param auth: an object which responds to get_headers() to be inserted into
8990 the xml-rpc headers. Example: `BasicAuthentication`
9091
@@ -100,9 +101,8 @@ class Client(object):
100101 _prefix = "SoftLayer_"
101102
102103 def __init__ (self , service_name = None , id = None , username = None , api_key = None ,
103- endpoint_url = None , timeout = None , verbose = False , auth = None ):
104+ endpoint_url = None , timeout = None , auth = None ):
104105 self ._service_name = service_name
105- self .verbose = verbose
106106 self ._headers = {}
107107 self ._raw_headers = {}
108108
@@ -113,15 +113,16 @@ def __init__(self, service_name=None, id=None, username=None, api_key=None,
113113 api_key = api_key or API_KEY or os .environ .get ('SL_API_KEY' ) or ''
114114 if username and api_key :
115115 self .auth = BasicAuthentication (username , api_key )
116- self .set_authentication (username , api_key )
117-
118- if id is not None :
119- self .set_init_parameter (int (id ))
120116
121117 self ._endpoint_url = (endpoint_url or API_BASE_URL or
122118 API_PUBLIC_ENDPOINT ).rstrip ('/' )
123119 self .timeout = timeout
124120
121+ super (Client , self ).__init__ (
122+ service_name = service_name , id = id , username = username ,
123+ api_key = api_key , endpoint_url = endpoint_url , timeout = timeout ,
124+ auth = auth )
125+
125126 def authenticate_with_password (self , username , password ,
126127 security_question_id = None ,
127128 security_question_answer = None ):
@@ -143,125 +144,6 @@ def authenticate_with_password(self, username, password,
143144 self .auth = TokenAuthentication (res ['userId' ], res ['hash' ])
144145 return (res ['userId' ], res ['hash' ])
145146
146- def add_raw_header (self , name , value ):
147- """ Set HTTP headers for API calls.
148-
149- :param name: the header name
150- :param value: the header value
151-
152- .. deprecated:: 2.0.0
153-
154- """
155- self ._raw_headers [name ] = value
156-
157- def add_header (self , name , value ):
158- """ Set a SoftLayer API call header.
159-
160- :param name: the header name
161- :param value: the header value
162-
163- .. deprecated:: 2.0.0
164-
165- """
166- name = name .strip ()
167- if name is None or name == '' :
168- raise SoftLayerError ('Please specify a header name.' )
169-
170- self ._headers [name ] = value
171-
172- def remove_header (self , name ):
173- """ Remove a SoftLayer API call header.
174-
175- :param name: the header name
176-
177- .. deprecated:: 2.0.0
178-
179- """
180- if name in self ._headers :
181- del self ._headers [name .strip ()]
182-
183- def set_authentication (self , username , api_key ):
184- """ Set user and key to authenticate a SoftLayer API call.
185-
186- Use this method if you wish to bypass the API_USER and API_KEY class
187- constants and set custom authentication per API call.
188-
189- See https://manage.softlayer.com/Administrative/apiKeychain for more
190- information.
191-
192- :param username: the username to authenticate with
193- :param api_key: the user's API key
194-
195- .. deprecated:: 2.0.0
196-
197- """
198- self .add_header ('authenticate' , {
199- 'username' : username .strip (),
200- 'apiKey' : api_key .strip (),
201- })
202-
203- def set_init_parameter (self , id ):
204- """ Set an initialization parameter header.
205-
206- Initialization parameters instantiate a SoftLayer API service object to
207- act upon during your API method call. For instance, if your account has
208- a server with ID number 1234, then setting an initialization parameter
209- of 1234 in the SoftLayer_Hardware_Server Service instructs the API to
210- act on server record 1234 in your method calls.
211-
212- See http://sldn.softlayer.com/article/Using-Initialization-Parameters-SoftLayer-API # NOQA
213- for more information.
214-
215- :param id: the ID of the SoftLayer API object to instantiate
216-
217- .. deprecated:: 2.0.0
218-
219- """
220- self .add_header (self ._service_name + 'InitParameters' , {
221- 'id' : int (id )
222- })
223-
224- def set_object_mask (self , mask ):
225- """ Set an object mask to a SoftLayer API call.
226-
227- Use an object mask to retrieve data related your API call's result.
228- Object masks are skeleton objects, or strings that define nested
229- relational properties to retrieve along with an object's local
230- properties. See
231- http://sldn.softlayer.com/article/Using-Object-Masks-SoftLayer-API
232- for more information.
233-
234- :param mask: the object mask you wish to define
235-
236- .. deprecated:: 2.0.0
237-
238- """
239- header = 'SoftLayer_ObjectMask'
240-
241- if isinstance (mask , dict ):
242- header = '%sObjectMask' % self ._service_name
243-
244- self .add_header (header , {'mask' : mask })
245-
246- def set_result_limit (self , limit , offset = 0 ):
247- """ Set a result limit on a SoftLayer API call.
248-
249- Many SoftLayer API methods return a group of results. These methods
250- support a way to limit the number of results retrieved from the
251- SoftLayer API in a way akin to an SQL LIMIT statement.
252-
253- :param limit: the number of results to limit a SoftLayer API call to
254- :param offset: An optional offset at which to begin a SoftLayer API
255- call's returned result
256-
257- .. deprecated:: 2.0.0
258-
259- """
260- self .add_header ('resultLimit' , {
261- 'limit' : int (limit ),
262- 'offset' : int (offset )
263- })
264-
265147 def __getitem__ (self , name ):
266148 """ Get a SoftLayer Service.
267149
@@ -343,8 +225,7 @@ def call(self, service, method, *args, **kwargs):
343225 return make_xml_rpc_api_call (uri , method , args ,
344226 headers = headers ,
345227 http_headers = http_headers ,
346- timeout = self .timeout ,
347- verbose = self .verbose )
228+ timeout = self .timeout )
348229
349230 __call__ = call
350231
@@ -424,31 +305,6 @@ def __format_object_mask(self, objectmask, service):
424305
425306 return {mheader : {'mask' : objectmask }}
426307
427- def __getattr__ (self , name ):
428- """ Attempt a SoftLayer API call.
429-
430- Use this as a catch-all so users can call SoftLayer API methods
431- directly against their client object. If the property or method
432- relating to their client object doesn't exist then assume the user is
433- attempting a SoftLayer API call and return a simple function that makes
434- an XML-RPC call.
435-
436- :param name: method name
437-
438- .. deprecated:: 2.0.0
439-
440- """
441- if name in ["__name__" , "__bases__" ]:
442- raise AttributeError ("'Obj' object has no attribute '%s'" % name )
443-
444- def call_handler (* args , ** kwargs ):
445- if self ._service_name is None :
446- raise SoftLayerError (
447- "Service is not set on Client instance." )
448- kwargs ['headers' ] = self ._headers
449- return self .call (self ._service_name , name , * args , ** kwargs )
450- return call_handler
451-
452308 def __repr__ (self ):
453309 return "<Client: endpoint=%s, user=%r>" \
454310 % (self ._endpoint_url , self .auth )
0 commit comments