git://git.onelab.eu
/
sfa.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
removed another bunch of references to geni
[sfa.git]
/
sfa
/
methods
/
register_peer_object.py
diff --git
a/sfa/methods/register_peer_object.py
b/sfa/methods/register_peer_object.py
index
244bd89
..
68b3105
100644
(file)
--- a/
sfa/methods/register_peer_object.py
+++ b/
sfa/methods/register_peer_object.py
@@
-5,11
+5,11
@@
from sfa.trust.certificate import Keypair, convert_public_key
from sfa.trust.gid import *
from sfa.util.faults import *
from sfa.trust.gid import *
from sfa.util.faults import *
-from sfa.util.
misc
import *
+from sfa.util.
namespace
import *
from sfa.util.method import Method
from sfa.util.parameter import Parameter, Mixed
from sfa.util.method import Method
from sfa.util.parameter import Parameter, Mixed
-from sfa.util.record import
Geni
Record
-from sfa.util.
genitable import Geni
Table
+from sfa.util.record import
Sfa
Record
+from sfa.util.
table import Sfa
Table
from sfa.util.debug import log
from sfa.trust.auth import Auth
from sfa.trust.gid import create_uuid
from sfa.util.debug import log
from sfa.trust.auth import Auth
from sfa.trust.gid import create_uuid
@@
-18,12
+18,11
@@
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
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
+
SFA
database, the appropriate records will also be created in the
PLC databases
@param cred credential string
@param record_dict dictionary containing record fields
PLC databases
@param cred credential string
@param record_dict dictionary containing record fields
-
@return gid string representation
"""
@return gid string representation
"""
@@
-31,36
+30,44
@@
class register_peer_object(Method):
accepts = [
Parameter(str, "Credential string"),
accepts = [
Parameter(str, "Credential string"),
- Parameter(dict, "Record dictionary containing record fields")
+ 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")
]
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
-
+ def call(self, cred, record_dict, origin_hrn=None):
+ user_cred = Credential(string=cred)
+
#log the call
#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))
+ 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']:
# make sure this is a peer record
if 'peer_authority' not in record_dict or \
not record_dict['peer_authority']:
- raise
Geni
InvalidArgument, "peer_authority must be specified"
+ raise
Sfa
InvalidArgument, "peer_authority must be specified"
- record =
Geni
Record(dict = record_dict)
+ record =
Sfa
Record(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)
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
# check if record already exists
- table =
Geni
Table()
+ table =
Sfa
Table()
existing_records = table.find({'type': type, 'hrn': hrn, 'peer_authority': peer_authority})
if existing_records:
existing_records = table.find({'type': type, 'hrn': hrn, 'peer_authority': peer_authority})
if existing_records:
- return 1
- record_id = table.insert(record)
+ 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
return 1