Changeset 89e2138


Ignore:
Timestamp:
May 19, 2010 4:06:11 AM (15 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
Children:
8a0c67f
Parents:
4d4dde4
Message:

Remove the phantom interfaces as well. It was sort of dumb to add them and
then remove them. Along the way I also cleaned up constraint names. They no
longer morph from string to tuple as they're localized. I added a topology
pointer.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/compose.py

    r4d4dde4 r89e2138  
    1919    """
    2020    def __init__(self, name=None, required=False, accepts=None, provides=None,
    21             match=None):
     21            topology=None, match=None):
    2222        self.name = name
    2323        self.required = required
    2424        self.accepts = accepts or []
    2525        self.provides = provides or []
     26        self.topology = None
    2627        self.match = match
    2728
     
    3233    def to_xml(self):
    3334        rv = "<constraint>"
    34         if isinstance(self.name, tuple):
    35             rv += "<name>%s</name>" % self.name[0]
    36         else:
    37             rv += "<name>%s</name>" % self.name
     35        rv += "<name>%s</name>" % self.name
    3836        rv += "<required>%s</required>" % self.required
    3937        for p in self.provides:
     
    188186    return n
    189187
    190 def add_interfaces(top, mark):
    191     """
    192     Add unconnected interfaces to the nodes whose names are keys in the mark
    193     dict.  As the interface is added change the name field of the contstraint
    194     in mark into a tuple containing the node name, interface name, and topology
    195     in which they reside.
    196     """
    197     for e in top.elements:
    198         if e.name in mark:
    199             con = mark[e.name]
    200             ii = make_new_name(set([x.name for x in e.interface]), "inf")
    201             e.interface.append(
    202                     topdl.Interface(substrate=[], name=ii, element=e))
    203             con.name = (e.name, ii, top)
    204 
    205188def localize_names(top, names, marks):
    206189    """
     
    225208        e.set_attribute('localized_name', e.name)
    226209        if e.name in names:
    227             nn= make_new_name(names, "computer")
     210            nn= make_new_name(names, "node")
    228211            if e.name in marks:
    229                 n, i, t = marks[e.name].name
    230                 marks[e.name].name = (nn, i, t)
     212                marks[e.name].name = nn
    231213            e.name = nn
    232214        else:
     
    259241                    # within the same topology.  This also excludes matched
    260242                    # constraints.
    261                     if can.name != c.name and can.name[2] != c.name[2] and \
     243                    if can.name != c.name and can.topology != c.topology and \
    262244                            not can.match:
    263245                        # Now check that the candidate also accepts c
     
    337319            sn = make_new_name(names, "sub")
    338320            s = topdl.Substrate(name=sn)
    339             connected = 0
    340             # Walk through all the computers in the topology
     321
     322            # These are the nodes that need to be connected.  Put an new
     323            # interface on each one and hook them to the new substrate.
    341324            for e in [ e for e in top.elements \
    342                     if isinstance(e, topdl.Computer)]:
    343                 # if the computer matches the computer and interface name in
    344                 # either c or c.match, connect it.  Once both computers have
    345                 # been found and connected, exit the loop walking through all
    346                 # computers.
    347                 for comp, inf in (c.name[0:2], c.match.name[0:2]):
    348                     if e.name == comp:
    349                         for i in e.interface:
    350                             if i.name == inf:
    351                                 i.substrate.append(sn)
    352                                 connected += 1
    353                                 break
    354                         break
    355                 # Connected both, so add the substrate to the topology
    356                 if connected == 2:
    357                     top.substrates.append(s)
    358                     break
    359             # c and c.match have been processed, so add them to the done set
     325                    if isinstance(e, topdl.Computer) \
     326                        and e.name in (c.name, c.match.name)]:
     327                ii = make_new_name(set([x.name for x in e.interface]), "inf")
     328                e.interface.append(
     329                        topdl.Interface(substrate=[sn], name=ii, element=e))
     330
     331
     332            # c and c.match have been processed, so add them to the done set,
     333            # and add the substrate
     334            top.substrates.append(s)
    360335            done.add(c)
    361336            done.add(c.match)
    362 
    363     # All interfaces with matched constraints have been connected.  Cull any
    364     # interfaces unassigned to a substrate
    365     for e in [ e for e in top.elements if isinstance(e, topdl.Computer)]:
    366         if any([ not i.substrate for i in e.interface]):
    367             e.interface = [ i for i in e.interface if i.substrate ]
    368337
    369338    top.incorporate_elements()
     
    469438        """
    470439        print >>f, "<component>"
    471         print >>f, "<constraints>"
    472         for c in constraints:
    473             print >>f, c.to_xml()
    474         print >>f, "</constraints>"
     440        if constraints:
     441            print >>f, "<constraints>"
     442            for c in constraints:
     443                print >>f, c.to_xml()
     444            print >>f, "</constraints>"
    475445        print >>f, topdl.topology_to_xml(comp, top='experiment')
    476446        print >>f, "</component>"
     
    578548            t = top.clone()
    579549            m = copy.deepcopy(marks)
     550            # Bind the constraints in m (the marks copy) to this topology
     551            for c in m.values():
     552                c.topology = t
    580553            index_constraints(m.values(), provides, accepts)
    581             add_interfaces(t, m)
    582554            localize_names(t, names, m)
    583             t.incorporate_elements()
    584555            constraints.extend(m.values())
    585556            topos.append(t)
     
    608579        import_components(files)
    609580
    610 # Let the user know if they messed up on specifying constraints.
    611 if any([ not isinstance(c.name, tuple) for c in constraints]):
    612     warn("nodes not found for constraints on %s" % \
    613             ",".join([ c.name for c in constraints \
    614             if isinstance(c.name, basestring)]))
    615     constraints = [ c for c in constraints if isinstance(c.name, tuple )]
    616 
    617581# If more than one component was given, actually do the composition, otherwise
    618582# this is probably a format conversion.
     
    643607    # that had matches.
    644608    comp = topdl.Topology()
    645     for t in set([ c.name[2] for c in constraints if c.match]):
     609    for t in set([ c.topology for c in constraints if c.match]):
    646610        comp.elements.extend([e.clone() for e in t.elements])
    647611        comp.substrates.extend([s.clone() for s in t.substrates])
Note: See TracChangeset for help on using the changeset viewer.