From 791bffbe05e44d5eaecc6a3bc173369b6a89da6f Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Fri, 14 Sep 2012 11:37:14 -0400 Subject: [PATCH] cleanup --- PLC/Shell.py | 49 +++++++++++++++---------------------------------- 1 file changed, 15 insertions(+), 34 deletions(-) diff --git a/PLC/Shell.py b/PLC/Shell.py index df87e1cc..fb401d38 100644 --- a/PLC/Shell.py +++ b/PLC/Shell.py @@ -59,7 +59,7 @@ class Shell: # API authentication method method = None, # Password authentication - role = None, user = None, password = None, + role = None, user = None, password = None, tenant = None, # Session authentication session = None): """ @@ -69,8 +69,8 @@ class Shell: try: # If any XML-RPC options have been specified, do not try # connecting directly to the DB. - if (url, method, user, password, role, cacert, xmlrpc) != \ - (None, None, None, None, None, None, False): + if (url, method, user, password, role, tenant, cacert, xmlrpc) != \ + (None, None, None, None, None, None, None, False): raise Exception # Otherwise, first try connecting directly to the DB. This @@ -102,12 +102,12 @@ class Shell: if self.config is None: raise Exception, "Must specify API URL" - url = "https://" + self.config.PLC_API_HOST + \ - ":" + str(self.config.PLC_API_PORT) + \ - "/" + self.config.PLC_API_PATH + "/" + url = "https://" + self.config.api_host + \ + ":" + str(self.config.api_port) #+ \ + #"/" + self.config.PI_PATH + "/" if cacert is None: - cacert = self.config.PLC_API_CA_SSL_CRT + cacert = self.config.api_ca_ssl_cert self.url = url if cacert is not None: @@ -116,39 +116,19 @@ class Shell: self.server = xmlrpclib.ServerProxy(url, allow_none = 1) # Set up authentication structure - # Default is to use session or capability authentication - if (method, user, password) == (None, None, None): - 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": + if not method or method == "capability": # Load defaults from configuration file if using capability # authentication. if user is None and self.config is not None: - user = self.config.PLC_API_MAINTENANCE_USER + user = self.config.nova_admin_user if password is None and self.config is not None: - password = self.config.PLC_API_MAINTENANCE_PASSWORD - if role is None: - role = "admin" - elif method is None: - # Otherwise, default to password authentication - method = "password" - + password = self.config.nova_admin_password + if tenant is None and self.config is not None: + tenant = self.config.nova_admin_tenant + 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" @@ -158,7 +138,8 @@ class Shell: self.auth = {'AuthMethod': method, 'Username': user, - 'AuthString': password} + 'AuthString': password, + 'Tenant': tenant} if role is not None: self.auth['Role'] = role -- 2.47.0