X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Frspecs%2Faggregates%2Frspec_manager_max.py;h=c6504b997badb4cd701a60926bbc040b9c75c1bd;hb=3d7237fa0b5f2b4a60cb97c7fb3b6aecfd94558a;hp=65ace0e41ddf26b483e9417ab585c40f99ff8896;hpb=d0d4a1a11e155c8d7b8843e31725936153648d78;p=sfa.git diff --git a/sfa/rspecs/aggregates/rspec_manager_max.py b/sfa/rspecs/aggregates/rspec_manager_max.py index 65ace0e4..c6504b99 100644 --- a/sfa/rspecs/aggregates/rspec_manager_max.py +++ b/sfa/rspecs/aggregates/rspec_manager_max.py @@ -1,9 +1,9 @@ #!/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.namespace import * from sfa.util.rspec import * from sfa.util.specdict import * from sfa.util.faults import * @@ -18,24 +18,25 @@ import xml.dom.minidom SFA_MAX_CONF_FILE = '/etc/sfa/max_allocations' SFA_MAX_DEFAULT_RSPEC = '/etc/sfa/max_physical.xml' +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'] @@ -70,7 +71,6 @@ def get_interface_map(): def allocations_to_rspec(allocations): rspec = xml.dom.minidom.parse(SFA_MAX_DEFAULT_RSPEC) req = rspec.firstChild.appendChild(rspec.createElement("request")) - pdb.set_trace() for (iname,ip) in allocations: ifspec = req.appendChild(rspec.createElement("ifspec")) ifspec.setAttribute("name","tns:"+iname) @@ -82,7 +82,7 @@ def allocations_to_rspec(allocations): def if_endpoints(ifs): nodes=[] for l in ifs: - nodes.extend([topology[l][0]]) + nodes.extend(topology[l][0]) return nodes def lock_state_file(): @@ -121,22 +121,26 @@ def collapse_alloc_dict(d): return ret -def alloc_links(api, links_to_add, links_to_drop, foo): - #for l in links_to_add: - #(node1,ip1,node2,ip2) = l - #api.plshell.AddSliceTag(api.plauth, [slicename], ['node_ids']) +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] + 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): - requested_nodes = if_endpoints(requested_ifs) - create_slice_max_aggregate(api, hrn, requested_nodes) # 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 = {} @@ -249,10 +253,10 @@ def get_rspec(api, hrn): # plc.princeton.sapan vlan23,vlan45 allocations = read_alloc_dict() - if (hrn): - ret_rspec = allocations_to_rspec(allocations[hrn]) + if (hrn and allocations.has_key(hrn)): + ret_rspec = allocations_to_rspec(allocations[hrn]) else: - ret_rspec = open(SFA_MAX_DEFAULT_RSPEC).read() + ret_rspec = open(SFA_MAX_CANNED_RSPEC).read() return (ret_rspec) @@ -263,7 +267,7 @@ def create_slice(api, hrn, rspec_xml): # 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() @@ -282,12 +286,11 @@ def create_slice(api, hrn, rspec_xml): current_interfaces = map(lambda(elt):elt[0], current_allocations) current_hrn_interfaces = map(lambda(elt):elt[0], current_hrn_allocations) - pdb.set_trace() 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 @@ -313,15 +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') + #get_rspec(None,'foo') + create_slice(None, "plc.princeton.sap0", rspec_xml) if __name__ == "__main__": main()