From 2c9336a4e890aea0b16aac8d16bd78db226799e7 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Tue, 20 Sep 2011 13:53:45 +0900
Subject: [PATCH] Rename some helper functions for consistency

This changes the names for some helper functions so that future
patches are touching less unrelated code. The change replaces
shortened prefixes with the full type name.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Agata Murawska <agatamurawska@google.com>
---
 htools/Ganeti/HTools/CLI.hs            |  2 +-
 htools/Ganeti/HTools/Cluster.hs        |  4 +--
 htools/Ganeti/HTools/Program/Hspace.hs |  5 +--
 htools/Ganeti/HTools/QC.hs             |  2 +-
 htools/Ganeti/HTools/Simu.hs           |  2 +-
 htools/Ganeti/HTools/Text.hs           |  9 ++---
 htools/Ganeti/HTools/Types.hs          | 46 +++++++++++++-------------
 7 files changed, 36 insertions(+), 34 deletions(-)

diff --git a/htools/Ganeti/HTools/CLI.hs b/htools/Ganeti/HTools/CLI.hs
index 11344d123..e79923f19 100644
--- a/htools/Ganeti/HTools/CLI.hs
+++ b/htools/Ganeti/HTools/CLI.hs
@@ -199,7 +199,7 @@ oDiskMoves = Option "" ["no-disk-moves"]
 oDiskTemplate :: OptType
 oDiskTemplate = Option "" ["disk-template"]
                 (ReqArg (\ t opts -> do
-                           dt <- dtFromString t
+                           dt <- diskTemplateFromString t
                            return $ opts { optDiskTemplate = dt }) "TEMPLATE")
                 "select the desired disk template"
 
diff --git a/htools/Ganeti/HTools/Cluster.hs b/htools/Ganeti/HTools/Cluster.hs
index b11b3d476..57873fdc5 100644
--- a/htools/Ganeti/HTools/Cluster.hs
+++ b/htools/Ganeti/HTools/Cluster.hs
@@ -724,7 +724,7 @@ solutionDescription gl (groupId, result) =
     Bad message -> [printf "Group %s: error %s" gname message]
   where grp = Container.find groupId gl
         gname = Group.name grp
-        pol = apolToString (Group.allocPolicy grp)
+        pol = allocPolicyToString (Group.allocPolicy grp)
 
 -- | From a list of possibly bad and possibly empty solutions, filter
 -- only the groups with a valid result. Note that the result will be
@@ -830,7 +830,7 @@ tryReloc _ _ _ reqn _  = fail $ "Unsupported number of relocation \
 -- this function, whatever mode we have is just a primary change.
 failOnSecondaryChange :: (Monad m) => EvacMode -> DiskTemplate -> m ()
 failOnSecondaryChange ChangeSecondary dt =
-    fail $ "Instances with disk template '" ++ dtToString dt ++
+    fail $ "Instances with disk template '" ++ diskTemplateToString dt ++
          "' can't execute change secondary"
 failOnSecondaryChange _ _ = return ()
 
diff --git a/htools/Ganeti/HTools/Program/Hspace.hs b/htools/Ganeti/HTools/Program/Hspace.hs
index 932dc270f..0fc7d4dc6 100644
--- a/htools/Ganeti/HTools/Program/Hspace.hs
+++ b/htools/Ganeti/HTools/Program/Hspace.hs
@@ -295,7 +295,8 @@ printISpec :: Bool -> RSpec -> SpecType -> DiskTemplate -> IO ()
 printISpec True ispec spec disk_template = do
   printKeys $ map (\(a, fn) -> (prefix ++ "_" ++ a, fn ispec)) specData
   printKeys [ (prefix ++ "_RQN", printf "%d" req_nodes) ]
-  printKeys [ (prefix ++ "_DISK_TEMPLATE", dtToString disk_template) ]
+  printKeys [ (prefix ++ "_DISK_TEMPLATE",
+               diskTemplateToString disk_template) ]
       where req_nodes = Instance.requiredNodes disk_template
             prefix = specPrefix spec
 
@@ -303,7 +304,7 @@ printISpec False ispec spec disk_template =
   printf "%s instance spec is:\n  %s, using disk\
          \ template '%s'.\n"
          (specDescription spec)
