Changeset 2fdf4b3 for fedd


Ignore:
Timestamp:
Feb 19, 2010 8:32:58 AM (15 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
Children:
5b74b63
Parents:
6a8a9ec
Message:

RSPEC conversion passes the smell test. ProtoGENI's down so we can't test yet.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/topdl.py

    r6a8a9ec r2fdf4b3  
    749749"""
    750750    return out
     751
     752def topology_to_rspec(t, filters=[]):
     753    out = '<?xml version="1.0" encoding="UTF-8"?>\n' + \
     754        '<rspec xmlns="http://www.protogeni.net/resources/rspec/0.1"\n' + \
     755        '\txmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n' + \
     756        '\txsi:schemaLocation="http://www.protogeni.net/resources/rspec/0.1 '+ \
     757        'http://www.protogeni.net/resources/rspec/0.1/request.xsd"\n' + \
     758        '\ttype="request" >\n'
     759
     760    ifname = { }
     761    ifnode = { }
     762
     763    for e in [e for e in t.elements if isinstance(e, Computer)]:
     764        name = e.name[0]
     765        virt_type = e.get_attribute("virtualization_type") or "emulab-vnode"
     766        exclusive = e.get_attribute("exclusive") or "1"
     767        hw = e.get_attribute("type") or "pc";
     768        slots = e.get_attribute("slots") or "1";
     769        startup = e.get_attribute("startup")
     770        tarfiles = " ".join([ "%s %s" % (s.install, s.location) \
     771                for s in e.software if s.location and s.install ])
     772
     773        extras = ""
     774        if startup: extras += '\t\tstartup_command="%s"\n' % startup
     775        if tarfiles: extras +='\t\ttarfiles="%s"\n' % tarfiles
     776        out += '\t<node virtual_id="%s"\n\t\tvirtualization_type="%s"\n' % \
     777                (name, virt_type)
     778        out += '\t\texclusive="%s"' % exclusive
     779        if extras: out += '\n%s' % extras
     780        out += '>\n'
     781        out += '\t\t<node_type type_name="%s" slots="%s"/>\n' % (hw, slots)
     782        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
     786            ifnode[ii] = name
     787        for f in filters:
     788            out += f(s)
     789        out += '\t</node>\n'
     790
     791    for i, s in enumerate(t.substrates):
     792        out += '\t<link virtual_id="%s" link_type="ethernet">\n'
     793        if s.capacity and s.capacity.kind == "max":
     794            out += '\t\t<bandwidth>%f</bandwidth>\n' % s.capacity.rate
     795        if s.latency and s.latency.kind == "max":
     796            out += '\t\t<latency>%f</latency>\n' % s.latency.time
     797        for ii in s.interfaces:
     798            out += ('\t\t<interface_ref virtual_node_id="%s"' + \
     799                    'virtual_interface_id="%s"/>\n') % (ifnode[ii], ifname[ii])
     800        for f in filters:
     801            out += f(s)
     802        out += '\t</link>\n'
     803    out += '</rspec>\n'
     804    return out
     805
Note: See TracChangeset for help on using the changeset viewer.