##########
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:
+$(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
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>
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>
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>
# 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"
# 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"
## 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
# 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"
--- /dev/null
+As of nov 2011 this is not packaged, use as a template for your installation
# 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
# (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)
# 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
# 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
package_dirs = [
'sfa',
'sfa/trust',
+ 'sfa/storage',
'sfa/util',
'sfa/client',
'sfa/server',
]),
('/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)]
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}
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
%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
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):
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():
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)
##
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):
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
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
# 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']))
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
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):
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
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):
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):
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
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
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
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
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
from sfa.util.method import Method
-from sfa.util.parameter import Parameter
+
+from sfa.storage.parameter import Parameter
class GetVersion(Method):
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.
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
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
from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
+
+from sfa.storage.parameter import Parameter, Mixed
class RedeemTicket(Method):
"""
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
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,
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.
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):
"""
from sfa.util.method import Method
-from sfa.util.parameter import Parameter
+
+from sfa.storage.parameter import Parameter
class ResolveGENI(Method):
"""
-from sfa.util.parameter import Parameter
+from sfa.storage.parameter import Parameter
+
from sfa.methods.Stop import Stop
class Shutdown(Stop):
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):
"""
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
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
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
-from sfa.util.parameter import Parameter, Mixed
+from sfa.storage.parameter import Parameter, Mixed
+
from sfa.methods.CreateSliver import CreateSliver
class UpdateSliver(CreateSliver):
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).
-#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):
"""
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):
"""
#
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
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):
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.
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):
# 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})
####################
# 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']
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
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):
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]
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:
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()
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):
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):
"""
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):
--- /dev/null
+--
+-- 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);
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):
if tables:
return True
return False
+
def db_fields(self, obj=None):
db_fields = self.db.fields(self.SFA_TABLE_PREFIX)
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']}
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
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
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:
"""
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):
from types import *
from optparse import OptionParser
-from sfa.util.parameter import Parameter,Mixed
+from sfa.storage.parameter import Parameter,Mixed
import globals