31
31
from urllib import urlencode
32
32
from urlparse import urlparse
33
33
34
- from ovirtsdk4 import version
35
34
from ovirtsdk4 .http import Response
36
35
36
+ def get_version ():
37
+ from ovirtsdk4 import version
38
+ return version .VERSION
37
39
38
40
class Error (Exception ):
39
41
"""
@@ -44,20 +46,22 @@ class Error(Exception):
44
46
def __init__ (self , message , code = None , fault = None ):
45
47
"""
46
48
Creates an instance of Error class.
47
-
48
- `message`:: The exception message.
49
-
50
- `code`:: An error code associated to the error. For HTTP related
51
- errors, this will be the HTTP response code returned by the server.
52
- For example, if retrieving of a virtual machine fails because it
53
- doesn't exist this attribute will contain the integer value 404. Note
54
- that this may be `nil` if the error is not HTTP related.
55
-
56
- `fault`:: The `Fault` object associated to the error.
57
49
"""
58
50
super (Error , self ).__init__ (message )
51
+ """
52
+ Creates an instance of Error class.
53
+ """
59
54
self .code = code
55
+ """
56
+ An error code associated to the error. For HTTP related
57
+ errors, this will be the HTTP response code returned by the server.
58
+ For example, if retrieving of a virtual machine fails because it
59
+ doesn't exist this attribute will contain the integer value 404. Note
60
+ that this may be `nil` if the error is not HTTP related."""
60
61
self .fault = fault
62
+ """
63
+ The `Fault` object associated to the error.
64
+ """
61
65
62
66
63
67
class AuthError (Error ):
@@ -230,70 +234,87 @@ def __init__(
230
234
231
235
This method supports the following parameters:
232
236
233
- `url`:: A string containing the base URL of the server, usually
237
+ `url` \n
238
+ A string containing the base URL of the server, usually
234
239
something like `https://server.example.com/ovirt-engine/api`.
235
240
236
- `username`:: The name of the user, something like `admin@internal`.
241
+ `username` \n
242
+ The name of the user, something like `admin@internal`.
237
243
238
- `password`:: The name password of the user.
244
+ `password` \n
245
+ The name password of the user.
239
246
240
- `token`:: : The token to be used to access API. Optionally, user can
247
+ `token` \n
248
+ The token to be used to access API. Optionally, user can
241
249
use token, instead of username and password to access API. If user
242
250
don't specify `token` parameter, SDK will automatically create one.
243
251
244
- `insecure`:: A boolean flag that indicates if the server TLS
252
+ `insecure` \n
253
+ A boolean flag that indicates if the server TLS
245
254
certificate and host name should be checked.
246
255
247
- `ca_file`:: A PEM file containing the trusted CA certificates. The
256
+ `ca_file` \n
257
+ A PEM file containing the trusted CA certificates. The
248
258
certificate presented by the server will be verified using these CA
249
259
certificates. If `ca_file` parameter is not set, system wide
250
260
CA certificate store is used.
251
261
252
- `debug`:: A boolean flag indicating if debug output should be
262
+ `debug` \n
263
+ A boolean flag indicating if debug output should be
253
264
generated. If the value is `True` and the `log` parameter isn't
254
265
`None` then the data sent to and received from the server will
255
266
be written to the log. Be aware that user names and passwords will
256
267
also be written, so handle it with care.
257
268
258
- `log`:: The logger where the log messages will be written.
269
+ `log` \n
270
+ The logger where the log messages will be written.
259
271
260
- `kerberos`:: A boolean flag indicating if Kerberos
272
+ `kerberos` \n
273
+ A boolean flag indicating if Kerberos
261
274
authentication should be used instead of the default basic
262
275
authentication.
263
276
264
- `timeout`:: The maximum total time to wait for the response, in
277
+ `timeout` \n
278
+ The maximum total time to wait for the response, in
265
279
seconds. A value of zero (the default) means wait for ever. If
266
280
the timeout expires before the response is received an exception
267
281
will be raised.
268
282
269
- `compress`:: A boolean flag indicating if the SDK should ask
283
+ `compress` \n
284
+ A boolean flag indicating if the SDK should ask
270
285
the server to send compressed responses. The default is `True`.
271
286
Note that this is a hint for the server, and that it may return
272
287
uncompressed data even when this parameter is set to `True`.
273
288
Note that compression will be disabled if user pass `debug`
274
289
parameter set to `true`, so the debug messages are in plain text.
275
290
276
- `sso_url`:: A string containing the base SSO URL of the serve.
291
+ `sso_url` \n
292
+ A string containing the base SSO URL of the serve.
277
293
Default SSO url is computed from the `url` if no `sso_url` is provided.
278
294
279
- `sso_revoke_url`:: A string containing the base URL of the SSO
295
+ `sso_revoke_url` \n
296
+ A string containing the base URL of the SSO
280
297
revoke service. This needs to be specified only when using
281
298
an external authentication service. By default this URL
282
299
is automatically calculated from the value of the `url` parameter,
283
300
so that SSO token revoke will be performed using the SSO service
284
301
that is part of the engine.
285
302
286
- `sso_token_name`:: The token name in the JSON SSO response returned
303
+ `sso_token_name` \n
304
+ The token name in the JSON SSO response returned
287
305
from the SSO server. Default value is `access_token`.
288
306
289
- `headers`:: A dictionary with headers which should be send with every
307
+ `headers` \n
308
+ A dictionary with headers which should be send with every
290
309
request.
291
310
292
- `connections`:: The maximum number of connections to open to the host.
311
+ `connections` \n
312
+ The maximum number of connections to open to the host.
293
313
If the value is `0` (the default) then the number of connections will
294
314
be unlimited.
295
315
296
- `pipeline`:: The maximum number of request to put in an HTTP pipeline
316
+ `pipeline` \n
317
+ The maximum number of request to put in an HTTP pipeline
297
318
without waiting for the response. If the value is `0` (the default)
298
319
then pipelining is disabled.
299
320
"""
@@ -360,7 +381,8 @@ def send(self, request):
360
381
361
382
This method supports the following parameters.
362
383
363
- `request`:: The Request object containing the details of the HTTP
384
+ `request` \n
385
+ The Request object containing the details of the HTTP
364
386
request to send.
365
387
366
388
The returned value is a Request object containing the details of the
@@ -445,7 +467,7 @@ def __send(self, request):
445
467
for header_name , header_value in headers_dict .items ():
446
468
header_lines .append ('%s: %s' % (header_name , header_value ))
447
469
448
- header_lines .append ('User-Agent: PythonSDK/%s' % version . VERSION )
470
+ header_lines .append ('User-Agent: PythonSDK/%s' % get_version () )
449
471
header_lines .append ('Version: 4' )
450
472
header_lines .append ('Content-Type: application/xml' )
451
473
header_lines .append ('Accept: application/xml' )
@@ -796,7 +818,7 @@ def close(self, logout=True):
796
818
"""
797
819
Releases the resources used by this connection.
798
820
799
- `logout`:: A boolean, which specify if token should be revoked,
821
+ `logout` A boolean, which specify if token should be revoked,
800
822
and so user should be logged out.
801
823
"""
802
824
@@ -818,10 +840,10 @@ def _build_url(self, path='', query=None):
818
840
819
841
This method supports the following parameters:
820
842
821
- `path`:: The path that will be added to the base URL. The default is an
843
+ `path` The path that will be added to the base URL. The default is an
822
844
empty string.
823
845
824
- `query`:: A dictionary containing the query parameters to add to the
846
+ `query` A dictionary containing the query parameters to add to the
825
847
URL. The keys of the dictionary should be strings containing the names
826
848
of the parameters, and the values should be strings containing the
827
849
values.
@@ -841,7 +863,7 @@ def check_xml_content_type(self, response):
841
863
XML then it does nothing. If it isn't XML then it raises an
842
864
exception.
843
865
844
- `response`:: The HTTP response to check.
866
+ `response` The HTTP response to check.
845
867
"""
846
868
return self ._check_content_type (
847
869
self .__XML_CONTENT_TYPE_RE ,
@@ -855,7 +877,7 @@ def check_json_content_type(self, response):
855
877
JSON then it does nothing. If it isn't JSON then it raises an
856
878
exception.
857
879
858
- `response`:: The HTTP response to check.
880
+ `response` The HTTP response to check.
859
881
"""
860
882
return self ._check_content_type (
861
883
self .__JSON_CONTENT_TYPE_RE ,
@@ -868,10 +890,10 @@ def _check_content_type(self, expected_re, expected_name, headers):
868
890
Checks the given content type and raises an exception if it isn't the
869
891
expected one.
870
892
871
- `expected_re`:: The regular expression used to check the expected
893
+ `expected_re` The regular expression used to check the expected
872
894
content type.
873
- `expected_name`:: The name of the expected content type.
874
- `headers`:: The HTTP headers to check.
895
+ `expected_name` The name of the expected content type.
896
+ `headers` The HTTP headers to check.
875
897
"""
876
898
content_type = self ._get_header_value (headers , 'content-type' )
877
899
if expected_re .match (content_type ) is None :
@@ -892,7 +914,7 @@ def _read_reponse(self, context):
892
914
"""
893
915
Read the response.
894
916
895
- `context`:: tuple which contains cur easy, response body,
917
+ `context` tuple which contains cur easy, response body,
896
918
response headers, original request
897
919
"""
898
920
# Extract the response code and body:
@@ -935,8 +957,8 @@ def _get_header_value(self, headers, name):
935
957
"""
936
958
Return header value by its name.
937
959
938
- `headers`:: list of headers
939
- `name`:: name of the header
960
+ `headers` list of headers
961
+ `name` name of the header
940
962
"""
941
963
return next (
942
964
(h .split (':' )[1 ].strip () for h in headers if h .lower ().startswith (name )),
@@ -984,8 +1006,7 @@ class ConnectionBuilder(object):
984
1006
equivalent to calling the constructor of the `Connection`
985
1007
class. Typical use will be like this:
986
1008
987
- [source,python]
988
- ----
1009
+ ```python
989
1010
# Create the builder once:
990
1011
builder = ConnectionBuilder(
991
1012
url='https://enginer40.example.com/ovirt-engine/api',
@@ -1001,7 +1022,7 @@ class ConnectionBuilder(object):
1001
1022
# Create and use a second connection:
1002
1023
with builder.build() as connection:
1003
1024
...
1004
- ----
1025
+ ```
1005
1026
"""
1006
1027
1007
1028
def __init__ (self , ** kwargs ):
@@ -1029,7 +1050,7 @@ def build(self):
1029
1050
# import ovirtsdk4 as sdk
1030
1051
# vm = sdk.types.Vm()
1031
1052
#
1032
- from ovirtsdk4 import readers # noqa: F401
1033
- from ovirtsdk4 import services # noqa: F401
1034
- from ovirtsdk4 import types # noqa: F401
1035
- from ovirtsdk4 import writers # noqa: F401
1053
+ import ovirtsdk4 . readers as readers # noqa: F401
1054
+ import ovirtsdk4 . writers as writers # noqa: F401
1055
+ import ovirtsdk4 . types as types # noqa: F401
1056
+ import ovirtsdk4 . services as services # noqa: F401
0 commit comments