Skip to content

Commit fe5e7fe

Browse files
authored
Merge pull request python-oca#23 from python-oca/py3
Add py3 compatibility. Make tests py.test compatible
2 parents 4907393 + 69b14eb commit fe5e7fe

35 files changed

+106
-70
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
*.coverage
44
oca.egg*
55
.tox
6+
.cache/

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
language: python
22
python:
33
- "2.7"
4+
- "3.5"
5+
46
install:
5-
- pip install tox
7+
- pip install tox tox-travis
68
script: tox

oca/__init__.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,48 @@
11
# -*- coding: UTF-8 -*-
2-
import xmlrpclib
32
import os
43
import hashlib
54
import re
65
import socket
7-
import httplib
86

9-
from host import Host, HostPool
10-
from vm import VirtualMachine, VirtualMachinePool
11-
from user import User, UserPool
12-
from image import Image, ImagePool
13-
from vn import VirtualNetwork, VirtualNetworkPool
14-
from group import Group, GroupPool
15-
from template import VmTemplate, VmTemplatePool
16-
from exceptions import OpenNebulaException
17-
from cluster import Cluster, ClusterPool
18-
from datastore import Datastore, DatastorePool
7+
import http.client
8+
import xmlrpc.client
9+
10+
from .host import Host, HostPool
11+
from .vm import VirtualMachine, VirtualMachinePool
12+
from .user import User, UserPool
13+
from .image import Image, ImagePool
14+
from .vn import VirtualNetwork, VirtualNetworkPool
15+
from .group import Group, GroupPool
16+
from .template import VmTemplate, VmTemplatePool
17+
from .exceptions import OpenNebulaException
18+
from .cluster import Cluster, ClusterPool
19+
from .datastore import Datastore, DatastorePool
1920

2021

2122
CONNECTED = -3
2223
ALL = -2
2324
CONNECTED_AND_GROUP = -1
2425

25-
class TimeoutHTTPConnection(httplib.HTTPConnection):
26+
class TimeoutHTTPConnection(http.client.HTTPConnection):
2627
def connect(self):
27-
httplib.HTTPConnection.connect(self)
28+
http.client.HTTPConnection.connect(self)
2829
self.sock.settimeout(self.timeout)
2930

30-
class TimeoutHTTP(httplib.HTTP):
31+
class TimeoutHTTP(http.client.HTTPConnection):
3132
_connection_class = TimeoutHTTPConnection
3233

3334
def set_timeout(self, timeout):
3435
self._conn.timeout = timeout
3536

36-
class ProxiedTransport(xmlrpclib.Transport):
37+
class ProxiedTransport(xmlrpc.client.Transport):
3738
def __init__(self, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, *args, **kwargs):
38-
xmlrpclib.Transport.__init__(self, *args, **kwargs)
39+
xmlrpc.client.Transport.__init__(self, *args, **kwargs)
3940
self.timeout = timeout
4041
def set_proxy(self, proxy):
4142
self.proxy = proxy
4243
def make_connection(self, host):
4344
self.realhost = host
44-
h = httplib.HTTPConnection(self.proxy)
45+
h = http.client.HTTPConnection(self.proxy)
4546
return h
4647
def send_request(self, connection, handler, request_body):
4748
connection.putrequest("POST", 'http://%s%s' % (self.realhost, handler))
@@ -89,9 +90,9 @@ def __init__(self, secret=None, address=None, proxy=None):
8990
if proxy:
9091
p = ProxiedTransport(timeout=100)
9192
p.set_proxy(proxy)
92-
self.server = xmlrpclib.ServerProxy(self.one_address, transport=p)
93+
self.server = xmlrpc.client.ServerProxy(self.one_address, transport=p)
9394
else:
94-
self.server = xmlrpclib.ServerProxy(self.one_address)
95+
self.server = xmlrpc.client.ServerProxy(self.one_address)
9596

9697

9798
def call(self, function, *args):
@@ -115,7 +116,7 @@ def call(self, function, *args):
115116
except ValueError:
116117
data = ''
117118
is_success = False
118-
except socket.error, e:
119+
except socket.error as e:
119120
#connection error
120121
raise e
121122
if not is_success:

oca/cluster.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: UTF-8 -*-
2-
from pool import Pool, PoolElement, Template, extractString
2+
from .pool import Pool, PoolElement, Template, extractString
33

