- make Add() calling convention consistent among all functions that
[plcapi.git] / PLC / Methods / UpdateSlice.py
index 8b34ed1..058ad5b 100644 (file)
@@ -28,13 +28,15 @@ class UpdateSlice(Method):
 
     roles = ['admin', 'pi', 'user']
 
-    update_fields = dict(filter(can_update, Slice.fields.items()))
+    slice_fields = dict(filter(can_update, Slice.fields.items()))
+    for field in slice_fields.values():
+        field.optional = True
 
     accepts = [
         PasswordAuth(),
         Mixed(Slice.fields['slice_id'],
               Slice.fields['name']),
-        update_fields
+        slice_fields
         ]
 
     returns = Parameter(int, '1 if successful')
@@ -56,7 +58,7 @@ class UpdateSlice(Method):
                 raise PLCPermissionDenied, "Specified slice not associated with any of your sites"
 
         # Renewing
-        if 'expires' in update_fields and update_fields['expires'] > slice['expires']:
+        if 'expires' in slice_fields and slice_fields['expires'] > slice['expires']:
             sites = Sites(self.api, [slice['site_id']]).values()
             assert sites
             site = sites[0]
@@ -68,15 +70,15 @@ class UpdateSlice(Method):
             # XXX Make this configurable
             max_expires = time.time() + (8 * 7 * 24 * 60 * 60)
 
-            if 'admin' not in self.caller['roles'] and update_fields['expires'] > max_expires:
+            if 'admin' not in self.caller['roles'] and slice_fields['expires'] > max_expires:
                 raise PLCInvalidArgument, "Cannot renew a slice beyond 8 weeks from now"
 
-        if 'max_nodes' in update_fields and update_fields['max_nodes'] != slice['max_nodes']:
+        if 'max_nodes' in slice_fields and slice_fields['max_nodes'] != slice['max_nodes']:
             if 'admin' not in self.caller['roles'] and \
                'pi' not in self.caller['roles']:
                 raise PLCInvalidArgument, "Only admins and PIs may update max_nodes"
 
-        slice.update(update_fields)
+        slice.update(slice_fields)
 
         # XXX Make this a configurable policy
         if slice['description'] is None or not slice['description'].strip() or \