Merge branch 'master' into senslab2
authorNicolas Turro <Nicolas.Turro@inria.fr>
Fri, 18 Nov 2011 16:38:34 +0000 (17:38 +0100)
committerNicolas Turro <Nicolas.Turro@inria.fr>
Fri, 18 Nov 2011 16:38:34 +0000 (17:38 +0100)
Conflicts:
sfa/util/xml.py

76 files changed:
Makefile
docs/sfa-debian-installfromscratch.txt [deleted file]
sfa.spec
sfa/client/sfiAddAttribute.py
sfa/client/sfiAddLinks.py
sfa/client/sfiAddSliver.py
sfa/client/sfiDeleteAttribute.py
sfa/client/sfiDeleteSliver.py
sfa/client/sfiListNodes.py
sfa/client/sfiListSlivers.py
sfa/generic/__init__.py
sfa/generic/pl.py
sfa/managers/aggregate_manager.py
sfa/managers/component_manager_pl.py
sfa/managers/managerwrapper.py
sfa/managers/registry_manager.py
sfa/managers/slice_manager.py
sfa/methods/CreateGid.py
sfa/methods/GetCredential.py
sfa/methods/GetGids.py
sfa/methods/GetSelfCredential.py
sfa/methods/GetTicket.py
sfa/methods/List.py
sfa/methods/Register.py
sfa/methods/RegisterPeerObject.py [deleted file]
sfa/methods/Remove.py
sfa/methods/RemovePeerObject.py [deleted file]
sfa/methods/Resolve.py
sfa/methods/ResolveGENI.py
sfa/methods/Update.py
sfa/methods/__init__.py
sfa/methods/get_aggregates.py [deleted file]
sfa/methods/get_key.py
sfa/methods/get_registries.py [deleted file]
sfa/methods/register_peer_object.py [deleted file]
sfa/methods/remove_peer_object.py [deleted file]
sfa/plc/aggregate.py
sfa/plc/network.py [deleted file]
sfa/plc/plshell.py
sfa/rspecs/baseversion.py [moved from sfa/rspecs/rspec_version.py with 100% similarity]
sfa/rspecs/elements/bwlimit.py
sfa/rspecs/elements/component_manager.py [deleted file]
sfa/rspecs/elements/element.py
sfa/rspecs/elements/execute.py
sfa/rspecs/elements/hardware_type.py
sfa/rspecs/elements/install.py
sfa/rspecs/elements/interface.py
sfa/rspecs/elements/link.py
sfa/rspecs/elements/link_type.py [deleted file]
sfa/rspecs/elements/location.py
sfa/rspecs/elements/login.py
sfa/rspecs/elements/network.py [deleted file]
sfa/rspecs/elements/node.py
sfa/rspecs/elements/pltag.py
sfa/rspecs/elements/property.py
sfa/rspecs/elements/services.py
sfa/rspecs/elements/sliver.py
sfa/rspecs/elements/tag.py [deleted file]
sfa/rspecs/elements/versions/element_version.py [deleted file]
sfa/rspecs/elements/versions/pgv2Link.py
sfa/rspecs/elements/versions/pgv2Node.py
sfa/rspecs/elements/versions/pgv2Services.py
sfa/rspecs/elements/versions/pgv2SliverType.py
sfa/rspecs/elements/versions/sfav1Network.py [deleted file]
sfa/rspecs/elements/versions/sfav1Node.py
sfa/rspecs/elements/versions/sfav1PLTag.py [new file with mode: 0644]
sfa/rspecs/elements/versions/sfav1Sliver.py
sfa/rspecs/version_manager.py
sfa/rspecs/versions/pgv2.py
sfa/rspecs/versions/sfav1.py
sfa/server/sfa_component_setup.py
sfa/server/xmlrpcapi.py
sfa/util/sfatime.py
sfa/util/topology.py
sfa/util/xml.py [changed mode: 0644->0755]
tests/testInterfaces.py

index 72fa41a..701c329 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -146,5 +146,10 @@ else
        $(SSHCOMMAND) exec service sfa restart
 endif
 
+# 99% of the time this is enough
+fastsync:
+       +$(RSYNC) ./sfa/ $(SSHURL)/usr/lib\*/python2.\*/site-packages/sfa/
+       $(SSHCOMMAND) exec service sfa restart
+
 .PHONY: sync
 ##########
