summaryrefslogtreecommitdiffstats
path: root/lib/common/health.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 06:53:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 06:53:20 +0000
commite5a812082ae033afb1eed82c0f2df3d0f6bdc93f (patch)
treea6716c9275b4b413f6c9194798b34b91affb3cc7 /lib/common/health.c
parentInitial commit. (diff)
downloadpacemaker-e5a812082ae033afb1eed82c0f2df3d0f6bdc93f.tar.xz
pacemaker-e5a812082ae033afb1eed82c0f2df3d0f6bdc93f.zip
Adding upstream version 2.1.6.upstream/2.1.6
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/common/health.c')
-rw-r--r--lib/common/health.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/common/health.c b/lib/common/health.c
new file mode 100644
index 0000000..ee412be
--- /dev/null
+++ b/lib/common/health.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2022 the Pacemaker project contributors
+ *
+ * The version control history for this file may have further details.
+ *
+ * This source code is licensed under the GNU Lesser General Public License
+ * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
+ */
+
+#include <crm_internal.h>
+
+/*!
+ * \internal
+ * \brief Ensure a health strategy value is allowed
+ *
+ * \param[in] value Configured health strategy
+ *
+ * \return true if \p value is an allowed health strategy value, otherwise false
+ */
+bool
+pcmk__validate_health_strategy(const char *value)
+{
+ return pcmk__strcase_any_of(value,
+ PCMK__VALUE_NONE,
+ PCMK__VALUE_CUSTOM,
+ PCMK__VALUE_ONLY_GREEN,
+ PCMK__VALUE_PROGRESSIVE,
+ PCMK__VALUE_MIGRATE_ON_RED,
+ NULL);
+}
+
+/*!
+ * \internal
+ * \brief Parse node health strategy from a user-provided string
+ *
+ * \param[in] value User-provided configuration value for node-health-strategy
+ *
+ * \return Node health strategy corresponding to \p value
+ */
+enum pcmk__health_strategy
+pcmk__parse_health_strategy(const char *value)
+{
+ if (pcmk__str_eq(value, PCMK__VALUE_NONE,
+ pcmk__str_null_matches|pcmk__str_casei)) {
+ return pcmk__health_strategy_none;
+
+ } else if (pcmk__str_eq(value, PCMK__VALUE_MIGRATE_ON_RED,
+ pcmk__str_casei)) {
+ return pcmk__health_strategy_no_red;
+
+ } else if (pcmk__str_eq(value, PCMK__VALUE_ONLY_GREEN,
+ pcmk__str_casei)) {
+ return pcmk__health_strategy_only_green;
+
+ } else if (pcmk__str_eq(value, PCMK__VALUE_PROGRESSIVE,
+ pcmk__str_casei)) {
+ return pcmk__health_strategy_progressive;
+
+ } else if (pcmk__str_eq(value, PCMK__VALUE_CUSTOM,
+ pcmk__str_casei)) {
+ return pcmk__health_strategy_custom;
+
+ } else {
+ pcmk__config_err("Using default of \"" PCMK__VALUE_NONE "\" for "
+ PCMK__OPT_NODE_HEALTH_STRATEGY
+ " because '%s' is not a valid value",
+ value);
+ return pcmk__health_strategy_none;
+ }
+}