Project

General

Profile

Revision 685

Add support for new ONE_AUTH in OpenNebula (instead of containing a username and password, the environment variable points to a file with this information)

View differences:

opennebula_xmlrpc.py
1 1
import xmlrpclib
2 2
import os
3
import os.path
3 4
import hashlib
4 5

  
5 6
try:
......
9 10
    import elementtree.ElementTree as ET 
10 11

  
11 12
class OpenNebulaXMLRPCClient(object):
13
    
14
    DEFAULT_ONE_AUTH = "~/.one/one_auth"
15
    
12 16
    def __init__(self, host, port, user, password):
13 17
        uri = "http://%s:%i" % (host, port)
14 18
        self.rpc = xmlrpclib.ServerProxy(uri)
......
30 34
    @staticmethod
31 35
    def get_userpass_from_env():
32 36
        if not os.environ.has_key("ONE_AUTH"):
33
            return None
37
            one_auth = OpenNebulaXMLRPCClient.DEFAULT_ONE_AUTH
34 38
        else:
35
            auth = os.environ["ONE_AUTH"]
36
            user, passw = auth.split(":")
39
            one_auth = os.environ["ONE_AUTH"]
40
            
41
        one_auth = os.path.expanduser(one_auth)
42
        
43
        if not os.path.exists(one_auth):
44
            raise Exception("Authorization file %s does not exists" % one_auth) 
45
        
46
        f = open(one_auth, "r")
47
        try:
48
            line = f.readline().strip()
49
            user, passw = line.split(":")
37 50
            return user, passw
51
        except:
52
            raise Exception("Authorization file is malformed")
53

  
38 54
        
39 55
    def hostpool_info(self):
40 56
        try:

Also available in: Unified diff