44
class Cluster(PoolElement):
55
METHODS = {
@@ -13,9 +13,9 @@ class Cluster(PoolElement):
1313
XML_TYPES = {
1414
'id' : int,
1515
'name' : extractString,
16-
'host_ids' : ['HOSTS', lambda hosts: map(lambda host_id: int(host_id.text), hosts)],
17-
'datastore_ids' : ['DATASTORES', lambda datastores: map(lambda datastore_id: int(datastore_id.text), datastores)],
18-
'vnet_ids' : ['VNETS', lambda vnets: map(lambda vnet_id: int(vnet_id.text), vnets)],
16+
'host_ids' : ['HOSTS', lambda hosts: [int(host_id.text) for host_id in hosts]],
17+
'datastore_ids' : ['DATASTORES', lambda datastores: [int(datastore_id.text) for datastore_id in datastores]],
18+
'vnet_ids' : ['VNETS', lambda vnets: [int(vnet_id.text) for vnet_id in vnets]],
1919
'template' : ['TEMPLATE', Template],
2020
}
2121

oca/datastore.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: UTF-8 -*-
2-
from pool import Pool, PoolElement, Template, extractString
2+
from .pool import Pool, PoolElement, Template, extractString
33

44
class Datastore(PoolElement):
55
METHODS = {
@@ -29,7 +29,7 @@ class Datastore(PoolElement):
2929
'total_mb' : int,
3030
'free_mb' : int,
3131
'used_mb' : int,
32-
'image_ids' : ['IMAGES', lambda images: map(lambda image_id: int(image_id.text), images)],
32+
'image_ids' : ['IMAGES', lambda images: [int(image_id.text) for image_id in images]],
3333
'template' : ['TEMPLATE', Template],
3434
}
3535

oca/group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: UTF-8 -*-
2-
from pool import Pool, PoolElement, Template, extractString
2+
from .pool import Pool, PoolElement, Template, extractString
33

44

55
class Group(PoolElement):

oca/host.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: UTF-8 -*-
2-
from pool import Pool, PoolElement, Template, extractString
2+
from .pool import Pool, PoolElement, Template, extractString
33

44

55
class HostShare(Template):
@@ -48,7 +48,7 @@ class Host(PoolElement):
4848
'last_mon_time': int,
4949
'cluster': extractString,
5050
'cluster_id': int,
51-
'vm_ids': ['VMS', lambda vms: map(lambda vmid: int(vmid.text), vms)],
51+
'vm_ids': ['VMS', lambda vms: [int(vmid.text) for vmid in vms]],
5252
'template': ['TEMPLATE', Template],
5353
'host_share': ['HOST_SHARE', HostShare],
5454
}

oca/image.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: UTF-8 -*-
2-
from pool import Pool, PoolElement, Template, extractString
2+
from .pool import Pool, PoolElement, Template, extractString
33

44

55
class Image(PoolElement):
@@ -37,8 +37,8 @@ class Image(PoolElement):
3737
'cloning_id' : int,
3838
'datastore_id': int,
3939
'datastore' : extractString,
40-
'vm_ids' : ["VMS", lambda vms: map(lambda vm_id: int(vm_id.text), vms)],
41-
'clone_ids' : ["CLONES", lambda clones: map(lambda clone_id: int(clone_id.text), clones)],
40+
'vm_ids' : ["VMS", lambda vms: [int(vm_id.text) for vm_id in vms]],
41+
'clone_ids' : ["CLONES", lambda clones: [int(clone_id.text) for clone_id in clones]],
4242
'template' : ['TEMPLATE', Template],
4343
}
4444

oca/pool.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# -*- coding: UTF-8 -*-
22
import xml.etree.ElementTree as ET
3-
import new
43

5-
from exceptions import OpenNebulaException
4+
from .exceptions import OpenNebulaException
65

76

87
class WrongNameError(OpenNebulaException):
@@ -37,7 +36,7 @@ def parse_multiple(self, tag, element):
3736
attr = tag.lower() + 's'
3837
attr_list = getattr(self, attr, [])
3938

40-
class_obj = new.classobj(tag.capitalize(), (Template,), {})
39+
class_obj = type(tag.capitalize(), (Template,), {})
4140

4241
attr_list.append(class_obj(element))
4342
setattr(self, attr, attr_list)

oca/template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: UTF-8 -*-
2-
from pool import Pool, PoolElement, Template
2+
from .pool import Pool, PoolElement, Template
33

44

55
class VmTemplate(PoolElement):

0 commit comments

Comments
 (0)