X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FShell.py;h=df87e1cc7048e6c6b5ff0a33da7cd095cefba760;hb=19d4a01ccf66af9e00914351b3eacd5fc880f988;hp=d9e812c8fab712d1ce1b9eb4d16d394071f562db;hpb=193d16a419bde80772065c4bb3602a29a869cff4;p=plcapi.git diff --git a/PLC/Shell.py b/PLC/Shell.py index d9e812c..df87e1c 100644 --- a/PLC/Shell.py +++ b/PLC/Shell.py @@ -5,9 +5,8 @@ # Mark Huang # Copyright (C) 2005 The Trustees of Princeton University # -# $Id: Shell.py,v 1.1 2007/01/08 18:10:30 mlhuang Exp $ -# +import os import pydoc import xmlrpclib @@ -57,8 +56,12 @@ class Shell: config = None, # XML-RPC server url = None, xmlrpc = False, cacert = None, - # API authentication - method = None, role = None, user = None, password = None): + # API authentication method + method = None, + # Password authentication + role = None, user = None, password = None, + # Session authentication + session = None): """ Initialize a new shell instance. Re-initializes globals. """ @@ -103,17 +106,25 @@ class Shell: ":" + str(self.config.PLC_API_PORT) + \ "/" + self.config.PLC_API_PATH + "/" - if cacert is None and self.config is not None: - cacert = self.config.PLC_API_CA_SSL_CRT + if cacert is None: + cacert = self.config.PLC_API_CA_SSL_CRT self.url = url - self.server = xmlrpclib.ServerProxy(url, PyCurlTransport(url, cacert), allow_none = 1) + if cacert is not None: + self.server = xmlrpclib.ServerProxy(url, PyCurlTransport(url, cacert), allow_none = 1) + else: + self.server = xmlrpclib.ServerProxy(url, allow_none = 1) # Set up authentication structure - # Default is to use capability authentication + # Default is to use session or capability authentication if (method, user, password) == (None, None, None): - method = "capability" + if session is not None or os.path.exists("/etc/planetlab/session"): + method = "session" + if session is None: + session = "/etc/planetlab/session" + else: + method = "capability" if method == "capability": # Load defaults from configuration file if using capability @@ -130,6 +141,14 @@ class Shell: if role == "anonymous" or method == "anonymous": self.auth = {'AuthMethod': "anonymous"} + elif method == "session": + if session is None: + raise Exception, "Must specify session" + + if os.path.exists(session): + session = file(session).read() + + self.auth = {'AuthMethod': "session", 'session': session} else: if user is None: raise Exception, "Must specify username" @@ -144,7 +163,7 @@ class Shell: if role is not None: self.auth['Role'] = role - for method in PLC.Methods.methods: + for method in PLC.API.PLCAPI.all_methods: api_function = self.api.callable(method) if self.server is None: