source: fedd/federation/experiment_info.py @ fe6e0be

compt_changes
Last change on this file since fe6e0be was 6bedbdba, checked in by Ted Faber <faber@…>, 13 years ago

Split topdl and fedid out to different packages. Add differential
installs

  • Property mode set to 100644
File size: 3.6 KB
RevLine 
[29d5f7c]1#!/usr/local/bin/python
2
3import copy
[6bedbdba]4from deter import topdl
[6e33086]5from datetime import datetime, timedelta
6from numbers import Number
[29d5f7c]7
[ab3d6c5]8class federated_service:
9    def __init__(self, name, exporter=None, importers=None, params=None, 
10            reqs=None, portal=None):
11        self.name=name
12        self.exporter=exporter
13        if importers is None: self.importers = []
14        else: self.importers=importers
15        if params is None: self.params = { }
16        else: self.params = params
17        if reqs is None: self.reqs = []
18        else: self.reqs = reqs
19
20        if portal is not None:
21            self.portal = portal
22        else:
23            self.portal = (name in federated_service.needs_portal)
24
25    def to_topdl(self):
26        return topdl.Service(name=self.name, importer=self.importers)
27
28    def __str__(self):
29        return "name %s export %s import %s params %s reqs %s" % \
30                (self.name, self.exporter, self.importers, self.params,
31                        [ (r['name'], r['visibility']) for r in self.reqs] )
32
33    needs_portal = ('SMB', 'seer', 'tmcd', 'project_export', 'seer_master')
34
[29d5f7c]35class allocation_info:
36    """
37    An allocation identified by allocationID.  It includes the local name
38    of the testbed on which it was allocated and the uri on which to
39    contact it.  In addition, the proofs of access are included.
40    """
[ab3d6c5]41    def __init__(self, allocID, tb, uri, proof=None, services=None):
[29d5f7c]42        self.allocID = allocID
43        self.tb = tb
44        self.uri = uri
45        self.proof = proof
[ab3d6c5]46        if services is not None: self.services = services
47        else: self.services = [ ]
[9294673]48        self.attrs = { }
49
50    def set_attribute(self, a, v):
51        a = a.lower()
52        if a not in self.attrs: self.attrs[a] = v
53
54    def get_attribute(self, a, default=None):
55        a = a.lower()
56        return self.attrs.get(a, default)
[29d5f7c]57
58class experiment_info:
59    """
60    Information about an experiment in the eperiment controller.  It includes
61    the fedid and localnames, the identity the experiment acts as, current
62    status, topology allocation logs and the allocations themselves.
63    """
64    def __init__(self, fedid, localname, identity=None):
65        self.fedid = fedid
66        self.localname = localname
67        self.identity = identity
68        self.top = None
69        self.status = 'empty'
70        self.log = []
71        self.alloc = { }
[6e33086]72        self.last_update = datetime.now()
[29d5f7c]73
74    def add_allocation(self, a):
75        self.alloc[a.tb] = a
76
77    def get_allocation(self, tb):
78        return self.alloc.get(tb,None)
79
80    def get_all_allocations(self):
81        return self.alloc.values()
82
[6e33086]83    def updated(self):
84        self.last_update = datetime.now()
85
86    def older_than(self, secs=None, dt=None):
87        """
88        If the last update of this info was more than secs seconds ago, or
89        before dt (a datetime), return True.  If both secs and dt or neither is
90        given return False.  If the last update time is completelt unknown
91        (which should never happen) return True.
92        """
93        if self.last_update is None:
94            return True
95        elif dt is None and isinstance(secs, Number): 
96            return self.last_update + timedelta(seconds=secs) < datetime.now()
97        elif secs is None and isinstance(dt, datetime):
98            return self.last_update < dt
99        else:
100            return False
101
102
[29d5f7c]103    def get_info(self):
104        """
105        Return the information as a dict suitable for a soap return value.
106        This is an infoResponseType in fedd_types.xsd.
107        """
108        # The state may be massaged by the service function that called
109        # get_info (e.g., encoded for XMLRPC transport) so copy structured
110        # fields.
111        rv = {
112                'experimentID': [
113                    { 'fedid': copy.deepcopy(self.fedid) },
114                    {'localname': self.localname },
115                ],
116                'experimentStatus': self.status,
117            }
118        if self.log:
119            rv['allocationLog'] = "".join(self.log)
120        if self.identity is not None:
121            rv['experimentAccess'] = {'X509': copy.deepcopy(self.identity)}
122        if self.top is not None:
123            rv['experimentdescription'] = \
124                { 'topdldescription': self.top.to_dict() }
125        return rv
126
Note: See TracBrowser for help on using the repository browser.