1 {-| Implementation of the Ganeti Query2 node group queries.
7 Copyright (C) 2012, 2013 Google Inc.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 module Ganeti.Query.Group
32 import qualified Data.Map as Map
36 import Ganeti.Query.Language
37 import Ganeti.Query.Common
38 import Ganeti.Query.Types
39 import Ganeti.Utils (niceSort)
41 -- | There is no runtime.
42 data Runtime = Runtime
44 groupFields :: FieldList NodeGroup Runtime
46 [ (FieldDefinition "alloc_policy" "AllocPolicy" QFTText
47 "Allocation policy for group",
48 FieldSimple (rsNormal . groupAllocPolicy), QffNormal)
49 , (FieldDefinition "custom_diskparams" "CustomDiskParameters" QFTOther
50 "Custom disk parameters",
51 FieldSimple (rsNormal . groupDiskparams), QffNormal)
52 , (FieldDefinition "custom_ipolicy" "CustomInstancePolicy" QFTOther
53 "Custom instance policy limitations",
54 FieldSimple (rsNormal . groupIpolicy), QffNormal)
55 , (FieldDefinition "custom_ndparams" "CustomNDParams" QFTOther
56 "Custom node parameters",
57 FieldSimple (rsNormal . groupNdparams), QffNormal)
58 , (FieldDefinition "diskparams" "DiskParameters" QFTOther
59 "Disk parameters (merged)",
60 FieldConfig (\cfg -> rsNormal . getGroupDiskParams cfg), QffNormal)
61 , (FieldDefinition "ipolicy" "InstancePolicy" QFTOther
62 "Instance policy limitations (merged)",
63 FieldConfig (\cfg ng -> rsNormal (getGroupIpolicy cfg ng)), QffNormal)
64 , (FieldDefinition "name" "Group" QFTText "Group name",
65 FieldSimple (rsNormal . groupName), QffNormal)
66 , (FieldDefinition "ndparams" "NDParams" QFTOther "Node parameters",
67 FieldConfig (\cfg ng -> rsNormal (getGroupNdParams cfg ng)), QffNormal)
68 , (FieldDefinition "node_cnt" "Nodes" QFTNumber "Number of nodes",
69 FieldConfig (\cfg -> rsNormal . length . getGroupNodes cfg . groupUuid),
71 , (FieldDefinition "node_list" "NodeList" QFTOther "List of nodes",
72 FieldConfig (\cfg -> rsNormal . map nodeName .
73 getGroupNodes cfg . groupUuid), QffNormal)
74 , (FieldDefinition "pinst_cnt" "Instances" QFTNumber
75 "Number of primary instances",
77 (\cfg -> rsNormal . length . fst . getGroupInstances cfg . groupUuid),
79 , (FieldDefinition "pinst_list" "InstanceList" QFTOther
80 "List of primary instances",
81 -- FIXME: the niceSort here is not tested
82 FieldConfig (\cfg -> rsNormal . niceSort . map instName . fst .
83 getGroupInstances cfg . groupUuid), QffNormal)
85 map buildNdParamField allNDParamFields ++
88 serialFields "Group" ++
91 -- | The group fields map.
92 fieldsMap :: FieldMap NodeGroup Runtime
94 Map.fromList $ map (\v@(f, _, _) -> (fdefName f, v)) groupFields
96 -- | Dummy function for collecting live data (which groups don't have).
97 collectLiveData :: Bool -> ConfigData -> [NodeGroup]
98 -> IO [(NodeGroup, Runtime)]
99 collectLiveData _ _ = return . map (\n -> (n, Runtime))