From 732ebac1252dd270410b6673301647da09c75b74 Mon Sep 17 00:00:00 2001 From: Oyvind Albrigtsen Date: Mar 09 2021 06:18:53 +0000 Subject: Refactor: crmadmin/pcmk__list_nodes(): use crm_foreach_xpath_result() for all types of nodes --- diff --git a/include/crm/common/xml_internal.h b/include/crm/common/xml_internal.h index 4501bee..2193b50 100644 --- a/include/crm/common/xml_internal.h +++ b/include/crm/common/xml_internal.h @@ -125,6 +125,11 @@ do { /* XML search strings for guest, remote and pacemaker_remote nodes */ +/* search string to find CIB resources entries for cluster nodes */ +#define PCMK__XP_MEMBER_NODE_CONFIG \ + "//" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_NODES \ + "/" XML_CIB_TAG_NODE "[not(@type) or @type='member']" + /* search string to find CIB resources entries for guest nodes */ #define PCMK__XP_GUEST_NODE_CONFIG \ "//" XML_TAG_CIB "//" XML_CIB_TAG_CONFIGURATION "//" XML_CIB_TAG_RESOURCE \ diff --git a/lib/cluster/membership.c b/lib/cluster/membership.c index 97b78cc..83b95d9 100644 --- a/lib/cluster/membership.c +++ b/lib/cluster/membership.c @@ -1126,10 +1126,6 @@ known_peer_cache_refresh_helper(xmlNode *xml_node, void *user_data) } -#define PCMK__XP_MEMBER_NODE_CONFIG \ - "//" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_NODES \ - "/" XML_CIB_TAG_NODE "[not(@type) or @type='member']" - static void crm_known_peer_cache_refresh(xmlNode *cib) { diff --git a/lib/pacemaker/pcmk_cluster_queries.c b/lib/pacemaker/pcmk_cluster_queries.c index 9f19915..6e6acda 100644 --- a/lib/pacemaker/pcmk_cluster_queries.c +++ b/lib/pacemaker/pcmk_cluster_queries.c @@ -405,12 +405,13 @@ remote_node_print_helper(xmlNode *result, void *user_data) { struct node_data *data = user_data; pcmk__output_t *out = data->out; - const char *remote = crm_element_value(result, data->field); + const char *name = crm_element_value(result, XML_ATTR_UNAME); + const char *id = crm_element_value(result, data->field); // node name and node id are the same for remote/guest nodes out->message(out, "crmadmin-node", data->type, - remote, - remote, + name ? name : id, + id, data->BASH_EXPORT); data->found++; } @@ -434,8 +435,6 @@ pcmk__list_nodes(pcmk__output_t *out, char *node_types, gboolean BASH_EXPORT) rc = the_cib->cmds->query(the_cib, NULL, &xml_node, cib_scope_local | cib_sync_call); if (rc == pcmk_ok) { - xmlNode *node = NULL; - xmlNode *nodes = get_object_root(XML_CIB_TAG_NODES, xml_node); struct node_data data = { .out = out, .found = 0, @@ -449,18 +448,10 @@ pcmk__list_nodes(pcmk__output_t *out, char *node_types, gboolean BASH_EXPORT) } if (pcmk__str_empty(node_types) || strstr(node_types, "cluster")) { - for (node = first_named_child(nodes, XML_CIB_TAG_NODE); node != NULL; - node = crm_next_same_xml(node)) { - const char *node_type = crm_element_value(node, XML_ATTR_TYPE); - if (node_type == NULL) { - out->message(out, "crmadmin-node", node_type, - crm_str(crm_element_value(node, XML_ATTR_UNAME)), - crm_str(crm_element_value(node, XML_ATTR_ID)), - BASH_EXPORT); - data.found++; - } - - } + data.field = "id"; + data.type = "cluster"; + crm_foreach_xpath_result(xml_node, PCMK__XP_MEMBER_NODE_CONFIG, + remote_node_print_helper, &data); } if (pcmk__str_empty(node_types) || strstr(node_types, "guest")) {