Skip to content

Commit ca6ae7d

Browse files
gijzelaerrsysradium
authored andcommitted
fix pep8 errors and warnings, cleanup unused imports (python-oca#43)
* fix pep8 errors and warnings * test with python3.6
1 parent dab011e commit ca6ae7d

33 files changed

Lines changed: 549 additions & 551 deletions

oca/__init__.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,64 @@
11
# -*- coding: UTF-8 -*-
2+
import http.client
23
import os
3-
import hashlib
44
import re
55
import socket
6-
7-
import http.client
86
import xmlrpc.client
97

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

2219
CONNECTED = -3
2320
ALL = -2
2421
CONNECTED_AND_GROUP = -1
2522

23+
2624
class TimeoutHTTPConnection(http.client.HTTPConnection):
2725
def connect(self):
2826
http.client.HTTPConnection.connect(self)
2927
self.sock.settimeout(self.timeout)
3028

29+
3130
class TimeoutHTTP(http.client.HTTPConnection):
3231
_connection_class = TimeoutHTTPConnection
3332

3433
def set_timeout(self, timeout):
3534
self._conn.timeout = timeout
3635

36+
3737
class ProxiedTransport(xmlrpc.client.Transport):
3838
def __init__(self, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, *args, **kwargs):
3939
xmlrpc.client.Transport.__init__(self, *args, **kwargs)
4040
self.timeout = timeout
41+
4142
def set_proxy(self, proxy):
4243
self.proxy = proxy
44+
4345
def make_connection(self, host):
4446
self.realhost = host
4547
h = http.client.HTTPConnection(self.proxy)
4648
return h
49+
4750
def send_request(self, connection, handler, request_body):
4851
connection.putrequest("POST", 'http://%s%s' % (self.realhost, handler))
52+
4953
def send_host(self, connection, host):
5054
connection.putheader('Host', self.realhost)
5155

56+
5257
class Client(object):
53-
'''
58+
"""
5459
The client class, represents the connection with the core and handles the
5560
xml-rpc calls(see http://www.opennebula.org/documentation:rel3.2:api)
56-
'''
61+
"""
5762
DEFAULT_ONE_AUTH = "~/.one/one_auth"
5863
ONE_AUTH_RE = re.compile('^(.+?):(.+)$')
5964
DEFAULT_ONE_ADDRESS = "http://localhost:2633/RPC2"
@@ -93,10 +98,9 @@ def __init__(self, secret=None, address=None, proxy=None):
9398
self.server = xmlrpc.client.ServerProxy(self.one_address, transport=p)
9499
else:
95100
self.server = xmlrpc.client.ServerProxy(self.one_address)
96-
97101

98102
def call(self, function, *args):
99-
'''
103+
"""
100104
Calls rpc function.
101105
102106
Arguments
@@ -107,7 +111,7 @@ def call(self, function, *args):
107111
``args``
108112
function arguments
109113
110-
'''
114+
"""
111115
try:
112116
func = getattr(self.server.one, function)
113117
ret = func(self.one_auth, *args)
@@ -117,21 +121,21 @@ def call(self, function, *args):
117121
data = ''
118122
is_success = False
119123
except socket.error as e:
120-
#connection error
124+
# connection error
121125
raise e
122126
if not is_success:
123127
raise OpenNebulaException(data)
124128
return data
125129

126130
def version(self):
127-
'''
131+
"""
128132
Get the version of the connected OpenNebula server.
129-
'''
133+
"""
130134
return self.call('system.version')
131135

132-
__all__ = [Client, OpenNebulaException, Host, HostPool, VirtualMachine,
133-
VirtualMachinePool, User, UserPool,
134-
Image, ImagePool, VirtualNetwork, VirtualNetworkPool,
135-
Group, GroupPool, VmTemplate, VmTemplatePool, ALL, CONNECTED,
136-
Cluster, ClusterPool, Datastore, DatastorePool]
137136

137+
__all__ = [Client, OpenNebulaException, Host, HostPool, VirtualMachine,
138+
VirtualMachinePool, User, UserPool,
139+
Image, ImagePool, VirtualNetwork, VirtualNetworkPool,
140+
Group, GroupPool, VmTemplate, VmTemplatePool, ALL, CONNECTED,
141+
Cluster, ClusterPool, Datastore, DatastorePool]

oca/cluster.py

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

4+
45
class Cluster(PoolElement):
56
METHODS = {
6-
#'info' : 'cluster.info',
7-
'allocate' : 'cluster.allocate',
8-
'delete' : 'cluster.delete',
9-
#'enable' : 'cluster.enable',
10-
#'update' : 'cluster.update'
7+
# 'info' : 'cluster.info',
8+
'allocate': 'cluster.allocate',
9+
'delete': 'cluster.delete',
10+
# 'enable' : 'cluster.enable',
11+
# 'update' : 'cluster.update'
1112
}
1213

1314
XML_TYPES = {
14-
'id' : int,
15-
'name' : extractString,
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]],
19-
'template' : ['TEMPLATE', Template],
15+
'id': int,
16+
'name': extractString,
17+
'host_ids': ['HOSTS', lambda hosts: [int(host_id.text) for host_id in hosts]],
18+
'datastore_ids': ['DATASTORES', lambda datastores: [int(datastore_id.text) for datastore_id in datastores]],
19+
'vnet_ids': ['VNETS', lambda vnets: [int(vnet_id.text) for vnet_id in vnets]],
20+
'template': ['TEMPLATE', Template],
2021
}
2122

2223
ELEMENT_NAME = 'CLUSTER'
2324

