cleaned up globals - except in the foreign plugins for eucalyptus and MAX
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Mon, 4 Oct 2010 15:42:11 +0000 (17:42 +0200)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Mon, 4 Oct 2010 15:42:11 +0000 (17:42 +0200)
sfa/plc/sfa-import-plc.py
sfa/plc/sfaImport.py
sfa/server/modpythonapi/BaseClient.py
sfa/server/modpythonapi/test.py
sfa/server/sfa-server.py

index 814fffa..18727c6 100755 (executable)
@@ -31,7 +31,6 @@ from sfa.trust.gid import create_uuid
 from sfa.plc.sfaImport import sfaImport
 
 def process_options():
-   global hrn
 
    (options, args) = getopt.getopt(sys.argv[1:], '', [])
    for opt in options:
@@ -68,8 +67,6 @@ def main():
     if config.SFA_API_DEBUG: sfaImporter.logger.setLevel(logging.DEBUG)
     shell = sfaImporter.shell
     plc_auth = sfaImporter.plc_auth 
-    AuthHierarchy = sfaImporter.AuthHierarchy
-    TrustedRoots = sfaImporter.TrustedRoots
     table = SfaTable()
 
     if not table.exists():
@@ -81,8 +78,8 @@ def main():
         sfaImporter.create_top_level_auth_records(interface_hrn)
 
     sfaImporter.logger.info("Import: adding " + interface_hrn + " to trusted list")
-    authority = AuthHierarchy.get_auth_info(interface_hrn)
-    TrustedRoots.add_gid(authority.get_gid_object())
+    authority = sfaImporter.AuthHierarchy.get_auth_info(interface_hrn)
+    sfaImporter.TrustedRoots.add_gid(authority.get_gid_object())
 
     if ".vini" in interface_hrn and interface_hrn.endswith('vini'):
         # create a fake internet2 site first
index c5169e8..82dc17c 100644 (file)
@@ -68,7 +68,6 @@ class sfaImport:
 
 
     def create_top_level_auth_records(self, hrn):
-        AuthHierarchy = self.AuthHierarchy
         urn = hrn_to_urn(hrn, 'authority')
         # make sure parent exists
         parent_hrn = get_authority(hrn)
@@ -78,12 +77,12 @@ class sfaImport:
             self.create_top_level_auth_records(parent_hrn)
 
         # create the authority if it doesnt already exist 
-        if not AuthHierarchy.auth_exists(urn):
+        if not self.AuthHierarchy.auth_exists(urn):
             self.logger.info("Import: creating top level authorites")
-            AuthHierarchy.create_auth(urn)
+            self.AuthHierarchy.create_auth(urn)
         
         # create the db record if it doesnt already exist    
-        auth_info = AuthHierarchy.get_auth_info(hrn)
+        auth_info = self.AuthHierarchy.get_auth_info(hrn)
         table = SfaTable()
         auth_record = table.find({'type': 'authority', 'hrn': hrn})
 
@@ -95,7 +94,6 @@ class sfaImport:
 
 
     def import_person(self, parent_hrn, person):
-        AuthHierarchy = self.AuthHierarchy
         hrn = email_to_hrn(parent_hrn, person['email'])
 
         # ASN.1 will have problems with hrn's longer than 64 characters
@@ -122,7 +120,7 @@ class sfaImport:
 
         # create the gid
         urn = hrn_to_urn(hrn, 'user')
-        person_gid = AuthHierarchy.create_gid(urn, create_uuid(), pkey)
+        person_gid = self.AuthHierarchy.create_gid(urn, create_uuid(), pkey)
         table = SfaTable()
         person_record = SfaRecord(hrn=hrn, gid=person_gid, type="user", pointer=person['person_id'])
         person_record['authority'] = get_authority(person_record['hrn'])
@@ -136,7 +134,6 @@ class sfaImport:
             table.update(person_record)
 
     def import_slice(self, parent_hrn, slice):
-        AuthHierarchy = self.AuthHierarchy
         slicename = slice['name'].split("_",1)[-1]
         slicename = _cleanup_string(slicename)
 
@@ -149,7 +146,7 @@ class sfaImport:
 
         pkey = Keypair(create=True)
         urn = hrn_to_urn(hrn, 'slice')
-        slice_gid = AuthHierarchy.create_gid(urn, create_uuid(), pkey)
+        slice_gid = self.AuthHierarchy.create_gid(urn, create_uuid(), pkey)
         slice_record = SfaRecord(hrn=hrn, gid=slice_gid, type="slice", pointer=slice['slice_id'])
         slice_record['authority'] = get_authority(slice_record['hrn'])
         table = SfaTable()
@@ -163,7 +160,6 @@ class sfaImport:
             table.update(slice_record)
 
     def import_node(self, parent_hrn, node):
-        AuthHierarchy = self.AuthHierarchy
         nodename = node['hostname'].split(".")[0]
         nodename = _cleanup_string(nodename)
         
@@ -181,7 +177,7 @@ class sfaImport:
         node_record = table.find({'type': 'node', 'hrn': hrn})
         pkey = Keypair(create=True)
         urn = hrn_to_urn(hrn, 'node')
