initial checkin of register_peer_object
authorTony Mack <tmack@cs.princeton.edu>
Sat, 26 Sep 2009 01:50:48 +0000 (01:50 +0000)
committerTony Mack <tmack@cs.princeton.edu>
Sat, 26 Sep 2009 01:50:48 +0000 (01:50 +0000)
sfa/methods/__init__.py
sfa/methods/create_slice.py
sfa/methods/register_peer_object.py [new file with mode: 0644]

index 55c4c5f..c76da45 100644 (file)
@@ -11,11 +11,12 @@ get_slices
 get_ticket
 list
 register
+register_peer_object
 remove
 reset_slices
 resolve
 start_slice
 stop_slice
 update
-remove_remote_object
+remove_peer_object
 """.split()
index cb5eabb..bd86efa 100644 (file)
@@ -11,7 +11,7 @@ from sfa.util.config import Config
 # RSpecManager_pl is not used. It's used to make sure the module is in place.
 import sfa.rspecs.aggregates.rspec_manager_pl
 from sfa.trust.credential import Credential
-from sfatables.runtime import SFATablesRules
+#from sfatables.runtime import SFATablesRules
 
 
 class create_slice(Method):
@@ -37,24 +37,26 @@ class create_slice(Method):
     def call(self, cred, hrn, requested_rspec, caller_cred=None):
         if caller_cred==None:
             caller_cred=cred
+        
+        self.api.auth.check(cred, 'createslice')
+
         #log the call
         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, Credential(string=caller_cred).get_gid_caller().get_hrn(), hrn, self.name))
 
+        sfa_aggregate_type = Config().get_aggregate_rspec_type()
         rspec_manager = __import__("sfa.rspecs.aggregates.rspec_manager_"+sfa_aggregate_type, fromlist = ["sfa.rspecs.aggregates"])
         # Filter the incoming rspec using sfatables
-        incoming_rules = SFATablesRules('OUTGOING')
+        #incoming_rules = SFATablesRules('OUTGOING')
             
-        incoming_rules.set_slice(hrn) # This is a temporary kludge. Eventually, we'd like to fetch the context requested by the match/target
+        #incoming_rules.set_slice(hrn) # This is a temporary kludge. Eventually, we'd like to fetch the context requested by the match/target
 
-        contexts = incoming_rules.contexts
-        request_context = rspec_manager.get_context(hrn, Credential(string=caller_cred.get_gid_caller().get_hrn()), contexts)
-        incoming_rules.set_context(request_context)
-        rspec = incoming_rules.apply(requested_rspec)
+        #contexts = incoming_rules.contexts
+        #request_context = rspec_manager.get_context(hrn, Credential(string=caller_cred.get_gid_caller().get_hrn()), contexts)
+        #incoming_rules.set_context(request_context)
+        #rspec = incoming_rules.apply(requested_rspec)
+        rspec = requested_rspec
 
 
-        sfa_aggregate_type = Config().get_aggregate_rspec_type()
-        self.api.auth.check(cred, 'createslice')
-
         if (sfa_aggregate_type == 'pl'):
             slices = Slices(self.api, caller_cred=caller_cred)
             slices.create_slice(hrn, rspec)    
diff --git a/sfa/methods/register_peer_object.py b/sfa/methods/register_peer_object.py
new file mode 100644 (file)
index 0000000..244bd89
--- /dev/null
@@ -0,0 +1,66 @@
+### $Id: register.py 15001 2009-09-11 20:18:54Z tmack $
+### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/register.py $
+
+from sfa.trust.certificate import Keypair, convert_public_key
+from sfa.trust.gid import *
+
+from sfa.util.faults import *
+from sfa.util.misc import *
+from sfa.util.method import Method
+from sfa.util.parameter import Parameter, Mixed
+from sfa.util.record import GeniRecord
+from sfa.util.genitable import GeniTable
+from sfa.util.debug import log
+from sfa.trust.auth import Auth
+from sfa.trust.gid import create_uuid
+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
+    Geni 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")
+        ]
+
+    returns = Parameter(int, "1 if successful")
+    
+    def call(self, cred, record_dict, caller_cred=None):
+        self.api.auth.check(cred, "register")
+        if caller_cred==None:
+               caller_cred=cred
+               
+        #log the call
+        self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, Credential(string=caller_cred).get_gid_caller().get_hrn(), None, self.name))
+
+        # make sure this is a peer record
+        if 'peer_authority' not in record_dict or \
+           not record_dict['peer_authority']: 
+            raise GeniInvalidArgument, "peer_authority must be specified" 
+
+        record = GeniRecord(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)
+        self.api.auth.verify_object_permission(hrn)
+
+        # check if record already exists
+        table = GeniTable()
+        existing_records = table.find({'type': type, 'hrn': hrn, 'peer_authority': peer_authority})
+        if existing_records:
+            return 1
+        record_id = table.insert(record)
+        return 1