diff --git a/Makefile.am b/Makefile.am index 4150e8d9cddf1aa422c8c8323b20636a8b92da0f..3eba4ea63764ac02c8460429e42ff529437dcb04 100644 --- a/Makefile.am +++ b/Makefile.am @@ -487,6 +487,7 @@ HS_LIB_SRCS = \ src/Ganeti/DataCollectors/CLI.hs \ src/Ganeti/DataCollectors/Drbd.hs \ src/Ganeti/DataCollectors/Program.hs \ + src/Ganeti/DataCollectors/Types.hs \ src/Ganeti/Errors.hs \ src/Ganeti/HTools/Backend/IAlloc.hs \ src/Ganeti/HTools/Backend/Luxi.hs \ diff --git a/lib/constants.py b/lib/constants.py index 20c6495b08b3a393108ad1838bbb0fbcf9ec2a4b..d62834bc3f2069a018167c5a49d7f2625acb0aab 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -2315,5 +2315,8 @@ AUTO_REPAIR_ALL_RESULTS = frozenset([ AUTO_REPAIR_ENOPERM, ]) +# The version identifier for builtin data collectors +BUILTIN_DATA_COLLECTOR_VERSION = "B" + # Do not re-export imported modules del re, _vcsversion, _autoconf, socket, pathutils, compat diff --git a/src/Ganeti/DataCollectors/Types.hs b/src/Ganeti/DataCollectors/Types.hs new file mode 100644 index 0000000000000000000000000000000000000000..c423a47e6c63a38daab27936125400cec772a99e --- /dev/null +++ b/src/Ganeti/DataCollectors/Types.hs @@ -0,0 +1,58 @@ +{-# LANGUAGE TemplateHaskell #-} + +{-| Implementation of the Ganeti data collector types. + +-} + +{- + +Copyright (C) 2012 Google Inc. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301, USA. + +-} + +module Ganeti.DataCollectors.Types + ( DCReport(..) + , buildReport + ) where + +import Data.Maybe +import Text.JSON + +import Ganeti.Constants as C +import Ganeti.THH +import Ganeti.Utils (getCurrentTime) + +-- | This is the format of the report produced by each data collector. +$(buildObject "DCReport" "dcReport" + [ simpleField "name" [t| String |] + , simpleField "version" [t| String |] + , simpleField "format_version" [t| Int |] + , simpleField "timestamp" [t| Integer |] + , simpleField "data" [t| JSValue |] + ]) + +-- | Utility function for building a report automatically adding the current +-- timestamp (rounded up to seconds). +-- If the version is not specified, it will be set to the value indicating +-- a builtin collector. +buildReport :: String -> Maybe String -> Int -> JSValue -> IO DCReport +buildReport name version format_version jsonData = do + now <- getCurrentTime + let timestamp = now * 1000000000 :: Integer + ver = fromMaybe C.builtinDataCollectorVersion version + return $ DCReport name ver format_version timestamp jsonData