from sfa.util.faults import *
-from sfa.util.misc import *
-from sfa.util.rspec import Rspec
+from sfa.util.namespace import *
+from sfa.util.rspec import RSpec
from sfa.server.registry import Registries
from sfa.plc.nodes import *
from sfa.rspecs.aggregates.vini.utils import *
Copied from create_slice_aggregate() in sfa.plc.slices
"""
def create_slice_vini_aggregate(api, hrn, nodes):
- # Get the slice record from geni
+ # Get the slice record from SFA
slice = {}
registries = Registries(api)
registry = registries[api.hrn]
credential = api.getCredential()
records = registry.resolve(credential, hrn)
for record in records:
- if record.get_type() in ['slice']:
- slice = record.as_dict()
+ if record['type'] in ['slice']:
+ slice = record
if not slice:
raise RecordNotFound(hrn)
site_record = {}
if not site_records:
raise RecordNotFound(authority)
- site_record = site_records[0]
- site = site_record.as_dict()
+ site = site_records[0]
# add the site
site.pop('site_id')
person_record = {}
person_records = registry.resolve(credential, researcher)
for record in person_records:
- if record.get_type() in ['user']:
+ if record['type'] in ['user']:
person_record = record
if not person_record:
pass
- person_dict = person_record.as_dict()
+ person_dict = person_record
persons = api.plshell.GetPersons(api.plauth, [person_dict['email']],
['person_id', 'key_ids'])
return 1
def get_rspec(api, hrn):
- rspec = ViniRspec()
- topo = Topology(api)
-
- rspec.updateCapacity(topo)
-
+ topo = Topology(api)
if (hrn):
slicename = hrn_to_pl_slicename(hrn)
slice = get_slice(api, slicename)
if slice:
slice.hrn = hrn
topo.nodeTopoFromSliceTags(slice)
- rspec.updateRequest(slice, topo)
else:
# call the default sfa.plc.nodes.get_rspec() method
return Nodes(api).get_rspec(hrn)
- return rspec.toxml()
+ return topo.toxml(hrn)
-"""
-Check the requested topology against the available topology and capacity
-"""
-def check_request(hrn, rspec, nodes, sites, sitelinks, maxbw):
- linkspecs = rspec['Rspec']['Request'][0]['NetSpec'][0]['LinkSpec']
- if linkspecs:
- for l in linkspecs:
- n1 = Node.lookup(l['endpoint'][0])
- n2 = Node.lookup(l['endpoint'][1])
- bw = l['bw'][0]
- reqbps = get_tc_rate(bw)
- maxbps = get_tc_rate(maxbw)
-
- if reqbps <= 0:
- raise GeniInvalidArgument(bw, "BW")
- if reqbps > maxbps:
- raise PermissionError(" %s requested %s but max BW is %s" %
- (hrn, bw, maxbw))
-
- if adjacent_nodes(n1, n2, sites, sitelinks):
- availbps = get_avail_bps(n1, n2, sites, sitelinks)
- if availbps < reqbps:
- raise PermissionError("%s: capacity exceeded" % hrn)
- else:
- raise PermissionError("%s: nodes %s and %s not adjacent"
- % (hrn, n1.tag, n2.tag))
"""
Hook called via 'sfi.py create'
else:
raise PermissionError("%s not in VINI whitelist" % hrn)
- rspec = ViniRspec(xml)
+ rspec = RSpec(xml)
topo = Topology(api)
- topo.nodeTopoFromRspec(rspec)
+ topo.nodeTopoFromRSpec(rspec)
# Check request against current allocations
- #check_request(hrn, rspec, nodes, sites, sitelinks, maxbw)
+ topo.verifyNodeTopo(hrn, topo, maxbw)
nodes = topo.nodesInTopo()
hostnames = []
return True
+"""
+Returns the request context required by sfatables. At some point, this mechanism should be changed
+to refer to "contexts", which is the information that sfatables is requesting. But for now, we just
+return the basic information needed in a dict.
+"""
+def fetch_context(slice_hrn, user_hrn, contexts):
+ base_context = {'sfa':{'user':{'hrn':user_hrn},
+ 'slice':{'hrn':slice_hrn}}}
+ return base_context
def main():
- r = Rspec()
+ r = RSpec()
r.parseFile(sys.argv[1])
rspec = r.toDict()
create_slice(None,'plc',rspec)
-
+
if __name__ == "__main__":
main()