bunch of cleanups & fixes all over the place
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 9 Jul 2009 17:18:07 +0000 (17:18 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 9 Jul 2009 17:18:07 +0000 (17:18 +0000)
18 files changed:
Makefile
config/sfa-config-tty
config/sfa_config
setup.py
sfa.spec
sfa/client/genidump.py
sfa/client/sfi.py
sfa/methods/create_gid.py
sfa/methods/register.py
sfa/plc/sfa-import-plc.py
sfa/plc/sfa-nuke-plc.py
sfa/server/sfa-server.py [changed mode: 0644->0755]
sfa/trust/auth.py
sfa/trust/gid.py
sfa/trust/hierarchy.py
sfa/util/geniserver.py
sfa/util/genitable.py
sfa/util/record.py

index 0ada9fe..a6965bb 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -79,6 +79,11 @@ RSYNC_EXCLUDES               := --exclude .svn --exclude CVS --exclude '*~' --exclude TAGS $(
 RSYNC_COND_DRY_RUN     := $(if $(findstring n,$(MAKEFLAGS)),--dry-run,)
 RSYNC                  := rsync -a -v $(RSYNC_COND_DRY_RUN) $(RSYNC_EXCLUDES)
 
+BINS = ./config/sfa-config-tty ./sfa/plc/sfa-import-plc.py ./sfa/plc/sfa-nuke-plc.py \
+       ./sfa/server/sfa-server.py \
+       ./sfa/client/sfi.py ./sfa/client/getNodes.py ./sfa/client/getRecord.py \
+       ./sfa/client/setRecord.py ./sfa/client/genidump.py
+
 sync:
 ifeq (,$(SSHURL))
        @echo "sync: You must define, either PLC, or PLCHOST & GUEST, on the command line"
@@ -87,7 +92,7 @@ ifeq (,$(SSHURL))
        @exit 1
 else
        +$(RSYNC) ./sfa/ $(SSHURL)/usr/lib/python2.5/site-packages/sfa/
-       +$(RSYNC) ./config/sfa-config-tty $(SSHURL)/usr/bin
+       +$(RSYNC)  $(BINS) $(SSHURL)/usr/bin
        $(SSHCOMMAND) exec service sfa restart
 endif
 
index 2cf51bc..3e715d3 100755 (executable)
@@ -48,6 +48,7 @@ usual_variables = ["SFA_REGISTRY_ROOT_AUTH",
                    "SFA_REGISTRY_LEVEL1_AUTH",
                    "SFA_PLC_USER",
                    "SFA_PLC_PASSWORD",
+                   "SFA_PLC_DB_HOST",
                    "SFA_PLC_DB_USER",
                    "SFA_PLC_DB_PASSWORD",
                    ]
index f8d59e9..1a7e46a 100644 (file)
@@ -73,19 +73,14 @@ SFA_PLC_USER='root@localhost.localdomain'
 # Password for user account
 SFA_PLC_PASSWORD='root'
 
-# Hostname
-# Fully qualified hostname of PLC interface
+# Full URL of PLC interface
 SFA_PLC_URL='https://localhost:443/PLCAPI/'
 
-# PLC Shell PATH
-# This only applies if sfa services and PLC interface are running on the same machine
-SFA_PLC_SHELL_PATH='/usr/share/plc_api'
-
 # PLC DB Name
 SFA_PLC_DB_NAME='planetlab5'
 
 # PLC DB Host
-SFA_PLC_DB_HOST='www.planet-lab.org'
+SFA_PLC_DB_HOST='localhost'
 
 # PLC DB port
 SFA_PLC_DB_PORT=5432
index ded7f5e..ef545cd 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -32,7 +32,6 @@ data_files = [ ('/etc/sfa/', [ 'config/aggregates.xml',
                                ]),
                ('/etc/init.d/', ['sfa/init.d/sfa']),
                ]
-symlinks = [ '/usr/share/sfa' ]
 initscripts = [ '/etc/init.d/sfa' ]
         
 if sys.argv[1] in ['uninstall', 'remove', 'delete', 'clean']:
@@ -41,13 +40,14 @@ if sys.argv[1] in ['uninstall', 'remove', 'delete', 'clean']:
     remove_dirs = ['/etc/sfa/'] + site_packages_path
     remove_files = [ '/usr/bin/sfa-config-tty',
                      '/usr/bin/sfa-import-plc.py', 
+                     '/usr/bin/sfa-nuke-plc.py', 
                      '/usr/bin/sfa-server.py', 
                      '/usr/bin/sfi.py', 
                      '/usr/bin/getNodes.py',
                      '/usr/bin/getRecord.py',
                      '/usr/bin/setRecord.py',
                      '/usr/bin/genidump.py',
-                    ] + symlinks + initscripts
+                    ] + initscripts
     
     # remove files   
     for filepath in remove_files:
@@ -75,19 +75,3 @@ else:
           scripts = scripts,   
           )
 
