git://git.onelab.eu
/
plcapi.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
- added logging variable 'object_type'
[plcapi.git]
/
PLC
/
Methods
/
UpdateSite.py
diff --git
a/PLC/Methods/UpdateSite.py
b/PLC/Methods/UpdateSite.py
index
bb51747
..
bda0c04
100644
(file)
--- a/
PLC/Methods/UpdateSite.py
+++ b/
PLC/Methods/UpdateSite.py
@@
-2,52
+2,50
@@
from PLC.Faults import *
from PLC.Method import Method
from PLC.Parameter import Parameter, Mixed
from PLC.Sites import Site, Sites
from PLC.Method import Method
from PLC.Parameter import Parameter, Mixed
from PLC.Sites import Site, Sites
-from PLC.Auth import PasswordAuth
+from PLC.Auth import Auth
+
+can_update = lambda (field, value): field in \
+ ['name', 'abbreviated_name', 'login_base',
+ 'is_public', 'latitude', 'longitude', 'url',
+ 'max_slices', 'max_slivers']
class UpdateSite(Method):
"""
Updates a site. Only the fields specified in update_fields are
updated, all other fields are left untouched.
class UpdateSite(Method):
"""
Updates a site. Only the fields specified in update_fields are
updated, all other fields are left untouched.
- To remove a value without setting a new one in its place (for
- example, to remove an address from the node), specify -1 for int
- and double fields and 'null' for string fields. hostname and
- boot_state cannot be unset.
-
PIs can only update sites they are a member of. Only admins can
PIs can only update sites they are a member of. Only admins can
- update max_slices.
+ update max_slices
, max_slivers, and login_base
.
Returns 1 if successful, faults otherwise.
"""
roles = ['admin', 'pi']
Returns 1 if successful, faults otherwise.
"""
roles = ['admin', 'pi']
- can_update = lambda (field, value): field in \
- ['name', 'abbreviated_name',
- 'is_public', 'latitude', 'longitude', 'url',
- 'max_slices', 'max_slivers']
- update_fields = dict(filter(can_update, Site.fields.items()))
+ site_fields = dict(filter(can_update, Site.fields.items()))
accepts = [
accepts = [
-
Password
Auth(),
+ Auth(),
Mixed(Site.fields['site_id'],
Site.fields['login_base']),
Mixed(Site.fields['site_id'],
Site.fields['login_base']),
-
upda
te_fields
+
si
te_fields
]
returns = Parameter(int, '1 if successful')
]
returns = Parameter(int, '1 if successful')
- def call(self, auth, site_id_or_login_base, update_fields):
- # Check for invalid fields
-
if filter(lambda field: field not in self.update_fields, upda
te_fields):
- raise PLCInvalidArgument, "Invalid field specified"
+ object_type = 'Site'
+
+
def call(self, auth, site_id_or_login_base, si
te_fields):
+ site_fields = dict(filter(can_update, site_fields.items()))
# Get site information
sites = Sites(self.api, [site_id_or_login_base])
if not sites:
raise PLCInvalidArgument, "No such site"
# Get site information
sites = Sites(self.api, [site_id_or_login_base])
if not sites:
raise PLCInvalidArgument, "No such site"
+ site = sites[0]
- site = sites.values()[0]
+ if site['peer_id'] is not None:
+ raise PLCInvalidArgument, "Not a local site"
# Authenticated function
assert self.caller is not None
# Authenticated function
assert self.caller is not None
@@
-58,10
+56,16
@@
class UpdateSite(Method):
if site['site_id'] not in self.caller['site_ids']:
raise PLCPermissionDenied, "Not allowed to modify specified site"
if site['site_id'] not in self.caller['site_ids']:
raise PLCPermissionDenied, "Not allowed to modify specified site"
- if 'max_slices' or 'max_slivers' in update_fields:
- raise PLCInvalidArgument, "Only admins can update max_slices and max_slivers"
+ # Remove admin only fields
+ for key in 'max_slices', 'max_slivers', 'login_base':
+ del site_fields[key]
- site.update(
upda
te_fields)
+ site.update(
si
te_fields)
site.sync()
site.sync()
+ # Logging variables
+ self.object_ids = [site['site_id']]
+ self.message = 'Site %d updated: %s' % \
+ (site['site_id'], ", ".join(site_fields.keys()))
+
return 1
return 1