-         (formatResources ispec specData) (dtToString disk_template)
+         (formatResources ispec specData) (diskTemplateToString disk_template)
 
 -- | Prints the tiered results.
 printTiered :: Bool -> [(RSpec, Int)] -> Double
diff --git a/htools/Ganeti/HTools/QC.hs b/htools/Ganeti/HTools/QC.hs
index f8cc19b60..393866cfd 100644
--- a/htools/Ganeti/HTools/QC.hs
+++ b/htools/Ganeti/HTools/QC.hs
@@ -587,7 +587,7 @@ prop_Text_Load_Instance name mem dsk vcpus status
         nl = Data.Map.fromList ndx
         tags = ""
         sbal = if autobal then "Y" else "N"
-        sdt = Types.dtToString dt
+        sdt = Types.diskTemplateToString dt
         inst = Text.loadInst nl
                [name, mem_s, dsk_s, vcpus_s, status,
                 sbal, pnode, snode, sdt, tags]
diff --git a/htools/Ganeti/HTools/Simu.hs b/htools/Ganeti/HTools/Simu.hs
index ef1209f8e..22386ff6e 100644
--- a/htools/Ganeti/HTools/Simu.hs
+++ b/htools/Ganeti/HTools/Simu.hs
@@ -54,7 +54,7 @@ parseDesc :: String -> Result (AllocPolicy, Int, Int, Int, Int)
 parseDesc desc =
     case sepSplit ',' desc of
       [a, n, d, m, c] -> do
-        apol <- apolFromString a `mplus` apolAbbrev a
+        apol <- allocPolicyFromString a `mplus` apolAbbrev a
         ncount <- tryRead "node count" n
         disk <- annotateResult "disk size" (parseUnit d)
         mem <- annotateResult "memory size" (parseUnit m)
diff --git a/htools/Ganeti/HTools/Text.hs b/htools/Ganeti/HTools/Text.hs
index 172d67f80..1f20f550c 100644
--- a/htools/Ganeti/HTools/Text.hs
+++ b/htools/Ganeti/HTools/Text.hs
@@ -57,7 +57,7 @@ import qualified Ganeti.HTools.Instance as Instance
 serializeGroup :: Group.Group -> String
 serializeGroup grp =
     printf "%s|%s|%s" (Group.name grp) (Group.uuid grp)
-               (apolToString (Group.allocPolicy grp))
+               (allocPolicyToString (Group.allocPolicy grp))
 
 -- | Generate group file data from a group list.
 serializeGroups :: Group.List -> String
@@ -97,7 +97,7 @@ serializeInstance nl inst =
              iname (Instance.mem inst) (Instance.dsk inst)
              (Instance.vcpus inst) (Instance.runSt inst)
              (if Instance.autoBalance inst then "Y" else "N")
-             pnode snode (dtToString (Instance.diskTemplate inst))
+             pnode snode (diskTemplateToString (Instance.diskTemplate inst))
              (intercalate "," (Instance.tags inst))
 
 -- | Generate instance file data from instance objects.
@@ -121,7 +121,7 @@ loadGroup :: (Monad m) => [String]
           -> m (String, Group.Group) -- ^ The result, a tuple of group
                                      -- UUID and group object
 loadGroup [name, gid, apol] = do
-  xapol <- apolFromString apol
+  xapol <- allocPolicyFromString apol
   return (gid, Group.create name gid xapol)
 
 loadGroup s = fail $ "Invalid/incomplete group data: '" ++ show s ++ "'"