-    # create symlink to geniwrapper source in /usr/share
-    python_path = sys.path
-    site_packages_path = [ path + os.sep + 'sfa' for path in python_path if path.endswith('site-packages')]
-    # python path usualy has /usr/local/lib/ path , filter this out
-    site_packages_path = [x for x in site_packages_path if 'local' not in x]
-
-    # we can not do this here as installation root might change paths
-    # - baris
-    #
-    # for src in site_packages_path:
-    #     for dst in symlinks:
-    #         try: 
-    #             os.symlink(src, dst)
-    #         except: pass
-    # for initscript in initscripts:
-    #     os.chmod(initscript, 00744)
index 2c337eb..a30ff71 100644 (file)
--- a/sfa.spec
+++ b/sfa.spec
@@ -76,6 +76,7 @@ rm -rf $RPM_BUILD_ROOT
 /etc/init.d/sfa
 %{_bindir}/sfa-config-tty
 %{_bindir}/sfa-import-plc.py*
+%{_bindir}/sfa-nuke-plc.py*
 %{_bindir}/sfa-server.py*
 
 %files client
index 5024fb2..5ba11e4 100644 (file)
@@ -10,9 +10,8 @@ from optparse import OptionParser
 
 from sfa.trust.certificate import Certificate
 from sfa.trust.credential import Credential
-from sfa.trust.gid import create_uuid
 
-from sfa.util.geniclient import GeniClient, ServerException
+from sfa.util.geniclient import GeniClient
 from sfa.util.record import GeniRecord
 from sfa.util.rspec import Rspec
 
index cca9e67..aa13830 100755 (executable)
@@ -11,11 +11,11 @@ from optparse import OptionParser
 
 from sfa.trust.certificate import Keypair, Certificate
 from sfa.trust.credential import Credential
-from sfa.trust.gid import create_uuid
 
 from sfa.util.geniclient import GeniClient
 from sfa.util.record import *
 from sfa.util.rspec import Rspec
+from sfa.util.xmlrpcprotocol import ServerException
 
 # xxx todo xxx auto-load ~/.sfi/sfi_config
 
index 2cd9e19..12fe0f6 100644 (file)
@@ -6,6 +6,8 @@ from sfa.trust.certificate import Keypair
 from sfa.util.faults import *
 from sfa.util.method import Method
 from sfa.util.parameter import Parameter, Mixed
+
+from sfa.trust.gid import create_uuid
 from sfa.trust.auth import Auth
 
 class create_gid(Method):
index 83a21f3..9f5d019 100644 (file)
@@ -8,10 +8,12 @@ from sfa.util.faults import *
 from sfa.util.misc import *
 from sfa.util.method import Method
 from sfa.util.parameter import Parameter, Mixed
-from sfa.trust.auth import Auth
 from sfa.util.record import GeniRecord
 from sfa.util.debug import log
 
