From fc4be2bfc888dadbb58f7952908261d5bca74088 Mon Sep 17 00:00:00 2001 From: Michele Tartara <mtartara@google.com> Date: Thu, 25 Apr 2013 13:03:43 +0000 Subject: [PATCH] Determine status of one instance Added function for determining whether the status of an instance is ok, and to represent this information in the corresponding field in the report. Signed-off-by: Michele Tartara <mtartara@google.com> Reviewed-by: Klaus Aehlig <aehlig@google.com> --- src/Ganeti/DataCollectors/InstStatus.hs | 20 ++++++++++++++++++++ src/Ganeti/DataCollectors/InstStatusTypes.hs | 2 ++ 2 files changed, 22 insertions(+) diff --git a/src/Ganeti/DataCollectors/InstStatus.hs b/src/Ganeti/DataCollectors/InstStatus.hs index acd459bcd..9a7b30015 100644 --- a/src/Ganeti/DataCollectors/InstStatus.hs +++ b/src/Ganeti/DataCollectors/InstStatus.hs @@ -41,6 +41,7 @@ import Ganeti.Confd.Types import Ganeti.Common import Ganeti.DataCollectors.CLI import Ganeti.DataCollectors.InstStatusTypes +import Ganeti.DataCollectors.Types import Ganeti.Hypervisor.Xen import Ganeti.Hypervisor.Xen.Types import Ganeti.Objects @@ -78,6 +79,23 @@ getInstances node srvAddr srvPort = do Just (J.Error msg) -> BT.Bad msg Nothing -> BT.Bad "No answer from the Confd server" +-- | Determine the value of the status field for the report of one instance +computeStatusField :: AdminState -> ActualState -> DCStatus +computeStatusField AdminDown actualState = + if actualState `notElem` [ActualShutdown, ActualDying] + then DCStatus DCSCBad "The instance is not stopped as it should be" + else DCStatus DCSCOk "" +computeStatusField AdminUp ActualHung = + DCStatus DCSCUnknown "Instance marked as running, but it appears to be hung" +computeStatusField AdminUp actualState = + if actualState `notElem` [ActualRunning, ActualBlocked] + then DCStatus DCSCBad "The instance is not running as it should be" + else DCStatus DCSCOk "" +computeStatusField AdminOffline _ = + -- FIXME: The "offline" status seems not to be used anywhere in the source + -- code, but it is defined, so we have to consider it anyway here. + DCStatus DCSCUnknown "The instance is marked as offline" + -- Builds the status of an instance using runtime information about the Xen -- Domains, their uptime information and the static information provided by -- the ConfD server. @@ -99,6 +117,7 @@ buildStatus domains uptimes inst = do then ActualHung else domState dom _ -> ActualUnknown + status = computeStatusField adminState actualState return $ InstStatus name @@ -107,6 +126,7 @@ buildStatus domains uptimes inst = do actualState uptime (instMtime inst) + status -- | Main function. main :: Options -> [String] -> IO () diff --git a/src/Ganeti/DataCollectors/InstStatusTypes.hs b/src/Ganeti/DataCollectors/InstStatusTypes.hs index b26578c41..8e30db917 100644 --- a/src/Ganeti/DataCollectors/InstStatusTypes.hs +++ b/src/Ganeti/DataCollectors/InstStatusTypes.hs @@ -29,6 +29,7 @@ module Ganeti.DataCollectors.InstStatusTypes ) where +import Ganeti.DataCollectors.Types import Ganeti.Hypervisor.Xen.Types import Ganeti.Objects import Ganeti.THH @@ -42,4 +43,5 @@ $(buildObject "InstStatus" "iStat" , optionalNullSerField $ simpleField "uptime" [t| String |] , simpleField "mtime" [t| Double |] + , simpleField "status" [t| DCStatus |] ]) -- GitLab