cleanup
authorTony Mack <tmack@paris.CS.Princeton.EDU>
Fri, 14 Sep 2012 15:37:14 +0000 (11:37 -0400)
committerTony Mack <tmack@paris.CS.Princeton.EDU>
Fri, 14 Sep 2012 15:37:14 +0000 (11:37 -0400)
PLC/Shell.py

index df87e1c..fb401d3 100644 (file)
@@ -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