Use lxml.etree to parse VINI RSpec, validate against RelaxNG schema
[sfa.git] / sfa / managers / aggregate_manager_vini.py
index 4fb8882..418f034 100644 (file)
@@ -1,19 +1,16 @@
 from sfa.util.faults import *
-from sfa.util.misc import *
-from sfa.util.rspec import RSpec
+from sfa.util.namespace import *
 from sfa.server.registry import Registries
 from sfa.plc.nodes import *
+from sfa.plc.api import *
 from sfa.rspecs.aggregates.vini.utils import *
-from sfa.rspecs.aggregates.vini.rspec import *
 import sys
 
-SFA_VINI_WHITELIST = '/etc/sfa/vini.whitelist'
-
 """
 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
     slice = {}
     registries = Registries(api)
     registry = registries[api.hrn]
@@ -132,7 +129,8 @@ def create_slice_vini_aggregate(api, hrn, nodes):
 
     return 1
 
-def get_rspec(api, hrn):
+def get_rspec(api, xrn, origin_hrn):
+    hrn = urn_to_hrn(xrn)[0]
     topo = Topology(api)      
     if (hrn):
         slicename = hrn_to_pl_slicename(hrn)
@@ -151,27 +149,13 @@ def get_rspec(api, hrn):
 """
 Hook called via 'sfi.py create'
 """
-def create_slice(api, hrn, xml):
-    ### Check the whitelist
-    ### It consists of lines of the form: <slice hrn> <bw>
-    whitelist = {}
-    f = open(SFA_VINI_WHITELIST)
-    for line in f.readlines():
-        (slice, maxbw) = line.split()
-        whitelist[slice] = maxbw
-        
-    if hrn in whitelist:
-        maxbw = whitelist[hrn]
-    else:
-        raise PermissionError("%s not in VINI whitelist" % hrn)
-        
-    rspec = RSpec(xml)
+def create_slice(api, xrn, xml):
+    hrn = urn_to_hrn(xrn)[0]
     topo = Topology(api)
-    
-    topo.nodeTopoFromRSpec(rspec)
+    topo.nodeTopoFromRSpec(xml)
 
     # Check request against current allocations
-    topo.verifyNodeTopo(hrn, topo, maxbw)
+    topo.verifyNodeTopo(hrn, topo)
     
     nodes = topo.nodesInTopo()
     hostnames = []
@@ -184,6 +168,8 @@ def create_slice(api, hrn, xml):
     if slice:
         topo.updateSliceTags(slice)    
 
+    # print topo.toxml(hrn)
+
     return True
 
 """
@@ -192,14 +178,18 @@ to refer to "contexts", which is the information that sfatables is requesting. B
 return the basic information needed in a dict.
 """
 def fetch_context(slice_hrn, user_hrn, contexts):
-    base_context = {'sfa':{'user':{'hrn':user_hrn}}}
+    base_context = {'sfa':{'user':{'hrn':user_hrn},
+                           'slice':{'hrn':slice_hrn}}}
     return base_context
 
 def main():
-    r = RSpec()
-    r.parseFile(sys.argv[1])
-    rspec = r.toDict()
-    create_slice(None,'plc',rspec)
+    api = SfaAPI()
+    #rspec = get_rspec(api, "plc.princeton.iias", None)
+    #print rspec
+    f = open(sys.argv[1])
+    xml = f.read()
+    f.close()
+    create_slice(api, "plc.princeton.iias", xml)
 
 if __name__ == "__main__":
     main()