@@ -167,7 +167,8 @@ loadInst ktn [ name, mem, dsk, vcpus, status, auto_bal, pnode, snode
                     "N" -> return False
                     _ -> fail $ "Invalid auto_balance value '" ++ auto_bal ++
                          "' for instance " ++ name
-  disk_template <- annotateResult ("Instance " ++ name) (dtFromString dt)
+  disk_template <- annotateResult ("Instance " ++ name)
+                   (diskTemplateFromString dt)
   when (sidx == pidx) $ fail $ "Instance " ++ name ++
            " has same primary and secondary node - " ++ pnode
   let vtags = sepSplit ',' tags
diff --git a/htools/Ganeti/HTools/Types.hs b/htools/Ganeti/HTools/Types.hs
index ec774b012..75dbce59a 100644
--- a/htools/Ganeti/HTools/Types.hs
+++ b/htools/Ganeti/HTools/Types.hs
@@ -32,8 +32,8 @@ module Ganeti.HTools.Types
     , Weight
     , GroupID
     , AllocPolicy(..)
-    , apolFromString
-    , apolToString
+    , allocPolicyFromString
+    , allocPolicyToString
     , RSpec(..)
     , DynUtil(..)
     , zeroUtil
@@ -49,8 +49,8 @@ module Ganeti.HTools.Types
     , Placement
     , IMove(..)
     , DiskTemplate(..)
-    , dtToString
-    , dtFromString
+    , diskTemplateToString
+    , diskTemplateFromString
     , MoveJob
     , JobSet
     , Result(..)
@@ -110,8 +110,8 @@ data AllocPolicy
       deriving (Show, Read, Eq, Ord, Enum, Bounded)
 
 -- | Convert a string to an alloc policy.
-apolFromString :: (Monad m) => String -> m AllocPolicy
-apolFromString s =
+allocPolicyFromString :: (Monad m) => String -> m AllocPolicy
+allocPolicyFromString s =
     case () of
       _ | s == C.allocPolicyPreferred -> return AllocPreferred
         | s == C.allocPolicyLastResort -> return AllocLastResort
@@ -119,15 +119,15 @@ apolFromString s =
         | otherwise -> fail $ "Invalid alloc policy mode: " ++ s
 
 -- | Convert an alloc policy to the Ganeti string equivalent.
-apolToString :: AllocPolicy -> String
-apolToString AllocPreferred   = C.allocPolicyPreferred
-apolToString AllocLastResort  = C.allocPolicyLastResort
-apolToString AllocUnallocable = C.allocPolicyUnallocable
+allocPolicyToString :: AllocPolicy -> String
+allocPolicyToString AllocPreferred   = C.allocPolicyPreferred
+allocPolicyToString AllocLastResort  = C.allocPolicyLastResort
+allocPolicyToString AllocUnallocable = C.allocPolicyUnallocable
 
 instance JSON.JSON AllocPolicy where
-    showJSON = JSON.showJSON . apolToString
+    showJSON = JSON.showJSON . allocPolicyToString
     readJSON s = case JSON.readJSON s of
-                   JSON.Ok s' -> apolFromString s'
+                   JSON.Ok s' -> allocPolicyFromString s'
                    JSON.Error e -> JSON.Error $
                                    "Can't parse alloc_policy: " ++ e
 
@@ -191,17 +191,17 @@ data DiskTemplate = DTDiskless
                     deriving (Show, Read, Eq, Enum, Bounded)
 
 -- | Converts a DiskTemplate to String.
-dtToString :: DiskTemplate -> String
-dtToString DTDiskless   = C.dtDiskless
-dtToString DTFile       = C.dtFile
-dtToString DTSharedFile = C.dtSharedFile
-dtToString DTPlain      = C.dtPlain
-dtToString DTBlock      = C.dtBlock
-dtToString DTDrbd8      = C.dtDrbd8
+diskTemplateToString :: DiskTemplate -> String
+diskTemplateToString DTDiskless   = C.dtDiskless
+diskTemplateToString DTFile       = C.dtFile
+diskTemplateToString DTSharedFile = C.dtSharedFile
+diskTemplateToString DTPlain      = C.dtPlain
+diskTemplateToString DTBlock      = C.dtBlock
+diskTemplateToString DTDrbd8      = C.dtDrbd8
 
 -- | Converts a DiskTemplate from String.
-dtFromString :: (Monad m) => String -> m DiskTemplate
-dtFromString s =
+diskTemplateFromString :: (Monad m) => String -> m DiskTemplate
+diskTemplateFromString s =
     case () of
       _ | s == C.dtDiskless   -> return DTDiskless
         | s == C.dtFile       -> return DTFile
@@ -212,9 +212,9 @@ dtFromString s =
         | otherwise           -> fail $ "Invalid disk template: " ++ s
 
 instance JSON.JSON DiskTemplate where
-    showJSON = JSON.showJSON . dtToString
+    showJSON = JSON.showJSON . diskTemplateToString
     readJSON s = case JSON.readJSON s of
-                   JSON.Ok s' -> dtFromString s'
+                   JSON.Ok s' -> diskTemplateFromString s'
                    JSON.Error e -> JSON.Error $
                                    "Can't parse disk_template as string: " ++ e
 
-- 
GitLab