root / src / Ganeti / Confd / ClientFunctions.hs @ d24fc4b6
History | View | Annotate | Download (1.7 kB)
1 | 9611c32e | Michele Tartara | {-| Some utility functions, based on the Confd client, providing data |
---|---|---|---|
2 | 9611c32e | Michele Tartara | in a ready-to-use way. |
3 | 9611c32e | Michele Tartara | -} |
4 | 9611c32e | Michele Tartara | |
5 | 9611c32e | Michele Tartara | {- |
6 | 9611c32e | Michele Tartara | |
7 | 9611c32e | Michele Tartara | Copyright (C) 2013 Google Inc. |
8 | 9611c32e | Michele Tartara | |
9 | 9611c32e | Michele Tartara | This program is free software; you can redistribute it and/or modify |
10 | 9611c32e | Michele Tartara | it under the terms of the GNU General Public License as published by |
11 | 9611c32e | Michele Tartara | the Free Software Foundation; either version 2 of the License, or |
12 | 9611c32e | Michele Tartara | (at your option) any later version. |
13 | 9611c32e | Michele Tartara | |
14 | 9611c32e | Michele Tartara | This program is distributed in the hope that it will be useful, but |
15 | 9611c32e | Michele Tartara | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | 9611c32e | Michele Tartara | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 | 9611c32e | Michele Tartara | General Public License for more details. |
18 | 9611c32e | Michele Tartara | |
19 | 9611c32e | Michele Tartara | You should have received a copy of the GNU General Public License |
20 | 9611c32e | Michele Tartara | along with this program; if not, write to the Free Software |
21 | 9611c32e | Michele Tartara | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
22 | 9611c32e | Michele Tartara | 02110-1301, USA. |
23 | 9611c32e | Michele Tartara | |
24 | 9611c32e | Michele Tartara | -} |
25 | 9611c32e | Michele Tartara | |
26 | 9611c32e | Michele Tartara | module Ganeti.Confd.ClientFunctions |
27 | 9611c32e | Michele Tartara | ( getInstances |
28 | 9611c32e | Michele Tartara | ) where |
29 | 9611c32e | Michele Tartara | |
30 | 9611c32e | Michele Tartara | import qualified Text.JSON as J |
31 | 9611c32e | Michele Tartara | |
32 | 9611c32e | Michele Tartara | import Ganeti.BasicTypes as BT |
33 | 9611c32e | Michele Tartara | import Ganeti.Confd.Types |
34 | 9611c32e | Michele Tartara | import Ganeti.Confd.Client |
35 | 9611c32e | Michele Tartara | import Ganeti.Objects |
36 | 9611c32e | Michele Tartara | |
37 | 9611c32e | Michele Tartara | |
38 | 9611c32e | Michele Tartara | -- | Get the list of instances the given node is ([primary], [secondary]) for. |
39 | 9611c32e | Michele Tartara | -- The server address and the server port parameters are mainly intended |
40 | 9611c32e | Michele Tartara | -- for testing purposes. If they are Nothing, the default values will be used. |
41 | 9611c32e | Michele Tartara | getInstances |
42 | 9611c32e | Michele Tartara | :: String |
43 | 9611c32e | Michele Tartara | -> Maybe String |
44 | 9611c32e | Michele Tartara | -> Maybe Int |
45 | 9611c32e | Michele Tartara | -> IO (BT.Result ([Ganeti.Objects.Instance], [Ganeti.Objects.Instance])) |
46 | 9611c32e | Michele Tartara | getInstances node srvAddr srvPort = do |
47 | 9611c32e | Michele Tartara | client <- getConfdClient srvAddr srvPort |
48 | 9611c32e | Michele Tartara | reply <- query client ReqNodeInstances $ PlainQuery node |
49 | 9611c32e | Michele Tartara | return $ |
50 | 9611c32e | Michele Tartara | case fmap (J.readJSON . confdReplyAnswer) reply of |
51 | 9611c32e | Michele Tartara | Just (J.Ok instances) -> BT.Ok instances |
52 | 9611c32e | Michele Tartara | Just (J.Error msg) -> BT.Bad msg |
53 | 9611c32e | Michele Tartara | Nothing -> BT.Bad "No answer from the Confd server" |