source: fedd/federation/experiment_info.py @ 9294673

compt_changesinfo-ops
Last change on this file since 9294673 was 9294673, checked in by Ted Faber <faber@…>, 12 years ago

Turn (most) of another free floating dict into a class.

  • Property mode set to 100644
File size: 2.0 KB
Line 
1#!/usr/local/bin/python
2
3import copy
4
5class allocation_info:
6    """
7    An allocation identified by allocationID.  It includes the local name
8    of the testbed on which it was allocated and the uri on which to
9    contact it.  In addition, the proofs of access are included.
10    """
11    def __init__(self, allocID, tb, uri, proof=None):
12        self.allocID = allocID
13        self.tb = tb
14        self.uri = uri
15        self.proof = proof
16        self.attrs = { }
17
18    def set_attribute(self, a, v):
19        a = a.lower()
20        if a not in self.attrs: self.attrs[a] = v
21
22    def get_attribute(self, a, default=None):
23        a = a.lower()
24        return self.attrs.get(a, default)
25
26class experiment_info:
27    """
28    Information about an experiment in the eperiment controller.  It includes
29    the fedid and localnames, the identity the experiment acts as, current
30    status, topology allocation logs and the allocations themselves.
31    """
32    def __init__(self, fedid, localname, identity=None):
33        self.fedid = fedid
34        self.localname = localname
35        self.identity = identity
36        self.top = None
37        self.status = 'empty'
38        self.log = []
39        self.alloc = { }
40
41    def add_allocation(self, a):
42        self.alloc[a.tb] = a
43
44    def get_allocation(self, tb):
45        return self.alloc.get(tb,None)
46
47    def get_all_allocations(self):
48        return self.alloc.values()
49
50    def get_info(self):
51        """
52        Return the information as a dict suitable for a soap return value.
53        This is an infoResponseType in fedd_types.xsd.
54        """
55        # The state may be massaged by the service function that called
56        # get_info (e.g., encoded for XMLRPC transport) so copy structured
57        # fields.
58        rv = {
59                'experimentID': [
60                    { 'fedid': copy.deepcopy(self.fedid) },
61                    {'localname': self.localname },
62                ],
63                'experimentStatus': self.status,
64            }
65        if self.log:
66            rv['allocationLog'] = "".join(self.log)
67        if self.identity is not None:
68            rv['experimentAccess'] = {'X509': copy.deepcopy(self.identity)}
69        if self.top is not None:
70            rv['experimentdescription'] = \
71                { 'topdldescription': self.top.to_dict() }
72        return rv
73
Note: See TracBrowser for help on using the repository browser.