-        node_gid = AuthHierarchy.create_gid(urn, create_uuid(), pkey)
+        node_gid = self.AuthHierarchy.create_gid(urn, create_uuid(), pkey)
         node_record = SfaRecord(hrn=hrn, gid=node_gid, type="node", pointer=node['node_id'])
         node_record['authority'] = get_authority(node_record['hrn'])
         existing_records = table.find({'hrn': hrn, 'type': 'node', 'pointer': node['node_id']})
@@ -195,7 +191,6 @@ class sfaImport:
 
     
     def import_site(self, parent_hrn, site):
-        AuthHierarchy = self.AuthHierarchy
         shell = self.shell
         plc_auth = self.plc_auth
         sitename = site['login_base']
@@ -217,10 +212,10 @@ class sfaImport:
         self.logger.info("Import: importing site " + hrn)
 
         # create the authority
-        if not AuthHierarchy.auth_exists(urn):
-            AuthHierarchy.create_auth(urn)
+        if not self.AuthHierarchy.auth_exists(urn):
+            self.AuthHierarchy.create_auth(urn)
 
-        auth_info = AuthHierarchy.get_auth_info(urn)
+        auth_info = self.AuthHierarchy.get_auth_info(urn)
 
         table = SfaTable()
         auth_record = SfaRecord(hrn=hrn, gid=auth_info.get_gid_object(), type="authority", pointer=site['site_id'])
index 5dd72a1..56d7286 100755 (executable)
@@ -2,12 +2,6 @@ import xmlrpclib
 
 from ApiExceptionCodes import *
 
-VerboseExceptions = False
-
-def EnableVerboseExceptions(x=True):
-    global VerboseExceptions
-    VerboseExceptions = x
-
 class ExceptionUnmarshaller(xmlrpclib.Unmarshaller):
     def close(self):
         try:
@@ -19,7 +13,7 @@ class ExceptionUnmarshaller(xmlrpclib.Unmarshaller):
             if "\nFAULT_TRACEBACK:" in e.faultString:
                 parts = e.faultString.split("\nFAULT_TRACEBACK:")
                 e.faultString = parts[0]
-                if VerboseExceptions:
+                if BaseClient.VerboseExceptions:
                     print "\n|Server Traceback:", "\n|".join(parts[1].split("\n"))
 
             raise e
@@ -38,9 +32,17 @@ class ExceptionReportingTransport(xmlrpclib.Transport):
         return parser, unmarshaller
 
 class BaseClient():
+    
+    VerboseExceptions = False
+
     def __init__(self, url):
         self.url = url
         self.server = xmlrpclib.ServerProxy(self.url, ExceptionReportingTransport())
 
     def noop(self, value):
         return self.server.noop(value)
+
+    @staticmethod
+    def EnableVerboseExceptions(x=True):
+        BaseClient.VerboseExceptions = x
+
index d3fafed..941cb05 100755 (executable)
@@ -1,10 +1,10 @@
 import sys
 import traceback
 
-from BaseClient import BaseClient, EnableVerboseExceptions
+from BaseClient import BaseClient
 from AuthenticatedClient import AuthenticatedClient
 
-EnableVerboseExceptions(True)
+BaseClient.EnableVerboseExceptions(True)
 
 HOST = "localhost"
 URL = "http://" + HOST + "/TESTAPI/"
index dfcc1e1..2685530 100755 (executable)
 ##
 
 # TCP ports for the three servers
-registry_port=12345
-aggregate_port=12346
-slicemgr_port=12347
+#registry_port=12345
+#aggregate_port=12346
+#slicemgr_port=12347
+### xxx todo not in the config yet
 component_port=12346
 import os, os.path
 import sys
@@ -162,13 +163,6 @@ def sync_interfaces(server_key_file, server_cert_file):
     aggregates.sync_interfaces()
 
 def main():
-    # xxx get rid of globals - name consistently CamelCase or under_score
-    global AuthHierarchy
-    global TrustedRoots
-    global registry_port
-    global aggregate_port
-    global slicemgr_port
-
     # Generate command line parser
     parser = OptionParser(usage="sfa-server [options]")
     parser.add_option("-r", "--registry", dest="registry", action="store_true",
@@ -200,24 +194,25 @@ def main():
     # start registry server
     if (options.registry):
         from sfa.server.registry import Registry
-        r = Registry("", registry_port, server_key_file, server_cert_file)
+        r = Registry("", config.SFA_REGISTRY_PORT, server_key_file, server_cert_file)
         r.start()
 
     # start aggregate manager
     if (options.am):
         from sfa.server.aggregate import Aggregate
-        a = Aggregate("", aggregate_port, server_key_file, server_cert_file)
+        a = Aggregate("", config.SFA_AGGREGATE_PORT, server_key_file, server_cert_file)
         a.start()
 
     # start slice manager
     if (options.sm):
         from sfa.server.slicemgr import SliceMgr
-        s = SliceMgr("", slicemgr_port, server_key_file, server_cert_file)
+        s = SliceMgr("", config.SFA_SM_PORT, server_key_file, server_cert_file)
         s.start()
 
     if (options.cm):
         from sfa.server.component import Component
-        c = Component("", component_port, server_key_file, server_cert_file)
+        c = Component("", config.component_port, server_key_file, server_cert_file)
+#        c = Component("", config.SFA_COMPONENT_PORT, server_key_file, server_cert_file)
         c.start()
 
 if __name__ == "__main__":