Merge branch 'stable-2.12' into stable-2.13
[ganeti-github.git] / lib / client / gnt_instance.py
index 87d0d3b..1beb3f3 100644 (file)
@@ -815,7 +815,8 @@ def MigrateInstance(opts, args):
                                  target_node=target_node,
                                  allow_failover=opts.allow_failover,
                                  allow_runtime_changes=opts.allow_runtime_chgs,
-                                 ignore_ipolicy=opts.ignore_ipolicy)
+                                 ignore_ipolicy=opts.ignore_ipolicy,
+                                 ignore_hvversions=opts.ignore_hvversions)
   SubmitOrSend(op, cl=cl, opts=opts)
   return 0
 
@@ -1294,6 +1295,27 @@ def _ConvertNicDiskModifications(mods):
   return result
 
 
+def _ParseExtStorageParams(params):
+  """Parses the disk params for ExtStorage conversions.
+
+  """
+  if params:
+    if constants.IDISK_PROVIDER not in params:
+      raise errors.OpPrereqError("Missing required parameter '%s' when"
+                                 " converting to an ExtStorage disk template" %
+                                 constants.IDISK_PROVIDER, errors.ECODE_INVAL)
+    else:
+      for param in params.keys():
+        if (param != constants.IDISK_PROVIDER and
+            param in constants.IDISK_PARAMS):
+          raise errors.OpPrereqError("Invalid parameter '%s' when converting"
+                                     " to an ExtStorage template (it is not"
+                                     " allowed modifying existing disk"
+                                     " parameters)" % param, errors.ECODE_INVAL)
+
+  return params
+
+
 def _ParseDiskSizes(mods):
   """Parses disk sizes in parameters.
 
@@ -1359,13 +1381,33 @@ def SetInstanceParams(opts, args):
 
   disks = _ParseDiskSizes(_ConvertNicDiskModifications(opts.disks))
 
-  if (opts.disk_template and
-      opts.disk_template in constants.DTS_INT_MIRROR and
-      not opts.node):
-    ToStderr("Changing the disk template to a mirrored one requires"
-             " specifying a secondary node")
+  # verify the user provided parameters for disk template conversions
+  if opts.disk_template:
+    if (not opts.node and
+        opts.disk_template in constants.DTS_INT_MIRROR):
+      ToStderr("Changing the disk template to a mirrored one requires"
+               " specifying a secondary node")
+      return 1
+    elif (opts.ext_params and
+          opts.disk_template != constants.DT_EXT):
+      ToStderr("Specifying ExtStorage parameters requires converting"
+               " to the '%s' disk template" % constants.DT_EXT)
+      return 1
+    elif (not opts.ext_params and
+          opts.disk_template == constants.DT_EXT):
+      ToStderr("Provider option is missing, use either the"
+               " '--ext-params' or '-e' option")
+      return 1
+
+  if ((opts.file_driver or
+       opts.file_storage_dir) and
+      not opts.disk_template in constants.DTS_FILEBASED):
+    ToStderr("Specifying file-based configuration arguments requires"
+             " converting to a file-based disk template")
     return 1
 
+  ext_params = _ParseExtStorageParams(opts.ext_params)
+
   if opts.offline_inst:
     offline = True
   elif opts.online_inst:
@@ -1381,6 +1423,9 @@ def SetInstanceParams(opts, args):
                                    hotplug=opts.hotplug,
                                    hotplug_if_possible=opts.hotplug_if_possible,
                                    disk_template=opts.disk_template,
+                                   ext_params=ext_params,
+                                   file_driver=opts.file_driver,
+                                   file_storage_dir=opts.file_storage_dir,
                                    remote_node=opts.node,
                                    pnode=opts.new_primary_node,
                                    hvparams=opts.hvparams,
@@ -1535,7 +1580,8 @@ commands = {
     MigrateInstance, ARGS_ONE_INSTANCE,
     [FORCE_OPT, NONLIVE_OPT, MIGRATION_MODE_OPT, CLEANUP_OPT, DRY_RUN_OPT,
      PRIORITY_OPT, DST_NODE_OPT, IALLOCATOR_OPT, ALLOW_FAILOVER_OPT,
-     IGNORE_IPOLICY_OPT, NORUNTIME_CHGS_OPT] + SUBMIT_OPTS,
+     IGNORE_IPOLICY_OPT, IGNORE_HVVERSIONS_OPT, NORUNTIME_CHGS_OPT]
+    + SUBMIT_OPTS,
     "[-f] <instance>", "Migrate instance to its secondary node"
     " (only for mirrored instances)"),
   "move": (
@@ -1599,7 +1645,8 @@ commands = {
      OSPARAMS_OPT, OSPARAMS_PRIVATE_OPT, DRY_RUN_OPT, PRIORITY_OPT, NWSYNC_OPT,
      OFFLINE_INST_OPT, ONLINE_INST_OPT, IGNORE_IPOLICY_OPT, RUNTIME_MEM_OPT,
      NOCONFLICTSCHECK_OPT, NEW_PRIMARY_OPT, HOTPLUG_OPT,
-     HOTPLUG_IF_POSSIBLE_OPT, INSTANCE_COMMUNICATION_OPT],
+     HOTPLUG_IF_POSSIBLE_OPT, INSTANCE_COMMUNICATION_OPT,
+     EXT_PARAMS_OPT, FILESTORE_DRIVER_OPT, FILESTORE_DIR_OPT],
     "<instance>", "Alters the parameters of an instance"),
   "shutdown": (
     GenericManyOps("shutdown", _ShutdownInstance), [ArgInstance()],