first stab at a design where each incoming API call has its own dbsession
[sfa.git] / sfa / managers / driver.py
1
2 # an attempt to document what a driver class should provide, 
3 # and implement reasonable defaults
4 #
5
6 class Driver:
7     
8     def __init__ (self, api): 
9         self.api = api
10         # this is the hrn attached to the running server
11         self.hrn = api.config.SFA_INTERFACE_HRN
12
13     ########################################
14     ########## registry oriented
15     ########################################
16
17     # NOTE: the is_enabled method is deprecated
18     # it was only making things confusing, as the (PL) import mechanism would
19     # ignore not enabled users anyway..
20
21     # the following is used in Resolve (registry) when run in full mode
22     #     after looking up the sfa db, we wish to be able to display
23     #     testbed-specific info as well
24     # based on the principle that SFA should not rely on the testbed database
25     # to perform such a core operation (i.e. getting rights right) 
26     # this is no longer in use when performing other SFA operations 
27     def augment_records_with_testbed_info (self, sfa_records):
28         return sfa_records
29
30     # incoming record, as provided by the client to the Register API call
31     # expected retcod 'pointer'
32     # 'pointer' is typically an int db id, that makes sense in the testbed environment
33     # -1 if this feature is not relevant 
34     def register (self, sfa_record, hrn, pub_key) : 
35         return -1
36
37     # incoming record is the existing sfa_record
38     # expected retcod boolean, error message logged if result is False
39     def remove (self, sfa_record): 
40         return True
41
42     # incoming are the sfa_record:
43     # (*) old_sfa_record is what we have in the db for that hrn
44     # (*) new_sfa_record is what was passed in the Update call
45     # expected retcod boolean, error message logged if result is False
46     # NOTE 1. about keys
47     # this is confusing because a user may have several ssh keys in 
48     # the planetlab database, but we need to pick one to generate its cert
49     # so as much as in principle we should be able to use new_sfa_record['keys']
50     # the manager code actually picks one (the first one), and it seems safer
51     # to pass it along rather than depending on the driver code to do the same
52     #
53     # NOTE 2. about keys
54     # when changing the ssh key through this method the gid gets changed too
55     # should anything be passed back to the caller in this case ?
56     def update (self, old_sfa_record, new_sfa_record, hrn, new_key): 
57         return True
58
59     # callack for register/update
60     # this allows to capture changes in the relations between objects
61     # the ids below are the ones found in the 'pointer' field
62     # this can get typically called with
63     # 'slice' 'user' 'researcher' slice_id user_ids 
64     # 'authority' 'user' 'pi' authority_id user_ids 
65     def update_relation (self, subject_type, target_type, relation_name, subject_id, link_ids):
66         pass
67
68     ########################################
69     ########## aggregate oriented
70     ########################################
71     
72     # a name for identifying the kind of testbed
73     def testbed_name (self): return "undefined"
74
75     # a dictionary that gets appended to the generic answer to GetVersion
76     # 'geni_request_rspec_versions' and 'geni_ad_rspec_versions' are mandatory
77     def aggregate_version (self): return {}
78
79     # answer to ListResources
80     # returns : advertisment rspec (xml string)
81     def list_resources (self, version=None, options={}):
82         return "dummy Driver.list_resources needs to be redefined"
83
84     # the answer to Describe on a slice or a set of the slivers in a slice
85     # returns: a struct:
86     #{
87     #  geni_rspec: <geni.rspec, a Manifest RSpec>
88     #  geni_urn: <string slice urn of the containing slice>
89     #  geni_slivers: [
90     #              {
91     #                geni_sliver_urn: <string sliver urn>
92     #                geni_expires: <dateTime.rfc3339 allocation expiration string, as in geni_expires from SliversStatus>,
93     #                geni_allocation_status: <string sliver state - e.g. geni_allocated or geni_provisioned >,
94     #                geni_operational_status: <string sliver operational state>,
95     #                geni_error: <optional string. The field may be omitted entirely but may not be null/None, explaining any failure for a sliver.>
96     #              },
97     #              ...
98     #                ]
99     #}
100     def describe (self, urns, version, options={}):
101         return "dummy Driver.describe needs to be redefined"
102
103     # the answer to Allocate on a given slicei or a set of the slivers in a slice
104     # returns: same struct as for describe.
105     def allocate (self, urn, rspec_string, expiration, options={}):
106         return "dummy Driver.allocate needs to be redefined"
107
108     # the answer to Provision on a given slice or a set of the slivers in a slice
109     # returns: same struct as for describe.
110     def provision(self, urns, options={}):
111         return "dummy Driver.provision needs to be redefined"
112
113     # the answer to PerformOperationalAction on a given slice or a set of the slivers in a slice
114     # returns: struct containing "geni_slivers" list of the struct returned by describe.
115     def perform_operational_action (self, urns, action, options={}):
116         return "dummy Driver.perform_operational_action needs to be redefined"
117
118     # the answer to Status on a given slice or a set of the slivers in a slice
119     # returns: struct containing "geni_urn" and "geni_slivers" list of the struct returned by describe.
120     def status (self, urns, options={}): 
121         return "dummy Driver.status needs to be redefined"
122
123     # the answer to Renew on a given slice or a set of the slivers in a slice
124     # returns: struct containing "geni_slivers" list of the struct returned by describe.
125     def renew (self, urns, expiration_time, options={}):
126         return "dummy Driver.renew needs to be redefined"
127
128     # the answer to Delete on a given slice
129     # returns: struct containing "geni_slivers" list of the struct returned by describe.
130     def delete(self, urns, options={}):
131         return "dummy Driver.delete needs to be redefined"
132
133     # the answer to Shutdown on a given slice
134     # returns: boolean
135     def shutdown (self, xrn, options={}):
136         return False