Commit df726590 authored by Jose A. Lopes's avatar Jose A. Lopes
Browse files

Hs2Py constants: add 'devConsole' and syslog related



Add 'devConsole' and syslog related constants to the Haskell to Python
constant generation.
Signed-off-by: default avatarJose A. Lopes <jabolopes@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent e82d1e98
......@@ -207,7 +207,7 @@ DAEMONS_EXTRA_LOGFILES = \
for extra in DAEMONS_EXTRA_LOGBASE[daemon]))
for daemon in DAEMONS_EXTRA_LOGBASE)
DEV_CONSOLE = "/dev/console"
DEV_CONSOLE = _constants.DEV_CONSOLE
PROC_MOUNTS = "/proc/mounts"
......@@ -220,11 +220,11 @@ LUXI_OVERRIDE_MASTER = "master"
LUXI_OVERRIDE_QUERY = "query"
# one of "no", "yes", "only"
SYSLOG_USAGE = _autoconf.SYSLOG_USAGE
SYSLOG_NO = "no"
SYSLOG_YES = "yes"
SYSLOG_ONLY = "only"
SYSLOG_SOCKET = "/dev/log"
SYSLOG_USAGE = _constants.SYSLOG_USAGE
SYSLOG_NO = _constants.SYSLOG_NO
SYSLOG_YES = _constants.SYSLOG_YES
SYSLOG_ONLY = _constants.SYSLOG_ONLY
SYSLOG_SOCKET = _constants.SYSLOG_SOCKET
EXPORT_CONF_FILE = "config.ini"
......
......@@ -127,28 +127,8 @@ drbdBarriers = "DRBD_BARRIERS"
drbdNoMetaFlush :: Bool
drbdNoMetaFlush = DRBD_NO_META_FLUSH
data SyslogUsageT
= SyslogNo
| SyslogYes
| SyslogOnly
deriving (Bounded, Enum)
instance Read SyslogUsageT where
readsPrec _ r = do
(s, r') <- lex r
case s of
"no" -> [(SyslogNo, r')]
"yes" -> [(SyslogYes, r')]
"only" -> [(SyslogOnly, r')]
_ -> []
instance Show SyslogUsageT where
show SyslogNo = "no"
show SyslogYes = "yes"
show SyslogOnly = "only"
syslogUsage :: SyslogUsageT
syslogUsage = read "SYSLOG_USAGE" :: SyslogUsageT
syslogUsage :: String
syslogUsage = "SYSLOG_USAGE"
daemonsGroup :: String
daemonsGroup = "DAEMONS_GROUP"
......
......@@ -71,3 +71,11 @@ instance PyValue Protocol where
-- between 'Ganeti.HsConstants' and 'Ganeti.Runtime'
exitFailure :: Int
exitFailure = 1
-- | Console device
--
-- This is defined here and not in 'Ganeti.HsConstants' order to avoid
-- a circular dependency between 'Ganeti.HsConstants' and
-- 'Ganeti.Logging'
devConsole :: String
devConsole = "/dev/console"
......@@ -41,9 +41,11 @@ import qualified Data.Map as Map (fromList)
import AutoConf
import Ganeti.ConstantUtils (FrozenSet, Protocol(..))
import qualified Ganeti.ConstantUtils as ConstantUtils (mkSet, exitFailure)
import qualified Ganeti.ConstantUtils as ConstantUtils
import Ganeti.Runtime (GanetiDaemon(..), MiscGroup(..), GanetiGroup(..),
ExtraLogReason(..))
import Ganeti.Logging (SyslogUsage(..))
import qualified Ganeti.Logging as Logging (syslogUsageToRaw)
import qualified Ganeti.Runtime as Runtime
-- * Admin states
......@@ -178,6 +180,26 @@ extraLogreasonAccess = Runtime.daemonsExtraLogbase GanetiMond AccessLog
extraLogreasonError :: String
extraLogreasonError = Runtime.daemonsExtraLogbase GanetiMond ErrorLog
devConsole :: String
devConsole = ConstantUtils.devConsole
-- * Syslog
syslogUsage :: String
syslogUsage = AutoConf.syslogUsage
syslogNo :: String
syslogNo = Logging.syslogUsageToRaw SyslogNo
syslogYes :: String
syslogYes = Logging.syslogUsageToRaw SyslogYes
syslogOnly :: String
syslogOnly = Logging.syslogUsageToRaw SyslogOnly
syslogSocket :: String
syslogSocket = "/dev/log"
-- * Common exit codes
exitSuccess :: Int
......
......@@ -55,13 +55,13 @@ import System.Log.Formatter
import System.IO
import Ganeti.THH
import qualified Ganeti.Constants as C
import qualified Ganeti.ConstantUtils as ConstantUtils
-- | Syslog usage type.
$(declareSADT "SyslogUsage"
[ ("SyslogNo", 'C.syslogNo)
, ("SyslogYes", 'C.syslogYes)
, ("SyslogOnly", 'C.syslogOnly)
$(declareLADT ''String "SyslogUsage"
[ ("SyslogNo", "no")
, ("SyslogYes", "yes")
, ("SyslogOnly", "only")
])
-- | Builds the log formatter.
......@@ -98,7 +98,7 @@ setupLogging :: Maybe String -- ^ Log file
-> IO ()
setupLogging logf program debug stderr_logging console syslog = do
let level = if debug then DEBUG else INFO
destf = if console then Just C.devConsole else logf
destf = if console then Just ConstantUtils.devConsole else logf
fmt = logFormatter program False False
file_logging = syslog /= SyslogOnly
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment