From 8781c20a1d7e41b967283f800c9434c15370a7cd Mon Sep 17 00:00:00 2001 From: Ken Gaillot Date: Jan 22 2021 12:12:42 +0000 Subject: Feature: tools: add crm_resource --digests option This is not particularly useful for end users but can help during development, and can be used by higher-level tools to bypass Pacemaker's configuration change detection (with obvious risks). --- diff --git a/tools/crm_resource.c b/tools/crm_resource.c index 3bdb898..b00ea09 100644 --- a/tools/crm_resource.c +++ b/tools/crm_resource.c @@ -40,6 +40,7 @@ enum rsc_command { cmd_cts, cmd_delete, cmd_delete_param, + cmd_digests, cmd_execute_agent, cmd_fail, cmd_get_param, @@ -158,6 +159,8 @@ gboolean validate_or_force_cb(const gchar *option_name, const gchar *optarg, gpointer data, GError **error); gboolean restart_cb(const gchar *option_name, const gchar *optarg, gpointer data, GError **error); +gboolean digests_cb(const gchar *option_name, const gchar *optarg, + gpointer data, GError **error); gboolean wait_cb(const gchar *option_name, const gchar *optarg, gpointer data, GError **error); gboolean why_cb(const gchar *option_name, const gchar *optarg, gpointer data, GError **error); @@ -507,6 +510,14 @@ static GOptionEntry advanced_entries[] = { { "wait", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, wait_cb, "(Advanced) Wait until the cluster settles into a stable state", NULL }, + { "digests", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, digests_cb, + "(Advanced) Show parameter hashes that Pacemaker uses to detect\n" + INDENT "configuration changes (only accurate if there is resource\n" + INDENT "history on the specified node). Required: --resource, --node.\n" + INDENT "Optional: any NAME=VALUE parameters will be used to override\n" + INDENT "the configuration (to see what the hash would be with those\n" + INDENT "changes).", + NULL }, { "force-demote", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, validate_or_force_cb, "(Advanced) Bypass the cluster and demote a resource on the local\n" @@ -893,7 +904,9 @@ validate_or_force_cb(const gchar *option_name, const gchar *optarg, } options.operation = g_strdup(option_name + 2); // skip "--" options.find_flags = pe_find_renamed|pe_find_anon; - options.override_params = crm_str_table_new(); + if (options.override_params == NULL) { + options.override_params = crm_str_table_new(); + } return TRUE; } @@ -907,6 +920,20 @@ restart_cb(const gchar *option_name, const gchar *optarg, gpointer data, } gboolean +digests_cb(const gchar *option_name, const gchar *optarg, gpointer data, + GError **error) +{ + SET_COMMAND(cmd_digests); + options.find_flags = pe_find_renamed|pe_find_anon; + if (options.override_params == NULL) { + options.override_params = crm_str_table_new(); + } + options.require_node = TRUE; + options.require_dataset = TRUE; + return TRUE; +} + +gboolean wait_cb(const gchar *option_name, const gchar *optarg, gpointer data, GError **error) { SET_COMMAND(cmd_wait); options.require_resource = FALSE; @@ -1819,6 +1846,16 @@ main(int argc, char **argv) } break; + case cmd_digests: + node = pe_find_node(data_set->nodes, options.host_uname); + if (node == NULL) { + rc = pcmk_rc_node_unknown; + } else { + rc = pcmk__resource_digests(out, rsc, node, + options.override_params, data_set); + } + break; + case cmd_colocations: rc = out->message(out, "stacks-constraints", rsc, data_set, false); break;