X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FShell.py;h=7f050230cf3dbf98f995ed61e276d3592bff94f9;hb=9a3af0c09c5981d3c32fb798fd02b82190b81bc6;hp=7ab27c47a922127a51b674eb395b12f0fe0e2ace;hpb=489b68ef562a8c7155ea2c03a8634d8ffacef8ba;p=plcapi.git diff --git a/PLC/Shell.py b/PLC/Shell.py index 7ab27c4..7f05023 100644 --- a/PLC/Shell.py +++ b/PLC/Shell.py @@ -5,9 +5,10 @@ # Mark Huang # Copyright (C) 2005 The Trustees of Princeton University # -# $Id: Shell.py,v 1.2 2007/01/10 21:04:40 mlhuang Exp $ +# $Id: Shell.py,v 1.3 2007/01/16 16:25:12 thierry Exp $ # +import os import pydoc import xmlrpclib @@ -57,8 +58,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. """ @@ -114,9 +119,14 @@ class Shell: # 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 @@ -133,6 +143,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"