import sys
from types import StringTypes
-from sfa.util.misc import *
+from sfa.util.namespace import *
from sfa.util.rspec import *
from sfa.util.specdict import *
from sfa.util.faults import *
from sfa.util.storage import *
-from sfa.util.record import GeniRecord
+from sfa.util.record import SfaRecord
from sfa.util.policy import Policy
from sfa.util.prefixTree import prefixTree
from sfa.util.debug import log
rspec_to_slice_tag = {'max_rate':'net_max_rate'}
- def __init__(self, api, ttl = .5, gid_origin_caller=None):
+ def __init__(self, api, ttl = .5, origin_hrn=None):
self.api = api
self.ttl = ttl
self.threshold = None
SimpleStorage.__init__(self, self.slices_file)
self.policy = Policy(self.api)
self.load()
- self.gid_origin_caller=gid_origin_caller
+ self.origin_hrn = origin_hrn
- def get_slivers(self, hrn, node=None):
+ def get_slivers(self, xrn, node=None):
+ hrn, type = urn_to_hrn(xrn)
slice_name = hrn_to_pl_slicename(hrn)
# XX Should we just call PLCAPI.GetSliceTicket(slice_name) instead
return slivers
- def get_peer(self, hrn):
+ def get_peer(self, xrn):
+ hrn, type = urn_to_hrn(xrn)
# Becaues of myplc federation, we first need to determine if this
# slice belongs to out local plc or a myplc peer. We will assume it
# is a local site, unless we find out otherwise
return peer
- def get_sfa_peer(self, hrn):
+ def get_sfa_peer(self, xrn):
+ hrn, type = urn_to_hrn(xrn)
+
# return the authority for this hrn or None if we are the authority
sfa_peer = None
slice_authority = get_authority(hrn)
success = False
# request hash is optional so lets try the call without it
try:
- request_hash=None
- slices = aggregates[aggregate].get_slices(credential, request_hash)
+ slices = aggregates[aggregate].get_slices(credential)
slice_hrns.extend(slices)
success = True
except:
# try sending the request hash if the previous call failed
if not success:
arg_list = [credential]
- request_hash = self.api.key.compute_hash(arg_list)
try:
- slices = aggregates[aggregate].get_slices(credential, request_hash)
+ slices = aggregates[aggregate].get_slices(credential)
slice_hrns.extend(slices)
success = True
except:
def verify_site(self, registry, credential, slice_hrn, peer, sfa_peer):
+ import pdb
+ pdb.set_trace()
authority = get_authority(slice_hrn)
- try:
- site_records = registry.resolve(credential, authority)
- except:
- arg_list = [credential, authority]
- request_hash = self.api.key.compute_hash(arg_list)
- site_records = registry.resolve(credential, authority, request_hash)
+ authority_urn = hrn_to_urn(authority, 'authority')
+ site_records = registry.resolve(credential, authority_urn)
site = {}
for site_record in site_records:
# mark this site as an sfa peer record
if sfa_peer:
peer_dict = {'type': 'authority', 'hrn': authority, 'peer_authority': sfa_peer, 'pointer': site_id}
- try:
- registry.register_peer_object(credential, peer_dict)
- except:
- arg_list = [credential]
- request_hash = self.api.key.compute_hash(arg_list)
- registry.register_peer_object(credential, peer_dict, request_hash)
+ registry.register_peer_object(credential, peer_dict)
else:
site_id = sites[0]['site_id']
remote_site_id = sites[0]['peer_site_id']
+ old_site = sites[0]
+ #the site is alredy on the remote agg. Let us update(e.g. max_slices field) it with the latest info.
+ self.sync_site(old_site, site, peer)
return (site_id, remote_site_id)
slice = {}
slice_record = None
authority = get_authority(slice_hrn)
- try:
- slice_records = registry.resolve(credential, slice_hrn)
- except:
- arg_list = [credential, slice_hrn]
- request_hash = self.api.key.compute_hash(arg_list)
- slice_records = registry.resolve(credential, slice_hrn, request_hash)
+ slice_records = registry.resolve(credential, slice_hrn)
for record in slice_records:
if record['type'] in ['slice']:
# mark this slice as an sfa peer record
if sfa_peer:
peer_dict = {'type': 'slice', 'hrn': slice_hrn, 'peer_authority': sfa_peer, 'pointer': slice_id}
- try:
- registry.register_peer_object(credential, peer_dict)
- except:
- arg_list = [credential]
- request_hash = self.api.key.compute_hash(arg_list)
- registry.register_peer_object(credential, peer_dict, request_hash)
+ registry.register_peer_object(credential, peer_dict)
#this belongs to a peer
if peer:
researchers = slice_record.get('researcher', [])
for researcher in researchers:
person_record = {}
- try:
- person_records = registry.resolve(credential, researcher)
- except:
- arg_list = [credential, researcher]
- request_hash = self.api.key.compute_hash(arg_list)
- person_records = registry.resolve(credential, researcher, request_hash)
+ person_records = registry.resolve(credential, researcher)
for record in person_records:
if record['type'] in ['user']:
person_record = record
# mark this person as an sfa peer record
if sfa_peer:
peer_dict = {'type': 'user', 'hrn': researcher, 'peer_authority': sfa_peer, 'pointer': person_id}
- try:
- registry.register_peer_object(credential, peer_dict)
- except:
- arg_list = [credential]
- request_hash = self.api.key.compute_hash(arg_list)
- registry.register_peer_object(credential, peer_dict, request_hash)
+ registry.register_peer_object(credential, peer_dict)
if peer:
self.api.plshell.BindObjectToPeer(self.api.plauth, 'person', person_id, peer, person_dict['pointer'])
except: pass
- def create_slice_aggregate(self, hrn, rspec):
-
+ def create_slice_aggregate(self, xrn, rspec):
+ hrn, type = urn_to_hrn(xrn)
# Determine if this is a peer slice
peer = self.get_peer(hrn)
sfa_peer = self.get_sfa_peer(hrn)
return 1
+ def sync_site(self, old_record, new_record, peer):
+ if old_record['max_slices'] != new_record['max_slices']:
+ if peer:
+ self.api.plshell.UnBindObjectFromPeer(self.api.plauth, 'site', old_record['site_id'], peer)
+ self.api.plshell.UpdateSite(self.api.plauth, old_record['site_id'], {'max_slices' : new_record['max_slices']})
+ if peer:
+ self.api.plshell.BindObjectToPeer(self.api.plauth, 'site', old_record['site_id'], peer, old_record['peer_site_id'])
+ return 1
+
def sync_slice(self, old_record, new_record, peer):
if old_record['expires'] != new_record['expires']:
if peer: