Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / Query / Types.hs @ 3e02cd3c

History | View | Annotate | Download (2.5 kB)

1 046fe3f5 Iustin Pop
{-| Implementation of the Ganeti Query2 basic types.
2 046fe3f5 Iustin Pop
3 046fe3f5 Iustin Pop
These are types internal to the library, and for example clients that
4 046fe3f5 Iustin Pop
use the library should not need to import it.
5 046fe3f5 Iustin Pop
6 046fe3f5 Iustin Pop
 -}
7 046fe3f5 Iustin Pop
8 046fe3f5 Iustin Pop
{-
9 046fe3f5 Iustin Pop
10 046fe3f5 Iustin Pop
Copyright (C) 2012 Google Inc.
11 046fe3f5 Iustin Pop
12 046fe3f5 Iustin Pop
This program is free software; you can redistribute it and/or modify
13 046fe3f5 Iustin Pop
it under the terms of the GNU General Public License as published by
14 046fe3f5 Iustin Pop
the Free Software Foundation; either version 2 of the License, or
15 046fe3f5 Iustin Pop
(at your option) any later version.
16 046fe3f5 Iustin Pop
17 046fe3f5 Iustin Pop
This program is distributed in the hope that it will be useful, but
18 046fe3f5 Iustin Pop
WITHOUT ANY WARRANTY; without even the implied warranty of
19 046fe3f5 Iustin Pop
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 046fe3f5 Iustin Pop
General Public License for more details.
21 046fe3f5 Iustin Pop
22 046fe3f5 Iustin Pop
You should have received a copy of the GNU General Public License
23 046fe3f5 Iustin Pop
along with this program; if not, write to the Free Software
24 046fe3f5 Iustin Pop
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 046fe3f5 Iustin Pop
02110-1301, USA.
26 046fe3f5 Iustin Pop
27 046fe3f5 Iustin Pop
-}
28 046fe3f5 Iustin Pop
29 a2ae14e9 Iustin Pop
module Ganeti.Query.Types
30 a2ae14e9 Iustin Pop
  ( FieldGetter(..)
31 f94a9680 Iustin Pop
  , QffMode(..)
32 a2ae14e9 Iustin Pop
  , FieldData
33 a2ae14e9 Iustin Pop
  , FieldList
34 a2ae14e9 Iustin Pop
  , FieldMap
35 a2ae14e9 Iustin Pop
  , isRuntimeField
36 a2ae14e9 Iustin Pop
  ) where
37 046fe3f5 Iustin Pop
38 046fe3f5 Iustin Pop
import qualified Data.Map as Map
39 046fe3f5 Iustin Pop
40 4cab6703 Iustin Pop
import Ganeti.Query.Language
41 046fe3f5 Iustin Pop
import Ganeti.Objects
42 046fe3f5 Iustin Pop
43 046fe3f5 Iustin Pop
-- | The type of field getters. The \"a\" type represents the type
44 046fe3f5 Iustin Pop
-- we're querying, whereas the \"b\" type represents the \'runtime\'
45 046fe3f5 Iustin Pop
-- data for that type (if any). Note that we don't support multiple
46 046fe3f5 Iustin Pop
-- runtime sources, and we always consider the entire configuration as
47 046fe3f5 Iustin Pop
-- a given (so no equivalent for Python's /*_CONFIG/ and /*_GROUP/;
48 046fe3f5 Iustin Pop
-- configuration accesses are cheap for us).
49 046fe3f5 Iustin Pop
data FieldGetter a b = FieldSimple  (a -> ResultEntry)
50 046fe3f5 Iustin Pop
                     | FieldRuntime (b -> a -> ResultEntry)
51 046fe3f5 Iustin Pop
                     | FieldConfig  (ConfigData -> a -> ResultEntry)
52 046fe3f5 Iustin Pop
                     | FieldUnknown
53 046fe3f5 Iustin Pop
54 f94a9680 Iustin Pop
-- | Type defining how the value of a field is used in filtering. This
55 f94a9680 Iustin Pop
-- implements the equivalent to Python's QFF_ flags, except that we
56 f94a9680 Iustin Pop
-- don't use OR-able values.
57 f94a9680 Iustin Pop
data QffMode = QffNormal     -- ^ Value is used as-is in filters
58 f94a9680 Iustin Pop
             | QffTimestamp  -- ^ Value is a timestamp tuple, convert to float
59 f94a9680 Iustin Pop
               deriving (Show, Eq)
60 f94a9680 Iustin Pop
61 f94a9680 Iustin Pop
62 046fe3f5 Iustin Pop
-- | Alias for a field data (definition and getter).
63 f94a9680 Iustin Pop
type FieldData a b = (FieldDefinition, FieldGetter a b, QffMode)
64 046fe3f5 Iustin Pop
65 046fe3f5 Iustin Pop
-- | Alias for a field data list.
66 046fe3f5 Iustin Pop
type FieldList a b = [FieldData a b]
67 046fe3f5 Iustin Pop
68 046fe3f5 Iustin Pop
-- | Alias for field maps.
69 046fe3f5 Iustin Pop
type FieldMap a b = Map.Map String (FieldData a b)
70 a2ae14e9 Iustin Pop
71 a2ae14e9 Iustin Pop
-- | Helper function to check if a getter is a runtime one.
72 a2ae14e9 Iustin Pop
isRuntimeField :: FieldGetter a b -> Bool
73 a2ae14e9 Iustin Pop
isRuntimeField (FieldRuntime _) = True
74 a2ae14e9 Iustin Pop
isRuntimeField _                = False