+from sfa.trust.auth import Auth
+from sfa.trust.gid import create_uuid
+
 class register(Method):
     """
     Register an object with the registry. In addition to being stored in the
index 4cb7513..1ab6aed 100755 (executable)
@@ -21,14 +21,16 @@ import getopt
 import sys
 import tempfile
 
-from sfa.trust.certificate import convert_public_key, Keypair
-from sfa.trust.trustedroot import *
-
-from sfa.trust.hierarchy import *
 from sfa.util.record import *
-from sfa.util.genitable import *
+from sfa.util.genitable import GeniTable
 from sfa.util.misc import *
 from sfa.util.config import *
+from sfa.util.report import trace, error
+
+from sfa.trust.certificate import convert_public_key, Keypair
+from sfa.trust.trustedroot import *
+from sfa.trust.hierarchy import *
+from sfa.trust.gid import create_uuid
 
 # get PL account settings from config module
 pl_auth = get_pl_auth()
@@ -41,8 +43,8 @@ def connect_shell():
 
     # connect to planetlab
     if "Url" in pl_auth:
-        from sfa.plc import remoteshell
-        shell = remoteshell.RemoteShell()
+        from sfa.plc.remoteshell import RemoteShell
+        shell = RemoteShell()
     else:
         import PLC.Shell
         shell = PLC.Shell.Shell(globals = globals())
@@ -110,7 +112,7 @@ def get_auth_table(auth_name):
     # into this authority yet.
 
     if not table.exists():
-        report.trace("Import: creating table for authority " + auth_name)
+        trace("Import: creating table for authority " + auth_name)
         table.create()
 
     return table
@@ -135,7 +137,7 @@ def import_person(parent_hrn, person):
     if len(hrn) > 64:
         hrn = hrn[:64]
 
-    report.trace("Import: importing person " + hrn)
+    trace("Import: importing person " + hrn)
 
     table = get_auth_table(parent_hrn)
 
@@ -150,7 +152,7 @@ def import_person(parent_hrn, person):
         pkey =convert_public_key(key)
     else:
         # the user has no keys
-        report.trace("   person " + hrn + " does not have a PL public key")
+        trace("   person " + hrn + " does not have a PL public key")
 
         # if a key is unavailable, then we still need to put something in the
         # user's GID. So make one up.
@@ -160,11 +162,11 @@ def import_person(parent_hrn, person):
     person_gid = AuthHierarchy.create_gid(hrn, create_uuid(), pkey)
     person_record = table.resolve("user", hrn)
     if not person_record:
-        report.trace("  inserting user record for " + hrn)
+        trace("  inserting user record for " + hrn)
         person_record = GeniRecord(hrn=hrn, gid=person_gid, type="user", pointer=person['person_id'])
         table.insert(person_record)
     else:
-        report.trace("  updating user record for " + hrn)
+        trace("  updating user record for " + hrn)
         person_record = GeniRecord(hrn=hrn, gid=person_gid, type="user", pointer=person['person_id'])
         table.update(person_record)
             
@@ -174,11 +176,11 @@ def import_slice(parent_hrn, slice):
     slicename = cleanup_string(slicename)
 
     if not slicename:
-        report.error("Import_Slice: failed to parse slice name " + slice['name'])
+        error("Import_Slice: failed to parse slice name " + slice['name'])
         return
 
     hrn = parent_hrn + "." + slicename
-    report.trace("Import: importing slice " + hrn)
+    trace("Import: importing slice " + hrn)
 
     table = get_auth_table(parent_hrn)
 
@@ -187,7 +189,7 @@ def import_slice(parent_hrn, slice):
         pkey = Keypair(create=True)
         slice_gid = AuthHierarchy.create_gid(hrn, create_uuid(), pkey)
         slice_record = GeniRecord(hrn=hrn, gid=slice_gid, type="slice", pointer=slice['slice_id'])
-        report.trace("  inserting slice record for " + hrn)
+        trace("  inserting slice record for " + hrn)
         table.insert(slice_record)
 
 def import_node(parent_hrn, node):
@@ -196,7 +198,7 @@ def import_node(parent_hrn, node):
     nodename = cleanup_string(nodename)
 
     if not nodename:
-        report.error("Import_node: failed to parse node name " + node['hostname'])
+        error("Import_node: failed to parse node name " + node['hostname'])
         return
 
     hrn = parent_hrn + "." + nodename
@@ -205,7 +207,7 @@ def import_node(parent_hrn, node):
     if len(hrn) > 64:
         hrn = hrn[:64]
 
-    report.trace("Import: importing node " + hrn)
+    trace("Import: importing node " + hrn)
 
     table = get_auth_table(parent_hrn)
 
@@ -214,7 +216,7 @@ def import_node(parent_hrn, node):
         pkey = Keypair(create=True)
         node_gid = AuthHierarchy.create_gid(hrn, create_uuid(), pkey)
         node_record = GeniRecord(hrn=hrn, gid=node_gid, type="node", pointer=node['node_id'])
-        report.trace("  inserting node record for " + hrn)
+        trace("  inserting node record for " + hrn)
         table.insert(node_record)
 
 def import_site(parent_hrn, site):
@@ -235,7 +237,7 @@ def import_site(parent_hrn, site):
             hrn = ".".join([parent_hrn, "internet2", sitename]) 
             sitename = sitename.replace("nlr", "")
          
-    report.trace("Import_Site: importing site " + hrn)
+    trace("Import_Site: importing site " + hrn)
 
     # create the authority
     if not AuthHierarchy.auth_exists(hrn):
@@ -248,7 +250,7 @@ def import_site(parent_hrn, site):
     auth_record = table.resolve("authority", hrn)
     if not auth_record:
         auth_record = GeniRecord(hrn=hrn, gid=auth_info.get_gid_object(), type="authority", pointer=site['site_id'])
-        report.trace("  inserting authority record for " + hrn)
+        trace("  inserting authority record for " + hrn)
         table.insert(auth_record)
 
     if 'person_ids' in site: 
@@ -258,7 +260,7 @@ def import_site(parent_hrn, site):
                 try: 
                     import_person(hrn, persons[0])
                 except Exception, e:
-                    report.trace("Failed to import: %s (%s)" % (persons[0], e))
+                    trace("Failed to import: %s (%s)" % (persons[0], e))
     if 'slice_ids' in site:
         for slice_id in site['slice_ids']:
             slices = shell.GetSlices(pl_auth, [slice_id])
@@ -266,7 +268,7 @@ def import_site(parent_hrn, site):
                 try:
                     import_slice(hrn, slices[0])
                 except Exception, e:
-                    report.trace("Failed to import: %s (%s)" % (slices[0], e))
+                    trace("Failed to import: %s (%s)" % (slices[0], e))
     if 'node_ids' in site:
         for node_id in site['node_ids']:
             nodes = shell.GetNodes(pl_auth, [node_id])
@@ -274,7 +276,7 @@ def import_site(parent_hrn, site):
                 try:
                     import_node(hrn, nodes[0])
                 except Exception, e:
-                    report.trace("Failed to import: %s (%s)" % (nodes[0], e))
+                    trace("Failed to import: %s (%s)" % (nodes[0], e))
 
 def create_top_level_auth_records(hrn):
     parent_hrn = get_authority(hrn)
@@ -287,7 +289,7 @@ def create_top_level_auth_records(hrn):
     auth_record = table.resolve("authority", hrn)
     if not auth_record:
         auth_record = GeniRecord(hrn=hrn, gid=auth_info.get_gid_object(), type="authority", pointer=-1)
-        report.trace("  inserting authority record for " + hrn)
+        trace("  inserting authority record for " + hrn)
         table.insert(auth_record)
 
 def main():
index e347f2b..e409587 100755 (executable)
@@ -1,3 +1,4 @@
+#!/usr/bin/python
 ##
 # Delete all the database records for Geni. This tool is used to clean out Geni
 # records during testing.
@@ -11,11 +12,10 @@ import sys
 
 from sfa.trust.hierarchy import *
 from sfa.util.record import *
-from sfa.util.genitable import *
+from sfa.util.genitable import GeniTable
 from sfa.util.config import *
 
 def process_options():
-   global hrn
 
    (options, args) = getopt.getopt(sys.argv[1:], '', [])
    for opt in options:
@@ -26,7 +26,7 @@ def main():
     process_options()
 
     print "purging geni records from database"
-    geni_records_purge(get_default_dbinfo())
+    GeniTable.geni_records_purge(get_default_dbinfo())
 
 if __name__ == "__main__":
     main()
old mode 100644 (file)
new mode 100755 (executable)
index c8251d6..3b0af02 100644 (file)
@@ -12,7 +12,7 @@ from sfa.trust.trustedroot import TrustedRootList
 from sfa.trust.rights import RightList
 from sfa.util.faults import *
 from sfa.trust.hierarchy import Hierarchy
-from sfa.util.genitable import *
+from sfa.util.genitable import GeniTable
 from sfa.util.config import *
 from sfa.util.misc import *
 
index 6c0436c..c1670be 100644 (file)
@@ -7,8 +7,8 @@
 ### $URL$
 
 import xmlrpclib
-
 import uuid
+
 from sfa.trust.certificate import Certificate
 
 ##
index 5900793..81ee194 100644 (file)
@@ -20,7 +20,7 @@ import os
 from sfa.util.report import *
 from sfa.trust.certificate import Keypair
 from sfa.trust.credential import *
-from sfa.trust.gid import *
+from sfa.trust.gid import GID, create_uuid
 
 from sfa.util.misc import *
 from sfa.util.config import *
index 7159df5..ed82f01 100644 (file)
@@ -141,7 +141,10 @@ class SecureXMLRpcRequestHandler(SimpleXMLRPCServer.SimpleXMLRPCRequestHandler):
 
         It was copied out from SimpleXMLRPCServer.py and modified to shutdown the socket cleanly.
         """
