Revision 9611c32e src/Ganeti/DataCollectors/InstStatus.hs

b/src/Ganeti/DataCollectors/InstStatus.hs
43 43
import Network.BSD (getHostName)
44 44
import qualified Text.JSON as J
45 45

  
46
import qualified Ganeti.BasicTypes as BT
47
import Ganeti.Confd.Client
48
import Ganeti.Confd.Types
46
import Ganeti.Confd.ClientFunctions
49 47
import Ganeti.Common
50 48
import Ganeti.DataCollectors.CLI
51 49
import Ganeti.DataCollectors.InstStatusTypes
......
95 93
arguments :: [ArgCompletion]
96 94
arguments = []
97 95

  
98
-- | Get the list of instances ([primary], [secondary]) on the given node.
99
-- Implemented as a function, even if used a single time, to specify in a
100
-- convenient and elegant way the return data type, required in order to
101
-- prevent incurring in the monomorphism restriction.
102
-- The server address and the server port parameters are mainly intended
103
-- for testing purposes. If they are Nothing, the default values will be used.
104
getInstances
105
  :: String
106
  -> Maybe String
107
  -> Maybe Int
108
  -> IO (BT.Result ([Ganeti.Objects.Instance], [Ganeti.Objects.Instance]))
109
getInstances node srvAddr srvPort = do
110
  client <- getConfdClient srvAddr srvPort
111
  reply <- query client ReqNodeInstances $ PlainQuery node
112
  return $
113
    case fmap (J.readJSON . confdReplyAnswer) reply of
114
      Just (J.Ok instances) -> BT.Ok instances
115
      Just (J.Error msg) -> BT.Bad msg
116
      Nothing -> BT.Bad "No answer from the Confd server"
117

  
118 96
-- | Try to get the reason trail for an instance. In case it is not possible,
119 97
-- log the failure and return an empty list instead.
120 98
getReasonTrail :: String -> IO ReasonTrail

Also available in: Unified diff