resolve_raw no longer exists, call resolve directly on genitable. If we are doing...
[sfa.git] / geni / util / api.py
index 6244fbe..b501fd7 100644 (file)
@@ -14,6 +14,8 @@ from geni.util.faults import *
 from geni.util.debug import *
 from geni.util.rights import *
 from geni.util.credential import *
+from geni.util.misc import *
+
 # See "2.2 Characters" in the XML specification:
 #
 # #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD]
@@ -119,7 +121,7 @@ class GeniAPI:
     def getPLCShell(self):
         self.plauth = {'Username': self.config.GENI_PLC_USER,
                          'AuthMethod': 'password',
-                         'AuthString': self.config.GENI_PLC_PASSWORD} 
+                         'AuthString': self.config.GENI_PLC_PASSWORD}
         try:
             import PLC.Shell
             shell = PLC.Shell.Shell(globals = globals())
@@ -138,11 +140,32 @@ class GeniAPI:
             return shell
 
     def getCredential(self):
-        return self.getCredentialFromRegistry()
+        if self.interface in ['registry']:
+            return self.getCredentialFromLocalRegistry()
+        else:
+            return self.getCredentialFromRegistry()
+    
 
     def getCredentialFromRegistry(self):
+        """ 
+        Get our credential from a remote registry using a geniclient connection
+        """
+        type = 'sa'
+        cred_filename = ".".join([self.server_basedir, self.interface, self.hrn, type, "cred"]) 
+        try:
+            credential = Credential(filename = cred_filename)
+            return credential
+        except IOError:
+            from geni.registry import Registries
+            registries = Registries(self)
+            registry = registries[self.hrn] 
+            self_cred = registry.get_credential(None, type, self.hrn)
+            cred = registry.get_credential(self_cred, type, self.hrn)
+            cred.save_to_file(cred_filename, save_parents=True)
+
+    def getCredentialFromLocalRegistry(self):
         """
-        Get our current credential from the local registry.
+        Get our current credential directly from the local registry. 
         """
     
         hrn = self.hrn
@@ -373,8 +396,15 @@ class GeniAPI:
         # their pointer
         newIdList = []
         for hrn in newList:
-            userRecord = self.resolve_raw("user", hrn)[0]
-            newIdList.append(userRecord.get_pointer())
+            auth_hrn = self.auth.get_authority(hrn)
+            if not auth_hrn:
+                auth_hrn = hrn
+            auth_info = self.auth.get_auth_info(auth_hrn)
+            table = self.auth.get_auth_table(auth_hrn)
+            records = table.resolve('user', hrn)
+            if records:
+                userRecord = records[0]    
+                newIdList.append(userRecord.get_pointer())
 
         # build a list of the old person ids from the person_ids field of the
         # pl_info
@@ -427,6 +457,7 @@ class GeniAPI:
             callablemethod = getattr(module, classname)(self)
             return getattr(module, classname)(self)
         except ImportError, AttributeError:
+            raise
             raise GeniInvalidAPIMethod, method
 
     def call(self, source, method, *args):