Merge branch 'master' of ssh://bakers@git.planet-lab.org/git/sfa
authorsmbaker <smbaker@fc8clean.lan>
Tue, 29 Nov 2011 02:35:05 +0000 (18:35 -0800)
committersmbaker <smbaker@fc8clean.lan>
Tue, 29 Nov 2011 02:35:05 +0000 (18:35 -0800)
59 files changed:
Makefile
config/default_config.xml
config/sfa_component_config
cron.d/readme [new file with mode: 0644]
cron.d/sfa.cron [moved from sfa/cron.d/sfa.cron with 100% similarity]
init.d/sfa [moved from sfa/init.d/sfa with 92% similarity]
init.d/sfa-cm [moved from sfa/init.d/sfa-cm with 100% similarity]
setup.py
sfa.spec
sfa/client/sfadump.py
sfa/importer/sfa-import-plc.py
sfa/importer/sfa-nuke-plc.py
sfa/importer/sfaImport.py
sfa/managers/registry_manager.py
sfa/methods/CreateGid.py
sfa/methods/CreateSliver.py
sfa/methods/DeleteSliver.py
sfa/methods/GetCredential.py
sfa/methods/GetGids.py
sfa/methods/GetSelfCredential.py
sfa/methods/GetTicket.py
sfa/methods/GetVersion.py
sfa/methods/List.py
sfa/methods/ListResources.py
sfa/methods/ListSlices.py
sfa/methods/RedeemTicket.py
sfa/methods/Register.py
sfa/methods/Remove.py
sfa/methods/RenewSliver.py
sfa/methods/Resolve.py
sfa/methods/ResolveGENI.py
sfa/methods/Shutdown.py
sfa/methods/SliverStatus.py
sfa/methods/Start.py
sfa/methods/Stop.py
sfa/methods/Update.py
sfa/methods/UpdateSliver.py
sfa/methods/get_key_from_incoming_ip.py
sfa/methods/get_trusted_certs.py
sfa/methods/reset_slice.py
sfa/plc/pldriver.py
sfa/rspecs/version_manager.py
sfa/server/sfa-ca.py
sfa/server/sfa-clean-peer-records.py
sfa/server/sfa-start.py
sfa/server/sfaapi.py
sfa/storage/PostgreSQL.py [moved from sfa/util/PostgreSQL.py with 100% similarity]
sfa/storage/__init__.py [new file with mode: 0644]
sfa/storage/filter.py [moved from sfa/util/filter.py with 98% similarity]
sfa/storage/parameter.py [moved from sfa/util/parameter.py with 100% similarity]
sfa/storage/record.py [moved from sfa/util/record.py with 99% similarity]
sfa/storage/row.py [moved from sfa/util/row.py with 100% similarity]
sfa/storage/sfa.sql [new file with mode: 0644]
sfa/storage/table.py [moved from sfa/util/table.py with 81% similarity]
sfa/util/config.py
sfa/util/faults.py
sfa/util/method.py
tests/testRecord.py
wsdl/sfa2wsdl.py

index 701c329..6d770b4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -90,7 +90,7 @@ force:
 
 ##########
 tags:  
-       find . -type f | egrep -v '/\.git/|/\.svn/|TAGS|~$$|\.(py[co]|doc|html|pdf|png|svg|out|bak|xml|dg)$$' | xargs etags
+       find . -type f | egrep -v '/\.git/|/\.svn/|TAGS|AA-|~$$|\.(py[co]|doc|html|pdf|png|svg|out|bak|xml|dg)$$' | xargs etags
 .PHONY: tags
 
 signatures:
@@ -141,7 +141,7 @@ else
        +$(RSYNC) ./sfa/ $(SSHURL)/usr/lib\*/python2.\*/site-packages/sfa/
        +$(RSYNC) ./tests/ $(SSHURL)/root/tests-sfa
        +$(RSYNC)  $(BINS) $(SSHURL)/usr/bin/
-       +$(RSYNC) ./sfa/init.d/sfa  $(SSHURL)/etc/init.d/
+       +$(RSYNC) ./init.d/sfa  $(SSHURL)/etc/init.d/
        +$(RSYNC) ./config/default_config.xml $(SSHURL)/etc/sfa/
        $(SSHCOMMAND) exec service sfa restart
 endif
index 5427283..99c5d37 100644 (file)
@@ -85,13 +85,6 @@ Thierry Parmentelat
          registry.</description>
        </variable>
 
-       <variable id="type" type="string">
-         <name>Registry type</name>
-         <value>pl</value>
-         <description>The type of backend server for this
-         registry. Some registries may not be myplc.</description>
-       </variable>
-
        <variable id="host" type="hostname">
          <name>Hostname</name>
          <value>localhost</value>
@@ -129,13 +122,6 @@ Thierry Parmentelat
          slice manager.</description>
        </variable>
 
-       <variable id="type" type="string">
-         <name>Slice Manager type</name>
-         <value>pl</value>
-         <description>The type of backend server for this
-         slice manager. Not all slice managers are myplc.</description>
-       </variable>
-
        <variable id="host" type="hostname">
          <name>Hostname</name>
          <value>localhost</value>
@@ -165,13 +151,6 @@ Thierry Parmentelat
          aggregate manager.</description>
        </variable>
 
-       <variable id="type" type="string">
-         <name>Aggregate type</name>
-         <value>pl</value>
-         <description>The type of backend server for this
-         aggregate. Some aggregates may not be myplc.</description>
-       </variable>
-    
     <variable id="rspec_schema" type="string">
       <name>RSpec Schema</name>
       <value>/etc/sfa/pl.rng</value>
