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