-        self.api = GeniAPI(peer_cert = self.server.peer_cert, interface = self.server.interface, key_file = self.server.key_file, cert_file = self.server.cert_file)
+        self.api = GeniAPI(peer_cert = self.server.peer_cert, 
+                           interface = self.server.interface, 
+                           key_file = self.server.key_file, 
+                           cert_file = self.server.cert_file)
         try:
             # get arguments
             request = self.rfile.read(int(self.headers["content-length"]))
index 8155be4..ad27672 100644 (file)
@@ -15,16 +15,16 @@ from sfa.trust.gid import *
 from sfa.util.record import *
 from sfa.util.debug import *
 
-GENI_TABLE_PREFIX = "sfa$"
-
 class GeniTable:
+
+    GENI_TABLE_PREFIX = "sfa$"
+
     def __init__(self, create=False, hrn="unspecified.default.registry", cninfo=None):
-        global GENI_TABLE_PREFIX
 
         self.hrn = hrn
 
         # pgsql doesn't like table names with "." in them, to replace it with "$"
-        self.tablename = GENI_TABLE_PREFIX + self.hrn.replace(".", "$")
+        self.tablename = GeniTable.GENI_TABLE_PREFIX + self.hrn.replace(".", "$")
 
         # establish a connection to the pgsql server
         self.cnx = DB(cninfo['dbname'], cninfo['address'], port=cninfo['port'], user=cninfo['user'], passwd=cninfo['password'])
@@ -135,19 +135,15 @@ class GeniTable:
             result_rec_list.append(GeniRecord(dict=dict).as_dict())
         return result_rec_list
 
-def set_geni_table_prefix(x):
-    global GENI_TABLE_PREFIX
-
-    GENI_TABLE_PREFIX = x
-
-def geni_records_purge(cninfo):
-    global GENI_TABLE_PREFIX
-
-    cnx = DB(cninfo['dbname'], cninfo['address'], port=cninfo['port'], user=cninfo['user'], passwd=cninfo['password'])
-    tableList = cnx.get_tables()
-    for table in tableList:
-        if table.startswith(GENI_TABLE_PREFIX) or \
-           table.startswith('public.' + GENI_TABLE_PREFIX) or \
-           table.startswith('public."' + GENI_TABLE_PREFIX):
-               report.trace("dropping table " + table)
-               cnx.query("DROP TABLE " + table)
+    @staticmethod
+    def geni_records_purge(cninfo):
+
+        cnx = DB(cninfo['dbname'], cninfo['address'], 
+                 port=cninfo['port'], user=cninfo['user'], passwd=cninfo['password'])
+        tableList = cnx.get_tables()
+        for table in tableList:
+            if table.startswith(GeniTable.GENI_TABLE_PREFIX) or \
+                    table.startswith('public.' + GeniTable.GENI_TABLE_PREFIX) or \
+                    table.startswith('public."' + GeniTable.GENI_TABLE_PREFIX):
+                report.trace("dropping table " + table)
+                cnx.query("DROP TABLE " + table)
index 3075edb..bfa166f 100644 (file)
@@ -229,10 +229,7 @@ class GeniRecord(dict):
         """
         Given a list of field names, return a list of values for those public.
         """
-        strs = []
-        for fieldname in fieldnames:
-            strs.append(self.get_field_value_string(fieldname))
-        return strs
+        return [ self.get_field_value_string (fieldname) for fieldname in fieldnames ]
 
     ##
     # Return the record in the form of a dictionary