Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / Query / Export.hs @ c92b4671

History | View | Annotate | Download (2.6 kB)

1 c4bf507b Iustin Pop
{-| Implementation of the Ganeti Query2 export queries.
2 c4bf507b Iustin Pop
3 c4bf507b Iustin Pop
 -}
4 c4bf507b Iustin Pop
5 c4bf507b Iustin Pop
{-
6 c4bf507b Iustin Pop
7 c4bf507b Iustin Pop
Copyright (C) 2013 Google Inc.
8 c4bf507b Iustin Pop
9 c4bf507b Iustin Pop
This program is free software; you can redistribute it and/or modify
10 c4bf507b Iustin Pop
it under the terms of the GNU General Public License as published by
11 c4bf507b Iustin Pop
the Free Software Foundation; either version 2 of the License, or
12 c4bf507b Iustin Pop
(at your option) any later version.
13 c4bf507b Iustin Pop
14 c4bf507b Iustin Pop
This program is distributed in the hope that it will be useful, but
15 c4bf507b Iustin Pop
WITHOUT ANY WARRANTY; without even the implied warranty of
16 c4bf507b Iustin Pop
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 c4bf507b Iustin Pop
General Public License for more details.
18 c4bf507b Iustin Pop
19 c4bf507b Iustin Pop
You should have received a copy of the GNU General Public License
20 c4bf507b Iustin Pop
along with this program; if not, write to the Free Software
21 c4bf507b Iustin Pop
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 c4bf507b Iustin Pop
02110-1301, USA.
23 c4bf507b Iustin Pop
24 c4bf507b Iustin Pop
-}
25 c4bf507b Iustin Pop
26 c4bf507b Iustin Pop
module Ganeti.Query.Export
27 c4bf507b Iustin Pop
  ( Runtime
28 c4bf507b Iustin Pop
  , fieldsMap
29 c4bf507b Iustin Pop
  , collectLiveData
30 c4bf507b Iustin Pop
  ) where
31 c4bf507b Iustin Pop
32 c4bf507b Iustin Pop
import Control.Monad (liftM)
33 c4bf507b Iustin Pop
34 c4bf507b Iustin Pop
import Ganeti.Objects
35 c4bf507b Iustin Pop
import Ganeti.Rpc
36 c4bf507b Iustin Pop
import Ganeti.Query.Language
37 c4bf507b Iustin Pop
import Ganeti.Query.Common
38 c4bf507b Iustin Pop
import Ganeti.Query.Types
39 c4bf507b Iustin Pop
40 c4bf507b Iustin Pop
-- | The parsed result of the ExportList. This is a bit tricky, in
41 c4bf507b Iustin Pop
-- that we already do parsing of the results in the RPC calls, so the
42 c4bf507b Iustin Pop
-- runtime type is a plain 'ResultEntry', as we have just one type.
43 c4bf507b Iustin Pop
type Runtime = ResultEntry
44 c4bf507b Iustin Pop
45 c4bf507b Iustin Pop
-- | Small helper for rpc to rs.
46 c4bf507b Iustin Pop
rpcErrToRs :: RpcError -> ResultEntry
47 c4bf507b Iustin Pop
rpcErrToRs err = ResultEntry (rpcErrorToStatus err) Nothing
48 c4bf507b Iustin Pop
49 c4bf507b Iustin Pop
-- | Helper for extracting fields from RPC result.
50 c4bf507b Iustin Pop
rpcExtractor :: Node -> Either RpcError RpcResultExportList
51 c4bf507b Iustin Pop
             -> [(Node, ResultEntry)]
52 c4bf507b Iustin Pop
rpcExtractor node (Right res) =
53 c4bf507b Iustin Pop
  [(node, rsNormal path) | path <- rpcResExportListExports res]
54 c4bf507b Iustin Pop
rpcExtractor node (Left err)  = [(node, rpcErrToRs err)]
55 c4bf507b Iustin Pop
56 c4bf507b Iustin Pop
-- | List of all node fields.
57 c4bf507b Iustin Pop
exportFields :: FieldList Node Runtime
58 c4bf507b Iustin Pop
exportFields =
59 c4bf507b Iustin Pop
  [ (FieldDefinition "node" "Node" QFTText "Node name",
60 7c17db26 Iustin Pop
     FieldRuntime (\_ n -> rsNormal $ nodeName n), QffHostname)
61 c4bf507b Iustin Pop
  , (FieldDefinition "export" "Export" QFTText "Export name",
62 c4bf507b Iustin Pop
     FieldRuntime (curry fst), QffNormal)
63 c4bf507b Iustin Pop
  ]
64 c4bf507b Iustin Pop
65 c4bf507b Iustin Pop
-- | The node fields map.
66 c4bf507b Iustin Pop
fieldsMap :: FieldMap Node Runtime
67 c92b4671 Klaus Aehlig
fieldsMap = fieldListToFieldMap exportFields
68 c4bf507b Iustin Pop
69 c4bf507b Iustin Pop
-- | Collect live data from RPC query if enabled.
70 c4bf507b Iustin Pop
--
71 c4bf507b Iustin Pop
-- Note that this function is \"funny\": the returned rows will not be
72 c4bf507b Iustin Pop
-- 1:1 with the input, as nodes without exports will be pruned,
73 c4bf507b Iustin Pop
-- whereas nodes with multiple exports will be listed multiple times.
74 c4bf507b Iustin Pop
collectLiveData:: Bool -> ConfigData -> [Node] -> IO [(Node, Runtime)]
75 c4bf507b Iustin Pop
collectLiveData False _ nodes =
76 c4bf507b Iustin Pop
  return [(n, rpcErrToRs $ RpcResultError "Live data disabled") | n <- nodes]
77 c4bf507b Iustin Pop
collectLiveData True _ nodes =
78 c4bf507b Iustin Pop
  concatMap (uncurry rpcExtractor) `liftM`
79 c4bf507b Iustin Pop
    executeRpcCall nodes RpcCallExportList