index d51c93b..1bb57c8 100644 (file)
@@ -16,11 +16,6 @@ SFA_API_DEBUG=1
 # Enable the registry interface 
 SFA_REGISTRY_ENABLED=0
 
-#
-# The type of backend server for this registry
-# Some registries may not be myplc 
-SFA_REGISTRY_TYPE='pl'
-
 # Root Auth
 # The hrn of the registry's root auth
 SFA_REGISTRY_ROOT_AUTH="plc"
@@ -32,6 +27,8 @@ SFA_REGISTRY_ROOT_AUTH="plc"
 # xxx could be determined from hrn above
 SFA_REGISTRY_LEVEL1_AUTH=""
 
+SFA_GENERIC_FLAVOUR='pl'
+
 # Hostname
 # The fully qualified hostname of the registry server
 SFA_REGISTRY_HOST="localhost"
@@ -47,12 +44,6 @@ SFA_REGISTRY_PORT=12345
 ## Enable the aggregate inteface.
 SFA_AGGREGATE_ENABLED=0
 
-# Aggregate Type
-#
-# The type of backend server for this aggregate
-# Some aggregates may not be myplc 
-SFA_AGGREGATE_TYPE='pl'
-
 #
 #
 ## Hostname
@@ -70,14 +61,6 @@ SFA_AGGREGATE_PORT=12346
 # Enable the slice manager  
 SFA_SM_ENABLED=0
 
-# Slice Manager type
-#
-## The type of backend server for this slice manager
-## The slice manager doesnt rely on a specific backend server so 
-## you probably will never need to change this type unless you 
-## need to reimplement the slice manager
-SFA_SM_TYPE='pl' 
-
 # Host
 ## The fully qualified hostname or IP address of the slice manager server
 SFA_SM_HOST="localhost"
