Fix a bug in command line option parsing code
[ganeti-local] / lib / rapi / client.py
index 213712d..f41b6fc 100644 (file)
@@ -63,6 +63,10 @@ REPLACE_DISK_SECONDARY = "replace_on_secondary"
 REPLACE_DISK_CHG = "replace_new_secondary"
 REPLACE_DISK_AUTO = "replace_auto"
 
+NODE_EVAC_PRI = "primary-only"
+NODE_EVAC_SEC = "secondary-only"
+NODE_EVAC_ALL = "all"
+
 NODE_ROLE_DRAINED = "drained"
 NODE_ROLE_MASTER_CANDIATE = "master-candidate"
 NODE_ROLE_MASTER = "master"
@@ -956,7 +960,7 @@ class GanetiRapiClient(object): # pylint: disable=R0904
                               (GANETI_RAPI_VERSION, instance)), query, None)
 
   def ReplaceInstanceDisks(self, instance, disks=None, mode=REPLACE_DISK_AUTO,
-                           remote_node=None, iallocator=None, dry_run=False):
+                           remote_node=None, iallocator=None):
     """Replaces disks on an instance.
 
     @type instance: str
@@ -971,8 +975,6 @@ class GanetiRapiClient(object): # pylint: disable=R0904
     @type iallocator: str or None
     @param iallocator: instance allocator plugin to use (for use with
                        replace_auto mode)
-    @type dry_run: bool
-    @param dry_run: whether to perform a dry run
 
     @rtype: string
     @return: job id
@@ -982,18 +984,17 @@ class GanetiRapiClient(object): # pylint: disable=R0904
       ("mode", mode),
       ]
 
-    if disks:
+    # TODO: Convert to body parameters
+
+    if disks is not None:
       query.append(("disks", ",".join(str(idx) for idx in disks)))
 
-    if remote_node:
+    if remote_node is not None:
       query.append(("remote_node", remote_node))
 
-    if iallocator:
+    if iallocator is not None:
       query.append(("iallocator", iallocator))
 
-    if dry_run:
-      query.append(("dry-run", 1))
-
     return self._SendRequest(HTTP_POST,
                              ("/%s/instances/%s/replace-disks" %
                               (GANETI_RAPI_VERSION, instance)), query, None)
@@ -1287,7 +1288,7 @@ class GanetiRapiClient(object): # pylint: disable=R0904
 
   def EvacuateNode(self, node, iallocator=None, remote_node=None,
                    dry_run=False, early_release=None,
-                   primary=None, secondary=None, accept_old=False):
+                   mode=None, accept_old=False):
     """Evacuates instances from a Ganeti node.
 
     @type node: str
@@ -1300,10 +1301,8 @@ class GanetiRapiClient(object): # pylint: disable=R0904
     @param dry_run: whether to perform a dry run
     @type early_release: bool
     @param early_release: whether to enable parallelization
-    @type primary: bool
-    @param primary: Whether to evacuate primary instances
-    @type secondary: bool
-    @param secondary: Whether to evacuate secondary instances
+    @type mode: string
+    @param mode: Node evacuation mode
     @type accept_old: bool
     @param accept_old: Whether caller is ready to accept old-style (pre-2.5)
         results
@@ -1326,6 +1325,7 @@ class GanetiRapiClient(object): # pylint: disable=R0904
       query.append(("dry-run", 1))
 
     if _NODE_EVAC_RES1 in self.GetFeatures():
+      # Server supports body parameters
       body = {}
 
       if iallocator is not None:
@@ -1334,10 +1334,8 @@ class GanetiRapiClient(object): # pylint: disable=R0904
         body["remote_node"] = remote_node
       if early_release is not None:
         body["early_release"] = early_release
-      if primary is not None:
-        body["primary"] = primary
-      if secondary is not None:
-        body["secondary"] = secondary
+      if mode is not None:
+        body["mode"] = mode
     else:
       # Pre-2.5 request format
       body = None
@@ -1347,7 +1345,8 @@ class GanetiRapiClient(object): # pylint: disable=R0904
                              " not accept old-style results (parameter"
                              " accept_old)")
 
-      if primary or primary is None or not (secondary is None or secondary):
+      # Pre-2.5 servers can only evacuate secondaries
+      if mode is not None and mode != NODE_EVAC_SEC:
         raise GanetiApiError("Server can only evacuate secondary instances")
 
       if iallocator: