[haizea-commit] r846 - branches/1.1/src/haizea/common
haizea-commit at mailman.cs.uchicago.edu
haizea-commit at mailman.cs.uchicago.edu
Wed Oct 27 17:57:18 CDT 2010
Author: borja
Date: 2010-10-27 17:57:18 -0500 (Wed, 27 Oct 2010)
New Revision: 846
Modified:
branches/1.1/src/haizea/common/opennebula_xmlrpc.py
Log:
Merged changes from trunk to correctly support ONE_AUTH and the OpenNebula authorization file.
Modified: branches/1.1/src/haizea/common/opennebula_xmlrpc.py
===================================================================
--- branches/1.1/src/haizea/common/opennebula_xmlrpc.py 2010-10-20 19:58:45 UTC (rev 845)
+++ branches/1.1/src/haizea/common/opennebula_xmlrpc.py 2010-10-27 22:57:18 UTC (rev 846)
@@ -9,6 +9,9 @@
import elementtree.ElementTree as ET
class OpenNebulaXMLRPCClient(object):
+
+ DEFAULT_ONE_AUTH = "~/.one/one_auth"
+
def __init__(self, host, port, user, password):
uri = "http://%s:%i" % (host, port)
self.rpc = xmlrpclib.ServerProxy(uri)
@@ -30,11 +33,22 @@
@staticmethod
def get_userpass_from_env():
if not os.environ.has_key("ONE_AUTH"):
- return None
+ one_auth = OpenNebulaXMLRPCClient.DEFAULT_ONE_AUTH
else:
- auth = os.environ["ONE_AUTH"]
- user, passw = auth.split(":")
+ one_auth = os.environ["ONE_AUTH"]
+
+ one_auth = os.path.expanduser(one_auth)
+
+ if not os.path.exists(one_auth):
+ raise Exception("Authorization file %s does not exists" % one_auth)
+
+ f = open(one_auth, "r")
+ try:
+ line = f.readline().strip()
+ user, passw = line.split(":")
return user, passw
+ except:
+ raise Exception("Authorization file is malformed")
def hostpool_info(self):
try:
More information about the Haizea-commit
mailing list