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