From c0e4a2c3d28e2a7d534d36d4b57c0e8481712b73 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Fri, 13 Feb 2009 15:34:48 +0000
Subject: [PATCH] =?UTF-8?q?Implement=20the=20backward-compatible=20?=
 =?UTF-8?q?=E2=80=98-s=E2=80=99=20disk=20option?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This patch adds back to the instance creation command (gnt-instace add,
gnt-backup import) the β€˜-s’ short form option for specifying a
single-disk instance.

Also a small bug in gnt-backup import is fixed.

Reviewed-by: ultrotter
---
 man/gnt-backup.sgml   | 17 +++++++++++++----
 man/gnt-instance.sgml | 36 ++++++++++++++++++++++++------------
 scripts/gnt-backup    | 15 ++++++++++++---
 scripts/gnt-instance  | 13 +++++++++++--
 4 files changed, 60 insertions(+), 21 deletions(-)

diff --git a/man/gnt-backup.sgml b/man/gnt-backup.sgml
index fec40912f..da01af234 100644
--- a/man/gnt-backup.sgml
+++ b/man/gnt-backup.sgml
@@ -151,10 +151,19 @@
       </para>
 
       <para>
-        The minimum disk specification is therefore <userinput>--disk
-        0:size=20G</userinput>, and a three-disk instance can be
-        specified as <userinput>--disk 0:size=20G --disk 1:size=4G
-        --disk 2:size=100G</userinput>.
+        Alternatively, a single-disk instance can be created via the
+        <option>-s</option> option which takes a single argument,
+        the size of the disk. This is similar to the Ganeti 1.2
+        version (but will only create one disk).
+      </para>
+
+      <para>
+        The minimum disk specification is therefore
+        <userinput>--disk 0:size=20G</userinput> (or <userinput>-s
+          20G</userinput> when using the <option>-s</option> option),
+        and a three-disk instance can be specified as
+        <userinput>--disk 0:size=20G --disk 1:size=4G --disk
+          2:size=100G</userinput>.
       </para>
 
       <para>
diff --git a/man/gnt-instance.sgml b/man/gnt-instance.sgml
index c6c511c03..d50fb658a 100644
--- a/man/gnt-instance.sgml
+++ b/man/gnt-instance.sgml
@@ -65,7 +65,18 @@
         <cmdsynopsis>
           <command>add</command>
           <sbr>
-          <arg rep="repeat">--disk=<replaceable>N</replaceable>:size=<replaceable>VAL</replaceable><arg>,mode=<replaceable>ro|rw</replaceable></arg></arg>
+          <arg choice="req">-t<group choice="req">
+              <arg>diskless</arg>
+              <arg>file</arg>
+              <arg>plain</arg>
+              <arg>drbd</arg>
+            </group></arg>
+          <sbr>
+
+          <group choice="req">
+            <arg rep="repeat">--disk=<replaceable>N</replaceable>:size=<replaceable>VAL</replaceable><arg>,mode=<replaceable>ro|rw</replaceable></arg></arg>
+            <arg>-s <replaceable>SIZE</replaceable></arg>
+          </group>
           <sbr>
           <group>
             <arg rep="repeat">--net=<replaceable>N</replaceable><arg rep="repeat">:options</arg></arg>
@@ -85,14 +96,6 @@
             </group></arg>
           <sbr>
 
-          <arg choice="req">-t<group choice="req">
-              <arg>diskless</arg>
-              <arg>file</arg>
-              <arg>plain</arg>
-              <arg>drbd</arg>
-            </group></arg>
-          <sbr>
-
           <group choice="req">
             <arg>-n <replaceable>node<optional>:secondary-node</optional></replaceable></arg>
             <arg>--iallocator <replaceable>name</replaceable></arg>
@@ -127,11 +130,20 @@
           these suffixes map to mebibytes, gibibytes and tebibytes.
         </para>
 
+        <para>
+          Alternatively, a single-disk instance can be created via the
+          <option>-s</option> option which takes a single argument,
+          the size of the disk. This is similar to the Ganeti 1.2
+          version (but will only create one disk).
+        </para>
+
         <para>
           The minimum disk specification is therefore
