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', 'login_base',
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
18 update max_slices, max_slivers, and login_base.
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')
38 def call(self, auth, site_id_or_login_base, site_fields):
39 site_fields = dict(filter(can_update, site_fields.items()))
41 # Get site information
42 sites = Sites(self.api, [site_id_or_login_base])
44 raise PLCInvalidArgument, "No such site"
47 if site['peer_id'] is not None:
48 raise PLCInvalidArgument, "Not a local site"
50 # Authenticated function
51 assert self.caller is not None
53 # If we are not an admin, make sure that the caller is a
55 if 'admin' not in self.caller['roles']:
56 if site['site_id'] not in self.caller['site_ids']:
57 raise PLCPermissionDenied, "Not allowed to modify specified site"
59 # Remove admin only fields
60 for key in 'max_slices', 'max_slivers', 'login_base':
63 site.update(site_fields)
67 self.object_ids = [site['site_id']]
68 self.message = 'Site %d updated: %s' % \
69 (site['site_id'], ", ".join(site_fields.keys()))