From 2ef8013fef1d0882aa612c3e7caef26562bc4b63 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Tue, 20 Sep 2011 17:29:04 +0900
Subject: [PATCH] hspace: add short forms for the group policy

This adds a shortened versions of the allocation policies, as writing
out the whole name in the command line can become tedious.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Agata Murawska <agatamurawska@google.com>
---
 htools/Ganeti/HTools/Simu.hs | 11 ++++++++++-
 man/hspace.rst               |  3 ++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/htools/Ganeti/HTools/Simu.hs b/htools/Ganeti/HTools/Simu.hs
index 8126f2d62..ef1209f8e 100644
--- a/htools/Ganeti/HTools/Simu.hs
+++ b/htools/Ganeti/HTools/Simu.hs
@@ -31,6 +31,7 @@ module Ganeti.HTools.Simu
     , parseData
     ) where
 
+import Control.Monad (mplus)
 import Text.Printf (printf)
 
 import Ganeti.HTools.Utils
@@ -40,12 +41,20 @@ import qualified Ganeti.HTools.Container as Container
 import qualified Ganeti.HTools.Group as Group
 import qualified Ganeti.HTools.Node as Node
 
+-- | Parse a shortened policy string (for command line usage).
+apolAbbrev :: String -> Result AllocPolicy
+apolAbbrev c | c == "p"  = return AllocPreferred
+             | c == "a"  = return AllocLastResort
+             | c == "u"  = return AllocUnallocable
+             | otherwise = fail $ "Cannot parse AllocPolicy abbreviation '"
+                           ++ c ++ "'"
+
 -- | Parse the string description into nodes.
 parseDesc :: String -> Result (AllocPolicy, Int, Int, Int, Int)
 parseDesc desc =
     case sepSplit ',' desc of
       [a, n, d, m, c] -> do
-        apol <- apolFromString a
+        apol <- apolFromString a `mplus` apolAbbrev a
         ncount <- tryRead "node count" n
         disk <- annotateResult "disk size" (parseUnit d)
         mem <- annotateResult "memory size" (parseUnit m)
diff --git a/man/hspace.rst b/man/hspace.rst
index 2aff21d13..91375af2d 100644
--- a/man/hspace.rst
+++ b/man/hspace.rst
@@ -282,7 +282,8 @@ The options that can be passed to the program are as follows:
   description. The *description* parameter must be a comma-separated
   list of five elements, describing in order:
 
-  - the allocation policy for this node group
+  - the allocation policy for this node group (*preferred*, *allocable*
+    or *unallocable*, or alternatively the short forms *p*, *a* or *u*)
   - the number of nodes in the cluster
   - the disk size of the nodes (default in mebibytes, units can be used)
   - the memory size of the nodes (default in mebibytes, units can be used)
-- 
GitLab