Commit 2c9336a4 authored by Iustin Pop's avatar Iustin Pop
Browse files

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: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarAgata Murawska <agatamurawska@google.com>
parent f047f90f
......@@ -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"
......
......@@ -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 ()
......
......@@ -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
......
......@@ -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]
......
......@@ -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)
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment