renamed create_slice into CreateSliver on the managers side
[sfa.git] / sfa / rspecs / aggregates / rspec_manager_max.py
index 5d93b26..c706ab1 100644 (file)
@@ -1,15 +1,15 @@
 #!/usr/bin/python
 
-from sfa.util.rspec import Rspec
+from sfa.util.rspec import RSpec
 import sys
 import pdb
-from sfa.util.misc import *
+from sfa.util.xrn import get_authority
+from sfa.util.plxrn import hrn_to_pl_slicename 
 from sfa.util.rspec import *
 from sfa.util.specdict import *
 from sfa.util.faults import *
 from sfa.util.storage import *
 from sfa.util.policy import Policy
-from sfa.util.debug import log
 from sfa.server.aggregate import Aggregates
 from sfa.server.registry import Registries
 from sfa.util.faults import *
@@ -22,21 +22,21 @@ SFA_MAX_CANNED_RSPEC = '/etc/sfa/max_physical_canned.xml'
 
 topology = {}
 
-class GeniOutOfResource(GeniFault):
+class SfaOutOfResource(SfaFault):
     def __init__(self, interface):
         faultString = "Interface " + interface + " not available"
-        GeniFault.__init__(self, 100, faultString, '')
+        SfaFault.__init__(self, 100, faultString, '')
 
-class GeniNoPairRspec(GeniFault):
+class SfaNoPairRSpec(SfaFault):
     def __init__(self, interface, interface2):
         faultString = "Interface " + interface + " should be paired with " + interface2
-        GeniFault.__init__(self, 100, faultString, '')
+        SfaFault.__init__(self, 100, faultString, '')
 
 # Returns a mapping from interfaces to the nodes they lie on and their peer interfaces
 # i -> node,i_peer
 
 def get_interface_map():
-    r = Rspec()
+    r = RSpec()
     r.parseFile(SFA_MAX_DEFAULT_RSPEC)
     rspec = r.toDict()
     capacity = rspec['rspec']['capacity']
@@ -125,7 +125,12 @@ def alloc_links(api, hrn, links_to_add, links_to_drop):
     slicename=hrn_to_pl_slicename(hrn)
     for (iface,ip) in links_to_add:
         node = topology[iface][0][0]
-        api.plshell.AddSliceTag(api.plauth, slicename, "ip_addresses", ip, node)
+        try:
+            api.plshell.AddSliceTag(api.plauth, slicename, "ip_addresses", ip, node)
+            api.plshell.AddSliceTag(api.plauth, slicename, "vsys", "getvlan", node)
+        except Exception: 
+            # Probably a duplicate tag. XXX July 21
+            pass
     return True
 
 def alloc_nodes(api,hrn, requested_ifs):
@@ -135,7 +140,7 @@ def alloc_nodes(api,hrn, requested_ifs):
 # Taken from slices.py
 
 def create_slice_max_aggregate(api, hrn, nodes):
-    # Get the slice record from geni
+    # Get the slice record from SFA
     global topology
     topology = get_interface_map()
     slice = {}
@@ -243,7 +248,7 @@ def create_slice_max_aggregate(api, hrn, nodes):
     return 1
 
 
-def get_rspec(api, hrn):
+def ListResources(api, hrn):
     # Eg. config line:
     # plc.princeton.sapan vlan23,vlan45
 
@@ -256,13 +261,13 @@ def get_rspec(api, hrn):
     return (ret_rspec)
 
 
-def create_slice(api, hrn, rspec_xml):
+def CreateSliver(api, hrn, rspec_xml):
     global topology
     topology = get_interface_map()
 
     # Check if everything in rspec is either allocated by hrn
     # or not allocated at all.
-    r = Rspec()
+    r = RSpec()
     r.parseString(rspec_xml)
     rspec = r.toDict()
 
@@ -283,9 +288,9 @@ def create_slice(api, hrn, rspec_xml):
 
     for a in requested_interfaces:
         if (a not in current_hrn_interfaces and a in current_interfaces):
-            raise GeniOutOfResource(a)
+            raise SfaOutOfResource(a)
         if (topology[a][1] not in requested_interfaces):
-            raise GeniNoPairRspec(a,topology[a][1])
+            raise SfaNoPairRSpec(a,topology[a][1])
     # Request OK
 
     # Allocations to delete
@@ -311,16 +316,16 @@ def rspec_to_allocations(rspec):
         for l in ifspecs:
             ifs.extend([(l['name'].replace('tns:',''),l['ip'])])
     except KeyError:
-        # Bad Rspec
+        # Bad RSpec
         pass
     return ifs
 
 def main():
     t = get_interface_map()
-    r = Rspec()
+    r = RSpec()
     rspec_xml = open(sys.argv[1]).read()
-    #get_rspec(None,'foo')
-    create_slice(None, "plc.princeton.sap0", rspec_xml)
+    #ListResources(None,'foo')
+    CreateSliver(None, "plc.princeton.sap0", rspec_xml)
     
 if __name__ == "__main__":
     main()