2425
@staticmethod
2526
def allocate(client, cluster_name):
26-
'''
27+
"""
2728
Adds a cluster to the cluster list
2829
2930
Arguments
3031
3132
``cluster_name``
3233
Clustername to add
33-
'''
34+
"""
3435
cluster_id = client.call(Cluster.METHODS['allocate'], cluster_name)
3536
return cluster_id
3637

@@ -44,7 +45,7 @@ def __repr__(self):
4445

4546
class ClusterPool(Pool):
4647
METHODS = {
47-
'info' : 'clusterpool.info',
48+
'info': 'clusterpool.info',
4849
}
4950

5051
def __init__(self, client):
@@ -53,4 +54,3 @@ def __init__(self, client):
5354
def _factory(self, xml):
5455
c = Cluster(xml, self.client)
5556
return c
56-

oca/datastore.py

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

4+
45
class Datastore(PoolElement):
56
METHODS = {
6-
#'info' : 'datastore.info',
7-
'allocate' : 'datastore.allocate',
8-
'delete' : 'datastore.delete',
9-
#'enable' : 'datastore.enable',
10-
#'update' : 'datastore.update'
7+
# 'info' : 'datastore.info',
8+
'allocate': 'datastore.allocate',
9+
'delete': 'datastore.delete',
10+
# 'enable' : 'datastore.enable',
11+
# 'update' : 'datastore.update'
1112
}
1213

1314
XML_TYPES = {
14-
'id' : int,
15-
'name' : extractString,
16-
'uid' : int,
17-
'gid' : int,
18-
'uname' : extractString,
19-
'gname' : extractString,
20-
#'permissions' : Permissions,
21-
'ds_mad' : extractString,
22-
'tm_mad' : extractString,
23-
'base_path' : extractString,
24-
'type' : int,
25-
'disk_type' : int,
26-
#'state' : ???,
27-
'cluster_id' : int,
28-
'cluster' : extractString,
29-
'total_mb' : int,
30-
'free_mb' : int,
31-
'used_mb' : int,
32-
'image_ids' : ['IMAGES', lambda images: [int(image_id.text) for image_id in images]],
33-
'template' : ['TEMPLATE', Template],
15+
'id': int,
16+
'name': extractString,
17+
'uid': int,
18+
'gid': int,
19+
'uname': extractString,
20+
'gname': extractString,
21+
# 'permissions' : Permissions,
22+
'ds_mad': extractString,
23+
'tm_mad': extractString,
24+
'base_path': extractString,
25+
'type': int,
26+
'disk_type': int,
27+
# 'state' : ???,
28+
'cluster_id': int,
29+
'cluster': extractString,
30+
'total_mb': int,
31+
'free_mb': int,
32+
'used_mb': int,
33+
'image_ids': ['IMAGES', lambda images: [int(image_id.text) for image_id in images]],
34+
'template': ['TEMPLATE', Template],
3435
}
3536

3637
ELEMENT_NAME = 'DATASTORE'
3738

3839
@staticmethod
3940
def allocate(client, datastore_template):
40-
'''
41+
"""
4142
Adds a datastore to the datastore list
4243
4344
Arguments
4445
4546
``datastore_template``
4647
Template for the datastore to add
47-
'''
48+
"""
4849
datastore_id = client.call(Datastore.METHODS['allocate'], datastore_template)
4950
return datastore_id
5051

@@ -58,7 +59,7 @@ def __repr__(self):
5859

5960
class DatastorePool(Pool):
6061
METHODS = {
61-
'info' : 'datastorepool.info',
62+
'info': 'datastorepool.info',
6263
}
6364

6465
def __init__(self, client):

oca/exceptions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33

44
class OpenNebulaException(Exception):
55
pass
6-

oca/group.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@
44

55
class Group(PoolElement):
66
METHODS = {
7-
'info' : 'group.info',
8-
'allocate' : 'group.allocate',
9-
'delete' : 'group.delete',
7+
'info': 'group.info',
8+
'allocate': 'group.allocate',
9+
'delete': 'group.delete',
1010
}
1111

1212
XML_TYPES = {
13-
'id' : int,
14-
'name' : extractString,
15-
'template' : ['TEMPLATE', Template],
16-
'users' : ['USERS', lambda users: [int(i.text) for i in users]],
17-
#'resource_providers': handled separately
18-
#'datastore_quota': handled separately
19-
#'network_quota': handled separately
20-
#'vm_quota': handled separately
21-
#'image_quota'
22-
#'default_group_quotas'
13+
'id': int,
14+
'name': extractString,
15+
'template': ['TEMPLATE', Template],
16+
'users': ['USERS', lambda users: [int(i.text) for i in users]],
17+
# 'resource_providers': handled separately
18+
# 'datastore_quota': handled separately
19+
# 'network_quota': handled separately
20+
# 'vm_quota': handled separately
21+
# 'image_quota'
22+
# 'default_group_quotas'
2323
}
2424

2525
ELEMENT_NAME = 'GROUP'
2626

2727
@staticmethod
2828
def allocate(client, group_name):
29-
'''
29+
"""
3030
Allocates a new group in OpenNebula
3131
3232
Arguments
@@ -36,7 +36,7 @@ def allocate(client, group_name):
3636
3737
``group``
3838
a string containing the group name
39-
'''
39+
"""
4040
group_id = client.call(Group.METHODS['allocate'], group_name)
4141
return group_id
4242

@@ -50,7 +50,7 @@ def __repr__(self):
5050

5151
class GroupPool(Pool):
5252
METHODS = {
53-
'info' : 'grouppool.info',
53+
'info': 'grouppool.info',
5454
}
5555

5656
def __init__(self, client):
@@ -60,4 +60,3 @@ def _factory(self, xml):
6060
i = Group(xml, self.client)
6161
i._convert_types()
6262
return i
63-

0 commit comments

Comments
 (0)