-          <userinput>--disk 0:size=20G</userinput>, and a three-disk
-          instance can be specified as <userinput>--disk 0:size=20G
-            --disk 1:size=4G --disk 2:size=100G</userinput>.
+          <userinput>--disk 0:size=20G</userinput> (or <userinput>-s
+          20G</userinput> when using the <option>-s</option> option),
+          and a three-disk instance can be specified as
+          <userinput>--disk 0:size=20G --disk 1:size=4G --disk
+          2:size=100G</userinput>.
         </para>
 
         <para>
diff --git a/scripts/gnt-backup b/scripts/gnt-backup
index 774e69608..c6ef4c971 100755
--- a/scripts/gnt-backup
+++ b/scripts/gnt-backup
@@ -113,13 +113,18 @@ def ImportInstance(opts, args):
     nics = [{}]
 
   if opts.disk_template == constants.DT_DISKLESS:
-    if opts.disks:
+    if opts.disks or opts.sd_size is not None:
       raise errors.OpPrereqError("Diskless instance but disk"
                                  " information passed")
     disks = []
   else:
-    if not opts.disks:
+    if not opts.disks and not opts.sd_size:
       raise errors.OpPrereqError("No disk information specified")
+    if opts.disks and opts.sd_size is not None:
+      raise errors.OpPrereqError("Please use either the '--disk' or"
+                                 " '-s' option")
+    if opts.sd_size is not None:
+      opts.disks = [(0, {"size": opts.sd_size})]
     try:
       disk_max = max(int(didx[0])+1 for didx in opts.disks)
     except ValueError, err:
@@ -137,7 +142,7 @@ def ImportInstance(opts, args):
       disks[didx] = ddict
 
   utils.ForceDictType(opts.beparams, constants.BES_PARAMETER_TYPES)
-  utils.ForceDictType(opts.hvparams, constants.HVS_PARAMETER_TYPES)
+  utils.ForceDictType(hvparams, constants.HVS_PARAMETER_TYPES)
 
   op = opcodes.OpCreateInstance(instance_name=instance,
                                 disk_template=opts.disk_template,
@@ -194,6 +199,10 @@ import_opts = [
              default=[], dest="disks",
              action="append",
              type="identkeyval"),
+  cli_option("-s", "--os-size", dest="sd_size", help="Disk size for a"
+             " single-disk configuration, when not using the --disk option,"
+             " in MiB unless a suffix is used",
+             default=None, type="unit", metavar="<size>"),
   ikv_option("--net", help="NIC information",
              default=[], dest="nics",
              action="append",
diff --git a/scripts/gnt-instance b/scripts/gnt-instance
index a5c30c8b7..fd8a455fe 100755
--- a/scripts/gnt-instance
+++ b/scripts/gnt-instance
@@ -332,13 +332,18 @@ def AddInstance(opts, args):
     nics = [{}]
 
   if opts.disk_template == constants.DT_DISKLESS:
-    if opts.disks:
+    if opts.disks or opts.sd_size is not None:
       raise errors.OpPrereqError("Diskless instance but disk"
                                  " information passed")
     disks = []
   else:
-    if not opts.disks:
+    if not opts.disks and not opts.sd_size:
       raise errors.OpPrereqError("No disk information specified")
+    if opts.disks and opts.sd_size is not None:
+      raise errors.OpPrereqError("Please use either the '--disk' or"
+                                 " '-s' option")
+    if opts.sd_size is not None:
+      opts.disks = [(0, {"size": opts.sd_size})]
     try:
       disk_max = max(int(didx[0])+1 for didx in opts.disks)
     except ValueError, err:
@@ -1276,6 +1281,10 @@ add_opts = [
   make_option("-t", "--disk-template", dest="disk_template",
               help="Custom disk setup (diskless, file, plain or drbd)",
               default=None, metavar="TEMPL"),
+  cli_option("-s", "--os-size", dest="sd_size", help="Disk size for a"
+             " single-disk configuration, when not using the --disk option,"
+             " in MiB unless a suffix is used",
+             default=None, type="unit", metavar="<size>"),
   ikv_option("--disk", help="Disk information",
              default=[], dest="disks",
              action="append",
-- 
GitLab