Incidents may request live repairs on a node. In this case, they are expected to also provide a command field in the incident description. Add a utility function to extract it, if present.
Signed-off-by: Klaus Aehlig <[email protected]> --- src/Ganeti/MaintD/Utils.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Ganeti/MaintD/Utils.hs b/src/Ganeti/MaintD/Utils.hs index 1002507..950dad4 100644 --- a/src/Ganeti/MaintD/Utils.hs +++ b/src/Ganeti/MaintD/Utils.hs @@ -34,13 +34,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. module Ganeti.MaintD.Utils ( annotateOpCode + , getRepairCommand ) where import Control.Lens.Setter (over) +import qualified Text.JSON as J import qualified Ganeti.Constants as C import Ganeti.JQueue (reasonTrailTimestamp) import Ganeti.JQueue.Objects (Timestamp) +import Ganeti.Objects.Maintenance (Incident(..)) import Ganeti.OpCodes (OpCode, MetaOpCode, wrapOpCode) import Ganeti.OpCodes.Lens (metaParamsL, opReasonL) @@ -51,3 +54,11 @@ annotateOpCode reason ts = over (metaParamsL . opReasonL) (++ [(C.opcodeReasonSrcMaintd, reason, reasonTrailTimestamp ts)]) . wrapOpCode + +-- | Get the name of the repair command from a live-repair incident. +getRepairCommand :: Incident -> Maybe String +getRepairCommand incident = case () of + _ | J.JSObject obj <- incidentOriginal incident, + Just (J.JSString cmd) <- lookup "command" $ J.fromJSObject obj -> + return $ J.fromJSString cmd + _ -> Nothing -- 2.6.0.rc0.131.gf624c3d
