Changeset f37e9bf for fedd


Ignore:
Timestamp:
Nov 18, 2011 10:06:55 AM (9 years ago)
Author:
Ted Faber <faber@…>
Branches:
compt_changes, info-ops, master
Children:
2ac64d1a
Parents:
cb0aafb
Message:

topdl code support for new fields. Still initial code, untested.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/topdl.py

    rcb0aafb rf37e9bf  
    113113        return "<time>%f</time><kind>%s</kind>" % (self.time, self.kind)
    114114
     115class ServiceParam(base):
     116    def __init__(self, name, type):
     117        self.name = self.init_string(name)
     118        self.type = self.init_string(type)
     119
     120    def clone(self):
     121        return ServiceParam(self.name. self.type)
     122
     123    def to_dict(self):
     124        return { 'name': name, 'type': type }
     125
     126    def to_xml(self):
     127        return "<name>%s</name><type>%s</type>" % (self.name, self.type)
     128
     129class Service(base):
     130    def __init__(self, name, importer=[], param=[], description=None,
     131            status=None):
     132        self.name = self.init_string(name)
     133        self.importer = [self.init_string(i) \
     134                for i in self.make_list(importer)]
     135        self.param = [ self.init_class(ServiceParam, p) \
     136                for p in self.make_list(param) ]
     137        self.description = self.init_string(description)
     138        self.status = self.init_string(status)
     139
     140    def clone(self):
     141        return Service(
     142                name=self.name,
     143                importer=[ i for i in self.importer],
     144                param=[p.clone() for p in self.param],
     145                description=self.description,
     146                status=self.status)
     147
     148    def to_dict(self):
     149        rv = { }
     150        if self.name is not None:
     151            rv['name'] = self.name
     152        if self.importer:
     153            rv['importer'] = [ i for i in self.importer ]
     154        if self.param:
     155            rv['param'] = [ p.to_dict() for p in self.param ]
     156        if self.description is not None:
     157            rv['description'] = self.description
     158        if self.status is not None:
     159            rv['status'] = self.status
     160        return rv
     161
     162    def to_xml(self):
     163        rv = ''
     164        if self.name is not None:
     165            rv += '<name>%s</name>' % self.name
     166        if self.importer:
     167            rv += join(['<importer>%s</importer>' % i \
     168                    for i in self.importer],'')
     169        if self.param:
     170            rv += join('<param>%s</param>' % p.to_xml() \
     171                    for p in self.param], '')
     172        if self.description is not None:
     173            rv += '<description>%s</description>' % self.description
     174        if self.status is not None:
     175            rv += '<status>%s</status>' % self.status
     176        return rv
     177
    115178class Substrate(base):
    116     def __init__(self, name, capacity=None, latency=None, attribute=[]):
     179    def __init__(self, name, capacity=None, latency=None, attribute=[],
     180            localname=[], status=None, service=[], operation=[]):
    117181        self.name = self.init_string(name)
    118182        self.capacity = self.init_class(Capacity, capacity)
     
    120184        self.attribute = [ self.init_class(Attribute, a) \
    121185                for a in self.make_list(attribute) ]
     186        self.localname = [ self.init_string(ln)\
     187                for ln in self.make_list(localname) ]
     188        self.status = self.init_string(status)
     189        self.service = [ self.init_class(Service, s) \
     190                for s in self.make_list(service)]
     191        self.operation = [self.init_string(op) \
     192                for op in self.make_list(operation)]
    122193        self.interfaces = [ ]
    123194
     
    132203                capacity=c,
    133204                latency=l,
    134                 attribute = [a.clone() for a in self.attribute])
     205                attribute = [a.clone() for a in self.attribute],
     206                localname = [ ln for ln in self.localname],
     207                status = self.status,
     208                service = [ s.clone() for s in self.service]
     209                operation=[ op for op in operation])
    135210
    136211    def to_dict(self):
     
    142217        if self.attribute:
    143218            rv['attribute'] = [ a.to_dict() for a in self.attribute ]
     219        if self.localname:
     220            rv['localname'] = [ ln for ln in self.localname ]
     221        if self.status:
     222            rv['status'] = self.status
     223        if self.service:
     224            rv['service'] = [s.to_dict() for s in self.service]
     225        if self.operation:
     226            rv['operation'] = [op for op in self.operation]
    144227        return rv
    145228
     
    154237            rv += join(["<attribute>%s</attribute>" % a.to_xml() \
    155238                    for a in self.attribute], "")
     239        if self.localname:
     240            rv += join('<localname>%s</localname>' % ln \
     241                    for ln in self.localname], '')
     242        if self.status is not None:
     243            rv += '<status>%s</status>' % self.status
     244        if self.service:
     245            rv += join(['<service>%s</service' % s.to_xml() \
     246                    for s in self.service], '')
     247        if self.operation:
     248            rv += join(['<operation>%s</operation>' % op \
     249                    for op in self.operation], '')
    156250        return rv
    157251
     
    360454class Computer(base):
    361455    def __init__(self, name, cpu=[], os=[], software=[], storage=[],
    362             interface=[], attribute=[]):
     456            interface=[], attribute=[], localname=[], status=None, service=[],
     457            operation=[]):
    363458        def assign_element(i):
    364459            i.element = self
     
    376471        self.attribute = [ self.init_class(Attribute, a) \
    377472                for a in self.make_list(attribute) ]
     473        self.localname = [ self.init_string(ln)\
     474                for ln in self.make_list(localname) ]
     475        self.status = self.init_string(status)
     476        self.service = [ self.init_class(Service, s) \
     477                for s in self.make_list(service)]
     478        self.operation = [self.init_string(op) \
     479                for op in self.make_list(operation)]
    378480        map(assign_element, self.interface)
    379481
     
    386488                storage=[x.clone() for x in self.storage],
    387489                interface=[x.clone() for x in self.interface],
    388                 attribute=[x.clone() for x in self.attribute])
     490                attribute=[x.clone() for x in self.attribute],
     491                localname =[ ln for for ln in self.localname],
     492                status = self.status,
     493                service = [s.clone() for s in self.service],
     494                operation = [op for op in self.operation])
    389495
    390496    def to_dict(self):
     
    404510        if self.attribute:
    405511            rv['attribute'] = [ i.to_dict() for i in self.attribute ]
     512        if self.localname:
     513            rv['localname'] = [ ln for ln in self.localname ]
     514        if self.status:
     515            rv['status'] = self.status
     516        if self.service:
     517            rv['service'] = [s.to_dict() for s in self.service]
     518        if self.operation:
     519            rv['operation'] = [op for op in self.operation]
    406520        return { 'computer': rv }
    407521
     
    424538            rv += join(["<attribute>%s</attribute>" % a.to_xml() \
    425539                    for a in self.attribute], "")
     540        if self.localname:
     541            rv += join('<localname>%s</localname>' % ln \
     542                    for ln in self.localname], '')
     543        if self.status is not None:
     544            rv += '<status>%s</status>' % self.status
     545        if self.service:
     546            rv += join(['<service>%s</service' % s.to_xml() \
     547                    for s in self.service], '')
     548        if self.operation:
     549            rv += join(['<operation>%s</operation>' % op \
     550                    for op in self.operation], '')
    426551        return "<computer>%s</computer>" % rv
    427552
     
    429554
    430555class Testbed(base):
    431     def __init__(self, uri, type, interface=[], attribute=[]):
     556    def __init__(self, uri, type, interface=[], attribute=[], localname=[],
     557            status=None, service=[], operation=[]):
    432558        self.uri = self.init_string(uri)
    433559        self.type = self.init_string(type)
     
    436562        self.attribute = [ self.init_class(Attribute, c) \
    437563                for c in self.make_list(attribute) ]
     564        self.localname = [ self.init_string(ln)\
     565                for ln in self.make_list(localname) ]
     566        self.status = self.init_string(status)
     567        self.service = [ self.init_class(Service, s) \
     568                for s in self.make_list(service)]
     569        self.operation = [self.init_string(op) \
     570                for op in self.make_list(operation)]
    438571
    439572    def clone(self):
    440573        return Testbed(self.uri, self.type,
    441574                interface=[i.clone() for i in self.interface],
    442                 attribute=[a.cone() for a in self.attribute])
     575                attribute=[a.cone() for a in self.attribute],
     576                localname = [ ln for ln in self.localname ],
     577                status=self.status,
     578                service=[s.clone() for s in self.service ],
     579                operation = [ op for op in self.operation ])
    443580
    444581    def to_dict(self):
     
    450587        if self.attribute:
    451588            rv['attribute'] = [ a.to_dict() for a in self.attribute]
     589        if self.localname:
     590            rv['localname'] = [ ln for ln in self.localname ]
     591        if self.status:
     592            rv['status'] = self.status
     593        if self.service:
     594            rv['service'] = [s.to_dict() for s in self.service]
     595        if self.operation:
     596            rv['operation'] = [op for op in self.operation]
    452597        return { 'testbed': rv }
    453598
     
    461606            rv += join(["<attribute>%s</attribute>" % a.to_xml() \
    462607                    for a in self.attribute], "")
     608        if self.localname:
     609            rv += join('<localname>%s</localname>' % ln \
     610                    for ln in self.localname], '')
     611        if self.status is not None:
     612            rv += '<status>%s</status>' % self.status
     613        if self.service:
     614            rv += join(['<service>%s</service' % s.to_xml() \
     615                    for s in self.service], '')
     616        if self.operation:
     617            rv += join(['<operation>%s</operation>' % op \
     618                    for op in self.operation], '')
    463619        return "<testbed>%s</testbed>" % rv
    464620
Note: See TracChangeset for help on using the changeset viewer.