diff --git a/docs/sfa-debian-installfromscratch.txt b/docs/sfa-debian-installfromscratch.txt
deleted file mode 100644 (file)
index 2dd2e91..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-Install on debian without prior myplc install
-
-apt-get install python-openssl python-m2crypto python-dateutil python-lxml  python-libxml2 python-libxslt1 python-pygresql python-psycopg2 python-zsi 
-easy_install xmlbuilder   
-apt-get install xmlsec1 libxmlsec1-dev (not sure about latter)
-/etc/postgresql/8.4/main/pg_hba.conf
-
-
-planetlab-europe-01:/etc/sfa/configs# su postgres
-postgres@planetlab-europe-01:/etc/sfa/configs$ psql -d template1
-template1=# create user pgsqluser password 'XXX';
-ou ALTER USER pgsqluser WITH PASSWORD 'XXX';
-template1=# create database planetlab5;
-template1=# grant all on database planetlab5 to pgsqluser;
-
-scp root@dev.top-hat.info:/etc/init.d/functions: /etc/init.d
-planetlab-europe-01:~/jordan/sfa# scp root@dev.top-hat.info:/usr/bin/plc-config* /usr/bin
-plc-config
-plc-config-tty
-
-scp root@dev.top-hat.info:/sbin/consoletype /sbin
-
-scp root@dev.top-hat.info:/usr/lib/python2.5/site-packages/plc_config.py /usr/lib/python2.5/site-packages/
-ou
-scp root@dev.top-hat.info:/usr/lib/python2.5/site-packages/plc_config.py /usr/lib/python2.6/
-
-mkdir /var/lock/subsys
-
-mkdir /etc/planetlab
-scp root@dev.top-hat.info:/etc/planetlab/plc_config /etc/planetlab
-
-harcoded in /etc/init.d/sfa
-planetlab-europe-01:~# ln -s /usr/local/bin/sfa-server.py /usr/bin
-planetlab-europe-01:~# ln -s /usr/local/bin/gen-sfa-cm-config.py /usr/bin
-planetlab-europe-01:~# ln -s /usr/local/bin/sfa_flashpolicy.py /usr/bin
-
-* when starting sfa without the import...
-IOError: [Errno 2] No such file or directory: '/var/lib/sfa/authorities/server.key'
-2011-06-03 20:12:21,086 - CRITICAL - SFA server is exiting END TRACEBACK
-
-THINK OF NAMING RESOURCES FOR NEW TESTBED
-
-packages installed in ./local/lib/python2.6/dist-packages/sfa/
-
-mkdir /var/log/httpd for crashlog
-ln -s /usr/local/bin/keyconvert.py /usr/bin
-
-ISSUES RESOLVED
-
-planetlab-europe-01:~/jordan/sfa# sfa-config-tty 
-Traceback (most recent call last):
- File "/usr/local/bin/sfa-config-tty", line 5, in 
-   import plc_config
-ImportError: No module named plc_config
-
-util/server.py has a dependency on plc !!!!!!!!
-
-util/api.py +146
-      self.logger=sfa_logger() # XXX jordan missing ()
-
-baseAPI
-    fill_record_info
-
-getDelegatedCredential
-
-
-
---------------------------------------------------------------------------------
-
-
-planetlab-europe-01:/etc/sfa# /etc/init.d/sfa restart
-/etc/init.d/sfa: line 17: /etc/init.d/functions: No such file or directory
-/etc/init.d/sfa: line 88: action: command not found
-/etc/init.d/sfa: line 34: plc-config: command not found
-SFA: Warning: Invalid configuration file(s) detected
-Traceback (most recent call last):
- File "/usr/local/bin/gen-sfa-cm-config.py", line 9, in 
-   sfa_config = SfaConfig()
- File "/usr/local/lib/python2.6/dist-packages/sfa/util/config.py", line 33, in __init__
-   self.load(config_file)
- File "/usr/local/lib/python2.6/dist-packages/sfa/util/config.py", line 79, in load
-   raise IOError, "Could not find the configuration file: %s" % config_file
-IOError: Could not find the configuration file: /etc/sfa/sfa_config.py
-touch: cannot touch `/var/lock/subsys/sfa-server.py': No such file or directory
index 55b6ec3..1fad71d 100644 (file)
--- a/sfa.spec
+++ b/sfa.spec
@@ -1,6 +1,6 @@
 %define name sfa
 %define version 1.1
-%define taglevel 2
+%define taglevel 4
 
 %define release %{taglevel}%{?pldistro:.%{pldistro}}%{?date:.%{date}}
 %global python_sitearch        %( python -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)" )
@@ -197,6 +197,14 @@ fi
 [ "$1" -ge "1" ] && service sfa-cm restart || :
 
 %changelog
+* Fri Nov 18 2011 Thierry Parmentelat <thierry.parmentelat@sophia.inria.fr> - sfa-1.1-4
+- fixed links and attributes in rspecs
+- minor cleanup in the API methods, and more consistent names in manager methods
+
+* Thu Nov 17 2011 Thierry Parmentelat <thierry.parmentelat@sophia.inria.fr> - sfa-1.1-3
+- ongoing refoactoring towards more genericity
+- passes tests again although known issues remain with attributes/tags
+
 * Mon Nov 07 2011 Thierry Parmentelat <thierry.parmentelat@sophia.inria.fr> - sfa-1.1-2
 - checkpoint tag: use SFA_GENERIC_FLAVOUR instead of SFA_*_TYPE
 - improvements in the pgv2 rspecs
index f22e63e..6fa51b4 100755 (executable)
@@ -1,9 +1,12 @@
 #! /usr/bin/env python
 
 import sys
+
+from sfa.util.sfalogging import logger
 from sfa.client.sfi_commands import Commands
 from sfa.rspecs.rspec import RSpec
 
+logger.enable_console()
 command = Commands(usage="%prog [options] [node1 node2...]",
                    description="Add sliver attributes to the RSpec. " +
                    "This command reads in an RSpec and outputs a modified " +
@@ -33,12 +36,12 @@ if command.opts.infile:
                 try:
                     rspec.version.add_default_sliver_attribute(name, value)
                 except:
-                    print >> sys.stderr, "FAILED: on all nodes: %s=%s" % (name, value)
+                    logger.log_exc("sfiAddAttribute FAILED on all nodes: %s=%s" % (name, value))
             else:
                 for node in nodes:
                     try:
                         rspec.version.add_sliver_attribute(node, name, value)
                     except:
-                        print >> sys.stderr, "FAILED: on node %s: %s=%s" % (node, name, value)
+                        logger.log_exc ("sfiAddAttribute FAILED on node %s: %s=%s" % (node, name, value))
 
     print rspec.toxml()
index f5b2888..2e667b1 100755 (executable)
@@ -1,10 +1,13 @@
 #! /usr/bin/env python
 
 import sys
+
+from sfa.util.sfalogging import logger
 from sfa.client.sfi_commands import Commands
 from sfa.rspecs.rspec import RSpec
 from sfa.rspecs.version_manager import VersionManager
 
+logger.enable_console()
 command = Commands(usage="%prog [options] node1 node2...",
                    description="Add links to the RSpec. " +
                    "This command reads in an RSpec and outputs a modified " +
@@ -38,8 +41,7 @@ try:
     request_rspec.version.merge(ad_rspec)
     request_rspec.version.add_link_requests(link_tuples)
 except:
-    print >> sys.stderr, "FAILED: %s" % links
-    raise
+    logger.log_exc("sfiAddLinks FAILED with links %s" % links)
     sys.exit(1)
 print >>outfile, request_rspec.toxml()
 sys.exit(0)
index c72dee3..84ffa8b 100755 (executable)
@@ -1,10 +1,13 @@
 #! /usr/bin/env python
 
 import sys
+
+from sfa.util.sfalogging import logger
 from sfa.client.sfi_commands import Commands
 from sfa.rspecs.rspec import RSpec
 from sfa.rspecs.version_manager import VersionManager
 
+logger.enable_console()
 command = Commands(usage="%prog [options] node1 node2...",
                    description="Add slivers to the RSpec. " +
                    "This command reads in an RSpec and outputs a modified " +
@@ -33,12 +36,10 @@ try:
     version_num = ad_rspec.version.version
     request_version = version_manager._get_version(type, version_num, 'request')    
     request_rspec = RSpec(version=request_version)
-    slivers = [{'hostname': node} for node in nodes]
     request_rspec.version.merge(ad_rspec)
-    request_rspec.version.add_slivers(slivers)
+    request_rspec.version.add_slivers(nodes)
 except:
-    print >> sys.stderr, "FAILED: %s" % nodes
-    raise
+    logger.log_exc("sfiAddSliver failed with nodes %s" % nodes)
     sys.exit(1)
 print >>outfile, request_rspec.toxml()
 sys.exit(0)
index 53b2542..7e6a5ae 100755 (executable)
@@ -1,9 +1,12 @@
 #! /usr/bin/env python
 
 import sys
+
+from sfa.util.sfalogging import logger
 from sfa.client.sfi_commands import Commands
 from sfa.rspecs.rspec import RSpec
 
+logger.enable_console()
 command = Commands(usage="%prog [options] [node1 node2...]",
                    description="Delete sliver attributes from the RSpec. " +
                    "This command reads in an RSpec and outputs a modified " +
@@ -33,12 +36,12 @@ if command.opts.infile:
                 try:
                     rspec.version.remove_default_sliver_attribute(name, value)
                 except:
-                    print >> sys.stderr, "FAILED: on all nodes: %s=%s" % (name, value)
+                    logger.log_exc("sfiDeleteAttribute FAILED on all nodes: %s=%s" % (name, value))
             else:
                 for node in nodes:
                     try:
                         rspec.version.remove_sliver_attribute(node, name, value)
                     except:
-                        print >> sys.stderr, "FAILED: on node %s: %s=%s" % (node, name, value)
+                        logger.log_exc("sfiDeleteAttribute FAILED on node %s: %s=%s" % (node, name, value))
 
     print rspec.toxml()
index be10f0b..3dc50e6 100755 (executable)
@@ -1,9 +1,12 @@
 #! /usr/bin/env python
 
 import sys
+
+from sfa.util.sfalogging import logger
 from sfa.client.sfi_commands import Commands
 from sfa.rspecs.rspec import RSpec
 
+logger.enable_console()
 command = Commands(usage="%prog [options] node1 node2...",
                    description="Delete slivers from the RSpec. " +
                    "This command reads in an RSpec and outputs a modified " +
@@ -24,7 +27,7 @@ if command.opts.infile:
         rspec.version.remove_slivers(slivers)
         print rspec.toxml()
     except:
-        print >> sys.stderr, "FAILED: %s" % nodes 
+        logger.log_exc("sfiDeleteSliver FAILED with nodes %s" % nodes)
 
     
 
index f9e794b..3de1657 100755 (executable)
@@ -2,7 +2,8 @@
 
 import sys
 from sfa.client.sfi_commands import Commands
-from sfa.rspecs.rspec import RSpec 
+from sfa.rspecs.rspec import RSpec
+from sfa.util.plxrn import xrn_to_hostname 
 
 command = Commands(usage="%prog [options]",
                    description="List all nodes in the RSpec. " + 
@@ -17,7 +18,11 @@ if command.opts.infile:
         sys.stdout = open(command.opts.outfile, 'w')
     
     for node in nodes:
-        print node
+        hostname = None
+        if node.get('component_id'):
+            hostname = xrn_to_hostname(node['component_id'])
+        if hostname:
+            print hostname 
 
 
 
index cf76823..c869f61 100755 (executable)
@@ -3,6 +3,7 @@
 import sys
 from sfa.client.sfi_commands import Commands
 from sfa.rspecs.rspec import RSpec
+from sfa.util.plxrn import xrn_to_hostname
 
 command = Commands(usage="%prog [options]",
                    description="List all slivers in the RSpec. " + 
@@ -23,10 +24,14 @@ if command.opts.infile:
                 print "  %s: %s" % (name, value)        
 
     for node in nodes:
-        print node
-        if command.opts.showatt:
-            atts = rspec.version.get_sliver_attributes(node)
-            for (name, value) in atts:
-                print "  %s: %s" % (name, value)
+        hostname = None
+        if node.get('component_id'):
+            hostname = xrn_to_hostname(node['component_id'])
+        if hostname:
+            print hostname
+            if command.opts.showatt:
+                atts = rspec.version.get_sliver_attributes(hostname)
+                for (name, value) in atts:
+                    print "  %s: %s" % (name, value)
 
     
index ea6ce05..0f9043b 100644 (file)
@@ -83,7 +83,7 @@ class Generic:
         classname = "%s_manager_class"%interface
         try:
             module = getattr(self,classname)()
-            logger.info("%s : %s"%(message,module))
+            logger.debug("%s : %s"%(message,module))
             return module
         except:
             logger.log_exc_critical(message)
@@ -99,7 +99,7 @@ class Generic:
             classname = "driver_class"
         try:
             class_obj = getattr(self,classname)()
-            logger.info("%s : %s"%(message,class_obj))
+            logger.debug("%s : %s"%(message,class_obj))
             return class_obj(config)
         except:
             logger.log_exc_critical(message)
index 098a27a..2c03619 100644 (file)
@@ -14,7 +14,7 @@ class pl (Generic):
 
     # the manager classes for the server-side services
     def registry_manager_class (self) : 
-        return sfa.managers.registry_manager
+        return sfa.managers.registry_manager.RegistryManager
     def slicemgr_manager_class (self) : 
         return sfa.managers.slice_manager.SliceManager
     def aggregate_manager_class (self) :
index 14ec7d0..1b069f7 100644 (file)
@@ -2,6 +2,7 @@ import datetime
 import time
 import sys
 
+from sfa.util.sfalogging import logger
 from sfa.util.faults import RecordNotFound, SliverDoesNotExist
 from sfa.util.xrn import get_authority, hrn_to_urn, urn_to_hrn, Xrn, urn_to_sliver_id
 from sfa.util.plxrn import slicename_to_hrn, hrn_to_pl_slicename
@@ -187,7 +188,7 @@ class AggregateManager:
         slices.verify_slice_attributes(slice, requested_attributes)
         
         # add/remove slice from nodes
-        requested_slivers = [node['component_name'] for node in rspec.version.get_nodes_with_slivers()]
+        requested_slivers = [node.get('component_name') for node in rspec.version.get_nodes_with_slivers()]
         slices.verify_slice_nodes(slice, requested_slivers, peer) 
    
         # add/remove links links 
@@ -322,7 +323,7 @@ class AggregateManager:
         return rspec
     
     
-    def get_ticket(self, api, xrn, creds, rspec, users):
+    def GetTicket(self, api, xrn, creds, rspec, users):
     
         (slice_hrn, _) = urn_to_hrn(xrn)
         slices = Slices(api)
@@ -340,7 +341,7 @@ class AggregateManager:
         for tmp_record in records:
             if tmp_record['type'] == 'slice' and \
                not tmp_record['peer_authority']:
-    #Error (E0602, get_ticket): Undefined variable 'SliceRecord'
+    #Error (E0602, GetTicket): Undefined variable 'SliceRecord'
                 record = SliceRecord(dict=tmp_record)
         if not record:
             raise RecordNotFound(slice_hrn)
index 164b2d6..6992971 100644 (file)
@@ -17,7 +17,7 @@ def init_server():
     except:
         # our keypair may be old, try refreshing
         sfa_component_setup.get_node_key()
-        sfa_component_setup.get_credential(force=True)
+        sfa_component_setup.GetCredential(force=True)
         sfa_component_setup.get_trusted_certs()
 
 def SliverStatus(api, slice_xrn, creds):
index b0326d6..86907e7 100644 (file)
@@ -29,6 +29,6 @@ class ManagerWrapper:
         
     def __getattr__(self, method):
         if not hasattr(self.manager, method):
-            raise SfaNotImplemented(method, self.interface)
+            raise SfaNotImplemented(self.interface, method)
         return getattr(self.manager, method)
         
index 5888b2b..941e4b0 100644 (file)
@@ -15,425 +15,423 @@ from sfa.trust.credential import Credential
 from sfa.trust.certificate import Certificate, Keypair, convert_public_key
 from sfa.trust.gid import create_uuid
 
-# The GENI GetVersion call
-def GetVersion(api):
-    peers =dict ([ (peername,v._ServerProxy__host) for (peername,v) in api.registries.iteritems() 
-                   if peername != api.hrn])
-    xrn=Xrn(api.hrn)
-    return version_core({'interface':'registry',
-                         'hrn':xrn.get_hrn(),
-                         'urn':xrn.get_urn(),
-                         'peers':peers})
-
-def get_credential(api, xrn, type, is_self=False):
-    # convert xrn to hrn     
-    if type:
-        hrn = urn_to_hrn(xrn)[0]
-    else:
-        hrn, type = urn_to_hrn(xrn)
+class RegistryManager:
+
+    def __init__ (self): pass
+
+    # The GENI GetVersion call
+    def GetVersion(self, api):
+        peers = dict ( [ (hrn,interface._ServerProxy__host) for (hrn,interface) in api.registries.iteritems() 
+                       if hrn != api.hrn])
+        xrn=Xrn(api.hrn)
+        return version_core({'interface':'registry',
+                             'hrn':xrn.get_hrn(),
+                             'urn':xrn.get_urn(),
+                             'peers':peers})
+    
+    def GetCredential(self, api, xrn, type, is_self=False):
+        # convert xrn to hrn     
+        if type:
+            hrn = urn_to_hrn(xrn)[0]
+        else:
+            hrn, type = urn_to_hrn(xrn)
+            
+        # Is this a root or sub authority
+        auth_hrn = api.auth.get_authority(hrn)
+        if not auth_hrn or hrn == api.config.SFA_INTERFACE_HRN:
+            auth_hrn = hrn
+        # get record info
+        auth_info = api.auth.get_auth_info(auth_hrn)
+        table = SfaTable()
+        records = table.findObjects({'type': type, 'hrn': hrn})
+        if not records:
+            raise RecordNotFound(hrn)
+        record = records[0]
+    
+        # verify_cancreate_credential requires that the member lists
+        # (researchers, pis, etc) be filled in
+        api.driver.fill_record_info(record, api.aggregates)
+        if record['type']=='user':
+           if not record['enabled']:
+              raise AccountNotEnabled(": PlanetLab account %s is not enabled. Please contact your site PI" %(record['email']))
+    
+        # get the callers gid
+        # if this is a self cred the record's gid is the caller's gid
+        if is_self:
+            caller_hrn = hrn
+            caller_gid = record.get_gid_object()
+        else:
+            caller_gid = api.auth.client_cred.get_gid_caller() 
+            caller_hrn = caller_gid.get_hrn()
         
-    # Is this a root or sub authority
-    auth_hrn = api.auth.get_authority(hrn)
-    if not auth_hrn or hrn == api.config.SFA_INTERFACE_HRN:
-        auth_hrn = hrn
-    # get record info
-    auth_info = api.auth.get_auth_info(auth_hrn)
-    table = SfaTable()
-    records = table.findObjects({'type': type, 'hrn': hrn})
-    if not records:
-        raise RecordNotFound(hrn)
-    record = records[0]
-
-    # verify_cancreate_credential requires that the member lists
-    # (researchers, pis, etc) be filled in
-    api.driver.fill_record_info(record, api.aggregates)
-    if record['type']=='user':
-       if not record['enabled']:
-          raise AccountNotEnabled(": PlanetLab account %s is not enabled. Please contact your site PI" %(record['email']))
-
-    # get the callers gid
-    # if this is a self cred the record's gid is the caller's gid
-    if is_self:
-        caller_hrn = hrn
-        caller_gid = record.get_gid_object()
-    else:
-        caller_gid = api.auth.client_cred.get_gid_caller() 
-        caller_hrn = caller_gid.get_hrn()
-    
-    object_hrn = record.get_gid_object().get_hrn()
-    rights = api.auth.determine_user_rights(caller_hrn, record)
-    # make sure caller has rights to this object
-    if rights.is_empty():
-        raise PermissionError(caller_hrn + " has no rights to " + record['name'])
-
-    object_gid = GID(string=record['gid'])
-    new_cred = Credential(subject = object_gid.get_subject())
-    new_cred.set_gid_caller(caller_gid)
-    new_cred.set_gid_object(object_gid)
-    new_cred.set_issuer_keys(auth_info.get_privkey_filename(), auth_info.get_gid_filename())
-    #new_cred.set_pubkey(object_gid.get_pubkey())
-    new_cred.set_privileges(rights)
-    new_cred.get_privileges().delegate_all_privileges(True)
-    if 'expires' in record:
-        new_cred.set_expiration(int(record['expires']))
-    auth_kind = "authority,ma,sa"
-    # Parent not necessary, verify with certs
-    #new_cred.set_parent(api.auth.hierarchy.get_auth_cred(auth_hrn, kind=auth_kind))
-    new_cred.encode()
-    new_cred.sign()
-
-    return new_cred.save_to_string(save_parents=True)
-
-
-def resolve(api, xrns, type=None, full=True):
-
-    # load all known registry names into a prefix tree and attempt to find
-    # the longest matching prefix
-    if not isinstance(xrns, types.ListType):
-        if not type:
-            type = Xrn(xrns).get_type()
-        xrns = [xrns]
-    hrns = [urn_to_hrn(xrn)[0] for xrn in xrns] 
-    # create a dict where key is a registry hrn and its value is a
-    # hrns at that registry (determined by the known prefix tree).  
-    xrn_dict = {}
-    registries = api.registries
-    tree = prefixTree()
-    registry_hrns = registries.keys()
-    tree.load(registry_hrns)
-    for xrn in xrns:
-        registry_hrn = tree.best_match(urn_to_hrn(xrn)[0])
-        if registry_hrn not in xrn_dict:
-            xrn_dict[registry_hrn] = []
-        xrn_dict[registry_hrn].append(xrn)
+        object_hrn = record.get_gid_object().get_hrn()
+        rights = api.auth.determine_user_rights(caller_hrn, record)
+        # make sure caller has rights to this object
+        if rights.is_empty():
+            raise PermissionError(caller_hrn + " has no rights to " + record['name'])
+    
+        object_gid = GID(string=record['gid'])
+        new_cred = Credential(subject = object_gid.get_subject())
+        new_cred.set_gid_caller(caller_gid)
+        new_cred.set_gid_object(object_gid)
+        new_cred.set_issuer_keys(auth_info.get_privkey_filename(), auth_info.get_gid_filename())
+        #new_cred.set_pubkey(object_gid.get_pubkey())
+        new_cred.set_privileges(rights)
+        new_cred.get_privileges().delegate_all_privileges(True)
+        if 'expires' in record:
+            new_cred.set_expiration(int(record['expires']))
+        auth_kind = "authority,ma,sa"
+        # Parent not necessary, verify with certs
+        #new_cred.set_parent(api.auth.hierarchy.get_auth_cred(auth_hrn, kind=auth_kind))
+        new_cred.encode()
+        new_cred.sign()
+    
+        return new_cred.save_to_string(save_parents=True)
+    
+    
+    def Resolve(self, api, xrns, type=None, full=True):
+    
+        # load all known registry names into a prefix tree and attempt to find
+        # the longest matching prefix
+        if not isinstance(xrns, types.ListType):
+            if not type:
+                type = Xrn(xrns).get_type()
+            xrns = [xrns]
+        hrns = [urn_to_hrn(xrn)[0] for xrn in xrns] 
+        # create a dict where key is a registry hrn and its value is a
+        # hrns at that registry (determined by the known prefix tree).  
+        xrn_dict = {}
+        registries = api.registries
+        tree = prefixTree()
+        registry_hrns = registries.keys()
+        tree.load(registry_hrns)
+        for xrn in xrns:
+            registry_hrn = tree.best_match(urn_to_hrn(xrn)[0])
+            if registry_hrn not in xrn_dict:
+                xrn_dict[registry_hrn] = []
+            xrn_dict[registry_hrn].append(xrn)
+            
+        records = [] 
+        for registry_hrn in xrn_dict:
+            # skip the hrn without a registry hrn
+            # XX should we let the user know the authority is unknown?       
+            if not registry_hrn:
+                continue
+    
+            # if the best match (longest matching hrn) is not the local registry,
+            # forward the request
+            xrns = xrn_dict[registry_hrn]
+            if registry_hrn != api.hrn:
+                credential = api.getCredential()
+                interface = api.registries[registry_hrn]
+                server = api.server_proxy(interface, credential)
+                peer_records = server.Resolve(xrns, credential)
+                records.extend([SfaRecord(dict=record).as_dict() for record in peer_records])
+    
+        # try resolving the remaining unfound records at the local registry
+        remaining_hrns = set(hrns).difference([record['hrn'] for record in records])
+        # convert set to list
+        remaining_hrns = [hrn for hrn in remaining_hrns] 
+        table = SfaTable()
+        local_records = table.findObjects({'hrn': remaining_hrns})
+        if full:
+            api.driver.fill_record_info(local_records, api.aggregates)
         
-    records = [] 
-    for registry_hrn in xrn_dict:
-        # skip the hrn without a registry hrn
-        # XX should we let the user know the authority is unknown?       
+        # convert local record objects to dicts
+        records.extend([dict(record) for record in local_records])
+        if not records:
+            raise RecordNotFound(str(hrns))
+    
+        if type:
+            records = filter(lambda rec: rec['type'] in [type], records)
+    
+        return records
+    
+    def List(self, api, xrn, origin_hrn=None):
+        hrn, type = urn_to_hrn(xrn)
+        # load all know registry names into a prefix tree and attempt to find
+        # the longest matching prefix
+        records = []
+        registries = api.registries
+        registry_hrns = registries.keys()
+        tree = prefixTree()
+        tree.load(registry_hrns)
+        registry_hrn = tree.best_match(hrn)
+       
+        #if there was no match then this record belongs to an unknow registry
         if not registry_hrn:
-            continue
-
+            raise MissingAuthority(xrn)
         # if the best match (longest matching hrn) is not the local registry,
         # forward the request
-        xrns = xrn_dict[registry_hrn]
+        records = []    
         if registry_hrn != api.hrn:
             credential = api.getCredential()
             interface = api.registries[registry_hrn]
             server = api.server_proxy(interface, credential)
-            peer_records = server.Resolve(xrns, credential)
-            records.extend([SfaRecord(dict=record).as_dict() for record in peer_records])
-
-    # try resolving the remaining unfound records at the local registry
-    remaining_hrns = set(hrns).difference([record['hrn'] for record in records])
-    # convert set to list
-    remaining_hrns = [hrn for hrn in remaining_hrns] 
-    table = SfaTable()
-    local_records = table.findObjects({'hrn': remaining_hrns})
-    if full:
-        api.driver.fill_record_info(local_records, api.aggregates)
-    
-    # convert local record objects to dicts
-    records.extend([dict(record) for record in local_records])
-    if not records:
-        raise RecordNotFound(str(hrns))
-
-    if type:
-        records = filter(lambda rec: rec['type'] in [type], records)
-
-    return records
-
-def list(api, xrn, origin_hrn=None):
-    hrn, type = urn_to_hrn(xrn)
-    # load all know registry names into a prefix tree and attempt to find
-    # the longest matching prefix
-    records = []
-    registries = api.registries
-    registry_hrns = registries.keys()
-    tree = prefixTree()
-    tree.load(registry_hrns)
-    registry_hrn = tree.best_match(hrn)
-   
-    #if there was no match then this record belongs to an unknow registry
-    if not registry_hrn:
-        raise MissingAuthority(xrn)
-    # if the best match (longest matching hrn) is not the local registry,
-    # forward the request
-    records = []    
-    if registry_hrn != api.hrn:
-        credential = api.getCredential()
-        interface = api.registries[registry_hrn]
-        server = api.server_proxy(interface, credential)
-        record_list = server.List(xrn, credential)
-        records = [SfaRecord(dict=record).as_dict() for record in record_list]
-    
-    # if we still have not found the record yet, try the local registry
-    if not records:
-        if not api.auth.hierarchy.auth_exists(hrn):
-            raise MissingAuthority(hrn)
-
+            record_list = server.List(xrn, credential)
+            records = [SfaRecord(dict=record).as_dict() for record in record_list]
+        
+        # if we still have not found the record yet, try the local registry
+        if not records:
+            if not api.auth.hierarchy.auth_exists(hrn):
+                raise MissingAuthority(hrn)
+    
+            table = SfaTable()
+            records = table.find({'authority': hrn})
+    
+        return records
+    
+    
+    def CreateGid(self, api, xrn, cert):
+        # get the authority
+        authority = Xrn(xrn=xrn).get_authority_hrn()
+        auth_info = api.auth.get_auth_info(authority)
+        if not cert:
+            pkey = Keypair(create=True)
+        else:
+            certificate = Certificate(string=cert)
+            pkey = certificate.get_pubkey()    
+        gid = api.auth.hierarchy.create_gid(xrn, create_uuid(), pkey) 
+        return gid.save_to_string(save_parents=True)
+        
+    def Register(self, api, record):
+    
+        hrn, type = record['hrn'], record['type']
+        urn = hrn_to_urn(hrn,type)
+        # validate the type
+        if type not in ['authority', 'slice', 'node', 'user']:
+            raise UnknownSfaType(type) 
+        
+        # check if record already exists
         table = SfaTable()
-        records = table.find({'authority': hrn})
-
-    return records
-
-
-def create_gid(api, xrn, cert):
-    # get the authority
-    authority = Xrn(xrn=xrn).get_authority_hrn()
-    auth_info = api.auth.get_auth_info(authority)
-    if not cert:
-        pkey = Keypair(create=True)
-    else:
-        certificate = Certificate(string=cert)
-        pkey = certificate.get_pubkey()    
-    gid = api.auth.hierarchy.create_gid(xrn, create_uuid(), pkey) 
-    return gid.save_to_string(save_parents=True)
-    
-def register(api, record):
-
-    hrn, type = record['hrn'], record['type']
-    urn = hrn_to_urn(hrn,type)
-    # validate the type
-    if type not in ['authority', 'slice', 'node', 'user']:
-        raise UnknownSfaType(type) 
-    
-    # check if record already exists
-    table = SfaTable()
-    existing_records = table.find({'type': type, 'hrn': hrn})
-    if existing_records:
-        raise ExistingRecord(hrn)
-       
-    record = SfaRecord(dict = record)
-    record['authority'] = get_authority(record['hrn'])
-    type = record['type']
-    hrn = record['hrn']
-    auth_info = api.auth.get_auth_info(record['authority'])
-    pub_key = None
-    # make sure record has a gid
-    if 'gid' not in record:
-        uuid = create_uuid()
-        pkey = Keypair(create=True)
-        if 'key' in record and record['key']:
-            if isinstance(record['key'], types.ListType):
-                pub_key = record['key'][0]
+        existing_records = table.find({'type': type, 'hrn': hrn})
+        if existing_records:
+            raise ExistingRecord(hrn)
+           
+        record = SfaRecord(dict = record)
+        record['authority'] = get_authority(record['hrn'])
+        type = record['type']
+        hrn = record['hrn']
+        auth_info = api.auth.get_auth_info(record['authority'])
+        pub_key = None
+        # make sure record has a gid
+        if 'gid' not in record:
+            uuid = create_uuid()
+            pkey = Keypair(create=True)
+            if 'key' in record and record['key']:
+                if isinstance(record['key'], types.ListType):
+                    pub_key = record['key'][0]
+                else:
+                    pub_key = record['key']
+                pkey = convert_public_key(pub_key)
+    
+            gid_object = api.auth.hierarchy.create_gid(urn, uuid, pkey)
+            gid = gid_object.save_to_string(save_parents=True)
+            record['gid'] = gid
+            record.set_gid(gid)
+    
+        if type in ["authority"]:
+            # update the tree
+            if not api.auth.hierarchy.auth_exists(hrn):
+                api.auth.hierarchy.create_auth(hrn_to_urn(hrn,'authority'))
+    
+            # get the GID from the newly created authority
+            gid = auth_info.get_gid_object()
+            record.set_gid(gid.save_to_string(save_parents=True))
+            pl_record = api.driver.sfa_fields_to_pl_fields(type, hrn, record)
+            sites = api.driver.GetSites([pl_record['login_base']])
+            if not sites:
+                pointer = api.driver.AddSite(pl_record)
             else:
-                pub_key = record['key']
-            pkey = convert_public_key(pub_key)
-
-        gid_object = api.auth.hierarchy.create_gid(urn, uuid, pkey)
-        gid = gid_object.save_to_string(save_parents=True)
-        record['gid'] = gid
-        record.set_gid(gid)
-
-    if type in ["authority"]:
-        # update the tree
-        if not api.auth.hierarchy.auth_exists(hrn):
-            api.auth.hierarchy.create_auth(hrn_to_urn(hrn,'authority'))
-
-        # get the GID from the newly created authority
-        gid = auth_info.get_gid_object()
-        record.set_gid(gid.save_to_string(save_parents=True))
-        pl_record = api.driver.sfa_fields_to_pl_fields(type, hrn, record)
-        sites = api.driver.GetSites([pl_record['login_base']])
-        if not sites:
-            pointer = api.driver.AddSite(pl_record)
-        else:
-            pointer = sites[0]['site_id']
-
-        record.set_pointer(pointer)
+                pointer = sites[0]['site_id']
+    
+            record.set_pointer(pointer)
+            record['pointer'] = pointer
+    
+        elif (type == "slice"):
+            acceptable_fields=['url', 'instantiation', 'name', 'description']
+            pl_record = api.driver.sfa_fields_to_pl_fields(type, hrn, record)
+            for key in pl_record.keys():
+                if key not in acceptable_fields:
+                    pl_record.pop(key)
+            slices = api.driver.GetSlices([pl_record['name']])
+            if not slices:
+                 pointer = api.driver.AddSlice(pl_record)
+            else:
+                 pointer = slices[0]['slice_id']
+            record.set_pointer(pointer)
+            record['pointer'] = pointer
+    
+        elif  (type == "user"):
+            persons = api.driver.GetPersons([record['email']])
+            if not persons:
+                pointer = api.driver.AddPerson(dict(record))
+            else:
+                pointer = persons[0]['person_id']
+    
+            if 'enabled' in record and record['enabled']:
+                api.driver.UpdatePerson(pointer, {'enabled': record['enabled']})
+            # add this persons to the site only if he is being added for the first
+            # time by sfa and doesont already exist in plc
+            if not persons or not persons[0]['site_ids']:
+                login_base = get_leaf(record['authority'])
+                api.driver.AddPersonToSite(pointer, login_base)
+    
+            # What roles should this user have?
+            api.driver.AddRoleToPerson('user', pointer)
+            # Add the user's key
+            if pub_key:
+                api.driver.AddPersonKey(pointer, {'key_type' : 'ssh', 'key' : pub_key})
+    
+        elif (type == "node"):
+            pl_record = api.driver.sfa_fields_to_pl_fields(type, hrn, record)
+            login_base = hrn_to_pl_login_base(record['authority'])
+            nodes = api.driver.GetNodes([pl_record['hostname']])
+            if not nodes:
+                pointer = api.driver.AddNode(login_base, pl_record)
+            else:
+                pointer = nodes[0]['node_id']
+    
         record['pointer'] = pointer
-
-    elif (type == "slice"):
-        acceptable_fields=['url', 'instantiation', 'name', 'description']
-        pl_record = api.driver.sfa_fields_to_pl_fields(type, hrn, record)
-        for key in pl_record.keys():
-            if key not in acceptable_fields:
-                pl_record.pop(key)
-        slices = api.driver.GetSlices([pl_record['name']])
-        if not slices:
-             pointer = api.driver.AddSlice(pl_record)
-        else:
-             pointer = slices[0]['slice_id']
         record.set_pointer(pointer)
-        record['pointer'] = pointer
-
-    elif  (type == "user"):
-        persons = api.driver.GetPersons([record['email']])
-        if not persons:
-            pointer = api.driver.AddPerson(dict(record))
+        record_id = table.insert(record)
+        record['record_id'] = record_id
+    
+        # update membership for researchers, pis, owners, operators
+        api.driver.update_membership(None, record)
+    
+        return record.get_gid_object().save_to_string(save_parents=True)
+    
+    def Update(self, api, record_dict):
+        new_record = SfaRecord(dict = record_dict)
+        type = new_record['type']
+        hrn = new_record['hrn']
+        urn = hrn_to_urn(hrn,type)
+        table = SfaTable()
+        # make sure the record exists
+        records = table.findObjects({'type': type, 'hrn': hrn})
+        if not records:
+            raise RecordNotFound(hrn)
+        record = records[0]
+        record['last_updated'] = time.gmtime()
+    
+        # Update_membership needs the membership lists in the existing record
+        # filled in, so it can see if members were added or removed
+        api.driver.fill_record_info(record, api.aggregates)
+    
+        # Use the pointer from the existing record, not the one that the user
+        # gave us. This prevents the user from inserting a forged pointer
+        pointer = record['pointer']
+        # update the PLC information that was specified with the record
+    
+        if (type == "authority"):
+            api.driver.UpdateSite(pointer, new_record)
+    
+        elif type == "slice":
+            pl_record=api.driver.sfa_fields_to_pl_fields(type, hrn, new_record)
+            if 'name' in pl_record:
+                pl_record.pop('name')
+                api.driver.UpdateSlice(pointer, pl_record)
+    
+        elif type == "user":
+            # SMBAKER: UpdatePerson only allows a limited set of fields to be
+            #    updated. Ideally we should have a more generic way of doing
+            #    this. I copied the field names from UpdatePerson.py...
+            update_fields = {}
+            all_fields = new_record
+            for key in all_fields.keys():
+                if key in ['first_name', 'last_name', 'title', 'email',
+                           'password', 'phone', 'url', 'bio', 'accepted_aup',
+                           'enabled']:
+                    update_fields[key] = all_fields[key]
+            api.driver.UpdatePerson(pointer, update_fields)
+    
+            if 'key' in new_record and new_record['key']:
+                # must check this key against the previous one if it exists
+                persons = api.driver.GetPersons([pointer], ['key_ids'])
+                person = persons[0]
+                keys = person['key_ids']
+                keys = api.driver.GetKeys(person['key_ids'])
+                key_exists = False
+                if isinstance(new_record['key'], types.ListType):
+                    new_key = new_record['key'][0]
+                else:
+                    new_key = new_record['key']
+                
+                # Delete all stale keys
+                for key in keys:
+                    if new_record['key'] != key['key']:
+                        api.driver.DeleteKey(key['key_id'])
+                    else:
+                        key_exists = True
+                if not key_exists:
+                    api.driver.AddPersonKey(pointer, {'key_type': 'ssh', 'key': new_key})
+    
+                # update the openssl key and gid
+                pkey = convert_public_key(new_key)
+                uuid = create_uuid()
+                gid_object = api.auth.hierarchy.create_gid(urn, uuid, pkey)
+                gid = gid_object.save_to_string(save_parents=True)
+                record['gid'] = gid
+                record = SfaRecord(dict=record)
+                table.update(record)
+    
+        elif type == "node":
+            api.driver.UpdateNode(pointer, new_record)
+    
         else:
-            pointer = persons[0]['person_id']
-
-        if 'enabled' in record and record['enabled']:
-            api.driver.UpdatePerson(pointer, {'enabled': record['enabled']})
-        # add this persons to the site only if he is being added for the first
-        # time by sfa and doesont already exist in plc
-        if not persons or not persons[0]['site_ids']:
-            login_base = get_leaf(record['authority'])
-            api.driver.AddPersonToSite(pointer, login_base)
-
-        # What roles should this user have?
-        api.driver.AddRoleToPerson('user', pointer)
-        # Add the user's key
-        if pub_key:
-            api.driver.AddPersonKey(pointer, {'key_type' : 'ssh', 'key' : pub_key})
-
-    elif (type == "node"):
-        pl_record = api.driver.sfa_fields_to_pl_fields(type, hrn, record)
-        login_base = hrn_to_pl_login_base(record['authority'])
-        nodes = api.driver.GetNodes([pl_record['hostname']])
-        if not nodes:
-            pointer = api.driver.AddNode(login_base, pl_record)
+            raise UnknownSfaType(type)
+    
+        # update membership for researchers, pis, owners, operators
+        api.driver.update_membership(record, new_record)
+        
+        return 1 
+    
+    # expecting an Xrn instance
+    def Remove(self, api, xrn, origin_hrn=None):
+    
+        table = SfaTable()
+        filter = {'hrn': xrn.get_hrn()}
+        hrn=xrn.get_hrn()
+        type=xrn.get_type()
+        if type and type not in ['all', '*']:
+            filter['type'] = type
+    
+        records = table.find(filter)
+        if not records: raise RecordNotFound(hrn)
+        record = records[0]
+        type = record['type']
+    
+        credential = api.getCredential()
+        registries = api.registries
+    
+        # Try to remove the object from the PLCDB of federated agg.
+        # This is attempted before removing the object from the local agg's PLCDB and sfa table
+        if hrn.startswith(api.hrn) and type in ['user', 'slice', 'authority']:
+            for registry in registries:
+                if registry not in [api.hrn]:
+                    try:
+                        result=registries[registry].remove_peer_object(credential, record, origin_hrn)
+                    except:
+                        pass
+        if type == "user":
+            persons = api.driver.GetPersons(record['pointer'])
+            # only delete this person if he has site ids. if he doesnt, it probably means
+            # he was just removed from a site, not actually deleted
+            if persons and persons[0]['site_ids']:
+                api.driver.DeletePerson(record['pointer'])
+        elif type == "slice":
+            if api.driver.GetSlices(record['pointer']):
+                api.driver.DeleteSlice(record['pointer'])
+        elif type == "node":
+            if api.driver.GetNodes(record['pointer']):
+                api.driver.DeleteNode(record['pointer'])
+        elif type == "authority":
+            if api.driver.GetSites(record['pointer']):
+                api.driver.DeleteSite(record['pointer'])
         else:
-            pointer = nodes[0]['node_id']
-
-    record['pointer'] = pointer
-    record.set_pointer(pointer)
-    record_id = table.insert(record)
-    record['record_id'] = record_id
-
-    # update membership for researchers, pis, owners, operators
-    api.driver.update_membership(None, record)
-
-    return record.get_gid_object().save_to_string(save_parents=True)
-
-def update(api, record_dict):
-    new_record = SfaRecord(dict = record_dict)
-    type = new_record['type']
-    hrn = new_record['hrn']
-    urn = hrn_to_urn(hrn,type)
-    table = SfaTable()
-    # make sure the record exists
-    records = table.findObjects({'type': type, 'hrn': hrn})
-    if not records:
-        raise RecordNotFound(hrn)
-    record = records[0]
-    record['last_updated'] = time.gmtime()
-
-    # Update_membership needs the membership lists in the existing record
-    # filled in, so it can see if members were added or removed
-    api.driver.fill_record_info(record, api.aggregates)
-
-    # Use the pointer from the existing record, not the one that the user
-    # gave us. This prevents the user from inserting a forged pointer
-    pointer = record['pointer']
-    # update the PLC information that was specified with the record
-
-    if (type == "authority"):
-        api.driver.UpdateSite(pointer, new_record)
-
-    elif type == "slice":
-        pl_record=api.driver.sfa_fields_to_pl_fields(type, hrn, new_record)
-        if 'name' in pl_record:
-            pl_record.pop('name')
-            api.driver.UpdateSlice(pointer, pl_record)
-
-    elif type == "user":
-        # SMBAKER: UpdatePerson only allows a limited set of fields to be
-        #    updated. Ideally we should have a more generic way of doing
-        #    this. I copied the field names from UpdatePerson.py...
-        update_fields = {}
-        all_fields = new_record
-        for key in all_fields.keys():
-            if key in ['first_name', 'last_name', 'title', 'email',
-                       'password', 'phone', 'url', 'bio', 'accepted_aup',
-                       'enabled']:
-                update_fields[key] = all_fields[key]
-        api.driver.UpdatePerson(pointer, update_fields)
-
-        if 'key' in new_record and new_record['key']:
-            # must check this key against the previous one if it exists
-            persons = api.driver.GetPersons([pointer], ['key_ids'])
-            person = persons[0]
-            keys = person['key_ids']
-            keys = api.driver.GetKeys(person['key_ids'])
-            key_exists = False
-            if isinstance(new_record['key'], types.ListType):
-                new_key = new_record['key'][0]
-            else:
-                new_key = new_record['key']
-            
-            # Delete all stale keys
-            for key in keys:
-                if new_record['key'] != key['key']:
-                    api.driver.DeleteKey(key['key_id'])
-                else:
-                    key_exists = True
-            if not key_exists:
-                api.driver.AddPersonKey(pointer, {'key_type': 'ssh', 'key': new_key})
-
-            # update the openssl key and gid
-            pkey = convert_public_key(new_key)
-            uuid = create_uuid()
-            gid_object = api.auth.hierarchy.create_gid(urn, uuid, pkey)
-            gid = gid_object.save_to_string(save_parents=True)
-            record['gid'] = gid
-            record = SfaRecord(dict=record)
-            table.update(record)
-
-    elif type == "node":
-        api.driver.UpdateNode(pointer, new_record)
-
-    else:
-        raise UnknownSfaType(type)
-
-    # update membership for researchers, pis, owners, operators
-    api.driver.update_membership(record, new_record)
+            raise UnknownSfaType(type)
     
-    return 1 
-
-# expecting an Xrn instance
-def remove(api, xrn, origin_hrn=None):
-
-    table = SfaTable()
-    filter = {'hrn': xrn.get_hrn()}
-    hrn=xrn.get_hrn()
-    type=xrn.get_type()
-    if type and type not in ['all', '*']:
-        filter['type'] = type
-
-    records = table.find(filter)
-    if not records: raise RecordNotFound(hrn)
-    record = records[0]
-    type = record['type']
-
-    credential = api.getCredential()
-    registries = api.registries
-
-    # Try to remove the object from the PLCDB of federated agg.
-    # This is attempted before removing the object from the local agg's PLCDB and sfa table
-    if hrn.startswith(api.hrn) and type in ['user', 'slice', 'authority']:
-        for registry in registries:
-            if registry not in [api.hrn]:
-                try:
-                    result=registries[registry].remove_peer_object(credential, record, origin_hrn)
-                except:
-                    pass
-    if type == "user":
-        persons = api.driver.GetPersons(record['pointer'])
-        # only delete this person if he has site ids. if he doesnt, it probably means
-        # he was just removed from a site, not actually deleted
-        if persons and persons[0]['site_ids']:
-            api.driver.DeletePerson(record['pointer'])
-    elif type == "slice":
-        if api.driver.GetSlices(record['pointer']):
-            api.driver.DeleteSlice(record['pointer'])
-    elif type == "node":
-        if api.driver.GetNodes(record['pointer']):
-            api.driver.DeleteNode(record['pointer'])
-    elif type == "authority":
-        if api.driver.GetSites(record['pointer']):
-            api.driver.DeleteSite(record['pointer'])
-    else:
-        raise UnknownSfaType(type)
-
-    table.remove(record)
-
-    return 1
-
-def remove_peer_object(api, record, origin_hrn=None):
-    pass
-
-def register_peer_object(api, record, origin_hrn=None):
-    pass
+        table.remove(record)
+    
+        return 1
index 3d6c0a6..50edb9a 100644 (file)
@@ -96,12 +96,12 @@ class SliceManager:
             if stats_tags:
                 stats_tag = stats_tags[0]
             else:
-                stats_tag = etree.SubElement(rspec.xml.root, "statistics", call=callname)
+                stats_tag = rspec.xml.root.add_element("statistics", call=callname)
 
-            stat_tag = etree.SubElement(stats_tag, "aggregate", name=str(aggname), elapsed=str(elapsed), status=str(status))
+            stat_tag = stats_tag.add_element("aggregate", name=str(aggname), elapsed=str(elapsed), status=str(status))
 
             if exc_info:
-                exc_tag = etree.SubElement(stat_tag, "exc_info", name=str(exc_info[1]))
+                exc_tag = stat_tag.add_element("exc_info", name=str(exc_info[1]))
 
                 # formats the traceback as one big text blob
                 #exc_tag.text = "\n".join(traceback.format_exception(exc_info[0], exc_info[1], exc_info[2]))
@@ -109,7 +109,7 @@ class SliceManager:
                 # formats the traceback as a set of xml elements
                 tb = traceback.extract_tb(exc_info[2])
                 for item in tb:
-                    exc_frame = etree.SubElement(exc_tag, "tb_frame", filename=str(item[0]), line=str(item[1]), func=str(item[2]), code=str(item[3]))
+                    exc_frame = exc_tag.add_element("tb_frame", filename=str(item[0]), line=str(item[1]), func=str(item[2]), code=str(item[3]))
 
         except Exception, e:
             logger.warn("add_slicemgr_stat failed on  %s: %s" %(aggname, str(e)))
@@ -419,7 +419,7 @@ class SliceManager:
         return slices
     
     
-    def get_ticket(self, api, xrn, creds, rspec, users):
+    def GetTicket(self, api, xrn, creds, rspec, users):
         slice_hrn, type = urn_to_hrn(xrn)
         # get the netspecs contained within the clients rspec
         aggregate_rspecs = {}
index 74ce9de..db69acd 100644 (file)
@@ -43,4 +43,4 @@ class CreateGid(Method):
         origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, xrn, self.name))
 
-        return self.api.manager.create_gid(self.api, xrn, cert)
+        return self.api.manager.CreateGid(self.api, xrn, cert)
index b645cd4..d966dd3 100644 (file)
@@ -42,5 +42,5 @@ class GetCredential(Method):
         origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))        
 
-        return self.api.manager.get_credential(self.api, xrn, type)
+        return self.api.manager.GetCredential(self.api, xrn, type)
 
index 601db6f..5c1470b 100644 (file)
@@ -31,7 +31,7 @@ class GetGids(Method):
         origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
         
         # resolve the record
-        records = self.api.manager.resolve(self.api, xrns, full = False)
+        records = self.api.manager.Resolve(self.api, xrns, full = False)
         if not records:
             raise RecordNotFound(xrns)
 
index 37f2e7b..efad180 100644 (file)
@@ -54,7 +54,7 @@ class GetSelfCredential(Method):
         
  
         # authenticate the gid
-        records = self.api.manager.resolve(self.api, xrn, type)
+        records = self.api.manager.Resolve(self.api, xrn, type)
         if not records:
             raise RecordNotFound(hrn)
         record = SfaRecord(dict=records[0])
@@ -71,4 +71,4 @@ class GetSelfCredential(Method):
                     self.api.logger.debug("ConnectionKeyGIDMismatch, %s filename: %s"%(name,obj.filename))
             raise ConnectionKeyGIDMismatch(gid.get_subject())
         
-        return self.api.manager.get_credential(self.api, xrn, type, is_self=True)
+        return self.api.manager.GetCredential(self.api, xrn, type, is_self=True)
index c21ce16..174bd4c 100644 (file)
@@ -51,5 +51,5 @@ class GetTicket(Method):
         rspec = run_sfatables(chain_name, hrn, origin_hrn, rspec)
         
         # remove nodes that are not available at this interface from the rspec
-        return self.api.manager.get_ticket(self.api, xrn, creds, rspec, users)
+        return self.api.manager.GetTicket(self.api, xrn, creds, rspec, users)
         
index ccd66b4..55dd7dd 100644 (file)
@@ -31,4 +31,4 @@ class List(Method):
         origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
        
-        return self.api.manager.list(self.api, xrn) 
+        return self.api.manager.List(self.api, xrn) 
index 92f230a..2d9cbfd 100644 (file)
@@ -36,4 +36,4 @@ class Register(Method):
         origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
         
-        return self.api.manager.register(self.api, record)
+        return self.api.manager.Register(self.api, record)
diff --git a/sfa/methods/RegisterPeerObject.py b/sfa/methods/RegisterPeerObject.py
deleted file mode 100644 (file)
index 2eec2f5..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-from sfa.util.faults import SfaInvalidArgument
-from sfa.util.xrn import get_authority
-from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
-from sfa.util.record import SfaRecord
-from sfa.util.table import SfaTable
-from sfa.trust.credential import Credential
-
-class RegisterPeerObject(Method):
-    """
-    Register a peer object with the registry. In addition to being stored in the
-    SFA database, the appropriate records will also be created in the
-    PLC databases
-    
-    @param cred credential string
-    @param record_dict dictionary containing record fields
-    @return gid string representation
-    """
-
-    interfaces = ['registry']
-    
-    accepts = [
-        Parameter(str, "Credential string"),
-        Parameter(dict, "Record dictionary containing record fields"),
-        Mixed(Parameter(str, "Human readable name of the original caller"),
-              Parameter(None, "Origin hrn not specified"))
-        ]
-
-    returns = Parameter(int, "1 if successful")
-    
-    def call(self, cred, record_dict, origin_hrn=None):
-        user_cred = Credential(string=cred)
-
-        #log the call
-        if not origin_hrn:
-            origin_hrn = user_cred.get_gid_caller().get_hrn()    
-        self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, None, self.name))
-
-        # validate the cred
-        self.api.auth.check(cred, "register")
-
-        # make sure this is a peer record
-        if 'peer_authority' not in record_dict or \
-           not record_dict['peer_authority']: 
-            raise SfaInvalidArgument, "peer_authority must be specified" 
-
-        record = SfaRecord(dict = record_dict)
-        type, hrn, peer_authority = record['type'], record['hrn'], record['peer_authority']
-        record['authority'] = get_authority(record['hrn'])
-        # verify permissions
-        self.api.auth.verify_cred_is_me(cred)
-
-        # check if record already exists
-        table = SfaTable()
-        existing_records = table.find({'type': type, 'hrn': hrn, 'peer_authority': peer_authority})
-        if existing_records:
-            for existing_record in existing_records:
-                if existing_record['pointer'] != record['pointer']:
-                    record['record_id'] = existing_record['record_id']
-                    table.update(record)
-        else:
-            record_id = table.insert(record)
-        return 1
index 98ef38b..1804fd9 100644 (file)
@@ -39,4 +39,4 @@ class Remove(Method):
         self.api.logger.info("interface: %s\tmethod-name: %s\tcaller-hrn: %s\ttarget-urn: %s"%(
                 self.api.interface, self.name, origin_hrn, xrn.get_urn()))
 
-        return self.api.manager.remove(self.api, xrn) 
+        return self.api.manager.Remove(self.api, xrn) 
diff --git a/sfa/methods/RemovePeerObject.py b/sfa/methods/RemovePeerObject.py
deleted file mode 100644 (file)
index c831924..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-from sfa.util.faults import UnknownSfaType, SfaInvalidArgument
-from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
-from sfa.util.table import SfaTable
-from sfa.trust.credential import Credential
-
-class RemovePeerObject(Method):
-    """
-    Remove an peer object from the PLC records of a local aggregate. 
-    This method will be called by registry.remove() while removing 
-    a record from the local aggreage's PLCDB and sfa table. This 
-    method need not be directly called by end-user.
-    
-    @param cred credential string
-    @param record record as stored in the local registry
-
-    @return 1 if successful, faults otherwise 
-    """
-
-    interfaces = ['registry']
-    
-    accepts = [
-        Parameter(str, "Credential string"),
-        Parameter(dict, "Record dictionary"),
-        Mixed(Parameter(str, "Human readable name of the original caller"),
-              Parameter(None, "Origin hrn not specified"))
-        ]
-
-    returns = Parameter(int, "1 if successful")
-    
-    def call(self, cred, record, origin_hrn=None):
-        user_cred = Credential(string=cred)
-
-        #log the call
-        if not origin_hrn:
-            origin_hrn = user_cred.get_gid_caller().get_hrn()
-        self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, record['hrn'], self.name))
-
-        self.api.auth.check(cred, "remove")
-
-        # Only allow the local interface or record owner to delete peer_records 
-        try: self.api.auth.verify_object_permission(record['hrn'])
-        except: self.api.auth.verify_cred_is_me(cred)
-        
-        table = SfaTable()
-        hrn, type = record['hrn'], record['type']
-        records = table.find({'hrn': hrn, 'type': type })
-        for record in records:
-            if record['peer_authority']:
-                self.remove_plc_record(record)
-                table.remove(record)
-            
-        return 1
-
-    def remove_plc_record(self, record):
-        type = record['type']        
-        if type == "user":
-            persons = self.api.driver.GetPersons({'person_id' : record['pointer']})
-            if not persons:
-                return 1
-            person = persons[0]
-            if person['peer_id']:
-                peer = self.get_peer_name(person['peer_id']) 
-                self.api.driver.UnBindObjectFromPeer('person', person['person_id'], peer)
-            self.api.driver.DeletePerson(person['person_id'])
-           
-        elif type == "slice":
-            slices=self.api.driver.GetSlices({'slice_id' : record['pointer']})
-            if not slices:
-                return 1
-            slice=slices[0]
-            if slice['peer_id']:
-                peer = self.get_peer_name(slice['peer_id']) 
-                self.api.driver.UnBindObjectFromPeer('slice', slice['slice_id'], peer)
-            self.api.driver.DeleteSlice(slice['slice_id'])
-        elif type == "authority":
-            sites=self.api.driver.GetSites({'site_id' : record['pointer']})
-            if not sites:
-                return 1
-            site=sites[0]
-            if site['peer_id']:
-                peer = self.get_peer_name(site['peer_id']) 
-                self.api.driver.UnBindObjectFromPeer('site', site['site_id'], peer)
-            self.api.driver.DeleteSite(site['site_id'])
-           
-        else:
-            raise UnknownSfaType(type)
-
-        return 1
-
-    def get_peer_name(self, peer_id):
-        peers = self.api.driver.GetPeers([peer_id], ['peername', 'shortname', 'hrn_root'])
-        if not peers:
-            raise SfaInvalidArgument, "No such peer"
-        peer = peers[0]
-        return peer['shortname'] 
-
-
-
index 6277e1b..094500f 100644 (file)
@@ -40,5 +40,5 @@ class Resolve(Method):
         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrns, self.name))
  
         # send the call to the right manager
-        return self.api.manager.resolve(self.api, xrns, type)
+        return self.api.manager.Resolve(self.api, xrns, type)
             
index d978197..7c9cc14 100644 (file)
@@ -15,13 +15,4 @@ class ResolveGENI(Method):
     returns = Parameter(bool, "Success or Failure")
 
     def call(self, xrn):
-
-        manager_base = 'sfa.managers'
-
-        if self.api.interface in ['registry']:
-            mgr_type = self.api.config.SFA_REGISTRY_TYPE
-            manager_module = manager_base + ".registry_manager_%s" % mgr_type
-            manager = __import__(manager_module, fromlist=[manager_base])
-            return manager.Resolve(self.api, xrn, '')
-               
-        return {}
+        return self.api.manager.Resolve(self.api, xrn, '')
index a90a44e..7643302 100644 (file)
@@ -35,5 +35,5 @@ class Update(Method):
         origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
        
-        return self.api.manager.update(self.api, record_dict)
+        return self.api.manager.Update(self.api, record_dict)
 
index eef24de..0e47df6 100644 (file)
@@ -13,9 +13,7 @@ ListResources
 ListSlices
 RedeemTicket
 Register
-RegisterPeerObject
 Remove
-RemovePeerObject
 RenewSliver
 Resolve
 ResolveGENI
@@ -25,11 +23,7 @@ Start
 Stop
 Update
 UpdateSliver
-get_aggregates
 get_key
-get_registries
 get_trusted_certs
-register_peer_object
-remove_peer_object
 reset_slice
 """.split()
diff --git a/sfa/methods/get_aggregates.py b/sfa/methods/get_aggregates.py
deleted file mode 100644 (file)
index 23c8d60..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-from sfa.util.xrn import urn_to_hrn
-from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
-from sfa.server.aggregate import Aggregates
-
-class get_aggregates(Method):
-    """
-    Get a list of connection information for all known aggregates.      
-
-    @param cred credential string specifying the rights of the caller
-    @param a Human readable name (hrn or urn), or list of hrns or None
-    @return list of dictionaries with aggregate information.  
-    """
-
-    interfaces = ['registry', 'aggregate', 'slicemgr']
-    
-    accepts = [
-        Parameter(str, "Credential string"),
-        Mixed(Parameter(str, "Human readable name (hrn or urn)"),
-              Parameter(None, "hrn not specified"))
-        ]
-
-    returns = [Parameter(dict, "Aggregate interface information")]
-    
-    def call(self, cred, xrn = None):
-        hrn, type = urn_to_hrn(xrn)
-        self.api.auth.check(cred, 'list')
-        aggregates = Aggregates(self.api).interfaces.values()
-        if hrn:
-            aggregates = [agg for agg in aggregates if agg['hrn'] == hrn]
-        return aggregates
index 638332e..1195d53 100644 (file)
@@ -22,7 +22,7 @@ class get_key(Method):
     returns = Parameter(int, "1 if successful, faults otherwise")
     
     def call(self):
-        # verify that the callers's ip address exist in the db and is an inteface
+        # verify that the callers's ip address exist in the db and is an interface
         # for a node in the db
         (ip, port) = self.api.remote_addr
         interfaces = self.api.driver.GetInterfaces({'ip': ip}, ['node_id'])
diff --git a/sfa/methods/get_registries.py b/sfa/methods/get_registries.py
deleted file mode 100644 (file)
index 65d9444..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-from sfa.util.xrn import urn_to_hrn
-from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
-from sfa.server.registry import Registries
-
-class get_registries(Method):
-    """
-    Get a list of connection information for all known registries.      
-
-    @param cred credential string specifying the rights of the caller
-    @param a Human readable name (hrn or urn), or list of names or None
-    @return list of dictionaries with aggregate information.  
-    """
-
-    interfaces = ['registry', 'aggregate', 'slicemgr']
-    
-    accepts = [
-        Parameter(str, "Credential string"),
-        Mixed(Parameter(str, "Human readable name (hrn or urn)"),
-              Parameter(None, "hrn not specified"))
-        ]
-
-    returns = [Parameter(dict, "Registry interface information")]
-    
-    def call(self, cred, xrn = None):
-        hrn, type = urn_to_hrn(xrn)
-        self.api.auth.check(cred, 'list')
-        registries = Registries(self.api).values()
-        if hrn:
-            registries = [reg for reg in registries if reg['hrn'] == hrn] 
-        return registries
diff --git a/sfa/methods/register_peer_object.py b/sfa/methods/register_peer_object.py
deleted file mode 100644 (file)
index 42ef240..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-
-from sfa.util.faults import SfaInvalidArgument
-from sfa.util.xrn import get_authority
-from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
-from sfa.util.record import SfaRecord
-from sfa.util.table import SfaTable
-from sfa.trust.credential import Credential
-
-class register_peer_object(Method):
-    """
-    Register a peer object with the registry. In addition to being stored in the
-    SFA database, the appropriate records will also be created in the
-    PLC databases
-    
-    @param cred credential string
-    @param record_dict dictionary containing record fields
-    @return gid string representation
-    """
-
-    interfaces = ['registry']
-    
-    accepts = [
-        Parameter(str, "Credential string"),
-        Parameter(dict, "Record dictionary containing record fields"),
-        Mixed(Parameter(str, "Human readable name of the original caller"),
-              Parameter(None, "Origin hrn not specified"))
-        ]
-
-    returns = Parameter(int, "1 if successful")
-    
-    def call(self, cred, record_dict, origin_hrn=None):
-        user_cred = Credential(string=cred)
-
-        #log the call
-        if not origin_hrn:
-            origin_hrn = user_cred.get_gid_caller().get_hrn()    
-        self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, None, self.name))
-
-        # validate the cred
-        self.api.auth.check(cred, "register")
-
-        # make sure this is a peer record
-        if 'peer_authority' not in record_dict or \
-           not record_dict['peer_authority']: 
-            raise SfaInvalidArgument, "peer_authority must be specified" 
-
-        record = SfaRecord(dict = record_dict)
-        type, hrn, peer_authority = record['type'], record['hrn'], record['peer_authority']
-        record['authority'] = get_authority(record['hrn'])
-        # verify permissions
-        self.api.auth.verify_cred_is_me(cred)
-
-        # check if record already exists
-        table = SfaTable()
-        existing_records = table.find({'type': type, 'hrn': hrn, 'peer_authority': peer_authority})
-        if existing_records:
-            for existing_record in existing_records:
-                if existing_record['pointer'] != record['pointer']:
-                    record['record_id'] = existing_record['record_id']
-                    table.update(record)
-        else:
-            record_id = table.insert(record)
-        return 1
diff --git a/sfa/methods/remove_peer_object.py b/sfa/methods/remove_peer_object.py
deleted file mode 100644 (file)
index 465ed05..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-from sfa.util.faults import UnknownSfaType, SfaInvalidArgument
-from sfa.util.method import Method
-from sfa.util.parameter import Parameter, Mixed
-from sfa.util.table import SfaTable
-from sfa.trust.credential import Credential
-
-class remove_peer_object(Method):
-    """
-    Remove a peer object from the PLC records of a local aggregate. 
-    This method will be called by registry.remove() while removing 
-    a record from the local aggreage's PLCDB and sfa table. This 
-    method need not be directly called by end-user.
-    
-    @param cred credential string
-    @param record record as stored in the local registry
-
-    @return 1 if successful, faults otherwise 
-    """
-
-    interfaces = ['registry']
-    
-    accepts = [
-        Parameter(str, "Credential string"),
-        Parameter(dict, "Record dictionary"),
-        Mixed(Parameter(str, "Human readable name of the original caller"),
-              Parameter(None, "Origin hrn not specified"))
-        ]
-
-    returns = Parameter(int, "1 if successful")
-    
-    def call(self, cred, record, origin_hrn=None):
-        user_cred = Credential(string=cred)
-
-        #log the call
-        if not origin_hrn:
-            origin_hrn = user_cred.get_gid_caller().get_hrn()
-        self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, record['hrn'], self.name))
-
-        self.api.auth.check(cred, "remove")
-
-        # Only allow the local interface or record owner to delete peer_records 
-        try: self.api.auth.verify_object_permission(record['hrn'])
-        except: self.api.auth.verify_cred_is_me(cred)
-        
-        table = SfaTable()
-        hrn, type = record['hrn'], record['type']
-        records = table.find({'hrn': hrn, 'type': type })
-        for record in records:
-            if record['peer_authority']:
-                self.remove_plc_record(record)
-                table.remove(record)
-            
-        return 1
-
-    def remove_plc_record(self, record):
-        type = record['type']        
-        if type == "user":
-            persons = self.api.driver.GetPersons({'person_id' : record['pointer']})
-            if not persons:
-                return 1
-            person = persons[0]
-            if person['peer_id']:
-                peer = self.get_peer_name(person['peer_id']) 
-                self.api.driver.UnBindObjectFromPeer('person', person['person_id'], peer)
-            self.api.driver.DeletePerson(person['person_id'])
-           
-        elif type == "slice":
-            slices=self.api.driver.GetSlices({'slice_id' : record['pointer']})
-            if not slices:
-                return 1
-            slice=slices[0]
-            if slice['peer_id']:
-                peer = self.get_peer_name(slice['peer_id']) 
-                self.api.driver.UnBindObjectFromPeer('slice', slice['slice_id'], peer)
-            self.api.driver.DeleteSlice(slice['slice_id'])
-        elif type == "authority":
-            sites=self.api.driver.GetSites({'site_id' : record['pointer']})
-            if not sites:
-                return 1
-            site=sites[0]
-            if site['peer_id']:
-                peer = self.get_peer_name(site['peer_id']) 
-                self.api.driver.UnBindObjectFromPeer('site', site['site_id'], peer)
-            self.api.driver.DeleteSite(site['site_id'])
-           
-        else:
-            raise UnknownSfaType(type)
-
-        return 1
-
-    def get_peer_name(self, peer_id):
-        peers = self.api.driver.GetPeers([peer_id], ['peername', 'shortname', 'hrn_root'])
-        if not peers:
-            raise SfaInvalidArgument, "No such peer"
-        peer = peers[0]
-        return peer['shortname'] 
-
-
-
index bda3bbc..3ec538a 100644 (file)
@@ -6,6 +6,7 @@ from sfa.rspecs.rspec import RSpec
 from sfa.rspecs.elements.hardware_type import HardwareType
 from sfa.rspecs.elements.node import Node
 from sfa.rspecs.elements.link import Link
+from sfa.rspecs.elements.sliver import Sliver
 from sfa.rspecs.elements.login import Login
 from sfa.rspecs.elements.location import Location
 from sfa.rspecs.elements.interface import Interface
@@ -14,6 +15,7 @@ from sfa.rspecs.elements.pltag import PLTag
 from sfa.util.topology import Topology
 from sfa.rspecs.version_manager import VersionManager
 from sfa.plc.vlink import get_tc_rate
+from sfa.util.sfatime import epochparse
 
 class Aggregate:
 
@@ -35,51 +37,49 @@ class Aggregate:
         interfaces = {}
         for interface in self.api.driver.GetInterfaces(filter):
             iface = Interface()
-            iface['interface_id'] = interface['interface_id']
-            iface['node_id'] = interface['node_id']
-            iface['ipv4'] = interface['ip']
-            iface['bwlimit'] = interface['bwlimit']
-            interfaces[iface['interface_id']] = iface
+            if interface['bwlimit']:
+                interface['bwlimit'] = str(int(interface['bwlimit'])/1000)
+            interfaces[interface['interface_id']] = interface
         return interfaces
 
-    def get_links(self, filter={}):
+    def get_links(self, sites, nodes, interfaces):
         
-        if not self.api.config.SFA_AGGREGATE_TYPE.lower() == 'vini':
-            return []
-
         topology = Topology() 
-        links = {}
+        links = []
         for (site_id1, site_id2) in topology:
+            site_id1 = int(site_id1)
+            site_id2 = int(site_id2)
             link = Link()
-            if not site_id1 in self.sites or site_id2 not in self.sites:
+            if not site_id1 in sites or site_id2 not in sites:
                 continue
-            site1 = self.sites[site_id1]
-            site2 = self.sites[site_id2]
+            site1 = sites[site_id1]
+            site2 = sites[site_id2]
             # get hrns
             site1_hrn = self.api.hrn + '.' + site1['login_base']
             site2_hrn = self.api.hrn + '.' + site2['login_base']
-            # get the first node
-            node1 = self.nodes[site1['node_ids'][0]]
-            node2 = self.nodes[site2['node_ids'][0]]
-
-            # set interfaces
-            # just get first interface of the first node
-            if1_xrn = PlXrn(auth=self.api.hrn, interface='node%s:eth0' % (node1['node_id']))
-            if1_ipv4 = self.interfaces[node1['interface_ids'][0]]['ip']
-            if2_xrn = PlXrn(auth=self.api.hrn, interface='node%s:eth0' % (node2['node_id']))
-            if2_ipv4 = self.interfaces[node2['interface_ids'][0]]['ip']
-
-            if1 = Interface({'component_id': if1_xrn.urn, 'ipv4': if1_ipv4} )
-            if2 = Interface({'component_id': if2_xrn.urn, 'ipv4': if2_ipv4} )
-
-            # set link
-            link = Link({'capacity': '1000000', 'latency': '0', 'packet_loss': '0', 'type': 'ipv4'})
-            link['interface1'] = if1
-            link['interface2'] = if2
-            link['component_name'] = "%s:%s" % (site1['login_base'], site2['login_base'])
-            link['component_id'] = PlXrn(auth=self.api.hrn, interface=link['component_name']).get_urn()
-            link['component_manager_id'] =  hrn_to_urn(self.api.hrn, 'authority+am')
-            links[link['component_name']] = link
+
+            for s1_node_id in site1['node_ids']:
+                for s2_node_id in site2['node_ids']:
+                    node1 = nodes[s1_node_id]
+                    node2 = nodes[s2_node_id]
+                    # set interfaces
+                    # just get first interface of the first node
+                    if1_xrn = PlXrn(auth=self.api.hrn, interface='node%s:eth0' % (node1['node_id']))
+                    if1_ipv4 = interfaces[node1['interface_ids'][0]]['ip']
+                    if2_xrn = PlXrn(auth=self.api.hrn, interface='node%s:eth0' % (node2['node_id']))
+                    if2_ipv4 = interfaces[node2['interface_ids'][0]]['ip']
+
+                    if1 = Interface({'component_id': if1_xrn.urn, 'ipv4': if1_ipv4} )
+                    if2 = Interface({'component_id': if2_xrn.urn, 'ipv4': if2_ipv4} )
+
+                    # set link
+                    link = Link({'capacity': '1000000', 'latency': '0', 'packet_loss': '0', 'type': 'ipv4'})
+                    link['interface1'] = if1
+                    link['interface2'] = if2
+                    link['component_name'] = "%s:%s" % (site1['login_base'], site2['login_base'])
+                    link['component_id'] = PlXrn(auth=self.api.hrn, interface=link['component_name']).get_urn()
+                    link['component_manager_id'] =  hrn_to_urn(self.api.hrn, 'authority+am')
+                    links.append(link)
 
         return links
 
@@ -105,7 +105,7 @@ class Aggregate:
         slice = None
         if not slice_xrn:
             return (slice, slivers)
-        slice_urn = hrn_to_urn(slice_xrn)
+        slice_urn = hrn_to_urn(slice_xrn, 'slice')
         slice_hrn, _ = urn_to_hrn(slice_xrn)
         slice_name = hrn_to_pl_slicename(slice_hrn)
         slices = self.api.driver.GetSlices(slice_name)
@@ -116,7 +116,8 @@ class Aggregate:
         # sort slivers by node id    
         for node_id in slice['node_ids']:
             sliver = Sliver({'sliver_id': urn_to_sliver_id(slice_urn, slice['slice_id'], node_id),
-                             'name': 'plab-vserver', 
+                             'name': slice['name'],
+                             'type': 'plab-vserver', 
                              'tags': []})
             slivers[node_id]= sliver
 
@@ -133,7 +134,7 @@ class Aggregate:
         
         return (slice, slivers)
 
-    def get_nodes (self, slice=None,slivers=[]):
+    def get_nodes_and_links(self, slice=None,slivers=[]):
         filter = {}
         tags_filter = {}
         if slice and 'node_ids' in slice and slice['node_ids']:
@@ -146,26 +147,23 @@ class Aggregate:
         site_ids = []
         interface_ids = []
         tag_ids = []
+        nodes_dict = {}
         for node in nodes:
             site_ids.append(node['site_id'])
             interface_ids.extend(node['interface_ids'])
             tag_ids.extend(node['node_tag_ids'])
+            nodes_dict[node['node_id']] = node
  
         # get sites
         sites_dict  = self.get_sites({'site_id': site_ids}) 
         # get interfaces
         interfaces = self.get_interfaces({'interface_id':interface_ids}) 
-        # get slivers
-        # 
-        # thierry: no get_slivers, we have slivers as a result of
-        # get_slice_and_slivers passed as an argument
-        # 
-#        slivers = self.get_slivers(slice)
-
         # get tags
         node_tags = self.get_node_tags(tags_filter)
         # get initscripts
         pl_initscripts = self.get_pl_initscripts()
+        
+        links = self.get_links(sites_dict, nodes_dict, interfaces)
 
         rspec_nodes = []
         for node in nodes:
@@ -183,20 +181,26 @@ class Aggregate:
             rspec_node['authority_id'] = hrn_to_urn(PlXrn.site_hrn(self.api.hrn, site['login_base']), 'authority+sa')
             rspec_node['boot_state'] = node['boot_state']
             rspec_node['exclusive'] = 'False'
-            rspec_node['hardware_types'].append(HardwareType({'name': 'plab-vserver'}))
+            rspec_node['hardware_types']= [HardwareType({'name': 'plab-pc'}),
+                                           HardwareType({'name': 'pc'})]
             # only doing this because protogeni rspec needs
             # to advertise available initscripts 
-            rspec_node['pl_initscripts'] = pl_initscripts
+            rspec_node['pl_initscripts'] = pl_initscripts.values()
              # add site/interface info to nodes.
             # assumes that sites, interfaces and tags have already been prepared.
             site = sites_dict[node['site_id']]
-            location = Location({'longitude': site['longitude'], 'latitude': site['latitude']})
-            rspec_node['location'] = location
+            if site['longitude'] and site['latitude']:  
+                location = Location({'longitude': site['longitude'], 'latitude': site['latitude']})
+                rspec_node['location'] = location
             rspec_node['interfaces'] = []
+            if_count=0
             for if_id in node['interface_ids']:
                 interface = Interface(interfaces[if_id]) 
-                interface['ipv4'] = interface['ipv4']
+                interface['ipv4'] = interface['ip']
+                interface['component_id'] = PlXrn(auth=self.api.hrn, interface='node%s:eth%s' % (node['node_id'], if_count)).get_urn()
                 rspec_node['interfaces'].append(interface)
+                if_count+=1
+
             tags = [PLTag(node_tags[tag_id]) for tag_id in node['node_tag_ids']]
             rspec_node['tags'] = tags
             if node['node_id'] in slivers:
@@ -204,14 +208,14 @@ class Aggregate:
                 sliver = slivers[node['node_id']]
                 rspec_node['sliver_id'] = sliver['sliver_id']
                 rspec_node['client_id'] = node['hostname']
-                rspec_node['slivers'] = [slivers[node['node_id']]]
+                rspec_node['slivers'] = [sliver]
                 
                 # slivers always provide the ssh service
-                login = Login({'authentication': 'ssh-keys', 'hostname': node['hostname'], port:'22'})
+                login = Login({'authentication': 'ssh-keys', 'hostname': node['hostname'], 'port':'22'})
                 service = Services({'login': login})
-                rspec_node['services'].append(service)
+                rspec_node['services'] = [service]
             rspec_nodes.append(rspec_node)
-        return rspec_nodes
+        return (rspec_nodes, links)
              
         
     def get_rspec(self, slice_xrn=None, version = None):
@@ -225,8 +229,12 @@ class Aggregate:
 
         slice, slivers = self.get_slice_and_slivers(slice_xrn)
         rspec = RSpec(version=rspec_version, user_options=self.user_options)
-        rspec.version.add_nodes(self.get_nodes(slice), slivers)
-        rspec.version.add_links(self.get_links(slice))
+        if slice and 'expires' in slice:
+            rspec.xml.set('expires',  epochparse(slice['expires']))
+
+        nodes, links = self.get_nodes_and_links(slice, slivers)
+        rspec.version.add_nodes(nodes)
+        rspec.version.add_links(links)
         
         # add sliver defaults
         default_sliver_attribs = slivers.get(None, [])
diff --git a/sfa/plc/network.py b/sfa/plc/network.py
deleted file mode 100644 (file)
index e97565c..0000000
+++ /dev/null
@@ -1,624 +0,0 @@
-from __future__ import with_statement
-import sys
-import re
-import socket
-from StringIO import StringIO
-from lxml import etree
-from xmlbuilder import XMLBuilder
-
-from sfa.util.faults import InvalidRSpec
-from sfa.util.xrn import get_authority
-from sfa.util.plxrn import hrn_to_pl_slicename, hostname_to_urn
-
-class Sliver:
-    def __init__(self, node):
-        self.node = node
-        self.network = node.network
-        self.slice = node.network.slice
-        
-    def toxml(self, xml):
-        with xml.sliver:
-            self.slice.tags_to_xml(xml, self.node)
-
-        
-class Iface:
-    def __init__(self, network, iface):
-        self.network = network
-        self.id = iface['interface_id']
-        self.idtag = "i%s" % self.id
-        self.ipv4 = iface['ip']
-        self.bwlimit = iface['bwlimit']
-        self.hostname = iface['hostname']
-        self.primary = iface['is_primary']
-
-    def toxml(self, xml):
-        """
-        Just print out bwlimit right now
-        """
-        if self.bwlimit:
-            with xml.bw_limit(units="kbps"):
-                xml << str(self.bwlimit / 1000)
-
-
-class Node:
-    def __init__(self, network, node):
-        self.network = network
-        self.id = node['node_id']
-        self.idtag = "n%s" % self.id
-        self.hostname = node['hostname']
-        self.site_id = node['site_id']
-        self.iface_ids = node['interface_ids']
-        self.sliver = None
-        self.whitelist = node['slice_ids_whitelist']
-        auth = self.network.api.hrn
-        login_base = self.get_site().idtag
-        self.urn = hostname_to_urn(auth, login_base, self.hostname)
-
-    def get_primary_iface(self):
-        for id in self.iface_ids:
-            iface = self.network.lookupIface(id)
-            if iface.primary:
-                return iface
-        return None
-        
-    def get_site(self):
-        return self.network.lookupSite(self.site_id)
-    
-    def add_sliver(self):
-        self.sliver = Sliver(self)
-
-    def toxml(self, xml):
-        slice = self.network.slice
-        if self.whitelist and not self.sliver:
-            if not slice or slice.id not in self.whitelist:
-                return
-
-        with xml.node(id = self.idtag):
-            with xml.hostname:
-                xml << self.hostname
-            with xml.urn:
-                xml << self.urn
-            iface = self.get_primary_iface()
-            if iface:
-                iface.toxml(xml)
-            if self.sliver:
-                self.sliver.toxml(xml)
-    
-
-class Site:
-    def __init__(self, network, site):
-        self.network = network
-        self.id = site['site_id']
-        self.node_ids = site['node_ids']
-        self.node_ids.sort()
-        self.name = site['abbreviated_name']
-        self.tag = site['login_base']
-        self.idtag = site['login_base']
-        self.public = site['is_public']
-        self.enabled = site['enabled']
-        self.links = set()
-        self.whitelist = False
-
-    def get_sitenodes(self):
-        n = []
-        for i in self.node_ids:
-            n.append(self.network.lookupNode(i))
-        return n
-    
-    def toxml(self, xml):
-        if not (self.public and self.enabled and self.node_ids):
-            return
-        with xml.site(id = self.idtag):
-            with xml.name:
-                xml << self.name
-            for node in self.get_sitenodes():
-                node.toxml(xml)
-   
-    
-class Slice:
-    def __init__(self, network, hrn, slice):
-        self.hrn = hrn
-        self.network = network
-        self.id = slice['slice_id']
-        self.name = slice['name']
-        self.peer_id = slice['peer_id']
-        self.node_ids = set(slice['node_ids'])
-        self.slice_tag_ids = slice['slice_tag_ids']
-    
-    """
-    Use with tags that can have more than one instance
-    """
-    def get_multi_tag(self, tagname, node = None):
-        tags = []
-        for i in self.slice_tag_ids:
-            try: 
-                tag = self.network.lookupSliceTag(i)                 
-                if tag.tagname == tagname:
-                    if node:
-                        if node.id == tag.node_id:
-                            tags.append(tag)
-                    elif not tag.node_id:
-                        tags.append(tag)
-            except InvalidRSpec, e: 
-                # As they're not needed, we ignore some tag types from 
-                # GetSliceTags call. See Slicetag.ignore_tags 
-                pass 
-        return tags
-        
-    """
-    Use with tags that have only one instance
-    """
-    def get_tag(self, tagname, node = None):
-        for i in self.slice_tag_ids:
-            try:
-                tag = self.network.lookupSliceTag(i) 
-                if tag.tagname == tagname: 
-                    if node:
-                        if node.id == tag.node_id:
-                            return tag
-                    elif not tag.node_id:
-                        return tag 
-            except InvalidRSpec, e:
-                # As they're not needed, we ignore some tag types from
-                # GetSliceTags call. See Slicetag.ignore_tags
-                pass
-        return None
-        
-    def get_nodes(self):
-        n = []
-        for id in self.node_ids:
-            if id in self.network.nodes:
-                n.append(self.network.nodes[id])
-        return n
-
-    # Add a new slice tag   
-    def add_tag(self, tagname, value, node = None, role = "user"):
-        tt = self.network.lookupTagType(tagname)
-        if not tt.permit_update(role):
-            raise InvalidRSpec("permission denied to modify '%s' tag" % tagname)
-        tag = Slicetag()
-        tag.initialize(tagname, value, node, self.network)
-        self.network.tags[tag.id] = tag
-        self.slice_tag_ids.append(tag.id)
-        return tag
-    
-    # Update a slice tag if it exists, else add it             
-    def update_tag(self, tagname, value, node = None, role = "user"):
-        tag = self.get_tag(tagname, node)
-        if tag and tag.value == value:
-            return tag
-
-        tt = self.network.lookupTagType(tagname)
-        if not tt.permit_update(role):
-            raise InvalidRSpec("permission denied to modify '%s' tag" % tagname)
-
-        if tag:
-            tag.change(value)
-        else:
-            tag = self.add_tag(tagname, value, node, role)
-        return tag
-            
-    def update_multi_tag(self, tagname, value, node = None, role = "user"):
-        tags = self.get_multi_tag(tagname, node)
-        for tag in tags:
-            if tag and tag.value == value:
-                break
-        else:
-            tag = self.add_tag(tagname, value, node, role)
-        return tag
-            
-    def tags_to_xml(self, xml, node = None):
-        tagtypes = self.network.getTagTypes()
-        for tt in tagtypes:
-            if tt.in_rspec:
-                if tt.multi:
-                    tags = self.get_multi_tag(tt.tagname, node)
-                    for tag in tags:
-                        if not tag.was_deleted():  ### Debugging
-                            xml << (tag.tagname, tag.value)
-                else:
-                    tag = self.get_tag(tt.tagname, node)
-                    if tag:
-                        if not tag.was_deleted():   ### Debugging
-                            xml << (tag.tagname, tag.value)
-
-    def toxml(self, xml):
-        with xml.sliver_defaults:
-            self.tags_to_xml(xml)
-
-
-class Slicetag:
-    newid = -1 
-    filter_fields = ['slice_tag_id','slice_id','tagname','value','node_id','category'] 
-    ignore_tags = ['hmac','ssh_key']
-    def __init__(self, tag = None):
-        if not tag:
-            return
-        self.id = tag['slice_tag_id']
-        self.slice_id = tag['slice_id']
-        self.tagname = tag['tagname']
-        self.value = tag['value']
-        self.node_id = tag['node_id']
-        self.category = tag['category']
-        self.status = None
-
-    # Create a new slicetag that will be written to the DB later
-    def initialize(self, tagname, value, node, network):
-        tt = network.lookupTagType(tagname)
-        self.id = Slicetag.newid
-        Slicetag.newid -=1
-        self.slice_id = network.slice.id
-        self.tagname = tagname
-        self.value = value
-        if node:
-            self.node_id = node.id
-        else:
-            self.node_id = None
-        self.category = tt.category
-        self.status = "new"
-
-    def change(self, value):
-        if self.value != value:
-            self.value = value
-            self.status = "change"
-        else:
-            self.status = "updated"
-        
-    # Mark a tag as deleted
-    def delete(self):
-        self.status = "delete"
-
-    def was_added(self):
-        return (self.id < 0)
-
-    def was_changed(self):
-        return (self.status == "change")
-
-    def was_deleted(self):
-        return (self.status == "delete")
-
-    def was_updated(self):
-        return (self.status != None)
-    
-    def write(self, api):
-        if self.was_added():
-            api.driver.AddSliceTag(self.slice_id, self.tagname, self.value, self.node_id)
-        elif self.was_changed():
-            api.driver.UpdateSliceTag(self.id, self.value)
-        elif self.was_deleted():
-            api.driver.DeleteSliceTag(self.id)
-
-
-class TagType:
-    ignore_tags = ['hmac','ssh_key']
-    def __init__(self, tagtype):
-        self.id = tagtype['tag_type_id']
-        self.category = tagtype['category']
-        self.tagname = tagtype['tagname']
-        self.roles = tagtype['roles']
-        self.multi = False
-        self.in_rspec = False
-        if self.category == 'slice/rspec':
-            self.in_rspec = True
-        if self.tagname in ['codemux', 'ip_addresses', 'vsys']:
-            self.multi = True
-
-    def permit_update(self, role):
-        if role in self.roles:
-            return True
-        return False
-        
-
-class Network:
-    """
-    A Network is a compound object consisting of:
-    * a dictionary mapping site IDs to Site objects
-    * a dictionary mapping node IDs to Node objects
-    * a dictionary mapping interface IDs to Iface objects
-    """
-    def __init__(self, api, type = "SFA"):
-        self.api = api
-        self.type = type
-        self.sites = self.get_sites(api)
-        self.nodes = self.get_nodes(api)
-        self.ifaces = self.get_ifaces(api)
-        self.tags = self.get_slice_tags(api)
-        self.tagtypes = self.get_tag_types(api)
-        self.slice = None
-        self.sitemap = {}
-        for s in self.sites:
-            site = self.sites[s]
-            self.sitemap[site.idtag] = site.id
-
-    def lookupSiteIdtag(self, name):
-        """ Lookup site id from name """
-        val = None
-        try:
-            val = self.sitemap[name]
-        except:
-            raise InvalidRSpec("site name '%s' not found" % name)
-        return val
-    
-    def lookupSite(self, id):
-        """ Lookup site based on id or idtag value """
-        val = None
-        if isinstance(id, basestring):
-            id = self.lookupSiteIdtag(id)
-        try:
-            val = self.sites[id]
-        except:
-            self.api.logger.error("Invalid RSpec: site ID %s not found" % id )
-            raise InvalidRSpec("site ID %s not found" % id)
-        return val
-    
-    def getSites(self):
-        sites = []
-        for s in self.sites:
-            sites.append(self.sites[s])
-        return sites
-        
-    def lookupNode(self, id):
-        """ Lookup node based on id or idtag value """
-        val = None
-        if isinstance(id, basestring):
-            id = int(id.lstrip('n'))
-        try:
-            val = self.nodes[id]
-        except:
-            raise InvalidRSpec("node ID %s not found" % id)
-        return val
-    
-    def getNodes(self):
-        nodes = []
-        for n in self.nodes:
-            nodes.append(self.nodes[n])
-        return nodes
-    
-    def lookupIface(self, id):
-        """ Lookup iface based on id or idtag value """
-        val = None
-        if isinstance(id, basestring):
-            id = int(id.lstrip('i'))
-        try:
-            val = self.ifaces[id]
-        except:
-            raise InvalidRSpec("interface ID %s not found" % id)
-        return val
-    
-    def getIfaces(self):
-        ifaces = []
-        for i in self.ifaces:
-            ifaces.append(self.ifaces[i])
-        return ifaces
-    
-    def nodesWithSlivers(self):
-        nodes = []
-        for n in self.nodes:
-            node = self.nodes[n]
-            if node.sliver:
-                nodes.append(node)
-        return nodes
-            
-    def lookupSliceTag(self, id):
-        val = None
-        try:
-            val = self.tags[id]
-        except:
-            raise InvalidRSpec("slicetag ID %s not found" % id)
-        return val
-    
-    def getSliceTags(self):
-        tags = []
-        for t in self.tags:
-            tags.append(self.tags[t])
-        return tags
-    
-    def lookupTagType(self, name):
-        val = None
-        try:
-            val = self.tagtypes[name]
-        except:
-            raise InvalidRSpec("tag %s not found" % name)
-        return val
-    
-    def getTagTypes(self):
-        tags = []
-        for t in self.tagtypes:
-            tags.append(self.tagtypes[t])
-        return tags
-    
-    def __process_attributes(self, element, node=None):
-        """
-        Process the elements under <sliver_defaults> or <sliver>
-        """
-        if element is None:
-            return 
-
-        tagtypes = self.getTagTypes()
-        for tt in tagtypes:
-            if tt.in_rspec:
-                if tt.multi:
-                    for e in element.iterfind("./" + tt.tagname):
-                        self.slice.update_multi_tag(tt.tagname, e.text, node)
-                else:
-                    e = element.find("./" + tt.tagname)
-                    if e is not None:
-                        self.slice.update_tag(tt.tagname, e.text, node)
-
-    def addRSpec(self, xml, schema=None):
-        """
-        Annotate the objects in the Network with information from the RSpec
-        """
-        try:
-            tree = etree.parse(StringIO(xml))
-        except etree.XMLSyntaxError:
-            message = str(sys.exc_info()[1])
-            raise InvalidRSpec(message)
-
-        # Filter out stuff that's not for us
-        rspec = tree.getroot()
-        for network in rspec.iterfind("./network"):
-            if network.get("name") != self.api.hrn:
-                rspec.remove(network)
-        for request in rspec.iterfind("./request"):
-            if request.get("name") != self.api.hrn:
-                rspec.remove(request)
-
-        if schema:
-            # Validate the incoming request against the RelaxNG schema
-            relaxng_doc = etree.parse(schema)
-            relaxng = etree.RelaxNG(relaxng_doc)
-        
-            if not relaxng(tree):
-                error = relaxng.error_log.last_error
-                message = "%s (line %s)" % (error.message, error.line)
-                self.api.logger.error("failed to validate rspec %r"%message)
-                self.api.logger.debug("---------- XML input BEG")
-                self.api.logger.debug(xml)
-                self.api.logger.debug("---------- XML input END")
-                raise InvalidRSpec(message)
-
-        self.rspec = rspec
-
-        defaults = rspec.find(".//sliver_defaults")
-        self.__process_attributes(defaults)
-
-        # Find slivers under node elements
-        for sliver in rspec.iterfind("./network/site/node/sliver"):
-            elem = sliver.getparent()
-            try:
-                node = self.lookupNode(elem.get("id"))
-            except:
-                # Don't worry about nodes from other aggregates
-                pass
-            else:
-                node.add_sliver()
-                self.__process_attributes(sliver, node)
-
-        # Find slivers that specify nodeid
-        for sliver in rspec.iterfind("./request/sliver[@nodeid]"):
-            try:
-                node = self.lookupNode(sliver.get("nodeid"))
-            except:
-                # Don't worry about nodes from other aggregates
-                pass
-            else:
-                node.add_sliver()
-                self.__process_attributes(sliver, node)
-
-        return
-
-    def addSlice(self):
-        """
-        Annotate the objects in the Network with information from the slice
-        """
-        slice = self.slice
-        if not slice:
-            raise InvalidRSpec("no slice associated with network")
-
-        for node in slice.get_nodes():
-            node.add_sliver()
-
-    def updateSliceTags(self):
-        """
-        Write any slice tags that have been added or modified back to the DB
-        """
-        for tag in self.getSliceTags():
-            if tag.category == 'slice/rspec' and not tag.was_updated():
-                tt = self.lookupTagType(tag.tagname)
-                if tt.permit_update("user"):
-                    tag.delete()
-
-        # Update slice tags in database
-        for tag in self.getSliceTags():
-            if tag.slice_id == self.slice.id:
-                tag.write(self.api) 
-
-    def toxml(self):
-        """
-        Produce XML directly from the topology specification.
-        """
-        xml = XMLBuilder(format = True, tab_step = "  ")
-        with xml.RSpec(type=self.type):
-            if self.slice:
-                element = xml.network(name=self.api.hrn, slice=self.slice.hrn)
-            else:
-                element = xml.network(name=self.api.hrn)
-                
-            with element:
-                if self.slice:
-                    self.slice.toxml(xml)
-                for site in self.getSites():
-                    site.toxml(xml)
-
-        header = '<?xml version="1.0"?>\n'
-        return header + str(xml)
-
-    def get_sites(self, api):
-        """
-        Create a dictionary of site objects keyed by site ID
-        """
-        tmp = []
-        for site in api.driver.GetSites({'peer_id': None}):
-            t = site['site_id'], Site(self, site)
-            tmp.append(t)
-        return dict(tmp)
-
-
-    def get_nodes(self, api):
-        """
-        Create a dictionary of node objects keyed by node ID
-        """
-        tmp = []
-        for node in api.driver.GetNodes({'peer_id': None}):
-            try:
-                t = node['node_id'], Node(self, node)
-                tmp.append(t)
-            except:
-                self.api.logger.error("Failed to add node %s (%s) to RSpec" % (node['hostname'], node['node_id']))
-                 
-        return dict(tmp)
-
-    def get_ifaces(self, api):
-        """
-        Create a dictionary of node objects keyed by node ID
-        """
-        tmp = []
-        for iface in api.driver.GetInterfaces():
-            t = iface['interface_id'], Iface(self, iface)
-            tmp.append(t)
-        return dict(tmp)
-
-    def get_slice_tags(self, api):
-        """
-        Create a dictionary of slicetag objects keyed by slice tag ID
-        """
-        tmp = []
-        for tag in api.driver.GetSliceTags({'~tagname':Slicetag.ignore_tags}, Slicetag.filter_fields): 
-            t = tag['slice_tag_id'], Slicetag(tag)
-            tmp.append(t)
-        return dict(tmp)
-    
-    def get_tag_types(self, api):
-        """
-        Create a list of tagtype obects keyed by tag name
-        """
-        tmp = []
-        for tag in api.driver.GetTagTypes({'~tagname':TagType.ignore_tags}):
-            t = tag['tagname'], TagType(tag)
-            tmp.append(t)
-        return dict(tmp)
-    
-    def get_slice(self, api, hrn):
-        """
-        Return a Slice object for a single slice
-        """
-        slicename = hrn_to_pl_slicename(hrn)
-        slice = api.driver.GetSlices([slicename])
-        if len(slice):
-            self.slice = Slice(self, slicename, slice[0])
-            return self.slice
-        else:
-            return None
-    
-
index 863472f..972a97e 100644 (file)
@@ -30,9 +30,9 @@ class PlShell:
                        'AuthString': config.SFA_PLC_PASSWORD}
         
         self.url = config.SFA_PLC_URL
-        self.plauth = {'Username': 'root@test.onelab.eu',
-                       'AuthMethod': 'password',
-                       'AuthString': 'test++'}
+        #self.plauth = {'Username': 'root@test.onelab.eu',
+        #               'AuthMethod': 'password',
+        #               'AuthString': 'test++'}
         self.proxy_server = xmlrpclib.Server(self.url, verbose = 0, allow_none = True)
 
     def __getattr__(self, name):
index 027bb5b..6f75161 100644 (file)
@@ -1,8 +1,8 @@
 from sfa.rspecs.elements.element import Element
 
 class BWlimit(Element):
-    fields = { 
-        'units': None,
-        'value': None,
-    }
+    fields = [ 
+        'units',
+        'value',
+    ]
         
diff --git a/sfa/rspecs/elements/component_manager.py b/sfa/rspecs/elements/component_manager.py
deleted file mode 100644 (file)
index ec9d85c..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-from sfa.rspecs.elements.element import Element
-
-class ComponentManager(Element):
-    fields = {
-        'name': None,
-    }
-    
index 6757f8a..e185490 100644 (file)
@@ -2,8 +2,20 @@ class Element(dict):
 
     fields = {}
 
-    def __init__(self, fields={}, element=None):
+    def __init__(self, fields={}, element=None, keys=None):
         self.element = element
-        dict.__init__(self, self.fields) 
-        self.update(fields)
+        dict.__init__(self, dict.fromkeys(self.fields))
+        if not keys:
+            keys = fields.keys()
+        for key in keys:
+            if key in fields:
+                self[key] = fields[key] 
 
+
+    def __getattr__(self, name):
+        if hasattr(self, name):
+            return getattr(self, name)
+        elif hasattr(self.element, name):
+            return getattr(self.element, name)
+        else:
+            raise AttributeError, "class Element has not attribute %s" % name
index 43e6e62..e7ee706 100644 (file)
@@ -1,7 +1,7 @@
 from sfa.rspecs.elements.element import Element
 
 class Execute(Element):
-    fields = {
-        'shell': None,
-        'command': None,
-    }
+    fields = [
+        'shell',
+        'command',
+    ]
index 8dd959c..5f20c9b 100644 (file)
@@ -2,6 +2,6 @@ from sfa.rspecs.elements.element import Element
 
 class HardwareType(Element):
     
-    fields = {
-        'name': None,
-    }        
+    fields = [
+        'name'
+    ]        
index 1df60b6..227a797 100644 (file)
@@ -1,8 +1,8 @@
 from sfa.rspecs.elements.element import Element
  
 class Install(Element):
-    fields = {
-        'file_type': None,
-        'url': None,
-        'install_path': None,
-    }
+    fields = [
+        'file_type',
+        'url',
+        'install_path',
+    ]
index 7617ade..11045df 100644 (file)
@@ -1,12 +1,12 @@
 from sfa.rspecs.elements.element import Element
 
 class Interface(Element):
-    fields = {'component_id': None,
-              'role': None,
-              'client_id': None,
-              'ipv4': None,
-              'bwlimit': None,
-              'node_id': None,
-              'interface_id': None
-    
-    }    
+    fields = ['component_id',
+              'role',
+              'client_id',
+              'ipv4',
+              'bwlimit',
+              'node_id',
+              'interface_id',
+              'mac_address',  
+    ]    
index 02a8d10..3bbfe2b 100644 (file)
@@ -1,16 +1,16 @@
 from sfa.rspecs.elements.element import Element    
 
 class Link(Element):
-    fields = {
-        'client_id': None
-        'component_id': None,
-        'component_name': None,
-        'component_manager': None,
-        'type': None,
-        'interface1': None,
-        'interface2': None,
-        'capacity': None,
-        'latency': None,
-        'packet_loss': None,
-        'description': None,
-    }
+    fields = [
+        'client_id', 
+        'component_id',
+        'component_name',
+        'component_manager',
+        'type',
+        'interface1',
+        'interface2',
+        'capacity',
+        'latency',
+        'packet_loss',
+        'description',
+    ]
diff --git a/sfa/rspecs/elements/link_type.py b/sfa/rspecs/elements/link_type.py
deleted file mode 100644 (file)
index 882903d..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-from sfa.rspecs.elements.element import Element
-
-class LinkType(Element):
-    fields = {
-        'name': None,
-    } 
index a5a9260..57bfe0c 100644 (file)
@@ -2,8 +2,8 @@ from sfa.rspecs.elements.element import Element
 
 class Location(Element):
     
-    fields = {
-        'country': None,
-        'longitude': None,
-        'latitude': None,
-    }
+    fields = [
+        'country',
+        'longitude',
+        'latitude',
+    ]
index a64c759..ae42641 100644 (file)
@@ -1,8 +1,8 @@
 from sfa.rspecs.elements.element import Element
 
 class Login(Element):
-    fields = {
-        'authentication': None,
-        'hostname': None,
-        'port': None
-    }
+    fields = [
+        'authentication',
+        'hostname',
+        'port'
+    ]
diff --git a/sfa/rspecs/elements/network.py b/sfa/rspecs/elements/network.py
deleted file mode 100644 (file)
index 362b9ff..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-from sfa.rspecs.elements.element import Element
-class Network(Element):
-    
-    fields = {
-        'name': None,
-    }
-                
-      
index f90fff1..7358ee0 100644 (file)
@@ -2,25 +2,25 @@ from sfa.rspecs.elements.element import Element
  
 class Node(Element):
     
-    fields = {
-        'component_id': None,
-        'component_name': None,
-        'component_manager_id': None,
-        'client_id': None,
-        'sliver_id': None,
-        'authority_id': None,    
-        'exclusive': None,
-        'location': None,
-        'bw_unallocated': None,
-        'bw_limit': None,
-        'boot_state': None,    
-        'slivers': [],
-        'hardware_types': [],
-        'disk_images': [],
-        'interfaces': [],
-        'services': [],
-        'tags': [],
-        'pl_initscripts': [],
-    }
+    fields = [
+        'component_id',
+        'component_name',
+        'component_manager_id',
+        'client_id',
+        'sliver_id',
+        'authority_id',    
+        'exclusive',
+        'location',
+        'bw_unallocated',
+        'bw_limit',
+        'boot_state',    
+        'slivers',
+        'hardware_types',
+        'disk_images',
+        'interfaces',
+        'services',
+        'tags',
+        'pl_initscripts',
+    ]
                 
       
index 51b1e76..0868a94 100644 (file)
@@ -2,8 +2,8 @@ from sfa.rspecs.elements.element import Element
 
 class PLTag(Element):
 
-    fields = {
-        'name': None,
-        'value': None,
-    }
+    fields = [
+        'tagname',
+        'value',
+    ]
         
index 97a1ffc..472dede 100644 (file)
@@ -2,11 +2,11 @@ from sfa.rspecs.elements.element import Element
 
 class Property(Element):
     
-    fields = {
-        'source_id': None,
-        'dest_id': None,
-        'capacity': None,
-        'latency': None,
-        'packet_loss': None,
-    }
+    fields = [
+        'source_id',
+        'dest_id',
+        'capacity',
+        'latency',
+        'packet_loss',
+    ]
        
index a48be27..df0546d 100644 (file)
@@ -2,9 +2,9 @@ from sfa.rspecs.elements.element import Element
 
 class Services(Element):
 
-    fields = {
-        'install': [],
-        'execute': [],
-        'login': [],
-    }
+    fields = [
+        'install',
+        'execute',
+        'login',
+    ]
 
index bf2cc1f..8dd6542 100644 (file)
@@ -1,9 +1,11 @@
 from sfa.rspecs.elements.element import Element
 
 class Sliver(Element):
-    fields = {
-        'sliver_id': None,
-        'client_id': None,
-        'name': None,
-        'tags': [],
-    }
+    fields = [
+        'sliver_id',
+        'component_id',
+        'client_id',
+        'name',
+        'type',
+        'tags',
+    ]
diff --git a/sfa/rspecs/elements/tag.py b/sfa/rspecs/elements/tag.py
deleted file mode 100644 (file)
index 8b13789..0000000
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/sfa/rspecs/elements/versions/element_version.py b/sfa/rspecs/elements/versions/element_version.py
deleted file mode 100644 (file)
index e69de29..0000000
index db28f6c..65513d0 100644 (file)
@@ -1,81 +1,65 @@
-from lxml import etree
 from sfa.util.plxrn import PlXrn
 from sfa.util.xrn import Xrn
+from sfa.rspecs.elements.element import Element
 from sfa.rspecs.elements.link import Link
 from sfa.rspecs.elements.interface import Interface
-from sfa.rspecs.elements.link_type import LinkType
-from sfa.rspecs.elements.component_manager import ComponentManager
 from sfa.rspecs.elements.property import Property    
-from sfa.rspecs.rspec_elements import RSpecElement, RSpecElements
 
 class PGv2Link:
-    elements = {
-        'link': RSpecElement(RSpecElements.LINK, '//default:link | //link'),
-        'component_manager': RSpecElement(RSpecElements.COMPONENT_MANAGER, './default:component_manager | ./component_manager'),
-        'link_type': RSpecElement(RSpecElements.LINK_TYPE, './default:link_type | ./link_type'),
-        'property': RSpecElement(RSpecElements.PROPERTY, './default:property | ./property'),
-        'interface_ref': RSpecElement(RSpecElements.INTERFACE_REF, './default:interface_ref | ./interface_ref'), 
-    }
-    
     @staticmethod
     def add_links(xml, links):
         for link in links:
-            link_elem = etree.SubElement(xml, 'link')
-            for attrib in ['component_name', 'component_id', 'client_id']:
-                if attrib in link and link[attrib] is not None:
-                    link_elem.set(attrib, link[attrib])
+            
+            link_elem = xml.add_instance('link', link, ['component_name', 'component_id', 'client_id'])
+            # set component manager element            
             if 'component_manager' in link and link['component_manager']:
-                cm_element = etree.SubElement(link_elem, 'component_manager', name=link['component_manager'])
+                cm_element = link_elem.add_element('component_manager', name=link['component_manager'])
+            # set interface_ref elements
             for if_ref in [link['interface1'], link['interface2']]:
-                if_ref_elem = etree.SubElement(link_elem, 'interface_ref')
-                for attrib in Interface.fields:
-                    if attrib in if_ref and if_ref[attrib]:
-                        if_ref_elem.attrib[attrib] = if_ref[attrib]  
-            prop1 = etree.SubElement(link_elem, 'property', source_id = link['interface1']['component_id'],
+                link_elem.add_instance('interface_ref', if_ref, Interface.fields)
+            # set property elements
+            prop1 = link_elem.add_element('property', source_id = link['interface1']['component_id'],
                 dest_id = link['interface2']['component_id'], capacity=link['capacity'], 
                 latency=link['latency'], packet_loss=link['packet_loss'])
-            prop2 = etree.SubElement(link_elem, 'property', source_id = link['interface2']['component_id'],
+            prop2 = link_elem.add_element('property', source_id = link['interface2']['component_id'],
                 dest_id = link['interface1']['component_id'], capacity=link['capacity'], 
                 latency=link['latency'], packet_loss=link['packet_loss'])
-            if 'type' in link and link['type']:
-                type_elem = etree.SubElement(link_elem, 'link_type', name=link['type'])             
+            if link.get('type'):
+                type_elem = link_elem.add_element('link_type', name=link['type'])            
     @staticmethod 
     def get_links(xml):
         links = []
-        link_elems = xml.xpath(PGv2Link.elements['link'].path, namespaces=xml.namespaces)
+        link_elems = xml.xpath('//default:link | //link')
         for link_elem in link_elems:
             # set client_id, component_id, component_name
             link = Link(link_elem.attrib, link_elem)
+
             # set component manager
-            cm = link_elem.xpath('./default:component_manager', namespaces=xml.namespaces)
-            if len(cm) >  0:
-                cm = cm[0]
-                if  'name' in cm.attrib:
-                    link['component_manager'] = cm.attrib['name'] 
+            component_managers = link_elem.xpath('./default:component_manager | ./component_manager')
+            if len(component_managers) > 0 and 'name' in component_managers[0].attrib:
+                link['component_manager'] = component_managers[0].attrib['name']
+
             # set link type
-            link_types = link_elem.xpath(PGv2Link.elements['link_type'].path, namespaces=xml.namespaces)
-            if len(link_types) > 0:
-                link_type = link_types[0]
-                if 'name' in link_type.attrib:
-                    link['type'] = link_type.attrib['name']
+            link_types = link_elem.xpath('./default:link_type | ./link_type')
+            if len(link_types) > 0 and 'name' in link_types[0].attrib:
+                link['type'] = link_types[0].attrib['name']
           
             # get capacity, latency and packet_loss from first property  
-            props = link_elem.xpath(PGv2Link.elements['property'].path, namespaces=xml.namespaces)
-            if len(props) > 0:
-                prop = props[0]
+            property_fields = ['capacity', 'latency', 'packet_loss']
+            property_elems = link_elem.xpath('./default:property | ./property')
+            if len(propery_elems) > 0:
+                prop = property_elems[0]
                 for attrib in ['capacity', 'latency', 'packet_loss']:
-                    if attrib in prop.attrib:
-                        link[attrib] = prop.attrib[attrib]
+                    if attrib in prop:
+                        link[attrib] = prop[attrib]
                              
-            # get interfaces 
-            if_elems = link_elem.xpath(PGv2Link.elements['interface_ref'].path, namespaces=xml.namespaces)
-            ifs = []
-            for if_elem in if_elems:
-                if_ref = Interface(if_elem.attrib, if_elem)
-                ifs.append(if_ref)
-            if len(ifs) > 1:
-                link['interface1'] = ifs[0]
-                link['interface2'] = ifs[1] 
+            # get interfaces
+            iface_elems = link_elem.xpath('./default:interface_ref | ./interface_ref')
+            interfaces = [iface_elem.get_instance(Interface) for iface_elem in iface_elems]
+            if len(interfaces) > 1:
+                link['interface1'] = interfaces[0]
+                link['interface2'] = interfaces[1] 
             links.append(link)
         return links 
 
index b293b04..eb0518f 100644 (file)
-
-from lxml import etree
-from sfa.util.plxrn import PlXrn
+from sfa.util.plxrn import PlXrn, xrn_to_hostname
 from sfa.util.xrn import Xrn
+from sfa.util.xml import XpathFilter
 from sfa.rspecs.elements.node import Node
 from sfa.rspecs.elements.sliver import Sliver
-from sfa.rspecs.elements.network import Network
 from sfa.rspecs.elements.location import Location
 from sfa.rspecs.elements.hardware_type import HardwareType
 from sfa.rspecs.elements.disk_image import DiskImage
 from sfa.rspecs.elements.interface import Interface
 from sfa.rspecs.elements.bwlimit import BWlimit
 from sfa.rspecs.elements.pltag import PLTag
-from sfa.rspecs.rspec_elements import RSpecElement, RSpecElements
-from sfa.rspecs.elements.versions.pgv2Service import PGv2Service     
+from sfa.rspecs.elements.versions.pgv2Services import PGv2Services     
+from sfa.rspecs.elements.versions.pgv2SliverType import PGv2SliverType     
 
 class PGv2Node:
-    elements = {
-        'node': RSpecElement(RSpecElements.NODE, '//default:node | //node'),
-        'sliver': RSpecElement(RSpecElements.SLIVER, './default:sliver_type | ./sliver_type'),
-        'interface': RSpecElement(RSpecElements.INTERFACE, './default:interface | ./interface'),
-        'location': RSpecElement(RSpecElements.LOCATION, './default:location | ./location'),
-        'hardware_type': RSpecElement(RSpecElements.HARDWARE_TYPE, './default:hardware_type | ./hardware_type'),
-        'available': RSpecElement(RSpecElements.AVAILABLE, './default:available | ./available'),
-    } 
-    
     @staticmethod
     def add_nodes(xml, nodes):
         node_elems = []
         for node in nodes:
-            node_elem = etree.SubElement(xml, 'node')
+            node_fields = ['component_manager_id', 'component_id', 'client_id', 'sliver_id', 'exclusive']
+            node_elem = xml.add_instance('node', node, node_fields)
             node_elems.append(node_elem)
-            if node.get('component_manager_id'):
-                node_elem.set('component_manager_id', node['component_manager_id'])
+            # set component name
             if node.get('component_id'):
-                node_elem.set('component_id', node['component_id'])
-                component_name = Xrn(node['component_id']).get_leaf()
-                node_elem.set('component_nama', component_name)
-            if node.get('client_id'):
-                node_elem.set('client_id', node['client_id'])
-            if node.get('sliver_id'):
-                node_elem.set('sliver_id', node['sliver_id'])
-            if node.get('exclusive'):
-                node_elem.set('exclusive', node['exclusive'])
-            hardware_types = node.get('hardware_type', [])
-            for hardware_type in hardware_types:
-                hw_type_elem = etree.SubElement(node_elem, 'hardware_type')
-                if hardware_type.get('name'):
-                    hw_type_elem.set('name', hardware_type['name'])
+                component_name = xrn_to_hostname(node['component_id'])
+                node_elem.set('component_name', component_name)
+            # set hardware types
+            for hardware_type in node.get('hardware_types', []): 
+                node_elem.add_instance('hardware_type', hardware_type, HardwareType.fields)
+            # set location
+            if node.get('location'):
+                node_elem.add_instance('location', node['location'], Location.fields)       
+            # set interfaces
+            for interface in  node.get('interfaces', []):
+                node_elem.add_instance('interface', interface, ['component_id', 'client_id', 'ipv4'])
+            # set available element
             if node.get('boot_state', '').lower() == 'boot':
-                available_elem = etree.SubElement(node_elem, 'available', now='True')
+                available_elem = node_elem.add_element('available', now='True')
             else:
-                available_elem = etree.SubElement(node_elem, 'available', now='False')
-            
-            if node.get('services'):
-                PGv2Services.add_services(node_elem, node.get('services'))
-    
+                available_elem = node_elem.add_element('available', now='False')
+            # add services
+            PGv2Services.add_services(node_elem, node.get('services', [])) 
+            # add slivers
             slivers = node.get('slivers', [])
-            pl_initscripts = node.get('pl_initscripts', {})
-            for sliver in slivers:
-                sliver_elem = etree.SubElement(node_elem, 'sliver_type')
-                if sliver.get('name'):
-                    sliver_elem.set('name', sliver['name'])
-                if sliver.get('client_id'):
-                    sliver_elem.set('client_id', sliver['client_id'])      
-                for pl_initscript in pl_initscripts.values():
-                    etree.SubElement(sliver_elem, '{%s}initscript' % xml.namespaces['planetlab'], \
-                      name=pl_initscript['name'])
-            location = node.get('location')
-            #only add locaiton if long and lat are not null
-            if location.get('longitute') and location.get('latitude'):
-                location_elem = etree.SubElement(node_elem, country=location['country'],
-                  latitude=location['latitude'], longitude=location['longiutde'])
+            if not slivers:
+                # we must still advertise the available sliver types
+                slivers = Sliver({'type': 'plab-vserver'})
+                # we must also advertise the available initscripts
+                slivers['tags'] = []
+                for initscript in node.get('pl_initscripts', []):
+                    slivers['tags'].append({'name': 'initscript', 'value': initscript['name']})
+            PGv2SliverType.add_slivers(node_elem, slivers)
+        
         return node_elems
 
     @staticmethod
-    def get_nodes(xml):
+    def get_nodes(xml, filter={}):
+        xpath = '//node%s | //default:node%s' % (XpathFilter.xpath(filter), XpathFilter.xpath(filter))
+        node_elems = xml.xpath(xpath)
+        return PGv2Node.get_node_objs(node_elems)
+
+    @staticmethod
+    def get_nodes_with_slivers(xml, filter={}):
+        xpath = '//node[count(sliver_type)>0] | //default:node[count(default:sliver_type) > 0]' 
+        node_elems = xml.xpath(xpath)        
+        return PGv2Node.get_node_objs(node_elems)
+
+    @staticmethod
+    def get_node_objs(node_elems):
         nodes = []
-        node_elems = xml.xpath(PGv2Node.elements['node'].path)
         for node_elem in node_elems:
             node = Node(node_elem.attrib, node_elem)
             nodes.append(node) 
             if 'component_id' in node_elem.attrib:
                 node['authority_id'] = Xrn(node_elem.attrib['component_id']).get_authority_urn()
-
-            # set hardware type
-            node['hardware_types'] = []
-            hardware_type_elems = node_elem.xpath(PGv2Node.elements['hardware_type'].path, xml.namespaces)
-            for hardware_type_elem in hardware_type_elems:
-                node['hardware_types'].append(HardwareType(hardware_type_elem.attrib, hardware_type_elem))
             
-            # set location
-            location_elems = node_elem.xpath(PGv2Node.elements['location'].path, xml.namespaces)
-            if len(location_elems) > 0:
-                node['location'] = Location(location_elems[0].attrib, location_elems[0])
+            # get hardware types
+            hardware_type_elems = node_elem.xpath('./default:hardwate_type | ./hardware_type')
+            node['hardware_types'] = [hw_type.get_instnace(HardwareType) for hw_type in hardware_type_elems]
             
-            # set services
-            services_elems = node_elem.xpath(PGv2Service.elements['services'].path, xml.namespaces)
-            node['services'] = []
-            for services_elem in services_elems:
-                # services element has no useful info, but the child elements do  
-                for child in services_elem.iterchildren():
-                    pass
-                    
-            # set interfaces
-            interface_elems = node_elem.xpath(PGv2Node.elements['interface'].path, xml.namespaces)
-            node['interfaces'] = []
-            for interface_elem in interface_elems:
-                node['interfaces'].append(Interface(interface_elem.attrib, interface_elem))
+            # get location
+            location_elems = node_elem.xpath('./default:location | ./location')
+            locations = [location_elem.get_instance(Location) for location_elem in location_elems]
+            if len(locations) > 0:
+                node['location'] = locations[0]
 
-            # set available
-            available = node_elem.xpath(PGv2Node.elements['available'].path, xml.namespaces)
-            if len(available) > 0:
-                if available[0].attrib.get('now', '').lower() == 'true': 
+            # get interfaces
+            iface_elems = node_elem.xpath('./default:interface | ./interface')
+            node['interfaces'] = [iface_elem.get_instance(Interface) for iface_elem in iface_elems]
+
+            # get services
+            node['services'] = PGv2Services.get_services(node_elem)
+            
+            # get slivers
+            node['slivers'] = PGv2SliverType.get_slivers(node_elem)    
+            available_elems = node_elem.xpath('./default:available | ./available')
+            if len(available_elems) > 0 and 'name' in available_elems[0].attrib:
+                if available_elems[0].attrib.get('now', '').lower() == 'true': 
                     node['boot_state'] = 'boot'
                 else: 
                     node['boot_state'] = 'disabled' 
-
-            # set the slivers
-            sliver_elems = node_elem.xpath(PGv2Node.elements['sliver'].path, xml.namespaces)
-            node['slivers'] = []
-            for sliver_elem in sliver_elems:
-                node['slivers'].append(Sliver(sliver_elem.attrib, sliver_elem))            
-
         return nodes
 
 
     @staticmethod
     def add_slivers(xml, slivers):
-        pass
-   
-    @staticmethod
-    def get_nodes_with_slivers(xml):
-        nodes = PGv2Node.get_nodes(xml)
-        nodes_with_slivers = [node for node in nodes if node['slivers']]
-        return nodes_with_slivers 
+        component_ids = []
+        for sliver in slivers:
+            filter = {}
+            if isinstance(sliver, str):
+                filter['component_id'] = '*%s*' % sliver
+                sliver = {}
+            elif 'component_id' in sliver and sliver['component_id']:
+                filter['component_id'] = '*%s*' % sliver['component_id']
+            if not filter: 
+                continue
+            nodes = PGv2Node.get_nodes(xml, filter)
+            if not nodes:
+                continue
+            node = nodes[0]
+            PGv2SliverType.add_slivers(node, sliver)
 
+    @staticmethod
+    def remove_slivers(xml, hostnames):
+        for hostname in hostnames:
+            nodes = PGv2Node.get_nodes(xml, {'component_id': '*%s*' % hostname})
+            for node in nodes:
+                slivers = PGv2SliverType.get_slivers(node.element)
+                for sliver in slivers:
+                    node.element.remove(sliver.element) 
 if __name__ == '__main__':
     from sfa.rspecs.rspec import RSpec
     import pdb
index fe946b3..7cffc91 100644 (file)
@@ -1,65 +1,42 @@
-from lxml import etree
-from sfa.util.plxrn import PlXrn
-from sfa.util.xrn import Xrn
+from sfa.rspecs.elements.element import Element  
 from sfa.rspecs.elements.execute import Execute  
 from sfa.rspecs.elements.install import Install  
 from sfa.rspecs.elements.login import Login
-from sfa.rspecs.rspec_elements import RSpecElement, RSpecElements
 
 class PGv2Services:
-    elements = {
-        'services': RSpecElement(RSpecElements.SERVICES, '//default:services | //services'),
-        'install': RSpecElement(RSpecElements.INSTALL, './default:install | ./install'),
-        'execute': RSpecElement(RSpecElements.EXECUTE, './default:execute | ./execute'),
-        'login': RSpecElement(RSpecElements.LOGIN, './default:login | ./login'),
-    }  
-    
     @staticmethod
     def add_services(xml, services):
+        if not services:
+            return 
         for service in services:
-            service_elem = etree.SubElement(xml, 'service')
-            for install in service.get('install', []):
-                install_elem = etree.SubElement(service_elem, 'install')
-                for field in Install.fields:
-                    if field in install:
-                        install_elem.set(field, install[field])
-            for execute in service.get('execute', []):
-                execute_elem = etree.SubElement(service_elem, 'execute')
-                for field in Execute.fields:
-                    if field in execute:
-                        execute_elem.set(field, execute[field])
-            for login in service.get('login', []):
-                login_elem = etree.SubElement(service_elem, 'login')
-                for field in Login.fields:
-                    if field in login:
-                        login_elem.set(field, login[field]) 
-
+            service_elem = xml.add_element('services')
+            child_elements = {'install': Install.fields,
+                              'execute': Execute.fields,
+                              'login': Login.fields}
+            for (name, fields) in child_elements.items():
+                child = service.get(name)
+                if not child: 
+                    continue
+                if isinstance(child, dict):
+                    service_elem.add_instance(name, child, fields)
+                elif isinstance(child, list):
+                    for obj in child:
+                        service_elem.add_instance(name, obj, fields)
               
     @staticmethod
     def get_services(xml):
         services = []
-        for services_elem in xml.xpath(PGv2Services.elements['services'].path):
+        for services_elem in xml.xpath('./default:services | ./services'):
             service = Services(services_elem.attrib, services_elem)
-            
-            # get install elements
-            service['install'] = []
-            for install_elem in xml.xpath(PGv2Services.elements['install'].path):
-                install = Install(install_elem.attrib, install_elem)
-                service['install'].append(install)
-            
-            # get execute elements
-            service['execute'] = []
-            for execute_elem in xml.xpath(PGv2Services.elements['execute'].path):
-                execute = Execute(execute_elem.attrib, execute_elem)
-                service['execute'].append(execute)
-
-            # get login elements
-            service['login'] = []
-            for login_elem in xml.xpath(PGv2Services.elements['login'].path):
-                login = Login(login_elem.attrib, login_elem)
-                service['login'].append(login)             
-
+            # get install 
+            install_elems = xml.xpath('./default:install | ./install')
+            service['install'] = [install_elem.get_instance(Install) for install_elem in install_elems]
+            # get execute
+            execute_elems = xml.xpath('./default:execute | ./execute')
+            service['execute'] = [execute_elem.get_instance(Execute) for execute_elem in execute_elems]
+            # get login
+            login_elems = xml.xpath('./default:login | ./login')
+            service['login'] = [login_elem.get_instance(Login) for login_elem in login_elems]
             services.append(service)  
         return services
 
index e69de29..4271d21 100644 (file)
@@ -0,0 +1,40 @@
+from sfa.rspecs.elements.element import Element
+from sfa.rspecs.elements.sliver import Sliver
+
+class PGv2SliverType:
+
+    @staticmethod
+    def add_slivers(xml, slivers):
+        if not slivers:
+            return 
+        if not isinstance(slivers, list):
+            slivers = [slivers]
+        for sliver in slivers: 
+            sliver_elem = xml.add_instance('sliver_type', sliver, ['type', 'client_id'])
+            PGv2SliverType.add_sliver_attributes(sliver_elem, sliver.get('pl_tags', []))
+    
+    @staticmethod
+    def add_sliver_attributes(xml, attributes):
+        for attribute in attributes:
+            if attribute['name'] == 'initscript':
+                xml.add_element('{%s}initscript' % xml.namespaces['planetlab'], name=attribute['value'])
+            elif tag['tagname'] == 'flack_info':
+                attrib_elem = xml.add_element('{%s}info' % self.namespaces['flack'])
+                attrib_dict = eval(tag['value'])
+                for (key, value) in attrib_dict.items():
+                    attrib_elem.set(key, value)                
+    @staticmethod
+    def get_slivers(xml, filter={}):
+        xpath = './default:sliver_type | ./sliver_type'
+        sliver_elems = xml.xpath(xpath)
+        slivers = []
+        for sliver_elem in sliver_elems:
+            sliver = Sliver(sliver_elem.attrib,sliver_elem)
+            if 'component_id' in xml.attrib:     
+                sliver['component_id'] = xml.attrib['component_id']
+            slivers.append(sliver)
+        return slivers
+
+    @staticmethod
+    def get_sliver_attributes(xml, filter={}):
+        return []             
diff --git a/sfa/rspecs/elements/versions/sfav1Network.py b/sfa/rspecs/elements/versions/sfav1Network.py
deleted file mode 100644 (file)
index b529ad5..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-from lxml import etree
-from sfa.util.plxrn import PlXrn
-from sfa.util.xrn import Xrn
-from sfa.rspecs.rspec_elements import RSpecElement, RSpecElements
-
-class SFAv1Network:
-    elements = {
-        'network': RSpecElement(RSpecElements.NETWORK, '//network'),
-    }
-
-    @staticmethod
-    def add_network(xml, network):
-        found = False
-        network_objs = SFAv1Network.get_networks(xml)
-        for network_obj in network_objs:
-            if network_obj['name'] == network['name']:
-                found = True
-                network_elem = network_obj.element
-        if not found:
-            network_elem = etree.SubElement(xml, 'network', name = network['name'])
-        return network_elem  
-    
-    @staticmethod
-    def get_networks(xml):
-        networks = []
-        network_elems = xml.xpath(SFAv1Network.elements['network'].path)
-        for network_elem in network_elems:
-            network = Network({'name': network_elem.attrib.get('name', None)}, network_elem)
-            networks.append(network)
-        return networks
index 0b67c91..4e129e6 100644 (file)
-
-from lxml import etree
-from sfa.util.plxrn import PlXrn
+from sfa.util.sfalogging import logger
+from sfa.util.xml import XpathFilter
+from sfa.util.plxrn import PlXrn, xrn_to_hostname
 from sfa.util.xrn import Xrn
+from sfa.rspecs.elements.element import Element
 from sfa.rspecs.elements.node import Node
 from sfa.rspecs.elements.sliver import Sliver
-from sfa.rspecs.elements.network import Network 
 from sfa.rspecs.elements.location import Location
 from sfa.rspecs.elements.hardware_type import HardwareType
 from sfa.rspecs.elements.disk_image import DiskImage
 from sfa.rspecs.elements.interface import Interface
 from sfa.rspecs.elements.bwlimit import BWlimit
 from sfa.rspecs.elements.pltag import PLTag
-from sfa.rspecs.rspec_elements import RSpecElement, RSpecElements
-from sfa.rspecs.elements.versions.sfav1Network import SFAv1Network
+from sfa.rspecs.elements.versions.sfav1Sliver import SFAv1Sliver
+from sfa.rspecs.elements.versions.sfav1PLTag import SFAv1PLTag
 from sfa.rspecs.elements.versions.pgv2Services import PGv2Services
 
 class SFAv1Node:
 
-    elements = {
-        'node': RSpecElement(RSpecElements.NODE, '//default:node | //node'),
-        'sliver': RSpecElement(RSpecElements.SLIVER, './default:sliver | ./sliver'),
-        'interface': RSpecElement(RSpecElements.INTERFACE, './default:interface | ./interface'),
-        'location': RSpecElement(RSpecElements.LOCATION, './default:location | ./location'),
-        'bw_limit': RSpecElement(RSpecElements.BWLIMIT, './default:bw_limit | ./bw_limit'),
-    }
-    
     @staticmethod
     def add_nodes(xml, nodes):
-        network_elems = SFAv1Network.get_networks(xml)
+        network_elems = xml.xpath('//network')
         if len(network_elems) > 0:
             network_elem = network_elems[0]
         elif len(nodes) > 0 and nodes[0].get('component_manager_id'):
-            network_elem = SFAv1Network.add_network(xml.root, {'name': nodes[0]['component_manager_id']})
-            
+            network_urn = nodes[0]['component_manager_id']
+            network_elem = xml.add_element('network', name = Xrn(network_urn).get_hrn())     
+        else:
+            network_elem = xml
 
         node_elems = []       
         for node in nodes:
-            node_elem = etree.SubElement(network_elem, 'node')
+            node_fields = ['component_manager_id', 'component_id', 'boot_state']
+            node_elem = network_elem.add_instance('node', node, node_fields)
             node_elems.append(node_elem)
-            network = None 
+
+            # determine network hrn
+            network_hrn = None 
             if 'component_manager_id' in node and node['component_manager_id']:
-                node_elem.set('component_manager_id', node['component_manager_id'])
-                network = Xrn(node['component_manager_id']).get_hrn()
+                network_hrn = Xrn(node['component_manager_id']).get_hrn()
+
+            # set component_name attribute and  hostname element
             if 'component_id' in node and node['component_id']:
-                node_elem.set('component_id', node['component_id'])
-                xrn = Xrn(node['component_id'])
-                node_elem.set('component_name', xrn.get_leaf())
-                hostname_tag = etree.SubElement(node_elem, 'hostname').text = xrn.get_leaf()
+                component_name = xrn_to_hostname(node['component_id'])
+                node_elem.set('component_name', component_name)
+                hostname_elem = node_elem.add_element('hostname')
+                hostname_elem.set_text(component_name)
+
+            # set site id
             if 'authority_id' in node and node['authority_id']:
                 node_elem.set('site_id', node['authority_id'])
-            if 'boot_state' in node and node['boot_state']:
-                node_elem.set('boot_state', node['boot_state'])
-            if 'location' in node and node['location']:
-                location_elem = etree.SubElement(node_elem, 'location')
-                for field in Location.fields:
-                    if field in node['location'] and node['location'][field]:
-                        location_elem.set(field, node['location'][field])
-            if 'interfaces' in node and node['interfaces']:
-                i = 0
-                for interface in node['interfaces']:
-                    if 'bwlimit' in interface and interface['bwlimit']:
-                        bwlimit = etree.SubElement(node_elem, 'bw_limit', units='kbps').text = str(interface['bwlimit']/1000)
-                    comp_id = PlXrn(auth=network, interface='node%s:eth%s' % (interface['node_id'], i)).get_urn()
-                    ipaddr = interface['ipv4']
-                    interface_elem = etree.SubElement(node_elem, 'interface', component_id=comp_id, ipv4=ipaddr)
-                    i+=1
-            if 'bw_unallocated' in node and node['bw_unallocated']:
-                bw_unallocated = etree.SubElement(node_elem, 'bw_unallocated', units='kbps').text = str(int(node['bw_unallocated'])/1000)
 
-            if node.get('services'):
-                PGv2Services.add_services(node_elem, node.get('services'))
+            # add locaiton
+            location = node.get('location')
+            if location:
+                node_elem.add_instance('location', location, Location.fields)
 
-            if 'tags' in node:
-                for tag in node['tags']:
-                   # expose this hard wired list of tags, plus the ones that are marked 'sfa' in their category
-                   if tag['name'] in ['fcdistro', 'arch']:
-                        tag_element = etree.SubElement(node_elem, tag['name']).text=tag['value']
+            for interface in node.get('interfaces', []):
+                node_elem.add_instance('interface', interface, ['component_id', 'client_id', 'ipv4']) 
+            
+            #if 'bw_unallocated' in node and node['bw_unallocated']:
+            #    bw_unallocated = etree.SubElement(node_elem, 'bw_unallocated', units='kbps').text = str(int(node['bw_unallocated'])/1000)
 
-            if node.get('slivers'):
-                for sliver in node['slivers']:
-                    sliver_elem = etree.SubElement(node_elem, 'sliver')
-                    if sliver.get('sliver_id'): 
-                        sliver_id_leaf = Xrn(sliver.get('sliver_id')).get_leaf()
-                        sliver_id_parts = sliver_id_leaf.split(':')
-                        name = sliver_id_parts[0] 
-                        sliver_elem.set('name', name) 
+            PGv2Services.add_services(node_elem, node.get('services', []))
+            for tag in node.get('tags', []):
+                tag_elem = node_elem.add_element(tag['tagname'])
+                tag_elem.set_text(tag['value'])
+            SFAv1Sliver.add_slivers(node_elem, node.get('slivers', []))
 
     @staticmethod 
     def add_slivers(xml, slivers):
-        pass
+        component_ids = []
+        for sliver in slivers:
+            filter = {}
+            if isinstance(sliver, str):
+                filter['component_id'] = '*%s*' % sliver
+                sliver = {}
+            elif 'component_id' in sliver and sliver['component_id']:
+                filter['component_id'] = '*%s*' % sliver['component_id']
+            if not filter:
+                continue 
+            nodes = SFAv1Node.get_nodes(xml, filter)
+            if not nodes:
+                continue
+            node = nodes[0]
+            SFAv1Sliver.add_slivers(node, sliver)
+
+    @staticmethod
+    def remove_slivers(xml, hostnames):
+        for hostname in hostnames:
+            nodes = SFAv1Node.get_nodes(xml, {'component_id': '*%s*' % hostname})
+            for node in nodes:
+                slivers = SFAv1Slivers.get_slivers(node.element)
+                for sliver in slivers:
+                    node.element.remove(sliver.element)
+        
+    @staticmethod
+    def get_nodes(xml, filter={}):
+        xpath = '//node%s | //default:node%s' % (XpathFilter.xpath(filter), XpathFilter.xpath(filter))
+        node_elems = xml.xpath(xpath)
+        return SFAv1Node.get_node_objs(node_elems)
+
+    @staticmethod
+    def get_nodes_with_slivers(xml):
+        xpath = '//node[count(sliver)>0] | //default:node[count(default:sliver)>0]' 
+        node_elems = xml.xpath(xpath)
+        return SFAv1Node.get_node_objs(node_elems)
+
 
     @staticmethod
-    def get_nodes(xml):
-        nodes = []
-        node_elems = xml.xpath(SFAv1Node.elements['node'].path)
+    def get_node_objs(node_elems):
+        nodes = []    
         for node_elem in node_elems:
             node = Node(node_elem.attrib, node_elem)
             if 'site_id' in node_elem.attrib:
                 node['authority_id'] = node_elem.attrib['site_id']
-            if 'authority_id' in node_elem.attrib:
-                node['authority_id'] = node_elem.attrib['authority_id']
-            # set the location
-            location_elems = node_elem.xpath(SFAv1Node.elements['location'].path, xml.namespaces)
-            if len(location_elems) > 0:
-                node['location'] = Location(location_elems[0].attrib, location_elems[0])
-            
-            # set the bwlimit
-            bwlimit_elems = node_elem.xpath(SFAv1Node.elements['bw_limit'].path, xml.namespaces)
-            if len(bwlimit_elems) > 0:
-                bwlimit = BWlimit(bwlimit_elems[0].attrib, bwlimit_elems[0])
-                node['bwlimit'] = bwlimit
-
-            # set the interfaces
-            interface_elems = node_elem.xpath(SFAv1Node.elements['interface'].path, xml.namespaces)
-            node['interfaces'] = []
-            for interface_elem in interface_elems:
-                node['interfaces'].append(Interface(interface_elem.attrib, interface_elem))
-            
-            # set the slivers
-            sliver_elems = node_elem.xpath(SFAv1Node.elements['sliver'].path, xml.namespaces)
-            node['slivers'] = []
-            for sliver_elem in sliver_elems:
-                node['slivers'].append(Sliver(sliver_elem.attrib, sliver_elem))
-            
-            # set tags
-            node['tags'] = [] 
-            for child in node_elem.iterchildren():
-                if child.tag not in SFAv1Node.elements:
-                    tag = PLTag({'name': child.tag, 'value': child.text}, child)  
-                    node['tags'].append(tag) 
+            # get location
+            location_elems = node_elem.xpath('./default:location | ./location')
+            locations = [loc_elem.get_instance(Location) for loc_elem in location_elems]  
+            if len(locations) > 0:
+                node['location'] = locations[0]
+            # get bwlimit
+            bwlimit_elems = node_elem.xpath('./default:bw_limit | ./bw_limit')
+            bwlimits = [bwlimit_elem.get_instance(BWlimit) for bwlimit_elem in bwlimit_elems]
+            if len(bwlimits) > 0:
+                node['bwlimit'] = bwlimits[0]
+            # get interfaces
+            iface_elems = node_elem.xpath('./default:interface | ./interface')
+            ifaces = [iface_elem.get_instance(Interface) for iface_elem in iface_elems]
+            node['interfaces'] = ifaces
+            # get services
+            node['services'] = PGv2Services.get_services(node_elem) 
+            # get slivers
+            node['slivers'] = SFAv1Sliver.get_slivers(node_elem)
+            # get tags
+            node['tags'] =  SFAv1PLTag.get_pl_tags(node_elem, ignore=Node.fields)
             nodes.append(node)
-        return nodes
-        
-    @staticmethod
-    def get_nodes_with_slivers(xml):
-        nodes = SFAv1Node.get_nodes(xml)
-        nodes_with_slivers = [node for node in nodes if node['slivers']]
-        return nodes_with_slivers
-    
-             
+        return nodes            
+            
diff --git a/sfa/rspecs/elements/versions/sfav1PLTag.py b/sfa/rspecs/elements/versions/sfav1PLTag.py
new file mode 100644 (file)
index 0000000..a17d502
--- /dev/null
@@ -0,0 +1,19 @@
+from sfa.rspecs.elements.element import Element  
+from sfa.rspecs.elements.pltag import PLTag
+
+class SFAv1PLTag:
+    @staticmethod
+    def add_pl_tag(xml, name, value):
+        for pl_tag in pl_tags:
+            pl_tag_elem = xml.add_element(name)
+            pl_tag_elem.set_text(value)
+              
+    @staticmethod
+    def get_pl_tags(xml, ignore=[]):
+        pl_tags = []
+        for elem in xml.iterchildren():
+            if elem.tag not in ignore:
+                pl_tag = PLTag({'tagname': elem.tag, 'value': elem.text})
+                pl_tags.append(pl_tag)    
+        return pl_tags
+
index f12c977..d1519e9 100644 (file)
@@ -1,18 +1,54 @@
-
-from lxml import etree
-
+from sfa.util.xrn import Xrn
+from sfa.util.xml import XmlElement
+from sfa.rspecs.elements.element import Element
 from sfa.rspecs.elements.sliver import Sliver
+from sfa.rspecs.elements.versions.sfav1PLTag import SFAv1PLTag
 
-from sfa.util.xrn import Xrn
-from sfa.util.plxrn import PlXrn
 class SFAv1Sliver:
 
     @staticmethod
     def add_slivers(xml, slivers):
+        if not slivers:
+            return
+        if not isinstance(slivers, list):
+            slivers = [slivers]
         for sliver in slivers:
-            sliver_elem = etree.SubElement(xml, 'sliver')
-            if sliver.get('component_id'):
-                name_full = Xrn(sliver.get('component_id')).get_leaf()
-                name = name_full.split(':')
+            sliver_elem = xml.add_instance('sliver', sliver, ['name'])
+            for tag in sliver.get('tags', []):
+                SFAv1Sliver.add_sliver_attribute(sliver_elem, tag['tagname'], tag['value'])
+            if sliver.get('sliver_id'):
+                sliver_id_leaf = Xrn(sliver.get('sliver_id')).get_leaf()
+                sliver_id_parts = sliver_id_leaf.split(':')
+                name = sliver_id_parts[0]
                 sliver_elem.set('name', name)
-                     
+
+    @staticmethod
+    def add_sliver_attribute(xml, name, value):
+        elem = xml.add_element(name)
+        elem.set_text(value)
+    
+    @staticmethod
+    def get_sliver_attributes(xml):
+        attribs = []
+        for elem in xml.iterchildren():
+            if elem.tag not in Sliver.fields:
+                xml_element = XmlElement(elem, xml.namespaces)
+                instance = Element(xml_element)
+                instance['name'] = elem.tag
+                instance['value'] = elem.text
+                attribs.append(instance)
+        return attribs 
+                
+    @staticmethod
+    def get_slivers(xml, filter={}):
+        xpath = './default:sliver | ./sliver'
+        sliver_elems = xml.xpath(xpath)
+        slivers = []
+        for sliver_elem in sliver_elems:
+            sliver = Sliver(sliver_elem.attrib,sliver_elem)
+            if 'component_id' in xml.attrib:     
+                sliver['component_id'] = xml.attrib['component_id']
+            sliver['tags'] = SFAv1Sliver.get_sliver_attributes(sliver_elem)
+            slivers.append(sliver)
+        return slivers           
+
index f53ec6f..27eba93 100644 (file)
@@ -1,6 +1,6 @@
 import os
 from sfa.util.faults import InvalidRSpec
-from sfa.rspecs.rspec_version import BaseVersion 
+from sfa.rspecs.baseversion import BaseVersion 
 from sfa.util.sfalogging import logger    
 
 class VersionManager:
index b57cd9b..60387dc 100644 (file)
@@ -1,11 +1,11 @@
-from lxml import etree
 from copy import deepcopy
 from StringIO import StringIO
-from sfa.util.xrn import urn_to_sliver_id
+from sfa.util.xrn import Xrn, urn_to_sliver_id
 from sfa.util.plxrn import hostname_to_urn, xrn_to_hostname 
-from sfa.rspecs.rspec_version import BaseVersion
-from sfa.rspecs.rspec_elements import RSpecElement, RSpecElements
+from sfa.rspecs.baseversion import BaseVersion
 from sfa.rspecs.elements.versions.pgv2Link import PGv2Link
+from sfa.rspecs.elements.versions.pgv2Node import PGv2Node
+from sfa.rspecs.elements.versions.pgv2SliverType import PGv2SliverType
  
 class PGv2(BaseVersion):
     type = 'ProtoGENI'
@@ -18,58 +18,49 @@ class PGv2(BaseVersion):
         'planetlab': "http://www.planet-lab.org/resources/sfa/ext/planetlab/1",
     }
     namespaces = dict(extensions.items() + [('default', namespace)])
-    elements = []
-
-    def get_network(self):
-        network = None
-        nodes = self.xml.xpath('//default:node[@component_manager_id][1]', namespaces=self.namespaces)
-        if nodes:
-            network  = nodes[0].get('component_manager_id')
-        return network
 
+    # Networks    
     def get_networks(self):
-        networks = self.xml.xpath('//default:node[@component_manager_id]/@component_manager_id', namespaces=self.namespaces)
-        return set(networks)
-
-    def get_node_element(self, hostname, network=None):
-        nodes = self.xml.xpath('//default:node[@component_id[contains(., "%s")]] | node[@component_id[contains(., "%s")]]' % (hostname, hostname), namespaces=self.namespaces)
-        if isinstance(nodes,list) and nodes:
-            return nodes[0]
-        else:
-            return None
+        networks = set()
+        nodes = self.xml.xpath('//default:node[@component_manager_id]', namespaces=self.namespaces)
+        for node in nodes: 
+            if 'component_manager_id' in node:
+                network_urn  = node.get('component_manager_id')
+                network_hrn = Xrn(network_urn).get_hrn()[0]
+                networks.add({'name': network_hrn})
+        return list(networks)
 
-    def get_node_elements(self, network=None):
-        nodes = self.xml.xpath('//default:node | //node', namespaces=self.namespaces)
-        return nodes
+    # Nodes
 
+    def get_nodes(self, filter=None):
+        return PGv2Node.get_nodes(self.xml, filter)
 
-    def get_nodes(self, network=None):
-        xpath = '//default:node[@component_name]/@component_id | //node[@component_name]/@component_id'
-        nodes = self.xml.xpath(xpath, namespaces=self.namespaces)
-        nodes = [xrn_to_hostname(node) for node in nodes]
-        return nodes
+    def get_nodes_with_slivers(self):
+        return PGv2Node.get_nodes_with_slivers(self.xml)
 
-    def get_nodes_with_slivers(self, network=None):
-        if network:
-            nodes = self.xml.xpath('//default:node[@component_manager_id="%s"][sliver_type]/@component_id' % network, namespaces=self.namespaces)
-        else:
-            nodes = self.xml.xpath('//default:node[default:sliver_type]/@component_id', namespaces=self.namespaces)
-        nodes = [xrn_to_hostname(node) for node in nodes]
-        return nodes
-
-    def get_nodes_without_slivers(self, network=None):
-        return []
+    def add_nodes(self, nodes, check_for_dupes=False):
+        return PGv2Node.add_nodes(self.xml, nodes)
+    
+    def merge_node(self, source_node_tag):
+        # this is untested
+        self.xml.root.append(deepcopy(source_node_tag))
 
+    # Slivers
+    
     def get_sliver_attributes(self, hostname, network=None):
-        node = self.get_node_element(hostname, network)
-        sliver = node.xpath('./default:sliver_type', namespaces=self.namespaces)
-        if sliver is not None and isinstance(sliver, list):
-            sliver = sliver[0]
-        return self.attributes_list(sliver)
+        nodes = self.get_nodes({'component_id': '*%s*' %hostname})
+        attribs = []
+        if nodes is not None and isinstance(nodes, list) and len(nodes) > 0:
+            node = nodes[0]
+            sliver = node.xpath('./default:sliver_type', namespaces=self.namespaces)
+            if sliver is not None and isinstance(sliver, list) and len(sliver) > 0:
+                sliver = sliver[0]
+                #attribs = self.attributes_list(sliver)
+        return attribs
 
     def get_slice_attributes(self, network=None):
         slice_attributes = []
-        nodes_with_slivers = self.get_nodes_with_slivers(network)
+        nodes_with_slivers = self.get_nodes_with_slivers()
         # TODO: default sliver attributes in the PG rspec?
         default_ns_prefix = self.namespaces['default']
         for node in nodes_with_slivers:
@@ -92,18 +83,6 @@ class PGv2(BaseVersion):
 
         return slice_attributes
 
-    def get_links(self, network=None):
-        return PGv2Link.get_links(self.xml)
-
-    def get_link_requests(self):
-        return PGv2Link.get_link_requests(self.xml)  
-
-    def add_links(self, links):
-        PGv2Link.add_links(self.xml.root, links)
-
-    def add_link_requests(self, link_tuples, append=False):
-        PGv2Link.add_link_requests(self.xml.root, link_tuples, append)
-
     def attributes_list(self, elem):
         opts = []
         if elem is not None:
@@ -117,115 +96,70 @@ class PGv2(BaseVersion):
     def add_default_sliver_attribute(self, name, value, network=None):
         pass
 
-    def add_nodes(self, nodes, check_for_dupes=False):
-        if not isinstance(nodes, list):
-            nodes = [nodes]
-        for node in nodes:
-            urn = ""
-            if check_for_dupes and \
-              self.xml.xpath('//default:node[@component_uuid="%s"]' % urn, namespaces=self.namespaces):
-                # node already exists
-                continue
-
-            node_tag = etree.SubElement(self.xml.root, 'node', exclusive='false')
-            if 'network_urn' in node:
-                node_tag.set('component_manager_id', node['network_urn'])
-            if 'urn' in node:
-                node_tag.set('component_id', node['urn'])
-            if 'hostname' in node:
-                node_tag.set('component_name', node['hostname'])
-            # TODO: should replace plab-pc with pc model
-            node_type_tag = etree.SubElement(node_tag, 'hardware_type', name='plab-pc')
-            node_type_tag = etree.SubElement(node_tag, 'hardware_type', name='pc')
-            available_tag = etree.SubElement(node_tag, 'available', now='true')
-            sliver_type_tag = etree.SubElement(node_tag, 'sliver_type', name='plab-vserver')
-
-            pl_initscripts = node.get('pl_initscripts', {})
-            for pl_initscript in pl_initscripts.values():
-                etree.SubElement(sliver_type_tag, '{%s}initscript' % self.namespaces['planetlab'], name=pl_initscript['name'])
-
-            # protogeni uses the <sliver_type> tag to identify the types of
-            # vms available at the node.
-            # only add location tag if longitude and latitude are not null
-            if 'site' in node:
-                longitude = node['site'].get('longitude', None)
-                latitude = node['site'].get('latitude', None)
-                if longitude and latitude:
-                    location_tag = etree.SubElement(node_tag, 'location', country="us", \
-                                                    longitude=str(longitude), latitude=str(latitude))
-
-    def merge_node(self, source_node_tag):
-        # this is untested
-        self.xml.root.append(deepcopy(source_node_tag))
-
-    def add_slivers(self, slivers, sliver_urn=None, no_dupes=False, append=False):
-
+    def add_slivers(self, hostnames, attributes=[], sliver_urn=None, append=False):
         # all nodes hould already be present in the rspec. Remove all
         # nodes that done have slivers
-        slivers_dict = {}
-        for sliver in slivers:
-            if isinstance(sliver, basestring):
-                slivers_dict[sliver] = {'hostname': sliver}
-            elif isinstance(sliver, dict):
-                slivers_dict[sliver['hostname']] = sliver        
+        for hostname in hostnames:
+            node_elems = self.get_nodes({'component_id': '*%s*' % hostname})
+            if not node_elems:
+                continue
+            node_elem = node_elems[0]
+            
+            # determine sliver types for this node
+            valid_sliver_types = ['emulab-openvz', 'raw-pc', 'plab-vserver', 'plab-vnode']
+            requested_sliver_type = None
+            for sliver_type in node_elem.get('slivers', []):
+                if sliver_type.get('type') in valid_sliver_types:
+                    requested_sliver_type = sliver_type['type']
+            
+            if not requested_sliver_type:
+                continue
+            sliver = {'name': requested_sliver_type,
+                     'pl_tags': attributes}
+
+            # remove existing sliver_type tags
+            for sliver_type in node_elem.get('slivers', []):
+                node_elem.element.remove(sliver_type.element)
+
+            # set the client id
+            node_elem.element.set('client_id', hostname)
+            if sliver_urn:
+                pass
+                # TODO
+                # set the sliver id
+                #slice_id = sliver_info.get('slice_id', -1)
+                #node_id = sliver_info.get('node_id', -1)
+                #sliver_id = urn_to_sliver_id(sliver_urn, slice_id, node_id)
+                #node_elem.set('sliver_id', sliver_id)
+
+            # add the sliver type elemnt    
+            PGv2SliverType.add_slivers(node_elem.element, sliver)         
+
+        # remove all nodes without slivers
+        if not append:
+            for node_elem in self.get_nodes():
+                if not node_elem['client_id']:
+                    parent = node_elem.element.getparent()
+                    parent.remove(node_elem.element)
 
-        nodes = self.get_node_elements()
-        for node in nodes:
-            urn = node.get('component_id')
-            hostname = xrn_to_hostname(urn)
-            if hostname not in slivers_dict and not append:
-                parent = node.getparent()
-                parent.remove(node)
-            else:
-                sliver_info = slivers_dict[hostname]
-                sliver_type_elements = node.xpath('./default:sliver_type', namespaces=self.namespaces)
-                available_sliver_types = [element.attrib['name'] for element in sliver_type_elements]
-                valid_sliver_types = ['emulab-openvz', 'raw-pc', 'plab-vserver', 'plab-vnode']
-                requested_sliver_type = None
-                for valid_sliver_type in valid_sliver_types:
-                    if valid_sliver_type in available_sliver_types:
-                        requested_sliver_type = valid_sliver_type
-                if requested_sliver_type:
-                    # remove existing sliver_type tags,it needs to be recreated
-                    sliver_elem = node.xpath('./default:sliver_type | ./sliver_type', namespaces=self.namespaces)
-                    if sliver_elem and isinstance(sliver_elem, list):
-                        sliver_elem = sliver_elem[0]
-                        node.remove(sliver_elem)
-                    # set the client id
-                    node.set('client_id', hostname)
-                    if sliver_urn:
-                        # set the sliver id
-                        slice_id = sliver_info.get('slice_id', -1)
-                        node_id = sliver_info.get('node_id', -1)
-                        sliver_id = urn_to_sliver_id(sliver_urn, slice_id, node_id)
-                        node.set('sliver_id', sliver_id)
+    def remove_slivers(self, slivers, network=None, no_dupes=False):
+        PGv2Node.remove_slivers(self.xml, slivers) 
 
-                    # add the sliver element
-                    sliver_elem = etree.SubElement(node, 'sliver_type', name=requested_sliver_type)
-                    for tag in sliver_info.get('tags', []):
-                        if tag['tagname'] == 'flack_info':
-                            e = etree.SubElement(sliver_elem, '{%s}info' % self.namespaces['flack'], attrib=eval(tag['value']))
-                        elif tag['tagname'] == 'initscript':
-                            e = etree.SubElement(sliver_elem, '{%s}initscript' % self.namespaces['planetlab'], attrib={'name': tag['value']})                
-                else:
-                    # node isn't usable. just remove it from the request     
-                    parent = node.getparent()
-                    parent.remove(node)
+    # Links
 
-    
+    def get_links(self, network=None):
+        return PGv2Link.get_links(self.xml)
 
-    def remove_slivers(self, slivers, network=None, no_dupes=False):
-        for sliver in slivers:
-            node_elem = self.get_node_element(sliver['hostname'])
-            sliver_elem = node_elem.xpath('./default:sliver_type', self.namespaces)
-            if sliver_elem != None and sliver_elem != []:
-                node_elem.remove(sliver_elem[0])
+    def get_link_requests(self):
+        return PGv2Link.get_link_requests(self.xml)  
 
-    def add_default_sliver_attribute(self, name, value, network=None):
-        pass
+    def add_links(self, links):
+        PGv2Link.add_links(self.xml.root, links)
 
-    def add_interfaces(self, interfaces, no_dupes=False):
-        pass
+    def add_link_requests(self, link_tuples, append=False):
+        PGv2Link.add_link_requests(self.xml.root, link_tuples, append)
+
+    # Utility
 
     def merge(self, in_rspec):
         """
@@ -235,9 +169,9 @@ class PGv2(BaseVersion):
         # just copy over all the child elements under the root element
         if isinstance(in_rspec, RSpec):
             in_rspec = in_rspec.toxml()
-        tree = etree.parse(StringIO(in_rspec))
-        root = tree.getroot()
-        for child in root.getchildren():
+        
+        rspec = RSpec(in_rspec)
+        for child in rspec.xml.iterchildren():
             self.xml.root.append(child)
 
     def cleanup(self):
index 3917b39..d954f62 100644 (file)
@@ -1,10 +1,14 @@
 from copy import deepcopy
 from lxml import etree
+
+from sfa.util.sfalogging import logger
 from sfa.util.xrn import hrn_to_urn, urn_to_hrn
 from sfa.util.plxrn import PlXrn
-from sfa.rspecs.rspec_version import BaseVersion
-from sfa.rspecs.rspec_elements import RSpecElement, RSpecElements
+from sfa.rspecs.baseversion import BaseVersion
+from sfa.rspecs.elements.element import Element
 from sfa.rspecs.elements.versions.pgv2Link import PGv2Link
+from sfa.rspecs.elements.versions.sfav1Node import SFAv1Node
+from sfa.rspecs.elements.versions.sfav1Sliver import SFAv1Sliver
 
 class SFAv1(BaseVersion):
     enabled = True
@@ -15,225 +19,35 @@ class SFAv1(BaseVersion):
     namespace = None
     extensions = {}
     namespaces = None
-    elements = [] 
     template = '<RSpec type="%s"></RSpec>' % type
 
-    def get_network_elements(self):
-        return self.xml.xpath('//network')
-
+    # Network 
     def get_networks(self):
-        return self.xml.xpath('//network[@name]/@name')
-
-    def get_node_element(self, hostname, network=None):
-        if network:
-            names = self.xml.xpath('//network[@name="%s"]//node/hostname' % network)
-        else:
-            names = self.xml.xpath('//node/hostname')
-        for name in names:
-            if str(name.text).strip() == hostname:
-                return name.getparent()
-        return None
-
-    def get_node_elements(self, network=None):
-        if network:
-            return self.xml.xpath('//network[@name="%s"]//node' % network)
-        else:
-            return self.xml.xpath('//node')
-
-    def get_nodes(self, network=None):
-        if network == None:
-            nodes = self.xml.xpath('//node/hostname/text()')
-        else:
-            nodes = self.xml.xpath('//network[@name="%s"]//node/hostname/text()' % network)
-
-        nodes = [node.strip() for node in nodes]
-        return nodes
-
-    def get_nodes_with_slivers(self, network = None):
-        if network:
-            nodes =  self.xml.xpath('//network[@name="%s"]//node[sliver]/hostname/text()' % network)  
-        else:
-            nodes = self.xml.xpath('//node[sliver]/hostname/text()')
-
-        nodes = [node.strip() for node in nodes]
-        return nodes
-
-    def get_nodes_without_slivers(self, network=None):
-        xpath_nodes_without_slivers = '//node[not(sliver)]/hostname/text()'
-        xpath_nodes_without_slivers_in_network = '//network[@name="%s"]//node[not(sliver)]/hostname/text()'
-        if network:
-            return self.xml.xpath('//network[@name="%s"]//node[not(sliver)]/hostname/text()' % network)
-        else:
-            return self.xml.xpath('//node[not(sliver)]/hostname/text()')
-
-    def attributes_list(self, elem):
-        # convert a list of attribute tags into list of tuples
-        # (tagnme, text_value)
-        opts = []
-        if elem is not None:
-            for e in elem:
-                opts.append((e.tag, str(e.text).strip()))
-        return opts
-
-    def get_default_sliver_attributes(self, network=None):
-        if network:
-            defaults = self.xml.xpath("//network[@name='%s']/sliver_defaults" % network)
-        else:
-            defaults = self.xml.xpath("//sliver_defaults")
-        if isinstance(defaults, list) and defaults:
-            defaults = defaults[0]
-        return self.attributes_list(defaults)
-
-    def get_sliver_attributes(self, hostname, network=None):
-        attributes = []
-        node = self.get_node_element(hostname, network)
-        #sliver = node.find("sliver")
-        slivers = node.xpath('./sliver')
-        if isinstance(slivers, list) and slivers:
-            attributes = self.attributes_list(slivers[0])
-        return attributes
-
-    def get_slice_attributes(self, network=None):
-        slice_attributes = []
-        nodes_with_slivers = self.get_nodes_with_slivers(network)
-        for default_attribute in self.get_default_sliver_attributes(network):
-            attribute = {'name': str(default_attribute[0]), 'value': str(default_attribute[1]), 'node_id': None}
-            slice_attributes.append(attribute)
-        for node in nodes_with_slivers:
-            sliver_attributes = self.get_sliver_attributes(node, network)
-            for sliver_attribute in sliver_attributes:
-                attribute = {'name': str(sliver_attribute[0]), 'value': str(sliver_attribute[1]), 'node_id': node}
-                slice_attributes.append(attribute)
-        return slice_attributes
-
-    def get_site_nodes(self, siteid, network=None):
-        if network:
-            nodes = self.xml.xpath('//network[@name="%s"]/site[@id="%s"]/node/hostname/text()' % \
-                                    (network, siteid))
-        else:
-            nodes = self.xml.xpath('//site[@id="%s"]/node/hostname/text()' % siteid)
-        return nodes
-
-    def get_links(self, network=None):
-        return PGv2Link.get_links(self.xml)
-
-    def get_link_requests(self):
-        return PGv2Link.get_link_requests(self.xml) 
-
-    def get_link(self, fromnode, tonode, network=None):
-        fromsite = fromnode.getparent()
-        tosite = tonode.getparent()
-        fromid = fromsite.get("id")
-        toid = tosite.get("id")
-        if network:
-            query = "//network[@name='%s']" % network + "/link[@endpoints = '%s %s']"
-        else:
-            query = "//link[@endpoints = '%s %s']"
-
-        results = self.rspec.xpath(query % (fromid, toid))
-        if not results:
-            results = self.rspec.xpath(query % (toid, fromid))
-        return results
-
-    def query_links(self, fromnode, tonode, network=None):
-        return get_link(fromnode, tonode, network)
-
-    def get_vlinks(self, network=None):
-        vlinklist = []
-        if network:
-            vlinks = self.xml.xpath("//network[@name='%s']//vlink" % network)
-        else:
-            vlinks = self.xml.xpath("//vlink")
-        for vlink in vlinks:
-            endpoints = vlink.get("endpoints")
-            (end1, end2) = endpoints.split()
-            if network:
-                node1 = self.xml.xpath('//network[@name="%s"]//node[@id="%s"]/hostname/text()' % \
-                                       (network, end1))[0]
-                node2 = self.xml.xpath('//network[@name="%s"]//node[@id="%s"]/hostname/text()' % \
-                                       (network, end2))[0]
-            else:
-                node1 = self.xml.xpath('//node[@id="%s"]/hostname/text()' % end1)[0]
-                node2 = self.xml.xpath('//node[@id="%s"]/hostname/text()' % end2)[0]
-            desc = "%s <--> %s" % (node1, node2)
-            kbps = vlink.find("kbps")
-            vlinklist.append((endpoints, desc, kbps.text))
-        return vlinklist
-
-    def get_vlink(self, endponts, network=None):
-        if network:
-            query = "//network[@name='%s']//vlink[@endpoints = '%s']" % (network, endpoints)
-        else:
-            query = "//vlink[@endpoints = '%s']" % (network, endpoints)
-        results = self.rspec.xpath(query)
-        return results
+        network_elems = self.xml.xpath('//network')
+        networks = [network_elem.get_instance(fields=['name', 'slice']) for \
+                    network_elem in network_elems]
+        return networks    
 
-    def query_vlinks(self, endpoints, network=None):
-        return get_vlink(endpoints,network)
-
-    
-    ##################
-    # Builder
-    ##################
 
     def add_network(self, network):
         network_tags = self.xml.xpath('//network[@name="%s"]' % network)
         if not network_tags:
-            network_tag = etree.SubElement(self.xml.root, 'network', name=network)
+            network_tag = self.xml.add_element('network', name=network)
         else:
             network_tag = network_tags[0]
         return network_tag
 
-    def add_nodes(self, nodes, network = None, no_dupes=False):
-        if not isinstance(nodes, list):
-            nodes = [nodes]
-        for node in nodes:
-            if no_dupes and \
-              self.get_node_element(node['hostname']):
-                # node already exists
-                continue
 
-            network_tag = self.xml.root
-            if 'network' in node:
-                network = node['network']
-                network_tag = self.add_network(network)
-
-            node_tag = etree.SubElement(network_tag, 'node')
-            if 'network' in node:
-                node_tag.set('component_manager_id', hrn_to_urn(network, 'authority+sa'))
-            if 'urn' in node:
-                node_tag.set('component_id', node['urn'])
-            if 'site_urn' in node:
-                node_tag.set('site_id', node['site_urn'])
-            if 'node_id' in node:
-                node_tag.set('node_id', 'n'+str(node['node_id']))
-            if 'boot_state' in node:
-                node_tag.set('boot_state', node['boot_state'])
-            if 'hostname' in node:
-                node_tag.set('component_name', node['hostname']) 
-                hostname_tag = etree.SubElement(node_tag, 'hostname').text = node['hostname']
-            if 'interfaces' in node:
-                i = 0
-                for interface in node['interfaces']:
-                    if 'bwlimit' in interface and interface['bwlimit']:
-                        bwlimit = etree.SubElement(node_tag, 'bw_limit', units='kbps').text = str(interface['bwlimit']/1000)
-                    comp_id = PlXrn(auth=network, interface='node%s:eth%s' % (node['node_id'], i)).get_urn() 
-                    ipaddr = interface['ip'] 
-                    interface_tag = etree.SubElement(node_tag, 'interface', component_id=comp_id, ipv4=ipaddr)
-                    i+=1
-            if 'bw_unallocated' in node:
-                bw_unallocated = etree.SubElement(node_tag, 'bw_unallocated', units='kbps').text = str(node['bw_unallocated']/1000) 
-            if 'tags' in node:
-                for tag in node['tags']:
-                   # expose this hard wired list of tags, plus the ones that are marked 'sfa' in their category
-                   if tag['tagname'] in ['fcdistro', 'arch'] or 'sfa' in tag['category'].split('/'):
-                        tag_element = etree.SubElement(node_tag, tag['tagname']).text=tag['value']
-
-            if 'site' in node:
-                longitude = str(node['site']['longitude'])
-                latitude = str(node['site']['latitude'])
-                location = etree.SubElement(node_tag, 'location', country='unknown', \
-                                            longitude=longitude, latitude=latitude)
+    # Nodes
+    
+    def get_nodes(self, filter=None):
+        return SFAv1Node.get_nodes(self.xml, filter)
+
+    def get_nodes_with_slivers(self):
+        return SFAv1Node.get_nodes_with_slivers(self.xml)
+
+    def add_nodes(self, nodes, network = None, no_dupes=False):
+        SFAv1Node.add_nodes(self.xml, nodes)
 
     def merge_node(self, source_node_tag, network, no_dupes=False):
         if no_dupes and self.get_node_element(node['hostname']):
@@ -243,53 +57,78 @@ class SFAv1(BaseVersion):
         network_tag = self.add_network(network)
         network_tag.append(deepcopy(source_node_tag))
 
-    def add_interfaces(self, interfaces):
-        pass
-
-    def add_links(self, links):
-        networks = self.get_network_elements()
-        if len(networks) > 0:
-            xml = networks[0]
-        else:
-            xml = self.xml    
-        PGv2Link.add_links(xml, links)
-
-    def add_link_requests(self, links):
-        PGv2Link.add_link_requests(self.xml, links)
-
-    def add_slivers(self, slivers, network=None, sliver_urn=None, no_dupes=False, append=False):
+    # Slivers
+   
+    def add_slivers(self, hostnames, attributes=[], sliver_urn=None, append=False):
         # add slice name to network tag
         network_tags = self.xml.xpath('//network')
         if network_tags:
             network_tag = network_tags[0]
             network_tag.set('slice', urn_to_hrn(sliver_urn)[0])
-        
-        all_nodes = self.get_nodes()
-        nodes_with_slivers = [sliver['hostname'] for sliver in slivers]
-        nodes_without_slivers = set(all_nodes).difference(nodes_with_slivers)
-        
+
         # add slivers
-        for sliver in slivers:
-            node_elem = self.get_node_element(sliver['hostname'], network)
-            if not node_elem: continue
-            sliver_elem = etree.SubElement(node_elem, 'sliver')
-            if 'tags' in sliver:
-                for tag in sliver['tags']:
-                    etree.SubElement(sliver_elem, tag['tagname']).text = value=tag['value']
-            
+        sliver = {'name':sliver_urn,
+                  'pl_tags': attributes}
+        for hostname in hostnames:
+            if sliver_urn:
+                sliver['name'] = sliver_urn
+            node_elems = self.get_nodes({'component_id': '*%s*' % hostname})
+            if not node_elems:
+                continue
+            node_elem = node_elems[0]
+            SFAv1Sliver.add_slivers(node_elem.element, sliver)
+
         # remove all nodes without slivers
         if not append:
-            for node in nodes_without_slivers:
-                node_elem = self.get_node_element(node)
-                parent = node_elem.getparent()
-                parent.remove(node_elem)
+            for node_elem in self.get_nodes():
+                if not node_elem['slivers']:
+                    parent = node_elem.element.getparent()
+                    parent.remove(node_elem.element)
+
 
     def remove_slivers(self, slivers, network=None, no_dupes=False):
-        for sliver in slivers:
-            node_elem = self.get_node_element(sliver['hostname'], network)
-            sliver_elem = node_elem.find('sliver')
-            if sliver_elem != None:
-                node_elem.remove(sliver_elem)
+        SFAv1Node.remove_slivers(self.xml, slivers)
+    def get_slice_attributes(self, network=None):
+        attributes = []
+        nodes_with_slivers = self.get_nodes_with_slivers()
+        for default_attribute in self.get_default_sliver_attributes(network):
+            attribute['node_id'] = None
+            attributes.append(attribute)
+        for node in nodes_with_slivers:
+            nodename=node['component_name']
+            sliver_attributes = self.get_sliver_attributes(nodename, network)
+            for sliver_attribute in sliver_attributes:
+                sliver_attribute['node_id'] = nodename
+                attributes.append(attribute)
+        return attributes
+
+
+    def add_sliver_attribute(self, hostname, name, value, network=None):
+        nodes = self.get_nodes({'component_id': '*%s*' % hostname})
+        if not nodes:
+            node = nodes[0]
+            slivers = SFAv1Sliver.get_slivers(node)
+            if slivers:
+                sliver = slivers[0]
+                SFAv1Sliver.add_attribute(sliver, name, value)
+
+    def get_sliver_attributes(self, hostname, network=None):
+        nodes = self.get_nodes({'component_id': '*%s*' %hostname})
+        attribs = []
+        if nodes is not None and isinstance(nodes, list) and len(nodes) > 0:
+            node = nodes[0]
+            slivers = SFAv1Sliver.get_slivers(node.element)
+            if slivers is not None and isinstance(slivers, list) and len(slivers) > 0:
+                sliver = slivers[0]
+                attribs = SFAv1Sliver.get_sliver_attributes(sliver.element)
+        return attribs
+
+    def remove_sliver_attribute(self, hostname, name, value, network=None):
+        attribs = self.get_sliver_attributes(hostname)
+        for attrib in attribs:
+            if attrib['name'] == name and attrib['value'] == value:
+                attrib.element.delete()
 
     def add_default_sliver_attribute(self, name, value, network=None):
         if network:
@@ -300,46 +139,49 @@ class SFAv1(BaseVersion):
             network_tag = self.xml.xpath("//network[@name='%s']" % network)
             if isinstance(network_tag, list):
                 network_tag = network_tag[0]
-            defaults = self.xml.add_element('sliver_defaults', attrs={}, parent=network_tag)
+            defaults = network_tag.add_element('sliver_defaults')
         elif isinstance(defaults, list):
             defaults = defaults[0]
-        self.xml.add_attribute(defaults, name, value)
-
-    def add_sliver_attribute(self, hostname, name, value, network=None):
-        node = self.get_node_element(hostname, network)
-        sliver = node.find("sliver")
-        self.xml.add_attribute(sliver, name, value)
+        Sfav1Sliver.add_sliver_attribute(defaults, name, value)
 
+    def get_default_sliver_attributes(self, network=None):
+        if network:
+            defaults = self.xml.xpath("//network[@name='%s']/sliver_defaults" % network)
+        else:
+            defaults = self.xml.xpath("//sliver_defaults")
+        if not defaults: return []
+        return Sfav1Sliver.get_sliver_attributes(defaults)
+    
     def remove_default_sliver_attribute(self, name, value, network=None):
         if network:
             defaults = self.xml.xpath("//network[@name='%s']/sliver_defaults" % network)
         else:
             defaults = self.xml.xpath("//sliver_defaults" % network)
-        self.xml.remove_attribute(defaults, name, value)
+        attribs = Sfav1Sliver.get_sliver_attributes(defaults)
+        for attrib in attribs:
+            if attrib['name'] == name and attrib['value'] == value:
+                attrib.element.delete()    
 
-    def remove_sliver_attribute(self, hostname, name, value, network=None):
-        node = self.get_node_element(hostname, network)
-        sliver = node.find("sliver")
-        self.xml.remove_attribute(sliver, name, value)
+    # Links
 
-    def add_vlink(self, fromhost, tohost, kbps, network=None):
-        fromnode = self.get_node_element(fromhost, network)
-        tonode = self.get_node_element(tohost, network)
-        links = self.get_link(fromnode, tonode, network)
+    def get_links(self, network=None):
+        return PGv2Link.get_links(self.xml)
 
-        for link in links:
-            vlink = etree.SubElement(link, "vlink")
-            fromid = fromnode.get("id")
-            toid = tonode.get("id")
-            vlink.set("endpoints", "%s %s" % (fromid, toid))
-            self.xml.add_attribute(vlink, "kbps", kbps)
+    def get_link_requests(self):
+        return PGv2Link.get_link_requests(self.xml) 
 
+    def add_links(self, links):
+        networks = self.get_networks()
+        if len(networks) > 0:
+            xml = networks[0].element
+        else:
+            xml = self.xml
+        PGv2Link.add_links(xml, links)
 
-    def remove_vlink(self, endpoints, network=None):
-        vlinks = self.query_vlinks(endpoints, network)
-        for vlink in vlinks:
-            vlink.getparent().remove(vlink)
+    def add_link_requests(self, links):
+        PGv2Link.add_link_requests(self.xml, links)
 
+    # utility
 
     def merge(self, in_rspec):
         """
@@ -358,11 +200,11 @@ class SFAv1(BaseVersion):
 
         # just copy over all networks
         current_networks = self.get_networks()
-        networks = rspec.version.get_network_elements()
+        networks = rspec.version.get_networks()
         for network in networks:
             current_network = network.get('name')
             if current_network and current_network not in current_networks:
-                self.xml.root.append(network)
+                self.xml.append(network.element)
                 current_networks.append(current_network)
 
 if __name__ == '__main__':
index 16f358e..ed1ee30 100755 (executable)
@@ -78,9 +78,9 @@ def clean_key_cred():
             os.unlink(f)
    
     # install the new key pair
-    # get_credential will take care of generating the new keypair
+    # GetCredential will take care of generating the new keypair
     # and credential 
-    get_credential()
+    GetCredential()
     
              
 def get_node_key(registry=None, verbose=False):
@@ -113,7 +113,7 @@ def create_server_keypair(keyfile=None, certfile=None, hrn="component", verbose=
     cert.save_to_file(certfile, save_parents=True)       
 
 @handle_gid_mismatch_exception
-def get_credential(registry=None, force=False, verbose=False):
+def GetCredential(registry=None, force=False, verbose=False):
     config = Config()
     hierarchy = Hierarchy()
     key_dir= hierarchy.basedir
@@ -169,7 +169,7 @@ def get_trusted_certs(registry=None, verbose=False):
     node_gid = GID(filename=node_gid_file)
     hrn = node_gid.get_hrn()
     # get credential
-    cred = get_credential(registry=registry, verbose=verbose)
+    cred = GetCredential(registry=registry, verbose=verbose)
     # make sure server key cert pair exists
     create_server_keypair(keyfile=keyfile, certfile=certfile, hrn=hrn, verbose=verbose)
     registry = server_proxy(url=registry, keyfile=keyfile, certfile=certfile)
@@ -214,7 +214,7 @@ def get_gids(registry=None, verbose=False):
     hrn = node_gid.get_hrn()
     interface_hrn = config.SFA_INTERFACE_HRN
     # get credential
-    cred = get_credential(registry=registry, verbose=verbose)
+    cred = GetCredential(registry=registry, verbose=verbose)
     # make sure server key cert pair exists
     create_server_keypair(keyfile=keyfile, certfile=certfile, hrn=hrn, verbose=verbose)
     registry = server_proxy(url=registry, keyfile=keyfile, certfile=certfile)
index 456cd42..f182ee0 100644 (file)
@@ -151,7 +151,8 @@ class XmlrpcApi:
         try:
             result = self.call(source, method, *args)
         except SfaFault, fault:
-            result = fault 
+            result = fault
+            self.logger.log_exc("XmlrpcApi.handle has caught Exception") 
         except Exception, fault:
             self.logger.log_exc("XmlrpcApi.handle has caught Exception")
             result = SfaAPIError(fault)
index 11cc566..c5c6a55 100644 (file)
@@ -1,6 +1,7 @@
 from types import StringTypes
 import dateutil.parser
 import datetime
+import time
 
 from sfa.util.sfalogging import logger
 
@@ -24,3 +25,5 @@ For safety this can also handle inputs that are either timestamps, or datetimes
     else:
         logger.error("Unexpected type in utcparse [%s]"%type(input))
 
+def epochparse(input):
+    return time.strftime("%Y-%d-%m-T%H:%M:%SZ", time.localtime(input)) 
index bd7eb18..79482f1 100644 (file)
@@ -13,8 +13,7 @@ class Topology(set):
     Parse the topology configuration file. 
     """
 
-    #def __init__(self, config_file = "/etc/sfa/topology"):
-    def __init__(self, config_file = "/tmp/topology"):
+    def __init__(self, config_file = "/etc/sfa/topology"):
         set.__init__(self) 
         self.config_file = None
         self.config_path = None
old mode 100644 (file)
new mode 100755 (executable)
index bb298a3..1a7f2f3
@@ -3,7 +3,9 @@ from types import StringTypes
 from lxml import etree
 from StringIO import StringIO
 from sfa.util.faults import InvalidXML
+from sfa.rspecs.elements.element import Element
 
+# helper functions to help build xpaths
 class XpathFilter:
     @staticmethod
 
@@ -37,32 +39,76 @@ class XpathFilter:
                 xpath = '[' + xpath + ']'
         return xpath
 
-class XmlNode:
-    def __init__(self, node, namespaces):
-        self.node = node
-        self.text = node.text
+# a wrapper class around lxml.etree._Element
+# the reason why we need this one is because of the limitations
+# we've found in xpath to address documents with multiple namespaces defined
+# in a nutshell, we deal with xml documents that have
+# a default namespace defined (xmlns="http://default.com/") and specific prefixes defined
+# (xmlns:foo="http://foo.com")
+# according to the documentation instead of writing
+# element.xpath ( "//node/foo:subnode" ) 
+# we'd then need to write xpaths like
+# element.xpath ( "//{http://default.com/}node/{http://foo.com}subnode" ) 
+# which is a real pain..
+# So just so we can keep some reasonable programming style we need to manage the
+# namespace map that goes with the _Element (its internal .nsmap being unmutable)
+
+class XmlElement:
+    def __init__(self, element, namespaces):
+        self.element = element
         self.namespaces = namespaces
-        self.attrib = node.attrib
         
-
+    # redefine as few methods as possible
     def xpath(self, xpath, namespaces=None):
         if not namespaces:
             namespaces = self.namespaces 
-        elems = self.node.xpath(xpath, namespaces=namespaces)
-        return [XmlNode(elem, namespaces) for elem in elems]
+        elems = self.element.xpath(xpath, namespaces=namespaces)
+        return [XmlElement(elem, namespaces) for elem in elems]
     
     def add_element(self, tagname, **kwds):
-        element = etree.SubElement(self.node, tagname, **kwds)
-        return XmlNode(element, self.namespaces)
+        element = etree.SubElement(self.element, tagname, **kwds)
+        return XmlElement(element, self.namespaces)
 
     def append(self, elem):
-        if isinstance(elem, XmlNode):
-            self.node.append(elem.node)
+        if isinstance(elem, XmlElement):
+            self.element.append(elem.element)
         else:
-            self.node.append(elem)
+            self.element.append(elem)
 
     def getparent(self):
-        return XmlNode(self.node.getparent(), self.namespaces)
+        return XmlElement(self.element.getparent(), self.namespaces)
+
+    def get_instance(self, instance_class=None, fields=[]):
+        """
+        Returns an instance (dict) of this xml element. The instance
+        holds a reference to this xml element.   
+        """
+        if not instance_class:
+            instance_class = Element
+        if not fields and hasattr(instance_class, 'fields'):
+            fields = instance_class.fields
+
+        if not fields:
+            instance = instance_class(self.attrib, self)
+        else:
+            instance = instance_class({}, self)
+            for field in fields:
+                if field in self.attrib:
+                   instance[field] = self.attrib[field]  
+        return instance             
+
+    def add_instance(self, name, instance, fields=[]):
+        """
+        Adds the specifed instance(s) as a child element of this xml 
+        element. 
+        """
+        if not fields and hasattr(instance, 'keys'):
+            fields = instance.keys()
+        elem = self.add_element(name)
+        for field in fields:
+            if field in instance and instance[field]:
+                elem.set(field, unicode(instance[field]))
+        return elem                  
 
     def remove_elements(self, name):
         """
@@ -72,40 +118,41 @@ class XmlNode:
         
         if not element_name.startswith('//'):
             element_name = '//' + element_name
-        elements = self.node.xpath('%s ' % name, namespaces=self.namespaces) 
+        elements = self.element.xpath('%s ' % name, namespaces=self.namespaces) 
         for element in elements:
             parent = element.getparent()
             parent.remove(element)
 
+    def delete(self):
+        parent = self.getparent()
+        parent.remove(self)
+
     def remove(self, element):
-        if isinstance(element, XmlNode):
-            self.node.remove(element.node)
+        if isinstance(element, XmlElement):
+            self.element.remove(element.element)
         else:
-            self.node.remove(element)
-
-    def get(self, key, *args):
-        return self.node.get(key, *args)
+            self.element.remove(element)
 
-    def items(self): return self.node.items()
-
-    def set(self, key, value):
-        self.node.set(key, value)
-    
     def set_text(self, text):
-        self.node.text = text
+        self.element.text = text
     
+    # Element does not have unset ?!?
     def unset(self, key):
-        del self.node.attrib[key]
+        del self.element.attrib[key]
   
-    def iterchildren(self):
-        return self.node.iterchildren()
-     
     def toxml(self):
-        return etree.tostring(self.node, encoding='UTF-8', pretty_print=True)                    
+        return etree.tostring(self.element, encoding='UTF-8', pretty_print=True)                    
 
     def __str__(self):
         return self.toxml()
 
+    ### other method calls or attribute access like .text or .tag or .get 
+    # are redirected on self.element
+    def __getattr__ (self, name):
+        if not hasattr(self.element, name):
+            raise AttributeError, name
+        return getattr(self.element, name)
+
 class XML:
  
     def __init__(self, xml=None, namespaces=None):
@@ -115,7 +162,7 @@ class XML:
         self.schema = None
         if isinstance(xml, basestring):
             self.parse_xml(xml)
-        if isinstance(xml, XmlNode):
+        if isinstance(xml, XmlElement):
             self.root = xml
             self.namespaces = xml.namespaces
         elif isinstance(xml, etree._ElementTree) or isinstance(xml, etree._Element):
@@ -147,7 +194,7 @@ class XML:
         else:
             self.namespaces['default'] = 'default' 
 
-        self.root = XmlNode(root, self.namespaces)
+        self.root = XmlElement(root, self.namespaces)
         # set schema 
         for key in self.root.attrib.keys():
             if key.endswith('schemaLocation'):
@@ -210,48 +257,41 @@ class XML:
             namespaces = self.namespaces
         return self.root.xpath(xpath, namespaces=namespaces)
 
-    def set(self, key, value, node=None):
-        if not node:
-            node = self.root 
-        return node.set(key, value)
+    def set(self, key, value):
+        return self.root.set(key, value)
 
-    def remove_attribute(self, name, node=None):
-        if not node:
-            node = self.root
-        node.remove_attribute(name) 
+    def remove_attribute(self, name, element=None):
+        if not element:
+            element = self.root
+        element.remove_attribute(name) 
         
-    def add_element(self, name, **kwds):
+    def add_element(self, *args, **kwds):
         """
         Wrapper around etree.SubElement(). Adds an element to 
         specified parent node. Adds element to root node is parent is 
         not specified. 
         """
-        parent = self.root
-        xmlnode = parent.add_element(name, *kwds)
-        return xmlnode
+        return self.root.add_element(*args, **kwds)
 
-    def remove_elements(self, name, node = None):
+    def remove_elements(self, name, element = None):
         """
         Removes all occurences of an element from the tree. Start at 
         specified root_node if specified, otherwise start at tree's root.   
         """
-        if not node:
-            node = self.root
+        if not element:
+            element = self.root
 
-        node.remove_elements(name)
+        element.remove_elements(name)
 
-    def attributes_list(self, elem):
-        # convert a list of attribute tags into list of tuples
-        # (tagnme, text_value)
-        opts = []
-        if elem is not None:
-            for e in elem:
-                opts.append((e.tag, str(e.text).strip()))
-        return opts
+    def add_instance(self, *args, **kwds):
+        return self.root.add_instance(*args, **kwds)
+
+    def get_instance(self, *args, **kwds):
+        return self.root.get_instnace(*args, **kwds)
 
     def get_element_attributes(self, elem=None, depth=0):
         if elem == None:
-            elem = self.root_node
+            elem = self.root
         if not hasattr(elem, 'attrib'):
             # this is probably not an element node with attribute. could be just and an
             # attribute, return it
@@ -283,7 +323,7 @@ class XML:
         return self.toxml()
 
     def toxml(self):
-        return etree.tostring(self.root.node, encoding='UTF-8', pretty_print=True)  
+        return etree.tostring(self.root.element, encoding='UTF-8', pretty_print=True)  
     
     # XXX smbaker, for record.load_from_string
     def todict(self, elem=None):
index ce72936..fb57a71 100755 (executable)
@@ -51,9 +51,9 @@ class Client:
         # XX defaulting to user, but this should be configurable so we can
         # test from components persepctive
         self.type = 'user'
-        self.credential = self.get_credential(self.hrn)
+        self.credential = self.GetCredential(self.hrn)
         
-    def get_credential(self, hrn = None, type = 'user'):
+    def GetCredential(self, hrn = None, type = 'user'):
         if not hrn: hrn = self.hrn 
         if hrn == self.hrn:
             cert = self.cert.save_to_string(save_parents=True)
@@ -62,8 +62,8 @@ class Client:
             return credential
         else:
             if not self.credential:
-                self.credential = self.get_credential(self.hrn, 'user')
-            return self.registry.get_credential(self.credential, type, hrn)     
+                self.credential = self.GetCredential(self.hrn, 'user')
+            return self.registry.GetCredential(self.credential, type, hrn)     
 
 class BasicTestCase(unittest.TestCase):
     def __init__(self, testname, client, test_slice=None):
@@ -90,13 +90,13 @@ class RegistryTest(BasicTestCase):
         BasicTestCase.setUp(self)
 
     def testGetSelfCredential(self):
-        cred = self.client.get_credential()
+        cred = self.client.GetCredential()
         # this will raise an openssl error if the credential string isnt valid
         Credential(string=cred)
 
     def testRegister(self):
         authority = get_authority(self.hrn)
-        auth_cred = self.client.get_credential(authority, 'authority')
+        auth_cred = self.client.GetCredential(authority, 'authority')
         auth_record = {'hrn': '.'.join([authority, random_string(10).lower()]),
                        'type': 'authority'}
         node_record = {'hrn': '.'.join([authority, random_string(10)]),
@@ -113,12 +113,12 @@ class RegistryTest(BasicTestCase):
         all_records = [auth_record, node_record, slice_record, user_record]
         for record in all_records:
             try:
-                self.registry.register(auth_cred, record)
-                self.registry.resolve(self.credential, record['hrn'])
+                self.registry.Register(auth_cred, record)
+                self.registry.Resolve(self.credential, record['hrn'])
             except:
                 raise
             finally:
-                try: self.registry.remove(auth_cred, record['type'], record['hrn'])
+                try: self.registry.Remove(auth_cred, record['type'], record['hrn'])
                 except: pass
 
     
@@ -127,26 +127,26 @@ class RegistryTest(BasicTestCase):
    
     def testUpdate(self):
         authority = get_authority(self.hrn)
-        auth_cred = self.client.get_credential(authority, 'authority')
-        records = self.registry.resolve(self.credential, self.hrn)
+        auth_cred = self.client.GetCredential(authority, 'authority')
+        records = self.registry.Resolve(self.credential, self.hrn)
         if not records: assert False
         record = records[0]
         self.registry.update(auth_cred, record) 
 
     def testResolve(self):
         authority = get_authority(self.hrn)
-        self.registry.resolve(self.credential, self.hrn)
+        self.registry.Resolve(self.credential, self.hrn)
    
     def testRemove(self):
         authority = get_authority(self.hrn)
-        auth_cred = self.client.get_credential(authority, 'authority')
+        auth_cred = self.client.GetCredential(authority, 'authority')
         record = {'hrn': ".".join([authority, random_string(10)]),
                        'type': 'slice'}
-        self.registry.register(auth_cred, record)
-        self.registry.remove(auth_cred, record['type'], record['hrn'])
+        self.registry.Register(auth_cred, record)
+        self.registry.Remove(auth_cred, record['type'], record['hrn'])
         # should generate an exception
         try:
-            self.registry.resolve(self.credential,  record['hrn'])
+            self.registry.Resolve(self.credential,  record['hrn'])
             assert False
         except:       
             assert True
@@ -156,7 +156,7 @@ class RegistryTest(BasicTestCase):
 
     def testList(self):
         authority = get_authority(self.client.hrn)
-        self.registry.list(self.credential, authority)
+        self.registry.List(self.credential, authority)
              
     def testGetRegistries(self):
         self.registry.get_registries(self.credential)
@@ -196,17 +196,17 @@ class AggregateTest(BasicTestCase):
     def testCreateSlice(self):
         # get availabel resources   
         rspec = self.aggregate.get_resources(self.credential)
-        slice_credential = self.client.get_credential(self.slice['hrn'], 'slice')
+        slice_credential = self.client.GetCredential(self.slice['hrn'], 'slice')
         self.aggregate.CreateSliver(slice_credential, self.slice['hrn'], rspec)
 
     def testDeleteSlice(self):
-        slice_credential = self.client.get_credential(self.slice['hrn'], 'slice')
+        slice_credential = self.client.GetCredential(self.slice['hrn'], 'slice')
         self.aggregate.DeleteSliver(slice_credential, self.slice['hrn'],"call-id-delete-slice")
 
     def testGetTicket(self):
-        slice_credential = self.client.get_credential(self.slice['hrn'], 'slice')
+        slice_credential = self.client.GetCredential(self.slice['hrn'], 'slice')
         rspec = self.aggregate.get_resources(self.credential)
-        ticket = self.aggregate.get_ticket(slice_credential, self.slice['hrn'], rspec)
+        ticket = self.aggregate.GetTicket(slice_credential, self.slice['hrn'], rspec)
         # will raise an exception if the ticket inst valid
         SfaTicket(string=ticket)        
 
@@ -223,7 +223,7 @@ class SlicemgrTest(AggregateTest):
 class ComponentTest(BasicTestCase):
     def setUp(self):
         BasicTestCase.setUp(self)
-        self.slice_cred = self.client.get_credential(self.slice['hrn'], 'slice')
+        self.slice_cred = self.client.GetCredential(self.slice['hrn'], 'slice')
 
     def testStartSlice(self):
         self.cm.start_slice(self.slice_cred, self.slice['hrn'])
@@ -242,7 +242,7 @@ class ComponentTest(BasicTestCase):
 
     def testRedeemTicket(self):
         rspec = self.aggregate.get_resources(self.credential)
-        ticket = self.aggregate.get_ticket(slice_cred, self.slice['hrn'], rspec)
+        ticket = self.aggregate.GetTicket(slice_cred, self.slice['hrn'], rspec)
         self.cm.redeem_ticket(slice_cred, ticket)
 
 
@@ -252,17 +252,17 @@ def test_names(testcase):
 def CreateSliver(client):
     # register a slice that will be used for some test
     authority = get_authority(client.hrn)
-    auth_cred = client.get_credential(authority, 'authority')
+    auth_cred = client.GetCredential(authority, 'authority')
     slice_record = {'hrn': ".".join([authority, random_string(10)]),
                     'type': 'slice', 'researcher': [client.hrn]}
-    client.registry.register(auth_cred, slice_record)
+    client.registry.Register(auth_cred, slice_record)
     return  slice_record
  
 def DeleteSliver(client, slice):
     authority = get_authority(client.hrn)
-    auth_cred = client.get_credential(authority, 'authority')
+    auth_cred = client.GetCredential(authority, 'authority')
     if slice:
-        client.registry.remove(auth_cred, 'slice', slice['hrn'])
+        client.registry.Remove(auth_cred, 'slice', slice['hrn'])
     
 if __name__ == '__main__':