summaryrefslogtreecommitdiffstats
path: root/tools/crm_resource_ban.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/crm_resource_ban.c')
-rw-r--r--tools/crm_resource_ban.c188
1 files changed, 101 insertions, 87 deletions
diff --git a/tools/crm_resource_ban.c b/tools/crm_resource_ban.c
index 3b0e4a1..689a178 100644
--- a/tools/crm_resource_ban.c
+++ b/tools/crm_resource_ban.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2004-2023 the Pacemaker project contributors
+ * Copyright 2004-2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
@@ -72,62 +72,66 @@ cli_resource_ban(pcmk__output_t *out, const char *rsc_id, const char *host,
return EINVAL;
}
- fragment = create_xml_node(NULL, XML_CIB_TAG_CONSTRAINTS);
+ fragment = pcmk__xe_create(NULL, PCMK_XE_CONSTRAINTS);
- location = create_xml_node(fragment, XML_CONS_TAG_RSC_LOCATION);
+ location = pcmk__xe_create(fragment, PCMK_XE_RSC_LOCATION);
crm_xml_set_id(location, "cli-ban-%s-on-%s", rsc_id, host);
- out->info(out, "WARNING: Creating rsc_location constraint '%s' with a "
- "score of -INFINITY for resource %s on %s.\n\tThis will "
- "prevent %s from %s on %s until the constraint is removed "
- "using the clear option or by editing the CIB with an "
- "appropriate tool\n\tThis will be the case even if %s "
- "is the last node in the cluster",
- ID(location), rsc_id, host, rsc_id,
- (promoted_role_only? "being promoted" : "running"),
- host, host);
-
- crm_xml_add(location, XML_LOC_ATTR_SOURCE, rsc_id);
+ out->info(out,
+ "WARNING: Creating " PCMK_XE_RSC_LOCATION " constraint '%s' with "
+ "a score of " PCMK_VALUE_MINUS_INFINITY " for resource %s on %s."
+ "\n\tThis will prevent %s from %s on %s until the constraint is "
+ "removed using the clear option or by editing the CIB with an "
+ "appropriate tool.\n"
+ "\tThis will be the case even if %s is the last node in the "
+ "cluster",
+ pcmk__xe_id(location), rsc_id, host, rsc_id,
+ (promoted_role_only? "being promoted" : "running"), host, host);
+
+ crm_xml_add(location, PCMK_XA_RSC, rsc_id);
if(promoted_role_only) {
- crm_xml_add(location, XML_RULE_ATTR_ROLE, promoted_role);
+ crm_xml_add(location, PCMK_XA_ROLE, promoted_role);
} else {
- crm_xml_add(location, XML_RULE_ATTR_ROLE, PCMK__ROLE_STARTED);
+ crm_xml_add(location, PCMK_XA_ROLE, PCMK_ROLE_STARTED);
}
if (later_s == NULL) {
/* Short form */
- crm_xml_add(location, XML_CIB_TAG_NODE, host);
- crm_xml_add(location, XML_RULE_ATTR_SCORE, CRM_MINUS_INFINITY_S);
+ crm_xml_add(location, PCMK_XE_NODE, host);
+ crm_xml_add(location, PCMK_XA_SCORE, PCMK_VALUE_MINUS_INFINITY);
} else {
- xmlNode *rule = create_xml_node(location, XML_TAG_RULE);
- xmlNode *expr = create_xml_node(rule, XML_TAG_EXPRESSION);
+ xmlNode *rule = pcmk__xe_create(location, PCMK_XE_RULE);
+ xmlNode *expr = pcmk__xe_create(rule, PCMK_XE_EXPRESSION);
crm_xml_set_id(rule, "cli-ban-%s-on-%s-rule", rsc_id, host);
- crm_xml_add(rule, XML_RULE_ATTR_SCORE, CRM_MINUS_INFINITY_S);
- crm_xml_add(rule, XML_RULE_ATTR_BOOLEAN_OP, "and");
+ crm_xml_add(rule, PCMK_XA_SCORE, PCMK_VALUE_MINUS_INFINITY);
+ crm_xml_add(rule, PCMK_XA_BOOLEAN_OP, PCMK_VALUE_AND);
crm_xml_set_id(expr, "cli-ban-%s-on-%s-expr", rsc_id, host);
- crm_xml_add(expr, XML_EXPR_ATTR_ATTRIBUTE, CRM_ATTR_UNAME);
- crm_xml_add(expr, XML_EXPR_ATTR_OPERATION, "eq");
- crm_xml_add(expr, XML_EXPR_ATTR_VALUE, host);
- crm_xml_add(expr, XML_EXPR_ATTR_TYPE, "string");
+ crm_xml_add(expr, PCMK_XA_ATTRIBUTE, CRM_ATTR_UNAME);
+ crm_xml_add(expr, PCMK_XA_OPERATION, PCMK_VALUE_EQ);
+ crm_xml_add(expr, PCMK_XA_VALUE, host);
+ crm_xml_add(expr, PCMK_XA_TYPE, PCMK_VALUE_STRING);
- expr = create_xml_node(rule, "date_expression");
+ expr = pcmk__xe_create(rule, PCMK_XE_DATE_EXPRESSION);
crm_xml_set_id(expr, "cli-ban-%s-on-%s-lifetime", rsc_id, host);
- crm_xml_add(expr, "operation", "lt");
- crm_xml_add(expr, "end", later_s);
+ crm_xml_add(expr, PCMK_XA_OPERATION, PCMK_VALUE_LT);
+ crm_xml_add(expr, PCMK_XA_END, later_s);
}
crm_log_xml_notice(fragment, "Modify");
- rc = cib_conn->cmds->modify(cib_conn, XML_CIB_TAG_CONSTRAINTS, fragment,
+ rc = cib_conn->cmds->modify(cib_conn, PCMK_XE_CONSTRAINTS, fragment,
cib_options);
rc = pcmk_legacy2rc(rc);
free_xml(fragment);
free(later_s);
- if (rc != pcmk_rc_ok && promoted_role_only && strcmp(promoted_role, PCMK__ROLE_PROMOTED) == 0) {
+ if ((rc != pcmk_rc_ok)
+ && promoted_role_only
+ && (strcmp(promoted_role, PCMK_ROLE_PROMOTED) == 0)) {
+
int banrc = cli_resource_ban(out, rsc_id, host, move_lifetime,
cib_conn, cib_options, promoted_role_only,
PCMK__ROLE_PROMOTED_LEGACY);
@@ -159,52 +163,55 @@ cli_resource_prefer(pcmk__output_t *out,const char *rsc_id, const char *host,
return ENOTCONN;
}
- fragment = create_xml_node(NULL, XML_CIB_TAG_CONSTRAINTS);
+ fragment = pcmk__xe_create(NULL, PCMK_XE_CONSTRAINTS);
- location = create_xml_node(fragment, XML_CONS_TAG_RSC_LOCATION);
+ location = pcmk__xe_create(fragment, PCMK_XE_RSC_LOCATION);
crm_xml_set_id(location, "cli-prefer-%s", rsc_id);
- crm_xml_add(location, XML_LOC_ATTR_SOURCE, rsc_id);
+ crm_xml_add(location, PCMK_XA_RSC, rsc_id);
if(promoted_role_only) {
- crm_xml_add(location, XML_RULE_ATTR_ROLE, promoted_role);
+ crm_xml_add(location, PCMK_XA_ROLE, promoted_role);
} else {
- crm_xml_add(location, XML_RULE_ATTR_ROLE, PCMK__ROLE_STARTED);
+ crm_xml_add(location, PCMK_XA_ROLE, PCMK_ROLE_STARTED);
}
if (later_s == NULL) {
/* Short form */
- crm_xml_add(location, XML_CIB_TAG_NODE, host);
- crm_xml_add(location, XML_RULE_ATTR_SCORE, CRM_INFINITY_S);
+ crm_xml_add(location, PCMK_XE_NODE, host);
+ crm_xml_add(location, PCMK_XA_SCORE, PCMK_VALUE_INFINITY);
} else {
- xmlNode *rule = create_xml_node(location, XML_TAG_RULE);
- xmlNode *expr = create_xml_node(rule, XML_TAG_EXPRESSION);
+ xmlNode *rule = pcmk__xe_create(location, PCMK_XE_RULE);
+ xmlNode *expr = pcmk__xe_create(rule, PCMK_XE_EXPRESSION);
crm_xml_set_id(rule, "cli-prefer-rule-%s", rsc_id);
- crm_xml_add(rule, XML_RULE_ATTR_SCORE, CRM_INFINITY_S);
- crm_xml_add(rule, XML_RULE_ATTR_BOOLEAN_OP, "and");
+ crm_xml_add(rule, PCMK_XA_SCORE, PCMK_VALUE_INFINITY);
+ crm_xml_add(rule, PCMK_XA_BOOLEAN_OP, PCMK_VALUE_AND);
crm_xml_set_id(expr, "cli-prefer-expr-%s", rsc_id);
- crm_xml_add(expr, XML_EXPR_ATTR_ATTRIBUTE, CRM_ATTR_UNAME);
- crm_xml_add(expr, XML_EXPR_ATTR_OPERATION, "eq");
- crm_xml_add(expr, XML_EXPR_ATTR_VALUE, host);
- crm_xml_add(expr, XML_EXPR_ATTR_TYPE, "string");
+ crm_xml_add(expr, PCMK_XA_ATTRIBUTE, CRM_ATTR_UNAME);
+ crm_xml_add(expr, PCMK_XA_OPERATION, PCMK_VALUE_EQ);
+ crm_xml_add(expr, PCMK_XA_VALUE, host);
+ crm_xml_add(expr, PCMK_XA_TYPE, PCMK_VALUE_STRING);
- expr = create_xml_node(rule, "date_expression");
+ expr = pcmk__xe_create(rule, PCMK_XE_DATE_EXPRESSION);
crm_xml_set_id(expr, "cli-prefer-lifetime-end-%s", rsc_id);
- crm_xml_add(expr, "operation", "lt");
- crm_xml_add(expr, "end", later_s);
+ crm_xml_add(expr, PCMK_XA_OPERATION, PCMK_VALUE_LT);
+ crm_xml_add(expr, PCMK_XA_END, later_s);
}
crm_log_xml_info(fragment, "Modify");
- rc = cib_conn->cmds->modify(cib_conn, XML_CIB_TAG_CONSTRAINTS, fragment,
+ rc = cib_conn->cmds->modify(cib_conn, PCMK_XE_CONSTRAINTS, fragment,
cib_options);
rc = pcmk_legacy2rc(rc);
free_xml(fragment);
free(later_s);
- if (rc != pcmk_rc_ok && promoted_role_only && strcmp(promoted_role, PCMK__ROLE_PROMOTED) == 0) {
+ if ((rc != pcmk_rc_ok)
+ && promoted_role_only
+ && (strcmp(promoted_role, PCMK_ROLE_PROMOTED) == 0)) {
+
int preferrc = cli_resource_prefer(out, rsc_id, host, move_lifetime,
cib_conn, cib_options, promoted_role_only,
PCMK__ROLE_PROMOTED_LEGACY);
@@ -229,8 +236,9 @@ cli_resource_prefer(pcmk__output_t *out,const char *rsc_id, const char *host,
* </rule>
* </rsc_location>
*
- * (2) The mode could be given by node= in an rsc_location XML node. That's
- * what resource_clear_node_in_location handles. That XML looks like this:
+ * (2) The node could be given by node= in a PCMK_XE_RSC_LOCATION XML node.
+ * That's what resource_clear_node_in_location handles. That XML looks like
+ * this:
*
* <rsc_location id="cli-prefer-dummy" rsc="dummy" role="Started" node="node1" score="INFINITY"/>
*
@@ -243,13 +251,13 @@ resource_clear_node_in_expr(const char *rsc_id, const char *host, cib_t * cib_co
int rc = pcmk_rc_ok;
char *xpath_string = NULL;
-#define XPATH_FMT \
- "//" XML_CONS_TAG_RSC_LOCATION "[@" XML_ATTR_ID "='cli-prefer-%s']" \
- "[" XML_TAG_RULE \
- "[@" XML_ATTR_ID "='cli-prefer-rule-%s']" \
- "/" XML_TAG_EXPRESSION \
- "[@" XML_EXPR_ATTR_ATTRIBUTE "='#uname' " \
- "and @" XML_EXPR_ATTR_VALUE "='%s']" \
+#define XPATH_FMT \
+ "//" PCMK_XE_RSC_LOCATION "[@" PCMK_XA_ID "='cli-prefer-%s']" \
+ "[" PCMK_XE_RULE \
+ "[@" PCMK_XA_ID "='cli-prefer-rule-%s']" \
+ "/" PCMK_XE_EXPRESSION \
+ "[@" PCMK_XA_ATTRIBUTE "='" CRM_ATTR_UNAME "' " \
+ "and @" PCMK_XA_VALUE "='%s']" \
"]"
xpath_string = crm_strdup_printf(XPATH_FMT, rsc_id, rsc_id, host);
@@ -274,21 +282,22 @@ resource_clear_node_in_location(const char *rsc_id, const char *host, cib_t * ci
xmlNode *fragment = NULL;
xmlNode *location = NULL;
- fragment = create_xml_node(NULL, XML_CIB_TAG_CONSTRAINTS);
+ fragment = pcmk__xe_create(NULL, PCMK_XE_CONSTRAINTS);
if (clear_ban_constraints == TRUE) {
- location = create_xml_node(fragment, XML_CONS_TAG_RSC_LOCATION);
+ location = pcmk__xe_create(fragment, PCMK_XE_RSC_LOCATION);
crm_xml_set_id(location, "cli-ban-%s-on-%s", rsc_id, host);
}
- location = create_xml_node(fragment, XML_CONS_TAG_RSC_LOCATION);
+ location = pcmk__xe_create(fragment, PCMK_XE_RSC_LOCATION);
crm_xml_set_id(location, "cli-prefer-%s", rsc_id);
if (force == FALSE) {
- crm_xml_add(location, XML_CIB_TAG_NODE, host);
+ crm_xml_add(location, PCMK_XE_NODE, host);
}
crm_log_xml_info(fragment, "Delete");
- rc = cib_conn->cmds->remove(cib_conn, XML_CIB_TAG_CONSTRAINTS, fragment, cib_options);
+ rc = cib_conn->cmds->remove(cib_conn, PCMK_XE_CONSTRAINTS, fragment,
+ cib_options);
if (rc == -ENXIO) {
rc = pcmk_rc_ok;
} else {
@@ -349,12 +358,11 @@ build_clear_xpath_string(GString *buf, const xmlNode *constraint_node,
const char *rsc, const char *node,
bool promoted_role_only)
{
- const char *cons_id = ID(constraint_node);
- const char *cons_rsc = crm_element_value(constraint_node,
- XML_LOC_ATTR_SOURCE);
+ const char *cons_id = pcmk__xe_id(constraint_node);
+ const char *cons_rsc = crm_element_value(constraint_node, PCMK_XA_RSC);
GString *rsc_role_substr = NULL;
- const char *promoted_role_rule = "@" XML_RULE_ATTR_ROLE "='" PCMK__ROLE_PROMOTED
- "' or @" XML_RULE_ATTR_ROLE "='"
+ const char *promoted_role_rule = "@" PCMK_XA_ROLE "='" PCMK_ROLE_PROMOTED
+ "' or @" PCMK_XA_ROLE "='"
PCMK__ROLE_PROMOTED_LEGACY "'";
CRM_ASSERT(buf != NULL);
@@ -365,13 +373,13 @@ build_clear_xpath_string(GString *buf, const xmlNode *constraint_node,
return;
}
- g_string_append(buf, "//" XML_CONS_TAG_RSC_LOCATION);
+ g_string_append(buf, "//" PCMK_XE_RSC_LOCATION);
if ((node != NULL) || (rsc != NULL) || promoted_role_only) {
g_string_append_c(buf, '[');
if (node != NULL) {
- pcmk__g_strcat(buf, "@" XML_CIB_TAG_NODE "='", node, "'", NULL);
+ pcmk__g_strcat(buf, "@" PCMK_XE_NODE "='", node, "'", NULL);
if (promoted_role_only || (rsc != NULL)) {
g_string_append(buf, " and ");
@@ -381,13 +389,13 @@ build_clear_xpath_string(GString *buf, const xmlNode *constraint_node,
if ((rsc != NULL) && promoted_role_only) {
rsc_role_substr = g_string_sized_new(64);
pcmk__g_strcat(rsc_role_substr,
- "@" XML_LOC_ATTR_SOURCE "='", rsc, "' "
+ "@" PCMK_XA_RSC "='", rsc, "' "
"and (" , promoted_role_rule, ")", NULL);
} else if (rsc != NULL) {
rsc_role_substr = g_string_sized_new(64);
pcmk__g_strcat(rsc_role_substr,
- "@" XML_LOC_ATTR_SOURCE "='", rsc, "'", NULL);
+ "@" PCMK_XA_RSC "='", rsc, "'", NULL);
} else if (promoted_role_only) {
rsc_role_substr = g_string_sized_new(64);
@@ -401,18 +409,18 @@ build_clear_xpath_string(GString *buf, const xmlNode *constraint_node,
}
if (node != NULL) {
- g_string_append(buf, "|//" XML_CONS_TAG_RSC_LOCATION);
+ g_string_append(buf, "|//" PCMK_XE_RSC_LOCATION);
if (rsc_role_substr != NULL) {
pcmk__g_strcat(buf, "[", rsc_role_substr, "]", NULL);
}
pcmk__g_strcat(buf,
- "/" XML_TAG_RULE "[" XML_TAG_EXPRESSION
- "[@" XML_EXPR_ATTR_ATTRIBUTE "='" CRM_ATTR_UNAME "' "
- "and @" XML_EXPR_ATTR_VALUE "='", node, "']]", NULL);
+ "/" PCMK_XE_RULE "[" PCMK_XE_EXPRESSION
+ "[@" PCMK_XA_ATTRIBUTE "='" CRM_ATTR_UNAME "' "
+ "and @" PCMK_XA_VALUE "='", node, "']]", NULL);
}
- g_string_append(buf, "//" PCMK_XE_DATE_EXPRESSION "[@" XML_ATTR_ID "='");
+ g_string_append(buf, "//" PCMK_XE_DATE_EXPRESSION "[@" PCMK_XA_ID "='");
if (pcmk__starts_with(cons_id, "cli-ban-")) {
pcmk__g_strcat(buf, cons_id, "-lifetime']", NULL);
@@ -438,13 +446,14 @@ cli_resource_clear_all_expired(xmlNode *root, cib_t *cib_conn, int cib_options,
int i;
int rc = pcmk_rc_ok;
- cib_constraints = pcmk_find_cib_element(root, XML_CIB_TAG_CONSTRAINTS);
- xpathObj = xpath_search(cib_constraints, "//" XML_CONS_TAG_RSC_LOCATION);
+ cib_constraints = pcmk_find_cib_element(root, PCMK_XE_CONSTRAINTS);
+ xpathObj = xpath_search(cib_constraints, "//" PCMK_XE_RSC_LOCATION);
for (i = 0; i < numXpathResults(xpathObj); i++) {
xmlNode *constraint_node = getXpathResult(xpathObj, i);
xmlNode *date_expr_node = NULL;
crm_time_t *end = NULL;
+ int rc = pcmk_rc_ok;
if (buf == NULL) {
buf = g_string_sized_new(1024);
@@ -464,20 +473,25 @@ cli_resource_clear_all_expired(xmlNode *root, cib_t *cib_conn, int cib_options,
/* And then finally, see if the date expression is expired. If so,
* clear the constraint.
+ *
+ * @COMPAT Check for error once we are rejecting rules with invalid end
*/
- end = crm_time_new(crm_element_value(date_expr_node, "end"));
+ rc = pcmk__xe_get_datetime(date_expr_node, PCMK_XA_END, &end);
+ if (rc != pcmk_rc_ok) {
+ crm_trace("Invalid " PCMK_XA_END ": %s", pcmk_rc_str(rc));
+ }
if (crm_time_compare(now, end) == 1) {
xmlNode *fragment = NULL;
xmlNode *location = NULL;
- fragment = create_xml_node(NULL, XML_CIB_TAG_CONSTRAINTS);
- location = create_xml_node(fragment, XML_CONS_TAG_RSC_LOCATION);
- crm_xml_set_id(location, "%s", ID(constraint_node));
+ fragment = pcmk__xe_create(NULL, PCMK_XE_CONSTRAINTS);
+ location = pcmk__xe_create(fragment, PCMK_XE_RSC_LOCATION);
+ crm_xml_set_id(location, "%s", pcmk__xe_id(constraint_node));
crm_log_xml_info(fragment, "Delete");
- rc = cib_conn->cmds->remove(cib_conn, XML_CIB_TAG_CONSTRAINTS,
- fragment, cib_options);
+ rc = cib_conn->cmds->remove(cib_conn, PCMK_XE_CONSTRAINTS, fragment,
+ cib_options);
rc = pcmk_legacy2rc(rc);
if (rc != pcmk_rc_ok) {