Revision 846
Added by Borja Sotomayor over 13 years ago
branches/1.1/src/haizea/common/opennebula_xmlrpc.py | ||
---|---|---|
9 | 9 |
import elementtree.ElementTree as ET |
10 | 10 |
|
11 | 11 |
class OpenNebulaXMLRPCClient(object): |
12 |
|
|
13 |
DEFAULT_ONE_AUTH = "~/.one/one_auth" |
|
14 |
|
|
12 | 15 |
def __init__(self, host, port, user, password): |
13 | 16 |
uri = "http://%s:%i" % (host, port) |
14 | 17 |
self.rpc = xmlrpclib.ServerProxy(uri) |
... | ... | |
30 | 33 |
@staticmethod |
31 | 34 |
def get_userpass_from_env(): |
32 | 35 |
if not os.environ.has_key("ONE_AUTH"): |
33 |
return None
|
|
36 |
one_auth = OpenNebulaXMLRPCClient.DEFAULT_ONE_AUTH
|
|
34 | 37 |
else: |
35 |
auth = os.environ["ONE_AUTH"] |
|
36 |
user, passw = auth.split(":") |
|
38 |
one_auth = os.environ["ONE_AUTH"] |
|
39 |
|
|
40 |
one_auth = os.path.expanduser(one_auth) |
|
41 |
|
|
42 |
if not os.path.exists(one_auth): |
|
43 |
raise Exception("Authorization file %s does not exists" % one_auth) |
|
44 |
|
|
45 |
f = open(one_auth, "r") |
|
46 |
try: |
|
47 |
line = f.readline().strip() |
|
48 |
user, passw = line.split(":") |
|
37 | 49 |
return user, passw |
50 |
except: |
|
51 |
raise Exception("Authorization file is malformed") |
|
38 | 52 |
|
39 | 53 |
def hostpool_info(self): |
40 | 54 |
try: |
Also available in: Unified diff
Merged changes from trunk to correctly support ONE_AUTH and the OpenNebula authorization file.