removed all refrences to pl_info/geni_info in record object and anything that used...
[sfa.git] / geni / methods / update.py
1 from geni.util.faults import *
2 from geni.util.excep import *
3 from geni.util.method import Method
4 from geni.util.parameter import Parameter, Mixed
5 from geni.util.auth import Auth
6 from geni.util.record import GeniRecord
7 from geni.util.debug import log
8
9 class update(Method):
10     """
11     Update an object in the registry. Currently, this only updates the
12     PLC information associated with the record. The Geni fields (name, type,
13     GID) are fixed.
14     
15     @param cred credential string specifying rights of the caller
16     @param record a record dictionary to be updated
17
18     @return 1 if successful, faults otherwise 
19     """
20
21     interfaces = ['registry']
22     
23     accepts = [
24         Parameter(str, "Credential string"),
25         Parameter(dict, "Record dictionary to be updated")
26         ]
27
28     returns = Parameter(int, "1 if successful")
29     
30     def call(self, cred, record_dict):
31         self.api.auth.check(cred, "update")
32         record = GeniRecord(dict = record_dict)
33         type = record.get_type()
34         self.api.auth.verify_object_permission(record.get_name())
35         auth_name = self.api.auth.get_authority(record.get_name())
36         if not auth_name:
37             auth_name = record.get_name()
38         table = self.api.auth.get_auth_table(auth_name)
39
40         # make sure the record exists
41         existing_record_list = table.resolve(type, record.get_name())
42         if not existing_record_list:
43             raise RecordNotFound(record.get_name())
44         existing_record = existing_record_list[0]
45
46         # Update_membership needs the membership lists in the existing record
47         # filled in, so it can see if members were added or removed
48         self.api.fill_record_info(existing_record)
49
50          # Use the pointer from the existing record, not the one that the user
51         # gave us. This prevents the user from inserting a forged pointer
52         pointer = existing_record.get_pointer()
53
54         # update the PLC information that was specified with the record
55
56         if (type == "authority"):
57             self.api.plshell.UpdateSite(self.api.plauth, pointer, record)
58
59         elif type == "slice":
60             self.api.plshell.UpdateSlice(self.api.plauth, pointer, record)
61
62         elif type == "user":
63             # SMBAKER: UpdatePerson only allows a limited set of fields to be
64             #    updated. Ideally we should have a more generic way of doing
65             #    this. I copied the field names from UpdatePerson.py...
66             update_fields = {}
67             all_fields = record
68             for key in all_fields.keys():
69                 if key in ['first_name', 'last_name', 'title', 'email',
70                            'password', 'phone', 'url', 'bio', 'accepted_aup',
71                            'enabled']:
72                     update_fields[key] = all_fields[key]
73             self.api.plshell.UpdatePerson(self.api.plauth, pointer, update_fields)
74
75         elif type == "node":
76             self.api.plshell.UpdateNode(self.api.plauth, pointer, record)
77
78         else:
79             raise UnknownGeniType(type)
80
81         # update membership for researchers, pis, owners, operators
82         self.api.update_membership(existing_record, record)
83
84         return 1