Due to memory over-commitment forthcoming support obtaining memory_dom0 as an amount of actively-used memory becomes incorrect. This patch enables hv_state CLI option iand updates default values for hv_state parameters. Value of 1024M is typical amount of memory required by KVM hypervizor itself.
Python query module is stil used by qa tests and is extended in order to be almost consistent with the haskell query. The only difference is that python query node reports custom hv_state instead of a filled one because we don't care. Signed-off-by: Oleg Ponomarev <[email protected]> --- lib/query.py | 48 ++++++++++++++++++--------------------------- src/Ganeti/Config.hs | 32 ++++++++++++++++++++++++++++++ src/Ganeti/ConstantUtils.hs | 17 ++++++++++++++++ src/Ganeti/Constants.hs | 11 ++++++----- src/Ganeti/Query/Group.hs | 5 +++++ src/Ganeti/Query/Node.hs | 13 ++++++------ src/Ganeti/Query/Server.hs | 4 ++++ 7 files changed, 90 insertions(+), 40 deletions(-) diff --git a/lib/query.py b/lib/query.py index 43d8fad..085a60d 100644 --- a/lib/query.py +++ b/lib/query.py @@ -1309,32 +1309,6 @@ def _GetStatsField(field, kind, data): return _FS_UNAVAIL -def _GetNodeHvState(_, node): - """Converts node's hypervisor state for query result. - - """ - hv_state = node.hv_state - - if hv_state is None: - return _FS_UNAVAIL - - return dict((name, value.ToDict()) for (name, value) in hv_state.items()) - - -def _GetNodeDiskState(_, node): - """Converts node's disk state for query result. - - """ - disk_state = node.disk_state - - if disk_state is None: - return _FS_UNAVAIL - - return dict((disk_kind, dict((name, value.ToDict()) - for (name, value) in kind_state.items())) - for (disk_kind, kind_state) in disk_state.items()) - - def _BuildNodeFields(): """Builds list of fields for node queries. @@ -1361,10 +1335,16 @@ def _BuildNodeFields(): (_MakeField("custom_ndparams", "CustomNodeParameters", QFT_OTHER, "Custom node parameters"), NQ_GROUP, 0, _GetItemAttr("ndparams")), - (_MakeField("hv_state", "HypervisorState", QFT_OTHER, "Hypervisor state"), - NQ_CONFIG, 0, _GetNodeHvState), + # FIXME: The code below return custom hv_state instead of filled one. + # Anyway, this functionality is unlikely to be used. + (_MakeField("hv_state", "HypervisorState", QFT_OTHER, + "Static hypervisor state for default hypervisor only"), + NQ_CONFIG, 0, _GetItemAttr("hv_state_static")), + (_MakeField("custom_hv_state", "CustomHypervisorState", QFT_OTHER, + "Custom static hypervisor state"), + NQ_CONFIG, 0, _GetItemAttr("hv_state_static")), (_MakeField("disk_state", "DiskState", QFT_OTHER, "Disk state"), - NQ_CONFIG, 0, _GetNodeDiskState), + NQ_CONFIG, 0, _GetItemAttr("disk_state_static")), ] fields.extend(_BuildNDFields(False)) @@ -2463,6 +2443,11 @@ def _BuildGroupFields(): (_MakeField("custom_diskparams", "CustomDiskParameters", QFT_OTHER, "Custom disk parameters"), GQ_CONFIG, 0, _GetItemAttr("diskparams")), + (_MakeField("hv_state", "HypervisorState", QFT_OTHER, + "Custom static hypervisor state"), + GQ_CONFIG, 0, _GetItemAttr("hv_state_static")), + (_MakeField("disk_state", "DiskState", QFT_OTHER, "Disk state"), + GQ_CONFIG, 0, _GetItemAttr("disk_state_static")), ]) # ND parameters @@ -2775,6 +2760,11 @@ def _BuildClusterFields(): (_MakeField("master_node", "Master", QFT_TEXT, "Master node name"), CQ_CONFIG, QFF_HOSTNAME, lambda ctx, cluster: _GetNodeName(ctx, None, cluster.master_node)), + (_MakeField("hv_state", "HypervisorState", QFT_OTHER, + "Custom static hypervisor state"), + CQ_CONFIG, 0, _GetItemAttr("hv_state_static")), + (_MakeField("disk_state", "DiskState", QFT_OTHER, "Disk state"), + CQ_CONFIG, 0, _GetItemAttr("disk_state_static")), ] # Simple fields diff --git a/src/Ganeti/Config.hs b/src/Ganeti/Config.hs index 92c4c96..d20e128 100644 --- a/src/Ganeti/Config.hs +++ b/src/Ganeti/Config.hs @@ -68,6 +68,7 @@ module Ganeti.Config , getInstDisksFromObj , getDrbdMinorsForDisk , getDrbdMinorsForInstance + , getFilledHvStateParams , getFilledInstHvParams , getFilledInstBeParams , getFilledInstOsParams @@ -98,6 +99,7 @@ import System.IO import Ganeti.BasicTypes import qualified Ganeti.Constants as C +import qualified Ganeti.ConstantUtils as CU import Ganeti.Errors import Ganeti.JSON import Ganeti.Objects @@ -327,6 +329,36 @@ getGroupInstances cfg gname = ginsts = map (getNodeInstances cfg) gnodes in (concatMap fst ginsts, concatMap snd ginsts) +-- | default FilledHvStateParams. +defaultHvStateParams :: FilledHvStateParams +defaultHvStateParams = FilledHvStateParams + { hvstateCpuNode = CU.hvstDefaultCpuNode + , hvstateCpuTotal = CU.hvstDefaultCpuTotal + , hvstateMemHv = CU.hvstDefaultMemoryHv + , hvstateMemNode = CU.hvstDefaultMemoryNode + , hvstateMemTotal = CU.hvstDefaultMemoryTotal + } + +-- | Retrieves the node's static hypervisor state parameters, missing values +-- filled with group's parameters, missing group parameters are filled +-- with cluster's parameters. Currently, returns hvstate parameters only for +-- the default hypervisor. +getFilledHvStateParams :: ConfigData -> Node -> FilledHvState +getFilledHvStateParams cfg n = + let cluster_hv_state = + fromContainer . clusterHvStateStatic $ configCluster cfg + def_hv = getDefaultHypervisor cfg + cluster_fv = fromMaybe defaultHvStateParams $ M.lookup def_hv + cluster_hv_state + group_fv = case getGroupOfNode cfg n >>= + M.lookup def_hv . fromContainer . groupHvStateStatic of + Just pv -> fillParams cluster_fv pv + Nothing -> cluster_fv + node_fv = case M.lookup def_hv . fromContainer $ nodeHvStateStatic n of + Just pv -> fillParams group_fv pv + Nothing -> group_fv + in GenericContainer $ M.fromList [(def_hv, node_fv)] + -- | Retrieves the instance hypervisor params, missing values filled with -- cluster defaults. getFilledInstHvParams :: [String] -> ConfigData -> Instance -> HvParams diff --git a/src/Ganeti/ConstantUtils.hs b/src/Ganeti/ConstantUtils.hs index ddbbd75..dc966d6 100644 --- a/src/Ganeti/ConstantUtils.hs +++ b/src/Ganeti/ConstantUtils.hs @@ -217,3 +217,20 @@ ipolicyDefaultsSpindleRatio = 32.0 ipolicyDefaultsMemoryRatio :: Double ipolicyDefaultsMemoryRatio = 1.0 + +-- * Hypervisor state default parameters + +hvstDefaultCpuNode :: Int +hvstDefaultCpuNode = 1 + +hvstDefaultCpuTotal :: Int +hvstDefaultCpuTotal = 1 + +hvstDefaultMemoryHv :: Int +hvstDefaultMemoryHv = 1024 + +hvstDefaultMemoryTotal :: Int +hvstDefaultMemoryTotal = 1024 + +hvstDefaultMemoryNode :: Int +hvstDefaultMemoryNode = 4096 diff --git a/src/Ganeti/Constants.hs b/src/Ganeti/Constants.hs index 038b2f3..9fd7ad4 100644 --- a/src/Ganeti/Constants.hs +++ b/src/Ganeti/Constants.hs @@ -2027,11 +2027,12 @@ hvstsParameters = hvstDefaults :: Map String Int hvstDefaults = Map.fromList - [(hvstCpuNode, 1), - (hvstCpuTotal, 1), - (hvstMemoryHv, 0), - (hvstMemoryTotal, 0), - (hvstMemoryNode, 0)] + [ (hvstCpuNode , ConstantUtils.hvstDefaultCpuNode ) + , (hvstCpuTotal , ConstantUtils.hvstDefaultCpuTotal ) + , (hvstMemoryHv , ConstantUtils.hvstDefaultMemoryHv ) + , (hvstMemoryTotal, ConstantUtils.hvstDefaultMemoryTotal) + , (hvstMemoryNode , ConstantUtils.hvstDefaultMemoryNode ) + ] hvstsParameterTypes :: Map String VType hvstsParameterTypes = diff --git a/src/Ganeti/Query/Group.hs b/src/Ganeti/Query/Group.hs index c15906c..9fe246d 100644 --- a/src/Ganeti/Query/Group.hs +++ b/src/Ganeti/Query/Group.hs @@ -83,6 +83,11 @@ groupFields = "List of primary instances", FieldConfig (\cfg -> rsNormal . niceSort . mapMaybe instName . fst . getGroupInstances cfg . groupUuid), QffNormal) + , (FieldDefinition "hv_state" "HypervisorState" QFTOther + "Custom static hypervisor state", + FieldSimple (rsNormal . groupHvStateStatic), QffNormal) + , (FieldDefinition "disk_state" "DiskState" QFTOther "Disk state", + FieldSimple (rsNormal . groupDiskStateStatic), QffNormal) ] ++ map buildNdParamField allNDParamFields ++ timeStampFields ++ diff --git a/src/Ganeti/Query/Node.hs b/src/Ganeti/Query/Node.hs index ecf5dc2..6ada091 100644 --- a/src/Ganeti/Query/Node.hs +++ b/src/Ganeti/Query/Node.hs @@ -246,13 +246,14 @@ nodeFields = , (FieldDefinition "powered" "Powered" QFTBool "Whether node is thought to be powered on", FieldConfig getNodePower, QffNormal) - -- FIXME: the two fields below are incomplete in Python, part of the - -- non-implemented node resource model; they are declared just for - -- parity, but are not functional - , (FieldDefinition "hv_state" "HypervisorState" QFTOther "Hypervisor state", - FieldSimple (const rsUnavail), QffNormal) + , (FieldDefinition "hv_state" "HypervisorState" QFTOther + "Static hypervisor state for default hypervisor only", + FieldConfig $ (rsNormal .) . getFilledHvStateParams, QffNormal) + , (FieldDefinition "custom_hv_state" "CustomHypervisorState" QFTOther + "Custom static hypervisor state", + FieldSimple $ rsNormal . nodeHvStateStatic, QffNormal) , (FieldDefinition "disk_state" "DiskState" QFTOther "Disk state", - FieldSimple (const rsUnavail), QffNormal) + FieldSimple $ rsNormal . nodeDiskStateStatic, QffNormal) ] ++ map nodeLiveFieldBuilder nodeLiveFieldsDefs ++ map buildNdParamField allNDParamFields ++ diff --git a/src/Ganeti/Query/Server.hs b/src/Ganeti/Query/Server.hs index df5da87..4a3143c 100644 --- a/src/Ganeti/Query/Server.hs +++ b/src/Ganeti/Query/Server.hs @@ -280,6 +280,10 @@ handleCall _ _ cdata QueryClusterInfo = showJSON . maintBalance $ configMaintenance cdata) , ("maint_balance_threshold", showJSON . maintBalanceThreshold $ configMaintenance cdata) + , ("hv_state", + showJSON $ clusterHvStateStatic cluster) + , ("disk_state", + showJSON $ clusterDiskStateStatic cluster) ] in case master of -- 2.6.0.rc2.230.g3dd15c0
