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

Add vcpu_ratio definition to the IPolicy type



This will be "naturally" read in the JSON-based backends (Luxi/Rapi),
and we add explicit code for handling it in the Text backend.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent e6244d00
......@@ -122,6 +122,8 @@ nullIPolicy = Types.IPolicy
, Types.iSpecNicCount = 1
}
, Types.iPolicyDiskTemplates = [Types.DTDrbd8, Types.DTPlain]
, Types.iPolicyVcpuRatio = 1024 -- somewhat random value, high
-- enough to not impact us
}
......@@ -439,10 +441,12 @@ instance Arbitrary Types.IPolicy where
imax <- genBiggerISpec istd
num_tmpl <- choose (0, length allDiskTemplates)
dts <- genUniquesList num_tmpl
vcpu_ratio <- arbitrary
return Types.IPolicy { Types.iPolicyMinSpec = imin
, Types.iPolicyStdSpec = istd
, Types.iPolicyMaxSpec = imax
, Types.iPolicyDiskTemplates = dts
, Types.iPolicyVcpuRatio = vcpu_ratio
}
-- * Actual tests
......
......@@ -128,12 +128,13 @@ 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 = ipol
let IPolicy stdspec minspec maxspec dts vcpu_ratio = ipol
strings = [ owner
, serializeISpec stdspec
, serializeISpec minspec
, serializeISpec maxspec
, serializeDiskTemplates dts
, show vcpu_ratio
]
in intercalate "|" strings
......@@ -235,12 +236,13 @@ 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] = do
loadIPolicy [owner, stdspec, minspec, maxspec, dtemplates, vcpu_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
return $ (owner, IPolicy xstdspec xminspec xmaxspec xdts)
xvcpu_ratio <- tryRead (owner ++ "/vcpu_ratio") vcpu_ratio
return $ (owner, IPolicy xstdspec xminspec xmaxspec xdts xvcpu_ratio)
loadIPolicy s = fail $ "Invalid ipolicy data: '" ++ show s ++ "'"
loadOnePolicy :: (IPolicy, Group.List) -> String
......
......@@ -6,7 +6,7 @@
{-
Copyright (C) 2009, 2010, 2011 Google Inc.
Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -199,6 +199,8 @@ $(THH.buildObject "IPolicy" "iPolicy"
, THH.renameField "MaxSpec" $ THH.simpleField "max" [t| ISpec |]
, THH.renameField "DiskTemplates" $
THH.simpleField "disk_templates" [t| [DiskTemplate] |]
, THH.renameField "VcpuRatio" $
THH.simpleField "vcpu_ratio" [t| Double |]
])
-- | Converts an ISpec type to a RSpec one.
......@@ -217,6 +219,7 @@ defIPolicy = IPolicy { iPolicyStdSpec = defStdISpec
-- string values, not the actual type; and in
-- htools, we are mostly looking at DRBD
, iPolicyDiskTemplates = [DTDrbd8, DTPlain]
, iPolicyVcpuRatio = C.ipolicyDefaultsVcpuRatio
}
-- | 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