Skip to content

Commit f12b10c

Browse files
Sync with upstream
1 parent a55cb8c commit f12b10c

4 files changed

Lines changed: 94 additions & 67 deletions

File tree

lib/ovirtsdk4/__init__.py

Lines changed: 74 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import os
2222
import pycurl
2323
import re
24-
import six
2524
import sys
2625
import threading
2726

@@ -31,10 +30,14 @@
3130
from urllib import urlencode
3231
from urlparse import urlparse
3332

34-
from ovirtsdk4 import version
3533
from ovirtsdk4.http import Response
3634

3735

36+
def get_version():
37+
from ovirtsdk4 import version
38+
return version.VERSION
39+
40+
3841
class Error(Exception):
3942
"""
4043
General exception which is thrown by SDK,
@@ -44,20 +47,22 @@ class Error(Exception):
4447
def __init__(self, message, code=None, fault=None):
4548
"""
4649
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.
5750
"""
5851
super(Error, self).__init__(message)
52+
"""
53+
Creates an instance of Error class.
54+
"""
5955
self.code = code
56+
"""
57+
An error code associated to the error. For HTTP related
58+
errors, this will be the HTTP response code returned by the server.
59+
For example, if retrieving of a virtual machine fails because it
60+
doesn't exist this attribute will contain the integer value 404. Note
61+
that this may be `nil` if the error is not HTTP related."""
6062
self.fault = fault
63+
"""
64+
The `Fault` object associated to the error.
65+
"""
6166

6267

6368
class AuthError(Error):
@@ -230,70 +235,87 @@ def __init__(
230235
231236
This method supports the following parameters:
232237
233-
`url`:: A string containing the base URL of the server, usually
238+
`url` \n
239+
A string containing the base URL of the server, usually
234240
something like `https://server.example.com/ovirt-engine/api`.
235241
236-
`username`:: The name of the user, something like `admin@internal`.
242+
`username` \n
243+
The name of the user, something like `admin@internal`.
237244
238-
`password`:: The name password of the user.
245+
`password` \n
246+
The name password of the user.
239247
240-
`token`:: : The token to be used to access API. Optionally, user can
248+
`token` \n
249+
The token to be used to access API. Optionally, user can
241250
use token, instead of username and password to access API. If user
242251
don't specify `token` parameter, SDK will automatically create one.
243252
244-
`insecure`:: A boolean flag that indicates if the server TLS
253+
`insecure` \n
254+
A boolean flag that indicates if the server TLS
245255
certificate and host name should be checked.
246256
247-
`ca_file`:: A PEM file containing the trusted CA certificates. The
257+
`ca_file` \n
258+
A PEM file containing the trusted CA certificates. The
248259
certificate presented by the server will be verified using these CA
249260
certificates. If `ca_file` parameter is not set, system wide
250261
CA certificate store is used.
251262
252-
`debug`:: A boolean flag indicating if debug output should be
263+
`debug` \n
264+
A boolean flag indicating if debug output should be
253265
generated. If the value is `True` and the `log` parameter isn't
254266
`None` then the data sent to and received from the server will
255267
be written to the log. Be aware that user names and passwords will
256268
also be written, so handle it with care.
257269
258-
`log`:: The logger where the log messages will be written.
270+
`log` \n
271+
The logger where the log messages will be written.
259272
260-
`kerberos`:: A boolean flag indicating if Kerberos
273+
`kerberos` \n
274+
A boolean flag indicating if Kerberos
261275
authentication should be used instead of the default basic
262276
authentication.
263277
264-
`timeout`:: The maximum total time to wait for the response, in
278+
`timeout` \n
279+
The maximum total time to wait for the response, in
265280
seconds. A value of zero (the default) means wait for ever. If
266281
the timeout expires before the response is received an exception
267282
will be raised.
268283
269-
`compress`:: A boolean flag indicating if the SDK should ask
284+
`compress` \n
285+
A boolean flag indicating if the SDK should ask
270286
the server to send compressed responses. The default is `True`.
271287
Note that this is a hint for the server, and that it may return
272288
uncompressed data even when this parameter is set to `True`.
273289
Note that compression will be disabled if user pass `debug`
274290
parameter set to `true`, so the debug messages are in plain text.
275291
276-
`sso_url`:: A string containing the base SSO URL of the serve.
292+
`sso_url` \n
293+
A string containing the base SSO URL of the serve.
277294
Default SSO url is computed from the `url` if no `sso_url` is provided.
278295
279-
`sso_revoke_url`:: A string containing the base URL of the SSO
296+
`sso_revoke_url` \n
297+
A string containing the base URL of the SSO
280298
revoke service. This needs to be specified only when using
281299
an external authentication service. By default this URL
282300
is automatically calculated from the value of the `url` parameter,
283301
so that SSO token revoke will be performed using the SSO service
284302
that is part of the engine.
285303
286-
`sso_token_name`:: The token name in the JSON SSO response returned
304+
`sso_token_name` \n
305+
The token name in the JSON SSO response returned
287306
from the SSO server. Default value is `access_token`.
288307
289-
`headers`:: A dictionary with headers which should be send with every
308+
`headers` \n
309+
A dictionary with headers which should be send with every
290310
request.
291311
292-
`connections`:: The maximum number of connections to open to the host.
312+
`connections` \n
313+
The maximum number of connections to open to the host.
293314
If the value is `0` (the default) then the number of connections will
294315
be unlimited.
295316
296-
`pipeline`:: The maximum number of request to put in an HTTP pipeline
317+
`pipeline` \n
318+
The maximum number of request to put in an HTTP pipeline
297319
without waiting for the response. If the value is `0` (the default)
298320
then pipelining is disabled.
299321
"""
@@ -360,7 +382,8 @@ def send(self, request):
360382
361383
This method supports the following parameters.
362384
363-
`request`:: The Request object containing the details of the HTTP
385+
`request` \n
386+
The Request object containing the details of the HTTP
364387
request to send.
365388
366389
The returned value is a Request object containing the details of the
@@ -445,7 +468,7 @@ def __send(self, request):
445468
for header_name, header_value in headers_dict.items():
446469
header_lines.append('%s: %s' % (header_name, header_value))
447470

448-
header_lines.append('User-Agent: PythonSDK/%s' % version.VERSION)
471+
header_lines.append('User-Agent: PythonSDK/%s' % get_version())
449472
header_lines.append('Version: 4')
450473
header_lines.append('Content-Type: application/xml')
451474
header_lines.append('Accept: application/xml')
@@ -668,7 +691,7 @@ def _get_sso_response(self, url, params=''):
668691

669692
# Prepare headers:
670693
header_lines = [
671-
'User-Agent: PythonSDK/%s' % version.VERSION,
694+
'User-Agent: PythonSDK/%s' % get_version(),
672695
'Accept: application/json'
673696
]
674697
curl.setopt(pycurl.HTTPHEADER, header_lines)
@@ -742,7 +765,7 @@ def test(self, raise_exception=False):
742765
return True
743766
except Error:
744767
if raise_exception:
745-
six.reraise(*sys.exc_info())
768+
raise
746769
return False
747770
except Exception as exception:
748771
if raise_exception:
@@ -796,7 +819,7 @@ def close(self, logout=True):
796819
"""
797820
Releases the resources used by this connection.
798821
799-
`logout`:: A boolean, which specify if token should be revoked,
822+
`logout` A boolean, which specify if token should be revoked,
800823
and so user should be logged out.
801824
"""
802825