diff --git a/cron.d/readme b/cron.d/readme
new file mode 100644 (file)
index 0000000..53d10a1
--- /dev/null
@@ -0,0 +1 @@
+As of nov 2011 this is not packaged, use as a template for your installation
similarity index 100%
rename from sfa/cron.d/sfa.cron
rename to cron.d/sfa.cron
similarity index 92%
rename from sfa/init.d/sfa
rename to init.d/sfa
index 92c70ea..3e733ee 100755 (executable)
@@ -85,10 +85,10 @@ function reload () {
 
     # Convert configuration to various formats
     if [ -n "$force" -o $sfa_whole_config -nt /etc/sfa/sfa_config ] ; then
-       plc-config --shell $sfa_whole_config >/etc/sfa/sfa_config
+       plc-config --shell $sfa_whole_config > /etc/sfa/sfa_config
     fi
     if [ -n "$force" -o $sfa_whole_config -nt /etc/sfa/sfa_config.py ] ; then
-       plc-config --python $sfa_whole_config >/etc/sfa/sfa_config.py
+       plc-config --python $sfa_whole_config > /etc/sfa/sfa_config.py
     fi
 #    if [ -n "$force" -o $sfa_whole_config -nt /etc/sfa/php/sfa_config.php ] ; then
 #      mkdir -p /etc/sfa/php
@@ -101,6 +101,10 @@ function reload () {
     # (or there is no myplc at all) this should be turned off
     # as the component manager is not operational yet we skip this for now
     #gen-sfa-cm-config.py        
+
+    # reload the shell version
+    [ -f /etc/sfa/sfa_config ] && . /etc/sfa/sfa_config
+
 }
 
 ### initialize DB (don't chkconfig postgresql on)
@@ -208,8 +212,10 @@ function db_start () {
     # db
     if ! psql -U $SFA_DB_USER -c "" $SFA_DB_NAME >/dev/null 2>&1 ; then
        createdb -U postgres --template=template0 --encoding=UNICODE --owner=$SFA_DB_USER $SFA_DB_NAME
-        # xxx in case we'd like to ship the db schema separately
-        #psql -U $SFA_DB_USER -f /etc/sfa/or/someplace/else/sfa.sql $SFA_DB_NAME
+       check
+        # install db schema
+        psql -U $SFA_DB_USER -f /usr/share/sfa/sfa.sql $SFA_DB_NAME
+       check
     fi
     check
 
@@ -243,21 +249,14 @@ function start() {
     # install peer certs
     action $"SFA installing peer certs" daemon /usr/bin/sfa-start.py -t -d $OPTIONS 
 
-    if [ "$SFA_REGISTRY_ENABLED" -eq 1 ]; then
-        action $"SFA Registry" daemon /usr/bin/sfa-start.py -r -d $OPTIONS
-    fi
-
-    if [ "$SFA_AGGREGATE_ENABLED" -eq 1 ]; then
-        action $"SFA Aggregate" daemon /usr/bin/sfa-start.py -a -d $OPTIONS
-    fi
+    [ "$SFA_REGISTRY_ENABLED" == 1 ] && action $"SFA Registry" daemon /usr/bin/sfa-start.py -r -d $OPTIONS
+    
+    [ "$SFA_AGGREGATE_ENABLED" == 1 ] && action $"SFA Aggregate" daemon /usr/bin/sfa-start.py -a -d $OPTIONS
         
-    if [ "$SFA_SM_ENABLED" -eq 1 ]; then
-        action "SFA SliceMgr" daemon /usr/bin/sfa-start.py -s -d $OPTIONS
-    fi
+    [ "$SFA_SM_ENABLED" == 1 ] && action "SFA SliceMgr" daemon /usr/bin/sfa-start.py -s -d $OPTIONS
 
-    if [ "$SFA_FLASHPOLICY_ENABLED" -eq 1 ]; then
+    [ "$SFA_FLASHPOLICY_ENABLED" == 1 ] && \
         action "Flash Policy Server" daemon /usr/bin/sfa_flashpolicy.py --file="$SFA_FLASHPOLICY_CONFIG_FILE" --port=$SFA_FLASHPOLICY_PORT -d
-    fi
 
     touch /var/lock/subsys/sfa-start.py
 
similarity index 100%
rename from sfa/init.d/sfa-cm
rename to init.d/sfa-cm
index 47a1314..9f68e18 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -37,6 +37,7 @@ bins = [
 package_dirs = [
     'sfa', 
     'sfa/trust',
+    'sfa/storage',
     'sfa/util', 
     'sfa/client',
     'sfa/server',
@@ -72,7 +73,9 @@ data_files = [('/etc/sfa/', [ 'config/aggregates.xml',
                             ]),
               ('/etc/sfatables/matches/', glob('sfatables/matches/*.xml')),
               ('/etc/sfatables/targets/', glob('sfatables/targets/*.xml')),
-              ('/etc/init.d/', [ "sfa/init.d/%s"%x for x in initscripts ])]
+              ('/etc/init.d/', [ "init.d/%s"%x for x in initscripts ]),
+              ('/usr/share/sfa/', [ 'sfa/storage/sfa.sql' ] ),
+              ]
 
 # add sfatables processors as data_files
 processor_files = [f for f in glob('sfatables/processors/*') if os.path.isfile(f)]
index 0ec3279..9ef697d 100644 (file)
--- a/sfa.spec
+++ b/sfa.spec
@@ -14,6 +14,8 @@ License: GPL
 Group: Applications/System
 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
 
+# xxx TODO : package cron.d/
+
 Vendor: PlanetLab
 Packager: PlanetLab Central <support@planet-lab.org>
 Distribution: PlanetLab %{plrelease}
@@ -123,6 +125,8 @@ make VERSIONTAG="%{version}-%{taglevel}" SCMURL="%{SCMURL}"
 rm -rf $RPM_BUILD_ROOT
 make VERSIONTAG="%{version}-%{taglevel}" SCMURL="%{SCMURL}" install DESTDIR="$RPM_BUILD_ROOT"
 rm -rf $RPM_BUILD_ROOT/%{python_sitelib}/*egg-info
+# this gets duplicated
+rm -rf $RPM_BUILD_ROOT/%{python_sitelib}/sfa/storage/sfa.sql
 
 %clean
 rm -rf $RPM_BUILD_ROOT
@@ -138,6 +142,7 @@ rm -rf $RPM_BUILD_ROOT
 %config /etc/sfa/default_config.xml
 %config (noreplace) /etc/sfa/aggregates.xml
 %config (noreplace) /etc/sfa/registries.xml
+/usr/share/sfa/sfa.sql
 /var/www/html/wsdl/*.wsdl
 
 %files plc
index 52a9105..c45f771 100755 (executable)
@@ -8,11 +8,13 @@ import xmlrpclib
 from types import StringTypes, ListType
 from optparse import OptionParser
 
+from sfa.util.sfalogging import logger
+
 from sfa.trust.certificate import Certificate
 from sfa.trust.credential import Credential
 from sfa.trust.gid import GID
-from sfa.util.record import SfaRecord
-from sfa.util.sfalogging import logger
+
+from sfa.storage.record import SfaRecord
 
 def determine_sfa_filekind(fn):
 
index dad723b..4594534 100755 (executable)
@@ -18,12 +18,13 @@ import os
 import getopt
 import sys
 
-from sfa.util.table import SfaTable
 from sfa.util.xrn import get_leaf, get_authority
 from sfa.util.plxrn import hostname_to_hrn, slicename_to_hrn, email_to_hrn, hrn_to_pl_slicename
 from sfa.util.config import Config
 from sfa.util.xrn import Xrn
 
+from sfa.storage.table import SfaTable
+
 from sfa.importer.sfaImport import sfaImport
 
 def process_options():
index be7b0c1..5450a20 100755 (executable)
@@ -11,9 +11,10 @@ import sys
 import os
 from optparse import OptionParser
 
-from sfa.util.table import SfaTable
 from sfa.util.sfalogging import logger
 
+from sfa.storage.table import SfaTable
+
 def main():
    usage="%prog: trash the registry DB (the 'sfa' table in the 'planetlab5' database)"
    parser = OptionParser(usage=usage)
index 082d3ed..3f054ba 100644 (file)
@@ -9,17 +9,18 @@
 ##
 
 from sfa.util.sfalogging import _SfaLogger
-
-from sfa.util.record import SfaRecord
-from sfa.util.table import SfaTable
 from sfa.util.xrn import get_authority, hrn_to_urn
 from sfa.util.plxrn import email_to_hrn
 from sfa.util.config import Config
+
 from sfa.trust.certificate import convert_public_key, Keypair
 from sfa.trust.trustedroots import TrustedRoots
 from sfa.trust.hierarchy import Hierarchy
 from sfa.trust.gid import create_uuid
 
+from sfa.storage.record import SfaRecord
+from sfa.storage.table import SfaTable
+
 
 def _un_unicode(str):
    if isinstance(str, unicode):
index da0b127..93d2ea8 100644 (file)
@@ -8,8 +8,6 @@ import commands
 from sfa.util.faults import RecordNotFound, AccountNotEnabled, PermissionError, MissingAuthority, \
     UnknownSfaType, ExistingRecord, NonExistingRecord
 from sfa.util.prefixTree import prefixTree
-from sfa.util.record import SfaRecord
-from sfa.util.table import SfaTable
 from sfa.util.xrn import Xrn, get_authority, hrn_to_urn, urn_to_hrn
 from sfa.util.plxrn import hrn_to_pl_login_base
 from sfa.util.version import version_core
@@ -20,6 +18,9 @@ from sfa.trust.credential import Credential
 from sfa.trust.certificate import Certificate, Keypair, convert_public_key
 from sfa.trust.gid import create_uuid
 
+from sfa.storage.record import SfaRecord
+from sfa.storage.table import SfaTable
+
 class RegistryManager:
 
     def __init__ (self): pass
@@ -55,6 +56,7 @@ class RegistryManager:
     
         # verify_cancreate_credential requires that the member lists
         # (researchers, pis, etc) be filled in
+        self.driver.augment_records_with_testbed_info (record)
         if not self.driver.is_enabled (record):
               raise AccountNotEnabled(": PlanetLab account %s is not enabled. Please contact your site PI" %(record['email']))
     
@@ -211,10 +213,20 @@ class RegistryManager:
             pkey = certificate.get_pubkey()    
         gid = api.auth.hierarchy.create_gid(xrn, create_uuid(), pkey) 
         return gid.save_to_string(save_parents=True)
-        
+    
+    ####################
     # utility for handling relationships among the SFA objects 
     # given that the SFA db does not handle this sort of relationsships
     # it will rely on side-effects in the testbed to keep this persistent
+    
+    # subject_record describes the subject of the relationships
+    # ref_record contains the target values for the various relationships we need to manage
+    # (to begin with, this is just the slice x person relationship)
+    def update_relations (self, subject_record, ref_record):
+        type=subject_record['type']
+        if type=='slice':
+            self.update_relation(subject_record, 'researcher', ref_record.get('researcher'), 'user')
+        
     # field_key is the name of one field in the record, typically 'researcher' for a 'slice' record
     # hrns is the list of hrns that should be linked to the subject from now on
     # target_type would be e.g. 'user' in the 'slice' x 'researcher' example
@@ -280,8 +292,8 @@ class RegistryManager:
         record['record_id'] = record_id
     
         # update membership for researchers, pis, owners, operators
-        self.update_relation(record, 'researcher', record.get('researcher'), 'user')
-    
+        self.update_relations (record, record)
+        
         return record.get_gid_object().save_to_string(save_parents=True)
     
     def Update(self, api, record_dict):
@@ -329,7 +341,7 @@ class RegistryManager:
             table.update(record)
         
         # update membership for researchers, pis, owners, operators
-        self.update_relation(record, 'researcher', new_record.get('researcher'), 'user')
+        self.update_relations (record, new_record)
         
         return 1 
     
index db69acd..eb001a1 100644 (file)
@@ -1,7 +1,8 @@
 
 from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
+
+from sfa.storage.parameter import Parameter, Mixed
 from sfa.trust.credential import Credential
 
 class CreateGid(Method):
index 218986e..fb1a292 100644 (file)
@@ -1,9 +1,12 @@
 from sfa.util.faults import SfaInvalidArgument
 from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
 from sfa.util.sfatablesRuntime import run_sfatables
+
 from sfa.trust.credential import Credential
+
+from sfa.storage.parameter import Parameter, Mixed
+
 from sfa.rspecs.rspec import RSpec
 
 class CreateSliver(Method):
index fe07b6a..6be2bc4 100644 (file)
@@ -1,6 +1,6 @@
 from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
+from sfa.storage.parameter import Parameter, Mixed
 from sfa.trust.auth import Auth
 from sfa.trust.credential import Credential
 
index d966dd3..50525c2 100644 (file)
@@ -1,8 +1,10 @@
 from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
+
 from sfa.trust.credential import Credential
 
+from sfa.storage.parameter import Parameter, Mixed
+
 class GetCredential(Method):
     """
     Retrive a credential for an object
index 5c1470b..f67f5d4 100644 (file)
@@ -1,8 +1,10 @@
 from sfa.util.faults import RecordNotFound
 from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
+
 from sfa.trust.credential import Credential
 
+from sfa.storage.parameter import Parameter, Mixed
+
 class GetGids(Method):
     """
     Get a list of record information (hrn, gid and type) for 
index efad180..fd87ca0 100644 (file)
@@ -2,10 +2,12 @@
 from sfa.util.faults import RecordNotFound, ConnectionKeyGIDMismatch
 from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
-from sfa.util.record import SfaRecord
+
 from sfa.trust.certificate import Certificate
 
+from sfa.storage.parameter import Parameter, Mixed
+from sfa.storage.record import SfaRecord
+
 class GetSelfCredential(Method):
     """
     Retrive a credential for an object
index b1d8f87..2223e37 100644 (file)
@@ -1,10 +1,11 @@
 from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
 from sfa.util.sfatablesRuntime import run_sfatables
 
 from sfa.trust.credential import Credential
 
+from sfa.storage.parameter import Parameter, Mixed
+
 class GetTicket(Method):
     """
     Retrieve a ticket. This operation is currently implemented on PLC
index 801b339..9dc586f 100644 (file)
@@ -1,5 +1,6 @@
 from sfa.util.method import Method
-from sfa.util.parameter import Parameter
+
+from sfa.storage.parameter import Parameter
 
 
 class GetVersion(Method):
index 55dd7dd..bbd3e47 100644 (file)
@@ -1,10 +1,12 @@
 
 from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
-from sfa.util.record import SfaRecord
+
 from sfa.trust.credential import Credential
 
+from sfa.storage.parameter import Parameter, Mixed
+from sfa.storage.record import SfaRecord
+
 class List(Method):
     """
     List the records in an authority. 
index 6b1e785..65fd819 100644 (file)
@@ -2,10 +2,12 @@ import zlib
 
 from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
-from sfa.trust.credential import Credential
 from sfa.util.sfatablesRuntime import run_sfatables
 
+from sfa.trust.credential import Credential
+
+from sfa.storage.parameter import Parameter, Mixed
+
 class ListResources(Method):
     """
     Returns information about available resources or resources allocated to this slice
index eed408f..e14c9b6 100644 (file)
@@ -1,7 +1,9 @@
 from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
+
 from sfa.trust.credential import Credential
  
+from sfa.storage.parameter import Parameter, Mixed
+
 class ListSlices(Method):
     """
     List the slices instantiated at this interface       
index c6a75e2..522ff12 100644 (file)
@@ -1,5 +1,6 @@
 from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
+
+from sfa.storage.parameter import Parameter, Mixed
 
 class RedeemTicket(Method):
     """
index 2d9cbfd..87f9a0f 100644 (file)
@@ -1,7 +1,9 @@
 from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
+
 from sfa.trust.credential import Credential
 
+from sfa.storage.parameter import Parameter, Mixed
+
 class Register(Method):
     """
     Register an object with the registry. In addition to being stored in the
index 1804fd9..ee650f1 100644 (file)
@@ -1,8 +1,10 @@
 from sfa.util.xrn import Xrn
 from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
+
 from sfa.trust.credential import Credential
 
+from sfa.storage.parameter import Parameter, Mixed
+
 class Remove(Method):
     """
     Remove an object from the registry. If the object represents a PLC object,
index 48d6493..a380d99 100644 (file)
@@ -3,10 +3,12 @@ import datetime
 from sfa.util.faults import InsufficientRights
 from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
-from sfa.util.parameter import Parameter
-from sfa.trust.credential import Credential
 from sfa.util.sfatime import utcparse
 
+from sfa.trust.credential import Credential
+
+from sfa.storage.parameter import Parameter
+
 class RenewSliver(Method):
     """
     Renews the resources in a sliver, extending the lifetime of the slice.    
index 094500f..9a6dd47 100644 (file)
@@ -2,9 +2,11 @@ import types
 
 from sfa.util.xrn import Xrn, urn_to_hrn
 from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
+
 from sfa.trust.credential import Credential
-from sfa.util.record import SfaRecord
+
+from sfa.storage.parameter import Parameter, Mixed
+from sfa.storage.record import SfaRecord
 
 class Resolve(Method):
     """
index 7c9cc14..e32bf6d 100644 (file)
@@ -1,5 +1,6 @@
 from sfa.util.method import Method
-from sfa.util.parameter import Parameter
+
+from sfa.storage.parameter import Parameter
 
 class ResolveGENI(Method):
     """
index 9788608..273b991 100644 (file)
@@ -1,4 +1,5 @@
-from sfa.util.parameter import Parameter
+from sfa.storage.parameter import Parameter
+
 from sfa.methods.Stop import Stop
 
 class Shutdown(Stop):
index 2a0ac5d..f722c7c 100644 (file)
@@ -1,6 +1,7 @@
 from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
+
+from sfa.storage.parameter import Parameter, Mixed
 
 class SliverStatus(Method):
     """
index 7f8aefd..1412222 100644 (file)
@@ -1,8 +1,10 @@
 from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
+
 from sfa.trust.credential import Credential
 
+from sfa.storage.parameter import Parameter, Mixed
+
 class Start(Method):
     """
     Start the specified slice      
index 48974ab..0d80282 100644 (file)
@@ -1,8 +1,10 @@
 from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
+
 from sfa.trust.credential import Credential
  
+from sfa.storage.parameter import Parameter, Mixed
+
 class Stop(Method):
     """
     Stop the specified slice      
index 7643302..e0b1003 100644 (file)
@@ -1,7 +1,9 @@
 from sfa.util.method import Method
-from sfa.util.parameter import Parameter
+
 from sfa.trust.credential import Credential
 
+from sfa.storage.parameter import Parameter
+
 class Update(Method):
     """
     Update an object in the registry. Currently, this only updates the
index 245b207..3302b56 100644 (file)
@@ -1,4 +1,5 @@
-from sfa.util.parameter import Parameter, Mixed
+from sfa.storage.parameter import Parameter, Mixed
+
 from sfa.methods.CreateSliver import CreateSliver
 
 class UpdateSliver(CreateSliver):
index c7abb75..5887f99 100644 (file)
@@ -1,7 +1,8 @@
 from sfa.util.method import Method
-from sfa.util.parameter import Parameter
 from sfa.util.sfalogging import logger
 
+from sfa.storage.parameter import Parameter
+
 class get_key_from_incoming_ip(Method):
     """
     Generate a new keypair and gid for requesting caller (component/node).     
index 460ab4d..7a4e1c5 100644 (file)
@@ -1,9 +1,9 @@
-#from sfa.util.faults import *
 from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
+
 from sfa.trust.auth import Auth
 from sfa.trust.credential import Credential
 
+from sfa.storage.parameter import Parameter, Mixed
 
 class get_trusted_certs(Method):
     """
index 387981d..c3975ff 100644 (file)
@@ -1,6 +1,7 @@
 from sfa.util.xrn import urn_to_hrn
 from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
+
+from sfa.storage.parameter import Parameter, Mixed
 
 class reset_slice(Method):
     """
index 834661b..d5d5bf9 100644 (file)
@@ -1,12 +1,13 @@
 #
 from sfa.util.faults import MissingSfaInfo, UnknownSfaType
 from sfa.util.sfalogging import logger
-from sfa.util.table import SfaTable
 from sfa.util.defaultdict import defaultdict
-
 from sfa.util.xrn import hrn_to_urn, get_leaf
 from sfa.util.plxrn import slicename_to_hrn, hostname_to_hrn, hrn_to_pl_slicename, hrn_to_pl_login_base
 
+# one would think the driver should not need to mess with the SFA db, but..
+from sfa.storage.table import SfaTable
+
 # the driver interface, mostly provides default behaviours
 from sfa.managers.driver import Driver
 
@@ -35,24 +36,17 @@ class PlDriver (Driver, PlShell):
         PlShell.__init__ (self, config)
  
         self.hrn = config.SFA_INTERFACE_HRN
-        # xxx thgen fixme - use SfaTable hardwired for now 
-        # will need to extend generic to support multiple storage systems
-        #self.SfaTable = SfaTable
-        # Initialize the PLC shell only if SFA wraps a myPLC
-        rspec_type = config.get_aggregate_type()
-        assert (rspec_type == 'pl' or rspec_type == 'vini' or \
-                    rspec_type == 'eucalyptus' or rspec_type == 'max')
 
     ########## disabled users 
     def is_enabled (self, record):
-        self.fill_record_info(record, deep=False)
+        # the incoming record was augmented already, so 'enabled' should be set
         if record['type'] == 'user':
             return record['enabled']
         # only users can be disabled
         return True
 
     def augment_records_with_testbed_info (self, sfa_records):
-        return self.fill_record_info (sfa_records, deep=True)
+        return self.fill_record_info (sfa_records)
 
     ########## 
     def register (self, sfa_record, hrn, pub_key):
@@ -236,7 +230,7 @@ class PlDriver (Driver, PlShell):
         return pl_record
 
     ####################
-    def fill_record_info(self, records, deep=False):
+    def fill_record_info(self, records):
         """
         Given a (list of) SFA record, fill in the PLC specific 
         and SFA specific fields in the record. 
@@ -245,9 +239,8 @@ class PlDriver (Driver, PlShell):
             records = [records]
 
         self.fill_record_pl_info(records)
-        if deep:
-            self.fill_record_hrns(records)
-            self.fill_record_sfa_info(records)
+        self.fill_record_hrns(records)
+        self.fill_record_sfa_info(records)
         return records
 
     def fill_record_pl_info(self, records):
@@ -426,8 +419,6 @@ class PlDriver (Driver, PlShell):
         # we obtain
         
         # get the sfa records
-        # xxx thgen fixme - use SfaTable hardwired for now 
-        # table = self.SfaTable()
         table = SfaTable()
         person_list, persons = [], {}
         person_list = table.find({'type': 'user', 'pointer': person_ids})
@@ -502,7 +493,7 @@ class PlDriver (Driver, PlShell):
     ####################
     # plcapi works by changes, compute what needs to be added/deleted
     def update_relation (self, subject_type, target_type, subject_id, target_ids):
-        # hard-wire the code for slice/user for now
+        # hard-wire the code for slice/user for now, could be smarter if needed
         if subject_type =='slice' and target_type == 'user':
             subject=self.GetSlices (subject_id)[0]
             current_target_ids = subject['person_ids']
index 27eba93..caf2d23 100644 (file)
@@ -1,5 +1,5 @@
 import os
-from sfa.util.faults import InvalidRSpec
+from sfa.util.faults import InvalidRSpec, InvalidRSpecVersion
 from sfa.rspecs.baseversion import BaseVersion 
 from sfa.util.sfalogging import logger    
 
@@ -31,12 +31,12 @@ class VersionManager:
         retval = None
         for version in self.versions:
             if type is None or type.lower() == version.type.lower():
-                if version_num is None or version_num == version.version:
+                if version_num is None or str(version_num) == version.version:
                     if content_type is None or content_type.lower() == version.content_type.lower() \
                       or version.content_type == '*':
                         retval = version
         if not retval:
-            raise InvalidRSpec("No such version format: %s version: %s type:%s "% (type, version_num, content_type))
+            raise InvalidRSpecVersion("No such version format: %s version: %s type:%s "% (type, version_num, content_type))
         return retval
 
     def get_version(self, version=None):
index 0fbe140..b87e119 100755 (executable)
@@ -23,11 +23,12 @@ import sys
 from optparse import OptionParser
 
 from sfa.util.config import Config
-from sfa.util.table import SfaTable
 
 from sfa.trust.gid import GID, create_uuid
 from sfa.trust.hierarchy import Hierarchy
 
+from sfa.storage.table import SfaTable
+
 def main():
     args = sys.argv
     script_name = args[0]
index 0d99e98..62acb4b 100644 (file)
@@ -5,17 +5,19 @@ import os
 import traceback
 import socket
 
-import sfa.client.xmlrpcprotocol as xmlrpcprotocol 
-from sfa.util.table import SfaTable
 from sfa.util.prefixTree import prefixTree
 from sfa.util.config import Config
 
-from sfa.generic import Generic
-
 from sfa.trust.certificate import Keypair
 from sfa.trust.hierarchy import Hierarchy
 from sfa.server.registry import Registries
 
+from sfa.storage.table import SfaTable
+
+import sfa.client.xmlrpcprotocol as xmlrpcprotocol 
+
+from sfa.generic import Generic
+
 def main():
     config = Config()
     if not config.SFA_REGISTRY_ENABLED:
index dbd5e4f..6c05060 100755 (executable)
@@ -136,8 +136,8 @@ def update_cert_records(gids):
     Removes old records from the db.
     """
     # import SfaTable here so this module can be loaded by PlcComponentApi
-    from sfa.util.table import SfaTable
-    from sfa.util.record import SfaRecord
+    from sfa.storage.table import SfaTable
+    from sfa.storage.record import SfaRecord
     if not gids:
         return
     table = SfaTable()
index 9afe9b4..79a5540 100644 (file)
@@ -2,18 +2,21 @@ import os, os.path
 import datetime
 
 from sfa.util.faults import SfaFault, SfaAPIError
+from sfa.util.genicode import GENICODE
 from sfa.util.config import Config
 from sfa.util.cache import Cache
 from sfa.trust.auth import Auth
+
 from sfa.trust.certificate import Keypair, Certificate
 from sfa.trust.credential import Credential
 from sfa.trust.rights import determine_rights
+
 from sfa.server.xmlrpcapi import XmlrpcApi
-from sfa.util.genicode import GENICODE
+
 from sfa.client.return_value import ReturnValue
 
 # thgen xxx fixme this is wrong all right, but temporary, will use generic
-from sfa.util.table import SfaTable
+from sfa.storage.table import SfaTable
 
 ####################
 class SfaApi (XmlrpcApi): 
diff --git a/sfa/storage/__init__.py b/sfa/storage/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
similarity index 98%
rename from sfa/util/filter.py
rename to sfa/storage/filter.py
index 8f037ca..afe425d 100644 (file)
@@ -1,16 +1,9 @@
 from types import StringTypes
-try:
-    set
-except NameError:
-    from sets import Set
-    set = Set
-
-try: import pgdb
-except: pass
+import pgdb
  
 from sfa.util.faults import SfaInvalidArgument
-from sfa.util.parameter import Parameter, Mixed, python_type
 
+from sfa.storage.parameter import Parameter, Mixed, python_type
 
 class Filter(Parameter, dict):
     """
similarity index 99%
rename from sfa/util/record.py
rename to sfa/storage/record.py
index 7ebf379..46c6699 100644 (file)
@@ -8,9 +8,9 @@ from types import StringTypes
 
 from sfa.trust.gid import GID
 
-from sfa.util.parameter import Parameter
+from sfa.storage.parameter import Parameter
 from sfa.util.xrn import get_authority
-from sfa.util.row import Row
+from sfa.storage.row import Row
 from sfa.util.xml import XML 
 
 class SfaRecord(Row):
similarity index 100%
rename from sfa/util/row.py
rename to sfa/storage/row.py
diff --git a/sfa/storage/sfa.sql b/sfa/storage/sfa.sql
new file mode 100644 (file)
index 0000000..3d7984d
--- /dev/null
@@ -0,0 +1,55 @@
+--
+-- SFA database schema
+--
+
+SET client_encoding = 'UNICODE';
+
+--------------------------------------------------------------------------------
+-- Version
+--------------------------------------------------------------------------------
+
+-- Database version
+CREATE TABLE sfa_db_version (
+    version integer NOT NULL,
+    subversion integer NOT NULL DEFAULT 0
+) WITH OIDS;
+
+-- the migration scripts do not use the major 'version' number
+-- so 5.0 sets subversion at 100
+-- in case your database misses the site and persons tags feature, 
+-- you might wish to first upgrade to 4.3-rc16 before moving to some 5.0
+-- or run the up script here
+-- http://svn.planet-lab.org/svn/PLCAPI/branches/4.3/migrations/
+
+INSERT INTO sfa_db_version (version, subversion) VALUES (1, 1);
+
+--------------------------------------------------------------------------------
+-- Aggregates and store procedures
+--------------------------------------------------------------------------------
+
+-- Like MySQL GROUP_CONCAT(), this function aggregates values into a
+-- PostgreSQL array.
+CREATE AGGREGATE array_accum (
+    sfunc = array_append,
+    basetype = anyelement,
+    stype = anyarray,
+    initcond = '{}'
+);
+
+-- main table 
+CREATE TABLE sfa ( 
+    record_id serial PRIMARY KEY , 
+    hrn text NOT NULL, 
+    authority text NOT NULL, 
+    peer_authority text, 
+    gid text, 
+    type text NOT NULL, 
+    pointer integer, 
+    date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, 
+    last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
+);
+CREATE INDEX sfa_hrn_ids on sfa (hrn);
+CREATE INDEX sfa_type_ids on sfa (type);
+CREATE INDEX sfa_authority_ids on sfa (authority);
+CREATE INDEX sfa_peer_authority_ids on sfa (peer_authority);
+CREATE INDEX sfa_pointer_ids on sfa (pointer);
similarity index 81%
rename from sfa/util/table.py
rename to sfa/storage/table.py
index 065e8ab..3e47f3e 100644 (file)
@@ -6,10 +6,11 @@
 from types import StringTypes
 
 from sfa.util.config import Config
-from sfa.util.parameter import Parameter
-from sfa.util.filter import Filter
-from sfa.util.PostgreSQL import PostgreSQL
-from sfa.util.record import SfaRecord, AuthorityRecord, NodeRecord, SliceRecord, UserRecord
+
+from sfa.storage.parameter import Parameter
+from sfa.storage.filter import Filter
+from sfa.storage.PostgreSQL import PostgreSQL
+from sfa.storage.record import SfaRecord, AuthorityRecord, NodeRecord, SliceRecord, UserRecord
 
 class SfaTable(list):
 
@@ -34,6 +35,7 @@ class SfaTable(list):
         if tables:
             return True
         return False
+
     def db_fields(self, obj=None):
         
         db_fields = self.db.fields(self.SFA_TABLE_PREFIX)
@@ -54,34 +56,34 @@ class SfaTable(list):
 
 
     def create(self):
-        
-        querystr = "CREATE TABLE " + self.tablename + " ( \
-                record_id serial PRIMARY KEY , \
-                hrn text NOT NULL, \
-                authority text NOT NULL, \
-                peer_authority text, \
-                gid text, \
-                type text NOT NULL, \
-                pointer integer, \
-                date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, \
-                last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP);"
-        template = "CREATE INDEX %s_%s_idx ON %s (%s);"
-        indexes = [template % ( self.tablename, field, self.tablename, field) \
-                   for field in ['hrn', 'type', 'authority', 'peer_authority', 'pointer']]
-        # IF EXISTS doenst exist in postgres < 8.2
-        try:
-            self.db.do('DROP TABLE IF EXISTS ' + self.tablename)
-        except:
-            try:
-                self.db.do('DROP TABLE' + self.tablename)
-            except:
-                pass
-         
-        self.db.do(querystr)
-        for index in indexes:
-            self.db.do(index)
-        
-        self.db.commit()
+        pass
+#        querystr = "CREATE TABLE " + self.tablename + " ( \
+#                record_id serial PRIMARY KEY , \
+#                hrn text NOT NULL, \
+#                authority text NOT NULL, \
+#                peer_authority text, \
+#                gid text, \
+#                type text NOT NULL, \
+#                pointer integer, \
+#                date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, \
+#                last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP);"
+#        template = "CREATE INDEX %s_%s_idx ON %s (%s);"
+#        indexes = [template % ( self.tablename, field, self.tablename, field) \
+#                   for field in ['hrn', 'type', 'authority', 'peer_authority', 'pointer']]
+#        # IF EXISTS doenst exist in postgres < 8.2
+#        try:
+#            self.db.do('DROP TABLE IF EXISTS ' + self.tablename)
+#        except:
+#            try:
+#                self.db.do('DROP TABLE' + self.tablename)
+#            except:
+#                pass
+#         
+#        self.db.do(querystr)
+#        for index in indexes:
+#            self.db.do(index)
+#        
+#        self.db.commit()
     
     def remove(self, record):
         params = {'record_id': record['record_id']}
index 2261dda..f114a2d 100644 (file)
@@ -76,12 +76,6 @@ class Config:
 
         return (aggr_mgr_ip,aggr_mgr_port)
 
-    def get_aggregate_type(self):
-        if (hasattr(self,'SFA_AGGREGATE_TYPE')):
-            return self.SFA_AGGREGATE_TYPE
-        else:
-            return "pl"
-
     def get_interface_hrn(self):
         if (hasattr(self,'SFA_INTERFACE_HRN')):
             return self.SFA_INTERFACE_HRN
index 4a1a5e4..267932e 100644 (file)
@@ -255,6 +255,14 @@ class InvalidRSpec(SfaFault):
     def __str__(self):
         return repr(self.value)
 
+class InvalidRSpecVersion(SfaFault):
+    def __init__(self, value, extra = None):
+        self.value = value
+        faultString = "Invalid RSpec version: %(value)s" % locals()
+        SfaFault.__init__(self, GENICODE.BADVERSION, faultString, extra)
+    def __str__(self):
+        return repr(self.value)
+
 class InvalidRSpecElement(SfaFault):
     def __init__(self, value, extra = None):
         self.value = value
index 97ddb39..4bfeb9b 100644 (file)
@@ -7,10 +7,10 @@ import time
 from types import IntType, LongType, StringTypes
 import textwrap
 
-
 from sfa.util.sfalogging import logger
 from sfa.util.faults import SfaFault, SfaInvalidAPIMethod, SfaInvalidArgumentCount, SfaInvalidArgument
-from sfa.util.parameter import Parameter, Mixed, python_type, xmlrpc_type
+
+from sfa.storage.parameter import Parameter, Mixed, python_type, xmlrpc_type
 
 class Method:
     """
index 0eff8e8..329d84e 100755 (executable)
@@ -2,7 +2,7 @@ import unittest
 import xmlrpclib
 from sfa.trust.gid import *
 from sfa.util.config import *
-from sfa.util.record import *
+from sfa.storage.record import *
 
 class TestRecord(unittest.TestCase):
     def setUp(self):
index de44628..e794e89 100755 (executable)
@@ -16,7 +16,7 @@ import inspect
 from types import *
 from optparse import OptionParser
 
-from sfa.util.parameter import Parameter,Mixed
+from sfa.storage.parameter import Parameter,Mixed
 
 import globals