Changeset 5b74b63 for fedd/federation/topdl.py
- Timestamp:
- Feb 20, 2010 12:07:17 PM (14 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
- Children:
- 39ee3cc
- Parents:
- 2fdf4b3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/federation/topdl.py
r2fdf4b3 r5b74b63 55 55 56 56 class ConsistencyError(RuntimeError): pass 57 class NamespaceError(RuntimeError): pass 57 58 58 59 class Attribute(base): … … 199 200 200 201 class Interface(base): 201 def __init__(self, substrate, capacity=None, latency=None, attribute=[], 202 element=None): 202 def __init__(self, substrate, name=None, capacity=None, latency=None, 203 attribute=[], element=None): 204 self.name = name 203 205 self.substrate = self.make_list(substrate) 204 206 self.capacity = self.init_class(Capacity, capacity) … … 216 218 else: l = None 217 219 218 return Interface(substrate=self.substrate, 220 return Interface(substrate=self.substrate, name=self.name, 219 221 capacity=c, latency=l, 220 222 attribute = [ a.clone() for a in self.attribute]) 221 223 222 224 def to_dict(self): 223 rv = { 'substrate': self.substrate }225 rv = { 'substrate': self.substrate, 'name': self.name } 224 226 if self.capacity: 225 227 rv['capacity'] = self.capacity.to_dict() … … 403 405 self.incorporate_elements() 404 406 407 @staticmethod 408 def name_element_interfaces(e): 409 names = set([i.name for i in e.interface if i.name]) 410 inum = 0 411 for i in [ i for i in e.interface if not i.name]: 412 while inum < 1000: 413 n = "inf%03d" % inum 414 inum += 1 415 if n not in names: 416 i.name = n 417 break 418 else: 419 raise NamespaceError("Cannot make new interface name") 420 421 422 423 def name_interfaces(self): 424 """ 425 For any interface without a name attribute, assign a unique one within 426 its element. 427 """ 428 429 for e in self.elements: 430 self.name_element_interfaces(e) 431 432 405 433 def incorporate_elements(self): 406 434 … … 416 444 417 445 for e in self.elements: 446 self.name_element_interfaces(e) 418 447 for i in e.interface: 419 448 i.element = e … … 781 810 out += '\t\t<node_type type_name="%s" slots="%s"/>\n' % (hw, slots) 782 811 for i, ii in enumerate(e.interface): 783 iname = "if%03d" % i 784 out += '\t\t<interface virtual_id="%s"/>\n' % iname 785 ifname[ii] = iname 812 out += '\t\t<interface virtual_id="%s"/>\n' % ii.name 786 813 ifnode[ii] = name 787 814 for f in filters: … … 797 824 for ii in s.interfaces: 798 825 out += ('\t\t<interface_ref virtual_node_id="%s"' + \ 799 'virtual_interface_id="%s"/>\n') % (ifnode[ii], i fname[ii])826 'virtual_interface_id="%s"/>\n') % (ifnode[ii], ii.name) 800 827 for f in filters: 801 828 out += f(s)
Note: See TracChangeset
for help on using the changeset viewer.