Revision ac13f473

b/Makefile.am
415 415
	htools/Ganeti/OpCodes.hs \
416 416
	htools/Ganeti/Runtime.hs \
417 417
	htools/Ganeti/Ssconf.hs \
418
	htools/Ganeti/THH.hs
418
	htools/Ganeti/THH.hs \
419
	htools/Ganeti/Query2.hs
419 420

  
420 421
HS_BUILT_SRCS = htools/Ganeti/HTools/Version.hs htools/Ganeti/Constants.hs
421 422
HS_BUILT_SRCS_IN = $(patsubst %,%.in,$(HS_BUILT_SRCS))
b/htools/Ganeti/Query2.hs
1
{-# LANGUAGE TemplateHaskell #-}
2

  
3
{-| Implementation of the Ganeti Query2 language.
4

  
5
 -}
6

  
7
{-
8

  
9
Copyright (C) 2012 Google Inc.
10

  
11
This program is free software; you can redistribute it and/or modify
12
it under the terms of the GNU General Public License as published by
13
the Free Software Foundation; either version 2 of the License, or
14
(at your option) any later version.
15

  
16
This program is distributed in the hope that it will be useful, but
17
WITHOUT ANY WARRANTY; without even the implied warranty of
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19
General Public License for more details.
20

  
21
You should have received a copy of the GNU General Public License
22
along with this program; if not, write to the Free Software
23
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24
02110-1301, USA.
25

  
26
-}
27

  
28
module Ganeti.Query2
29
    ( Filter
30
    ) where
31

  
32

  
33
import Text.JSON.Types
34
import Text.JSON
35

  
36
import qualified Ganeti.Constants as C
37
import Ganeti.HTools.JSON
38
import Ganeti.THH
39

  
40
-- * THH declarations, that require ordering.
41

  
42
-- | Status of a query field.
43
$(declareIADT "ResultStatus"
44
  [ ("RSNormal",  'C.rsNormal )
45
  , ("RSUnknown", 'C.rsUnknown )
46
  , ("RSNoData",  'C.rsNodata )
47
  , ("RSUnavail", 'C.rsUnavail )
48
  , ("RSOffline", 'C.rsOffline )
49
  ])
50
$(makeJSONInstance ''ResultStatus)
51

  
52
-- | Type of a query field.
53
$(declareSADT "FieldType"
54
  [ ("QFTUnknown",   'C.qftUnknown )
55
  , ("QFTText",      'C.qftText )
56
  , ("QFTBool",      'C.qftBool )
57
  , ("QFTNumber",    'C.qftNumber )
58
  , ("QFTUnit",      'C.qftUnit )
59
  , ("QFTTimestamp", 'C.qftTimestamp )
60
  , ("QFTOther",     'C.qftOther )
61
  ])
62
$(makeJSONInstance ''FieldType)
63

  
64
-- | Supported items on which Query2 works.
65
$(declareSADT "ItemType"
66
  [ ("QRCluster",  'C.qrCluster )
67
  , ("QRInstance", 'C.qrInstance )
68
  , ("QRNode",     'C.qrNode )
69
  , ("QRLock",     'C.qrLock )
70
  , ("QRGroup",    'C.qrGroup )
71
  , ("QROs",       'C.qrOs )
72
  , ("QRJob",      'C.qrJob )
73
  , ("QRExport",   'C.qrExport )
74
  ])
75
$(makeJSONInstance ''ItemType)
76

  
77
-- * Main Query2 queries and responses.
78

  
79
-- | Query2 query.
80
data Query = Query ItemType Fields (Maybe Filter)
81

  
82
-- | Query2 result.
83
data QueryResult = QueryResult [ FieldDefinition ] [ ResultEntry ]
84

  
85
-- | Query2 Fields query.
86
-- (to get supported fields names, descriptions, and types)
87
data QueryFields = QueryFields ItemType Fields
88

  
89
-- | Query2 Fields result.
90
data QueryFieldsResult = QueryFieldsResult [ FieldDefinition ]
91

  
92
-- * Sub data types for query2 queries and responses.
93

  
94
-- | List of requested fields.
95
type Fields = [ String ]
96

  
97
-- | Query2 filter expression.
98
data Filter
99
    = AndFilter [ Filter ] -- ^ & [<expression>, ...]
100
    | OrFilter [ Filter ] -- ^ | [<expression>, ...]
101
    | NotFilter Filter -- ^ ! <expression>
102
    | TrueFilter FilterField -- ^ ? <field>
103
    | EqualFilter FilterField FilterValue -- ^ (=|!=) <field> <value>
104
    | RegexpFilter FilterField FilterRegexp -- ^ =~ <field> <regexp>
105
    | ContainsFilter FilterField FilterValue -- ^ =[] <list-field> <value>
106

  
107
-- | Field name to filter on.
108
type FilterField = String
109

  
110
-- | Value to compare the field value to, for filtering purposes.
111
type FilterValue = String
112

  
113
-- | Regexp to apply to the filter value, for filteriong purposes.
114
type FilterRegexp = String
115

  
116
-- | Definition of a field.
117
data FieldDefinition = FieldDefinition FieldName FieldTitle FieldType FieldDoc
118

  
119
-- | Name of a field.
120
type FieldName = String
121
-- | Title of a field, when represented in tabular format.
122
type FieldTitle = String
123
-- | Human redable description of a field.
124
type FieldDoc = String
125

  
126
--- | Single field entry result.
127
data ResultEntry = ResultEntry ResultStatus (Maybe ResultValue)
128

  
129
-- | Value of a field, in json encoding.
130
-- (its type will be depending on ResultStatus and FieldType)
131
type ResultValue = JSValue

Also available in: Unified diff