@@ -818,10 +841,10 @@ def _build_url(self, path='', query=None):
818841
819842
This method supports the following parameters:
820843
821-
`path`:: The path that will be added to the base URL. The default is an
844+
`path` The path that will be added to the base URL. The default is an
822845
empty string.
823846
824-
`query`:: A dictionary containing the query parameters to add to the
847+
`query` A dictionary containing the query parameters to add to the
825848
URL. The keys of the dictionary should be strings containing the names
826849
of the parameters, and the values should be strings containing the
827850
values.
@@ -841,7 +864,7 @@ def check_xml_content_type(self, response):
841864
XML then it does nothing. If it isn't XML then it raises an
842865
exception.
843866
844-
`response`:: The HTTP response to check.
867+
`response` The HTTP response to check.
845868
"""
846869
return self._check_content_type(
847870
self.__XML_CONTENT_TYPE_RE,
@@ -855,7 +878,7 @@ def check_json_content_type(self, response):
855878
JSON then it does nothing. If it isn't JSON then it raises an
856879
exception.
857880
858-
`response`:: The HTTP response to check.
881+
`response` The HTTP response to check.
859882
"""
860883
return self._check_content_type(
861884
self.__JSON_CONTENT_TYPE_RE,
@@ -868,10 +891,10 @@ def _check_content_type(self, expected_re, expected_name, headers):
868891
Checks the given content type and raises an exception if it isn't the
869892
expected one.
870893
871-
`expected_re`:: The regular expression used to check the expected
894+
`expected_re` The regular expression used to check the expected
872895
content type.
873-
`expected_name`:: The name of the expected content type.
874-
`headers`:: The HTTP headers to check.
896+
`expected_name` The name of the expected content type.
897+
`headers` The HTTP headers to check.
875898
"""
876899
content_type = self._get_header_value(headers, 'content-type')
877900
if expected_re.match(content_type) is None:
@@ -892,7 +915,7 @@ def _read_reponse(self, context):
892915
"""
893916
Read the response.
894917
895-
`context`:: tuple which contains cur easy, response body,
918+
`context` tuple which contains cur easy, response body,
896919
response headers, original request
897920
"""
898921
# Extract the response code and body:
@@ -929,14 +952,14 @@ def __parse_error(self, error):
929952
elif e_code == pycurl.E_OPERATION_TIMEOUTED:
930953
clazz = TimeoutError
931954

932-
six.reraise(clazz, clazz(error_msg), sys.exc_info()[2])
955+
raise clazz(error_msg).with_traceback(sys.exc_info()[2])
933956

934957
def _get_header_value(self, headers, name):
935958
"""
936959
Return header value by its name.
937960
938-
`headers`:: list of headers
939-
`name`:: name of the header
961+
`headers` list of headers
962+
`name` name of the header
940963
"""
941964
return next(
942965
(h.split(':')[1].strip() for h in headers if h.lower().startswith(name)),
@@ -984,8 +1007,7 @@ class ConnectionBuilder(object):
9841007
equivalent to calling the constructor of the `Connection`
9851008
class. Typical use will be like this:
9861009
987-
[source,python]
988-
----
1010+
```python
9891011
# Create the builder once:
9901012
builder = ConnectionBuilder(
9911013
url='https://enginer40.example.com/ovirt-engine/api',
@@ -1001,7 +1023,7 @@ class ConnectionBuilder(object):
10011023
# Create and use a second connection:
10021024
with builder.build() as connection:
10031025
...
1004-
----
1026+
```
10051027
"""
10061028

10071029
def __init__(self, **kwargs):
@@ -1029,7 +1051,7 @@ def build(self):
10291051
# import ovirtsdk4 as sdk
10301052
# vm = sdk.types.Vm()
10311053
#
1032-
from ovirtsdk4 import readers # noqa: F401 E402
1033-
from ovirtsdk4 import services # noqa: F401 E402
1034-
from ovirtsdk4 import types # noqa: F401 E402
1035-
from ovirtsdk4 import writers # noqa: F401 E402
1054+
import ovirtsdk4.readers as readers # noqa: E402, F401
1055+
import ovirtsdk4.writers as writers # noqa: E402, F401
1056+
import ovirtsdk4.types as types # noqa: E402, F401
1057+
import ovirtsdk4.services as services # noqa: E402, F401

lib/ovirtsdk4/reader.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import time
2121
import io
2222
import re
23-
import six
2423

2524
from ovirtsdk4 import Error
2625
from ovirtsdk4 import xml
@@ -304,8 +303,7 @@ def read(cls, source):
304303
# In Python 3 str is a list of 16 bits characters, so it
305304
# needs to be converted to an array of bytes, using UTF-8,
306305
# before trying to parse it.
307-
if six.PY3:
308-
source = source.encode('utf-8')
306+
source = source.encode('utf-8')
309307
cursor = xml.XmlReader(io.BytesIO(source))
310308
elif isinstance(source, bytes):
311309
cursor = xml.XmlReader(io.BytesIO(source))

lib/ovirtsdk4/service.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
# limitations under the License.
1717
#
1818

19-
import six
20-
2119
from ovirtsdk4 import AuthError
2220
from ovirtsdk4 import Error
2321
from ovirtsdk4 import NotFoundError
@@ -36,10 +34,13 @@ def __init__(self, connection, context, code):
3634
"""
3735
Creates a new future result.
3836
39-
`connection`:: The connection to be used by this future.
40-
`context`:: The request that this future will wait for when the `wait`
37+
`connection` \n
38+
The connection to be used by this future.
39+
`context` \n
40+
The request that this future will wait for when the `wait`
4141
method is called.
42-
`code`:: The function that will be executed to check the response, and
42+
`code` \n
43+
The function that will be executed to check the response, and
4344
to convert its body into the right type of object.
4445
"""
4546
self._connection = connection
@@ -100,7 +101,7 @@ def _raise_error(response, detail=None):
100101
msg += ' '
101102
msg = msg + 'HTTP response message is "%s".' % response.message
102103

103-
if isinstance(detail, six.string_types):
104+
if isinstance(detail, str):
104105
if msg:
105106
msg += ' '
106107
msg = msg + detail + '.'

0 commit comments

Comments
 (0)