added Regisries class. moved functions out of Registry
authorTony Mack <tmack@cs.princeton.edu>
Fri, 10 Apr 2009 02:38:04 +0000 (02:38 +0000)
committerTony Mack <tmack@cs.princeton.edu>
Fri, 10 Apr 2009 02:38:04 +0000 (02:38 +0000)
geni/registry.py

index c79f818..963da39 100644 (file)
@@ -6,19 +6,10 @@ import os
 import time
 import sys
 
-from geni.util.credential import Credential
-from geni.util.hierarchy import Hierarchy
-from geni.util.trustedroot import TrustedRootList
-from geni.util.cert import Keypair, Certificate
-from geni.util.gid import GID, create_uuid
 from geni.util.geniserver import GeniServer
 from geni.util.geniclient import GeniClient
-from geni.util.record import GeniRecord
-from geni.util.rights import RightList
 from geni.util.genitable import GeniTable
-from geni.util.geniticket import Ticket
 from geni.util.excep import *
-from geni.util.misc import *
 from geni.util.config import *
 from geni.util.storage import *
 
@@ -36,95 +27,29 @@ class Registry(GeniServer):
 
     def __init__(self, ip, port, key_file, cert_file, config = '/usr/share/geniwrapper/geni/util/geni_config'):
         GeniServer.__init__(self, ip, port, key_file, cert_file)
+        self.server.interface = 'registry' 
 
-        # get PL account settings from config module
-        self.pl_auth = get_pl_auth()
 
-        # connect to planetlab
-        if "Url" in self.pl_auth:
-            self.connect_remote_shell()
-        else:
-            self.connect_local_shell()
+##
+# Registries is a dictionary of geniclient registry connections keyed on the registry
+# hrn
 
-        self.key_file = key_file
-        self.cert_file = cert_file
-        self.config = Config(config)
-        self.basedir = self.config.GENI_BASE_DIR + os.sep
-        self.server_basedir = self.basedir + os.sep + "geni" + os.sep
-        self.hrn = self.config.GENI_INTERFACE_HRN
+class Registries(dict):
 
-        # get peer registry information
-        registries_file = self.server_basedir + os.sep + 'registries.xml'
+    def __init__(self, api):
+        dict.__init__(self, {})
+        self.api = api
+        registries_file = self.api.server_basedir + os.sep + 'registries.xml'
         connection_dict = {'hrn': '', 'addr': '', 'port': ''} 
         self.registry_info = XmlStorage(registries_file, {'registries': {'registry': [connection_dict]}})
         self.registry_info.load()
-        self.connectRegistry()
         self.connectRegistries()
         
-    ##
-    # Connect to a remote shell via XMLRPC
-
-    def connect_remote_shell(self):
-        from geni.util import remoteshell
-        self.shell = remoteshell.RemoteShell()
-
-    ##
-    # Connect to a local shell via local API functions
-
-    def connect_local_shell(self):
-        import PLC.Shell
-        self.shell = PLC.Shell.Shell(globals = globals())
-
-    ##
-    # Register the server RPCs for the registry
-
-    def loadCredential(self):
-        """
-        Attempt to load credential from file if it exists. If it doesnt get
-        credential from registry.
-        """
-
-        # see if this file exists
-        # XX This is really the aggregate's credential. Using this is easier than getting
-        # the registry's credential from iteslf (ssl errors).   
-        ma_cred_filename = self.server_basedir + os.sep + "agg." + self.hrn + ".ma.cred"
-        try:
-            self.credential = Credential(filename = ma_cred_filename)
-        except IOError:
-            self.credential = self.getCredentialFromRegistry()
-
-    def getCredentialFromRegistry(self):
-        """
-        Get our current credential from the registry.
-        """
-        # get self credential
-        self_cred_filename = self.server_basedir + os.sep + "smgr." + self.hrn + ".cred"
-        self_cred = self.registry.get_credential(None, 'ma', self.hrn)
-        self_cred.save_to_file(self_cred_filename, save_parents=True)
-
-        # get ma credential
-        ma_cred_filename = self.server_basedir + os.sep + "smgr." + self.hrn + ".sa.cred"
-        ma_cred = self.registry.get_credential(self_cred, 'sa', self.hrn)
-        ma_cred.save_to_file(ma_cred_filename, save_parents=True)
-        return ma_cred
-
-    def connectRegistry(self):
-        """
-        Connect to the registry
-        """
-        # connect to registry using GeniClient
-        address = self.config.GENI_REGISTRY_HOSTNAME
-        port = self.config.GENI_REGISTRY_PORT
-        url = 'http://%(address)s:%(port)s' % locals()
-        self.registry = GeniClient(url, self.key_file, self.cert_file)
-
     def connectRegistries(self):
         """
         Get connection details for the trusted peer registries from file and 
         create an GeniClient connection to each. 
         """
-        self.registries= {}
         required_fields = ['hrn', 'addr', 'port']
         registries = self.registry_info['registries']['registry']
         if isinstance(registries, dict):
@@ -133,10 +58,17 @@ class Registry(GeniServer):
             for registry in registries:
                 # create xmlrpc connection using GeniClient
                 if not set(required_fields).issubset(registry.keys()):
-                    continue  
+                    continue
                 hrn, address, port = registry['hrn'], registry['addr'], registry['port']
                 if not hrn or not address or not port:
                     continue
                 url = 'http://%(address)s:%(port)s' % locals()
-                self.registries[hrn] = GeniClient(url, self.key_file, self.cert_file)
+                self[hrn] = GeniClient(url, self.api.key_file, self.api.cert_file)
 
+        # set up a connection to the local registry
+        # connect to registry using GeniClient
+        address = self.api.config.GENI_REGISTRY_HOSTNAME
+        port = self.api.config.GENI_REGISTRY_PORT
+        url = 'http://%(address)s:%(port)s' % locals()
+        self[self.api.hrn] = GeniClient(url, self.api.key_file, self.api.cert_file)            
+