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