first step to merge senslab upstream:
[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     # the answer to ListSlices, a list of slice urns
79     def list_slices (self, creds, options):
80         return []
81
82     # answer to ListResources
83     # first 2 args are None in case of resource discovery
84     # expected : rspec (xml string)
85     def list_resources (self, slice_urn, slice_hrn, creds, options):
86         return "dummy Driver.list_resources needs to be redefined"
87
88     # the answer to SliverStatus on a given slice
89     def sliver_status (self, slice_urn, slice_hrn): return {}
90
91     # the answer to CreateSliver on a given slice
92     # expected to return a valid rspec 
93     # identical to ListResources after the slice was modified
94     def create_sliver (self, slice_urn, slice_hrn, creds, rspec_string, users, options):
95         return "dummy Driver.create_sliver needs to be redefined"
96
97     # the answer to DeleteSliver on a given slice
98     def delete_sliver (self, slice_urn, slice_hrn, creds, options):
99         return "dummy Driver.delete_sliver needs to be redefined"
100
101     # the answer to RenewSliver
102     # expected to return a boolean to indicate success
103     def renew_sliver (self, slice_urn, slice_hrn, creds, expiration_time, options):
104         return False
105
106     # the answer to start_slice/stop_slice
107     # 1 means success, otherwise raise exception
108     def start_slice (self, slice_urn, slice_xrn, creds):
109         return 1
110     def stop_slice (self, slice_urn, slice_xrn, creds):
111         return 1
112     # somehow this one does not have creds - not implemented in PL anyways
113     def reset_slice (self, slice_urn, slice_xrn, creds):
114         return 1
115
116     # the answer to GetTicket
117     # expected is a ticket, i.e. a certificate, as a string
118     def get_ticket (self, slice_urn, slice_xrn, creds, rspec, options):
119         return "dummy Driver.get_ticket needs to be redefined"
120