Revision c5a957c3 src/Ganeti/Hypervisor/Xen/XmParser.hs

b/src/Ganeti/Hypervisor/Xen/XmParser.hs
25 25
module Ganeti.Hypervisor.Xen.XmParser
26 26
  ( xmListParser
27 27
  , lispConfigParser
28
  , xmUptimeParser
29
  , uptimeLineParser
28 30
  ) where
29 31

  
30 32
import Control.Applicative
......
137 139
  case foldM foldResult Map.empty domains of
138 140
    Ok d -> return d
139 141
    Bad msg -> fail msg
142

  
143
-- | A parser for parsing the output of the @xm uptime@ command.
144
xmUptimeParser :: Parser (Map.Map Int UptimeInfo)
145
xmUptimeParser = do
146
  _ <- headerParser
147
  uptimes <- uptimeLineParser `AC.manyTill` A.endOfInput
148
  return $ Map.fromList [(uInfoID u, u) | u <- uptimes]
149
    where headerParser = A.string "Name" <* A.skipSpace <* A.string "ID"
150
            <* A.skipSpace <* A.string "Uptime" <* A.skipSpace
151

  
152
-- | A helper for parsing a single line of the @xm uptime@ output.
153
uptimeLineParser :: Parser UptimeInfo
154
uptimeLineParser = do
155
  name <- A.takeTill isSpace <* A.skipSpace
156
  idNum <- A.decimal <* A.skipSpace
157
  uptime <- A.takeTill (`elem` "\n\r") <* A.skipSpace
158
  return . UptimeInfo (unpack name) idNum $ unpack uptime

Also available in: Unified diff