Allow param `modify' during gnt-instance modify
authorConstantinos Venetsanopoulos <cven@grnet.gr>
Wed, 27 Jun 2012 15:27:28 +0000 (18:27 +0300)
committerRené Nussbaumer <rn@google.com>
Fri, 29 Jun 2012 08:38:47 +0000 (10:38 +0200)
With the new gnt-instance modify syntax for addition and removal of
disks/NICs on arbitrary indexes, we hit an assertion if the user
passes `modify' as one of the disk's parameters. E.g::

 gnt-instance modify --disk 2:modify,size=3G instance1
 gnt-instance modify --disk 3:add,size=1G,modify instance2

This patch fixes the bug, by allowing `modify' to be passed as a
parameter (as happens with `add' and `remove'), as long as it is
not done alongside `add' or `remove'. If so, it is treated in the
same way as if none of modify/add/remove is passed --> modify.

Signed-off-by: Constantinos Venetsanopoulos <cven@grnet.gr>
Signed-off-by: René Nussbaumer <rn@google.com>
Reviewed-by: René Nussbaumer <rn@google.com>
Reviewed-by: Agata Murawska <agatamurawska@google.com>

lib/client/gnt_instance.py

index c6dfd69..c59817b 100644 (file)
@@ -1306,16 +1306,25 @@ def _ConvertNicDiskModifications(mods):
 
       add = params.pop(constants.DDM_ADD, _MISSING)
       remove = params.pop(constants.DDM_REMOVE, _MISSING)
+      modify = params.pop(constants.DDM_MODIFY, _MISSING)
+
+      if modify is _MISSING:
+        if not (add is _MISSING or remove is _MISSING):
+          raise errors.OpPrereqError("Cannot add and remove at the same time",
+                                     errors.ECODE_INVAL)
+        elif add is not _MISSING:
+          action = constants.DDM_ADD
+        elif remove is not _MISSING:
+          action = constants.DDM_REMOVE
+        else:
+          action = constants.DDM_MODIFY
 
-      if not (add is _MISSING or remove is _MISSING):
-        raise errors.OpPrereqError("Cannot add and remove at the same time",
-                                   errors.ECODE_INVAL)
-      elif add is not _MISSING:
-        action = constants.DDM_ADD
-      elif remove is not _MISSING:
-        action = constants.DDM_REMOVE
       else:
-        action = constants.DDM_MODIFY
+        if add is _MISSING and remove is _MISSING:
+          action = constants.DDM_MODIFY
+        else:
+          raise errors.OpPrereqError("Cannot modify and add/remove at the"
+                                     " same time", errors.ECODE_INVAL)
 
       assert not (constants.DDMS_VALUES_WITH_MODIFY & set(params.keys()))