1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Sites import Site, Sites
5 from PLC.Auth import Auth
7 can_update = lambda (field, value): field in \
8 ['name', 'abbreviated_name',
9 'is_public', 'latitude', 'longitude', 'url',
10 'max_slices', 'max_slivers']
12 class UpdateSite(Method):
14 Updates a site. Only the fields specified in update_fields are
15 updated, all other fields are left untouched.
17 PIs can only update sites they are a member of. Only admins can
20 Returns 1 if successful, faults otherwise.
23 roles = ['admin', 'pi']
25 site_fields = dict(filter(can_update, Site.fields.items()))
29 Mixed(Site.fields['site_id'],
30 Site.fields['login_base']),
34 returns = Parameter(int, '1 if successful')
36 def call(self, auth, site_id_or_login_base, site_fields):
37 site_fields = dict(filter(can_update, site_fields.items()))
39 # Get site information
40 sites = Sites(self.api, [site_id_or_login_base])
42 raise PLCInvalidArgument, "No such site"
44 site = sites.values()[0]
46 # Authenticated function
47 assert self.caller is not None
49 # If we are not an admin, make sure that the caller is a
51 if 'admin' not in self.caller['roles']:
52 if site['site_id'] not in self.caller['site_ids']:
53 raise PLCPermissionDenied, "Not allowed to modify specified site"
55 if 'max_slices' or 'max_slivers' in site_fields:
56 raise PLCInvalidArgument, "Only admins can update max_slices and max_slivers"
58 site.update(site_fields)