Prefer the UuidObject type class over specific functions
[ganeti-github.git] / src / Ganeti / Query / Group.hs
1 {-| Implementation of the Ganeti Query2 node group queries.
2
3 -}
4
5 {-
6
7 Copyright (C) 2012, 2013 Google Inc.
8 All rights reserved.
9
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are
12 met:
13
14 1. Redistributions of source code must retain the above copyright notice,
15 this list of conditions and the following disclaimer.
16
17 2. Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 -}
34
35 module Ganeti.Query.Group
36 (fieldsMap) where
37
38 import Data.Maybe (mapMaybe)
39
40 import Ganeti.Config
41 import Ganeti.Objects
42 import Ganeti.Query.Language
43 import Ganeti.Query.Common
44 import Ganeti.Query.Types
45 import Ganeti.Utils (niceSort)
46
47 groupFields :: FieldList NodeGroup NoDataRuntime
48 groupFields =
49 [ (FieldDefinition "alloc_policy" "AllocPolicy" QFTText
50 "Allocation policy for group",
51 FieldSimple (rsNormal . groupAllocPolicy), QffNormal)
52 , (FieldDefinition "custom_diskparams" "CustomDiskParameters" QFTOther
53 "Custom disk parameters",
54 FieldSimple (rsNormal . groupDiskparams), QffNormal)
55 , (FieldDefinition "custom_ipolicy" "CustomInstancePolicy" QFTOther
56 "Custom instance policy limitations",
57 FieldSimple (rsNormal . groupIpolicy), QffNormal)
58 , (FieldDefinition "custom_ndparams" "CustomNDParams" QFTOther
59 "Custom node parameters",
60 FieldSimple (rsNormal . groupNdparams), QffNormal)
61 , (FieldDefinition "diskparams" "DiskParameters" QFTOther
62 "Disk parameters (merged)",
63 FieldConfig (\cfg -> rsNormal . getGroupDiskParams cfg), QffNormal)
64 , (FieldDefinition "ipolicy" "InstancePolicy" QFTOther
65 "Instance policy limitations (merged)",
66 FieldConfig (\cfg ng -> rsNormal (getGroupIpolicy cfg ng)), QffNormal)
67 , (FieldDefinition "name" "Group" QFTText "Group name",
68 FieldSimple (rsNormal . groupName), QffNormal)
69 , (FieldDefinition "ndparams" "NDParams" QFTOther "Node parameters",
70 FieldConfig (\cfg ng -> rsNormal (getGroupNdParams cfg ng)), QffNormal)
71 , (FieldDefinition "node_cnt" "Nodes" QFTNumber "Number of nodes",
72 FieldConfig (\cfg -> rsNormal . length . getGroupNodes cfg . uuidOf),
73 QffNormal)
74 , (FieldDefinition "node_list" "NodeList" QFTOther "List of nodes",
75 FieldConfig (\cfg -> rsNormal . map nodeName .
76 getGroupNodes cfg . uuidOf), QffNormal)
77 , (FieldDefinition "pinst_cnt" "Instances" QFTNumber
78 "Number of primary instances",
79 FieldConfig
80 (\cfg -> rsNormal . length . fst . getGroupInstances cfg . uuidOf),
81 QffNormal)
82 , (FieldDefinition "pinst_list" "InstanceList" QFTOther
83 "List of primary instances",
84 FieldConfig (\cfg -> rsNormal . niceSort . mapMaybe instName . fst .
85 getGroupInstances cfg . uuidOf), QffNormal)
86 ] ++
87 map buildNdParamField allNDParamFields ++
88 timeStampFields ++
89 uuidFields "Group" ++
90 serialFields "Group" ++
91 tagsFields
92
93 -- | The group fields map.
94 fieldsMap :: FieldMap NodeGroup NoDataRuntime
95 fieldsMap = fieldListToFieldMap groupFields