Merge branch 'upstreammaster'
[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     # this at minima should fill in the 'researcher' field for slice records
24     # as this information is then used to compute rights
25     # roadmap: there is an intention to redesign the SFA database so as to clear up 
26     # this constraint, based on the principle that SFA should not rely on the
27     # testbed database to perform such a core operation (i.e. getting rights right)
28     def augment_records_with_testbed_info (self, sfa_records):
29         return sfa_records
30
31     # incoming record, as provided by the client to the Register API call
32     # expected retcod 'pointer'
33     # 'pointer' is typically an int db id, that makes sense in the testbed environment
34     # -1 if this feature is not relevant 
35     def register (self, sfa_record, hrn, pub_key) : 
36         return -1
37
38     # incoming record is the existing sfa_record
39     # expected retcod boolean, error message logged if result is False
40     def remove (self, sfa_record): 
41         return True
42
43     # incoming are the sfa_record:
44     # (*) old_sfa_record is what we have in the db for that hrn
45     # (*) new_sfa_record is what was passed in the Update call
46     # expected retcod boolean, error message logged if result is False
47     # NOTE 1. about keys
48     # this is confusing because a user may have several ssh keys in 
49     # the planetlab database, but we need to pick one to generate its cert
50     # so as much as in principle we should be able to use new_sfa_record['keys']
51     # the manager code actually picks one (the first one), and it seems safer
52     # to pass it along rather than depending on the driver code to do the same
53     #
54     # NOTE 2. about keys
55     # when changing the ssh key through this method the gid gets changed too
56     # should anything be passed back to the caller in this case ?
57     def update (self, old_sfa_record, new_sfa_record, hrn, new_key): 
58         return True
59
60     # callack for register/update
61     # this allows to capture changes in the relations between objects
62     # the ids below are the ones found in the 'pointer' field
63     # this can get typically called with
64     # 'slice' 'user' 'researcher' slice_id user_ids 
65     # 'authority' 'user' 'pi' authority_id user_ids 
66     def update_relation (self, subject_type, target_type, relation_name, subject_id, link_ids):
67         pass
68
69     ########################################
70     ########## aggregate oriented
71     ########################################
72     
73     # a name for identifying the kind of testbed
74     def testbed_name (self): return "undefined"
75
76     # a dictionary that gets appended to the generic answer to GetVersion
77     # 'geni_request_rspec_versions' and 'geni_ad_rspec_versions' are mandatory
78     def aggregate_version (self): return {}
79
80     # the answer to ListSlices, a list of slice urns
81     def list_slices (self, creds, options):
82         return []
83
84     # answer to ListResources
85     # first 2 args are None in case of resource discovery
86     # expected : rspec (xml string)
87     def list_resources (self, slice_urn, slice_hrn, creds, options):
88         return "dummy Driver.list_resources needs to be redefined"
89
90     # the answer to SliverStatus on a given slice
91     def sliver_status (self, slice_urn, slice_hrn): return {}
92
93     # the answer to CreateSliver on a given slice
94     # expected to return a valid rspec 
95     # identical to ListResources after the slice was modified
96     def create_sliver (self, slice_urn, slice_hrn, creds, rspec_string, users, options):
97         return "dummy Driver.create_sliver needs to be redefined"
98
99     # the answer to DeleteSliver on a given slice
100     def delete_sliver (self, slice_urn, slice_hrn, creds, options):
101         return "dummy Driver.delete_sliver needs to be redefined"
102
103     # the answer to RenewSliver
104     # expected to return a boolean to indicate success
105     def renew_sliver (self, slice_urn, slice_hrn, creds, expiration_time, options):
106         return False
107
108     # the answer to start_slice/stop_slice
109     # 1 means success, otherwise raise exception
110     def start_slice (self, slice_urn, slice_xrn, creds):
111         return 1
112     def stop_slice (self, slice_urn, slice_xrn, creds):
113         return 1
114     # somehow this one does not have creds - not implemented in PL anyways
115     def reset_slice (self, slice_urn, slice_xrn, creds):
116         return 1
117
118     # the answer to GetTicket
119     # expected is a ticket, i.e. a certificate, as a string
120     def get_ticket (self, slice_urn, slice_xrn, creds, rspec, options):
121         return "dummy Driver.get_ticket needs to be redefined"
122