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', 'enabled', 'description']
10 class UpdateSite(Method):
12 Updates a site. Only the fields specified in update_fields are
13 updated, all other fields are left untouched.
15 PIs can only update sites they are a member of. Only admins can
16 update max_slices, max_slivers, and login_base.
18 Returns 1 if successful, faults otherwise.
21 roles = ['admin', 'pi']
23 site_fields = dict(filter(can_update, Site.fields.items()))
27 Site.fields['site_id'],
31 returns = Parameter(int, '1 if successful')
33 def call(self, auth, site_id, site_fields):
34 site_fields = dict(filter(can_update, site_fields.items()))
36 # Get site information
37 sites = Sites(self.api, site_id)
39 raise PLCInvalidArgument, "No such site"
42 # Authenticated function
43 assert self.caller is not None
45 # If we are not an admin, make sure that the caller is a
47 if 'admin' not in self.caller['roles']:
48 if site['site_id'] not in self.caller['site_id']:
49 raise PLCPermissionDenied, "Not allowed to modify specified site"
51 # Remove admin only fields
53 site.update(site_fields)