Statistics
| Branch: | Tag: | Revision:

root / htools / Ganeti / Query / Types.hs @ 29a30533

History | View | Annotate | Download (2.1 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 a2ae14e9 Iustin Pop
  , FieldData
32 a2ae14e9 Iustin Pop
  , FieldList
33 a2ae14e9 Iustin Pop
  , FieldMap
34 a2ae14e9 Iustin Pop
  , isRuntimeField
35 a2ae14e9 Iustin Pop
  ) where
36 046fe3f5 Iustin Pop
37 046fe3f5 Iustin Pop
import qualified Data.Map as Map
38 046fe3f5 Iustin Pop
39 4cab6703 Iustin Pop
import Ganeti.Query.Language
40 046fe3f5 Iustin Pop
import Ganeti.Objects
41 046fe3f5 Iustin Pop
42 046fe3f5 Iustin Pop
-- | The type of field getters. The \"a\" type represents the type
43 046fe3f5 Iustin Pop
-- we're querying, whereas the \"b\" type represents the \'runtime\'
44 046fe3f5 Iustin Pop
-- data for that type (if any). Note that we don't support multiple
45 046fe3f5 Iustin Pop
-- runtime sources, and we always consider the entire configuration as
46 046fe3f5 Iustin Pop
-- a given (so no equivalent for Python's /*_CONFIG/ and /*_GROUP/;
47 046fe3f5 Iustin Pop
-- configuration accesses are cheap for us).
48 046fe3f5 Iustin Pop
data FieldGetter a b = FieldSimple  (a -> ResultEntry)
49 046fe3f5 Iustin Pop
                     | FieldRuntime (b -> a -> ResultEntry)
50 046fe3f5 Iustin Pop
                     | FieldConfig  (ConfigData -> a -> ResultEntry)
51 046fe3f5 Iustin Pop
                     | FieldUnknown
52 046fe3f5 Iustin Pop
53 046fe3f5 Iustin Pop
-- | Alias for a field data (definition and getter).
54 046fe3f5 Iustin Pop
type FieldData a b = (FieldDefinition, FieldGetter a b)
55 046fe3f5 Iustin Pop
56 046fe3f5 Iustin Pop
-- | Alias for a field data list.
57 046fe3f5 Iustin Pop
type FieldList a b = [FieldData a b]
58 046fe3f5 Iustin Pop
59 046fe3f5 Iustin Pop
-- | Alias for field maps.
60 046fe3f5 Iustin Pop
type FieldMap a b = Map.Map String (FieldData a b)
61 a2ae14e9 Iustin Pop
62 a2ae14e9 Iustin Pop
-- | Helper function to check if a getter is a runtime one.
63 a2ae14e9 Iustin Pop
isRuntimeField :: FieldGetter a b -> Bool
64 a2ae14e9 Iustin Pop
isRuntimeField (FieldRuntime _) = True
65 a2ae14e9 Iustin Pop
isRuntimeField _                = False