Commit c22d4dd4 authored by Iustin Pop's avatar Iustin Pop
Browse files

Add spindle ratio to htool's IPolicy



Just the usual data/type declarations, read/save in the text backend,
etc. Also does a bit of unit-test cleanup (the way we build
ipolicies).
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent e2bdaf25
......@@ -97,6 +97,14 @@ maxDsk = 1024 * 1024 * 8
maxCpu :: Int
maxCpu = 1024
-- | Max vcpu ratio (random value).
maxVcpuRatio :: Double
maxVcpuRatio = 1024.0
-- | Max spindle ratio (random value).
maxSpindleRatio :: Double
maxSpindleRatio = 1024.0
-- | All disk templates (used later)
allDiskTemplates :: [Types.DiskTemplate]
allDiskTemplates = [minBound..maxBound]
......@@ -122,8 +130,9 @@ nullIPolicy = Types.IPolicy
, Types.iSpecNicCount = 1
}
, Types.iPolicyDiskTemplates = [Types.DTDrbd8, Types.DTPlain]
, Types.iPolicyVcpuRatio = 1024 -- somewhat random value, high
-- enough to not impact us
, Types.iPolicyVcpuRatio = maxVcpuRatio -- somewhat random value, high
-- enough to not impact us
, Types.iPolicySpindleRatio = maxSpindleRatio
}
......@@ -441,12 +450,14 @@ instance Arbitrary Types.IPolicy where
imax <- genBiggerISpec istd
num_tmpl <- choose (0, length allDiskTemplates)
dts <- genUniquesList num_tmpl
vcpu_ratio <- arbitrary
vcpu_ratio <- choose (1.0, maxVcpuRatio)
spindle_ratio <- choose (1.0, maxSpindleRatio)
return Types.IPolicy { Types.iPolicyMinSpec = imin
, Types.iPolicyStdSpec = istd
, Types.iPolicyMaxSpec = imax
, Types.iPolicyDiskTemplates = dts
, Types.iPolicyVcpuRatio = vcpu_ratio
, Types.iPolicySpindleRatio = spindle_ratio
}
-- * Actual tests
......
......@@ -128,13 +128,14 @@ serializeDiskTemplates = intercalate "," . map diskTemplateToRaw
-- | Generate policy data from a given policy object.
serializeIPolicy :: String -> IPolicy -> String
serializeIPolicy owner ipol =
let IPolicy stdspec minspec maxspec dts vcpu_ratio = ipol
let IPolicy stdspec minspec maxspec dts vcpu_ratio spindle_ratio = ipol
strings = [ owner
, serializeISpec stdspec
, serializeISpec minspec
, serializeISpec maxspec
, serializeDiskTemplates dts
, show vcpu_ratio
, show spindle_ratio
]
in intercalate "|" strings
......@@ -236,13 +237,16 @@ loadISpec owner s = fail $ "Invalid ispec data for " ++ owner ++ ": " ++ show s
-- | Loads an ipolicy from a field list.
loadIPolicy :: [String] -> Result (String, IPolicy)
loadIPolicy [owner, stdspec, minspec, maxspec, dtemplates, vcpu_ratio] = do
loadIPolicy [owner, stdspec, minspec, maxspec, dtemplates,
vcpu_ratio, spindle_ratio] = do
xstdspec <- loadISpec (owner ++ "/stdspec") (commaSplit stdspec)
xminspec <- loadISpec (owner ++ "/minspec") (commaSplit minspec)
xmaxspec <- loadISpec (owner ++ "/maxspec") (commaSplit maxspec)
xdts <- mapM diskTemplateFromRaw $ commaSplit dtemplates
xvcpu_ratio <- tryRead (owner ++ "/vcpu_ratio") vcpu_ratio
return $ (owner, IPolicy xstdspec xminspec xmaxspec xdts xvcpu_ratio)
xspindle_ratio <- tryRead (owner ++ "/spindle_ratio") spindle_ratio
return $ (owner, IPolicy xstdspec xminspec xmaxspec xdts
xvcpu_ratio xspindle_ratio)
loadIPolicy s = fail $ "Invalid ipolicy data: '" ++ show s ++ "'"
loadOnePolicy :: (IPolicy, Group.List) -> String
......
......@@ -217,6 +217,8 @@ $(THH.buildObject "IPolicy" "iPolicy"
THH.simpleField C.ipolicyDts [t| [DiskTemplate] |]
, THH.renameField "VcpuRatio" $
THH.simpleField C.ipolicyVcpuRatio [t| Double |]
, THH.renameField "SpindleRatio" $
THH.simpleField C.ipolicySpindleRatio [t| Double |]
])
-- | Converts an ISpec type to a RSpec one.
......@@ -236,6 +238,7 @@ defIPolicy = IPolicy { iPolicyStdSpec = defStdISpec
-- htools, we are mostly looking at DRBD
, iPolicyDiskTemplates = [DTDrbd8, DTPlain]
, iPolicyVcpuRatio = C.ipolicyDefaultsVcpuRatio
, iPolicySpindleRatio = C.ipolicyDefaultsSpindleRatio
}
-- | The dynamic resource specs of a machine (i.e. load or load
......
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