Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / Query / Types.hs @ 88772d17

History | View | Annotate | Download (2.9 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 91c1a265 Iustin Pop
Copyright (C) 2012, 2013 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 4fb78549 Klaus Aehlig
  , fieldListToFieldMap
37 a2ae14e9 Iustin Pop
  ) where
38 046fe3f5 Iustin Pop
39 046fe3f5 Iustin Pop
import qualified Data.Map as Map
40 046fe3f5 Iustin Pop
41 4cab6703 Iustin Pop
import Ganeti.Query.Language
42 046fe3f5 Iustin Pop
import Ganeti.Objects
43 046fe3f5 Iustin Pop
44 046fe3f5 Iustin Pop
-- | The type of field getters. The \"a\" type represents the type
45 046fe3f5 Iustin Pop
-- we're querying, whereas the \"b\" type represents the \'runtime\'
46 046fe3f5 Iustin Pop
-- data for that type (if any). Note that we don't support multiple
47 046fe3f5 Iustin Pop
-- runtime sources, and we always consider the entire configuration as
48 046fe3f5 Iustin Pop
-- a given (so no equivalent for Python's /*_CONFIG/ and /*_GROUP/;
49 046fe3f5 Iustin Pop
-- configuration accesses are cheap for us).
50 11d09d75 Hrvoje Ribicic
data FieldGetter a b = FieldSimple        (a -> ResultEntry)
51 11d09d75 Hrvoje Ribicic
                     | FieldRuntime       (b -> a -> ResultEntry)
52 11d09d75 Hrvoje Ribicic
                     | FieldConfig        (ConfigData -> a -> ResultEntry)
53 11d09d75 Hrvoje Ribicic
                     | FieldConfigRuntime (ConfigData -> b -> a -> ResultEntry)
54 046fe3f5 Iustin Pop
                     | FieldUnknown
55 046fe3f5 Iustin Pop
56 f94a9680 Iustin Pop
-- | Type defining how the value of a field is used in filtering. This
57 f94a9680 Iustin Pop
-- implements the equivalent to Python's QFF_ flags, except that we
58 f94a9680 Iustin Pop
-- don't use OR-able values.
59 f94a9680 Iustin Pop
data QffMode = QffNormal     -- ^ Value is used as-is in filters
60 f94a9680 Iustin Pop
             | QffTimestamp  -- ^ Value is a timestamp tuple, convert to float
61 91c1a265 Iustin Pop
             | QffHostname   -- ^ Value is a hostname, compare it smartly
62 f94a9680 Iustin Pop
               deriving (Show, Eq)
63 f94a9680 Iustin Pop
64 f94a9680 Iustin Pop
65 046fe3f5 Iustin Pop
-- | Alias for a field data (definition and getter).
66 f94a9680 Iustin Pop
type FieldData a b = (FieldDefinition, FieldGetter a b, QffMode)
67 046fe3f5 Iustin Pop
68 046fe3f5 Iustin Pop
-- | Alias for a field data list.
69 046fe3f5 Iustin Pop
type FieldList a b = [FieldData a b]
70 046fe3f5 Iustin Pop
71 046fe3f5 Iustin Pop
-- | Alias for field maps.
72 046fe3f5 Iustin Pop
type FieldMap a b = Map.Map String (FieldData a b)
73 a2ae14e9 Iustin Pop
74 a2ae14e9 Iustin Pop
-- | Helper function to check if a getter is a runtime one.
75 a2ae14e9 Iustin Pop
isRuntimeField :: FieldGetter a b -> Bool
76 11d09d75 Hrvoje Ribicic
isRuntimeField FieldRuntime {}       = True
77 11d09d75 Hrvoje Ribicic
isRuntimeField FieldConfigRuntime {} = True
78 11d09d75 Hrvoje Ribicic
isRuntimeField _                     = False
79 4fb78549 Klaus Aehlig
80 4fb78549 Klaus Aehlig
-- | Helper function to obtain a FieldMap from the corresponding FieldList.
81 4fb78549 Klaus Aehlig
fieldListToFieldMap :: FieldList a b -> FieldMap a b
82 4fb78549 Klaus Aehlig
fieldListToFieldMap = Map.fromList . map (\v@(f, _, _) -> (fdefName f, v))