root / src / Ganeti / Query / Group.hs @ d5b2753a
History | View | Annotate | Download (3.6 kB)
1 |
{-| Implementation of the Ganeti Query2 node group queries. |
---|---|
2 |
|
3 |
-} |
4 |
|
5 |
{- |
6 |
|
7 |
Copyright (C) 2012, 2013 Google Inc. |
8 |
|
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. |
13 |
|
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. |
18 |
|
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 |
22 |
02110-1301, USA. |
23 |
|
24 |
-} |
25 |
|
26 |
module Ganeti.Query.Group |
27 |
( Runtime |
28 |
, fieldsMap |
29 |
, collectLiveData |
30 |
) where |
31 |
|
32 |
import qualified Data.Map as Map |
33 |
|
34 |
import Ganeti.Config |
35 |
import Ganeti.Objects |
36 |
import Ganeti.Query.Language |
37 |
import Ganeti.Query.Common |
38 |
import Ganeti.Query.Types |
39 |
|
40 |
-- | There is no runtime. |
41 |
data Runtime = Runtime |
42 |
|
43 |
groupFields :: FieldList NodeGroup Runtime |
44 |
groupFields = |
45 |
[ (FieldDefinition "alloc_policy" "AllocPolicy" QFTText |
46 |
"Allocation policy for group", |
47 |
FieldSimple (rsNormal . groupAllocPolicy), QffNormal) |
48 |
, (FieldDefinition "custom_diskparams" "CustomDiskParameters" QFTOther |
49 |
"Custom disk parameters", |
50 |
FieldSimple (rsNormal . groupDiskparams), QffNormal) |
51 |
, (FieldDefinition "custom_ipolicy" "CustomInstancePolicy" QFTOther |
52 |
"Custom instance policy limitations", |
53 |
FieldSimple (rsNormal . groupIpolicy), QffNormal) |
54 |
, (FieldDefinition "custom_ndparams" "CustomNDParams" QFTOther |
55 |
"Custom node parameters", |
56 |
FieldSimple (rsNormal . groupNdparams), QffNormal) |
57 |
, (FieldDefinition "diskparams" "DiskParameters" QFTOther |
58 |
"Disk parameters (merged)", |
59 |
FieldConfig (\cfg -> rsNormal . getGroupDiskParams cfg), QffNormal) |
60 |
, (FieldDefinition "ipolicy" "InstancePolicy" QFTOther |
61 |
"Instance policy limitations (merged)", |
62 |
FieldConfig (\cfg ng -> rsNormal (getGroupIpolicy cfg ng)), QffNormal) |
63 |
, (FieldDefinition "name" "Group" QFTText "Group name", |
64 |
FieldSimple (rsNormal . groupName), QffNormal) |
65 |
, (FieldDefinition "ndparams" "NDParams" QFTOther "Node parameters", |
66 |
FieldConfig (\cfg ng -> rsNormal (getGroupNdParams cfg ng)), QffNormal) |
67 |
, (FieldDefinition "node_cnt" "Nodes" QFTNumber "Number of nodes", |
68 |
FieldConfig (\cfg -> rsNormal . length . getGroupNodes cfg . groupName), |
69 |
QffNormal) |
70 |
, (FieldDefinition "node_list" "NodeList" QFTOther "List of nodes", |
71 |
FieldConfig (\cfg -> rsNormal . map nodeName . |
72 |
getGroupNodes cfg . groupName), QffNormal) |
73 |
, (FieldDefinition "pinst_cnt" "Instances" QFTNumber |
74 |
"Number of primary instances", |
75 |
FieldConfig |
76 |
(\cfg -> rsNormal . length . fst . getGroupInstances cfg . groupName), |
77 |
QffNormal) |
78 |
, (FieldDefinition "pinst_list" "InstanceList" QFTOther |
79 |
"List of primary instances", |
80 |
FieldConfig (\cfg -> rsNormal . map instName . fst . |
81 |
getGroupInstances cfg . groupName), QffNormal) |
82 |
] ++ |
83 |
map buildNdParamField allNDParamFields ++ |
84 |
timeStampFields ++ |
85 |
uuidFields "Group" ++ |
86 |
serialFields "Group" ++ |
87 |
tagsFields |
88 |
|
89 |
-- | The group fields map. |
90 |
fieldsMap :: FieldMap NodeGroup Runtime |
91 |
fieldsMap = |
92 |
Map.fromList $ map (\v@(f, _, _) -> (fdefName f, v)) groupFields |
93 |
|
94 |
-- | Dummy function for collecting live data (which groups don't have). |
95 |
collectLiveData :: Bool -> ConfigData -> [NodeGroup] |
96 |
-> IO [(NodeGroup, Runtime)] |
97 |
collectLiveData _ _ = return . map (\n -> (n, Runtime)) |