- Timestamp:
- May 19, 2010 4:06:11 AM (15 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
- Children:
- 8a0c67f
- Parents:
- 4d4dde4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/compose.py
r4d4dde4 r89e2138 19 19 """ 20 20 def __init__(self, name=None, required=False, accepts=None, provides=None, 21 match=None):21 topology=None, match=None): 22 22 self.name = name 23 23 self.required = required 24 24 self.accepts = accepts or [] 25 25 self.provides = provides or [] 26 self.topology = None 26 27 self.match = match 27 28 … … 32 33 def to_xml(self): 33 34 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 38 36 rv += "<required>%s</required>" % self.required 39 37 for p in self.provides: … … 188 186 return n 189 187 190 def add_interfaces(top, mark):191 """192 Add unconnected interfaces to the nodes whose names are keys in the mark193 dict. As the interface is added change the name field of the contstraint194 in mark into a tuple containing the node name, interface name, and topology195 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 205 188 def localize_names(top, names, marks): 206 189 """ … … 225 208 e.set_attribute('localized_name', e.name) 226 209 if e.name in names: 227 nn= make_new_name(names, " computer")210 nn= make_new_name(names, "node") 228 211 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 231 213 e.name = nn 232 214 else: … … 259 241 # within the same topology. This also excludes matched 260 242 # 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 \ 262 244 not can.match: 263 245 # Now check that the candidate also accepts c … … 337 319 sn = make_new_name(names, "sub") 338 320 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. 341 324 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) 360 335 done.add(c) 361 336 done.add(c.match) 362 363 # All interfaces with matched constraints have been connected. Cull any364 # interfaces unassigned to a substrate365 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 ]368 337 369 338 top.incorporate_elements() … … 469 438 """ 470 439 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>" 475 445 print >>f, topdl.topology_to_xml(comp, top='experiment') 476 446 print >>f, "</component>" … … 578 548 t = top.clone() 579 549 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 580 553 index_constraints(m.values(), provides, accepts) 581 add_interfaces(t, m)582 554 localize_names(t, names, m) 583 t.incorporate_elements()584 555 constraints.extend(m.values()) 585 556 topos.append(t) … … 608 579 import_components(files) 609 580 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 617 581 # If more than one component was given, actually do the composition, otherwise 618 582 # this is probably a format conversion. … … 643 607 # that had matches. 644 608 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]): 646 610 comp.elements.extend([e.clone() for e in t.elements]) 647 611 comp.substrates.extend([s.clone() for s in t.substrates])
Note: See TracChangeset
for help on using the changeset viewer.