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