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 PasswordAuth
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 To remove a value without setting a new one in its place (for
18 example, to remove an address from the node), specify -1 for int
19 and double fields and 'null' for string fields. hostname and
20 boot_state cannot be unset.
22 PIs can only update sites they are a member of. Only admins can
25 Returns 1 if successful, faults otherwise.
28 roles = ['admin', 'pi']
30 update_fields = dict(filter(can_update, Site.fields.items()))
34 Mixed(Site.fields['site_id'],
35 Site.fields['login_base']),
39 returns = Parameter(int, '1 if successful')
41 def call(self, auth, site_id_or_login_base, site_fields):
42 site_fields = dict(filter(can_update, site_fields.items()))
44 # Get site information
45 sites = Sites(self.api, [site_id_or_login_base])
47 raise PLCInvalidArgument, "No such site"
49 site = sites.values()[0]
51 # Authenticated function
52 assert self.caller is not None
54 # If we are not an admin, make sure that the caller is a
56 if 'admin' not in self.caller['roles']:
57 if site['site_id'] not in self.caller['site_ids']:
58 raise PLCPermissionDenied, "Not allowed to modify specified site"
60 if 'max_slices' or 'max_slivers' in site_fields:
61 raise PLCInvalidArgument, "Only admins can update max_slices and max_slivers"
63 site.update(site_fields)