Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / Query / Types.hs @ e817723c

History | View | Annotate | Download (2.7 kB)

1
{-| Implementation of the Ganeti Query2 basic types.
2

    
3
These are types internal to the library, and for example clients that
4
use the library should not need to import it.
5

    
6
 -}
7

    
8
{-
9

    
10
Copyright (C) 2012, 2013 Google Inc.
11

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

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

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

    
27
-}
28

    
29
module Ganeti.Query.Types
30
  ( FieldGetter(..)
31
  , QffMode(..)
32
  , FieldData
33
  , FieldList
34
  , FieldMap
35
  , isRuntimeField
36
  ) where
37

    
38
import qualified Data.Map as Map
39

    
40
import Ganeti.Query.Language
41
import Ganeti.Objects
42

    
43
-- | The type of field getters. The \"a\" type represents the type
44
-- we're querying, whereas the \"b\" type represents the \'runtime\'
45
-- data for that type (if any). Note that we don't support multiple
46
-- runtime sources, and we always consider the entire configuration as
47
-- a given (so no equivalent for Python's /*_CONFIG/ and /*_GROUP/;
48
-- configuration accesses are cheap for us).
49
data FieldGetter a b = FieldSimple        (a -> ResultEntry)
50
                     | FieldRuntime       (b -> a -> ResultEntry)
51
                     | FieldConfig        (ConfigData -> a -> ResultEntry)
52
                     | FieldConfigRuntime (ConfigData -> b -> a -> ResultEntry)
53
                     | FieldUnknown
54

    
55
-- | Type defining how the value of a field is used in filtering. This
56
-- implements the equivalent to Python's QFF_ flags, except that we
57
-- don't use OR-able values.
58
data QffMode = QffNormal     -- ^ Value is used as-is in filters
59
             | QffTimestamp  -- ^ Value is a timestamp tuple, convert to float
60
             | QffHostname   -- ^ Value is a hostname, compare it smartly
61
               deriving (Show, Eq)
62

    
63

    
64
-- | Alias for a field data (definition and getter).
65
type FieldData a b = (FieldDefinition, FieldGetter a b, QffMode)
66

    
67
-- | Alias for a field data list.
68
type FieldList a b = [FieldData a b]
69

    
70
-- | Alias for field maps.
71
type FieldMap a b = Map.Map String (FieldData a b)
72

    
73
-- | Helper function to check if a getter is a runtime one.
74
isRuntimeField :: FieldGetter a b -> Bool
75
isRuntimeField FieldRuntime {}       = True
76
isRuntimeField FieldConfigRuntime {} = True
77
isRuntimeField _                     = False