21 #include <sys/param.h>
26 #include <sys/types.h>
38 #define attr_msg(level, fmt, args...) do { \
40 printf(fmt"\n", ##args); \
42 do_crm_log(level, fmt , ##args); \
47 #define attr_snprintf(_str, _offset, _limit, ...) do { \
48 _offset += snprintf(_str + _offset, \
49 (_limit > _offset) ? _limit - _offset : 0, \
55 const char *node_uuid,
const char *attr_set_type,
const char *set_name,
56 const char *attr_id,
const char *attr_name, gboolean to_console,
57 char **value,
const char *user_name)
60 static int xpath_max = 1024;
63 char *xpath_string = NULL;
64 xmlNode *xml_search = NULL;
65 const char *set_type = NULL;
69 set_type = attr_set_type;
91 }
else if (node_uuid == NULL) {
95 xpath_string = calloc(1, xpath_max);
96 CRM_CHECK(xpath_string != NULL,
return -ENOMEM);
101 attr_snprintf(xpath_string, offset, xpath_max,
"//%s", node_type);
103 }
else if (node_uuid) {
110 attr_snprintf(xpath_string, offset, xpath_max,
"//%s[@id='%s']", node_type,
115 attr_snprintf(xpath_string, offset, xpath_max,
"//%s[@id='%.128s']", set_type,
118 attr_snprintf(xpath_string, offset, xpath_max,
"//%s", set_type);
123 attr_snprintf(xpath_string, offset, xpath_max,
"@id='%s'", attr_id);
130 attr_snprintf(xpath_string, offset, xpath_max,
"@name='%.128s'", attr_name);
139 crm_trace(
"Query failed for attribute %s (section=%s, node=%s, set=%s, xpath=%s): %s",
140 attr_name, section,
crm_str(node_uuid),
crm_str(set_name), xpath_string,
147 xmlNode *child = NULL;
150 attr_msg(LOG_WARNING,
"Multiple attributes match name=%s", attr_name);
152 for (child = __xml_first_child(xml_search); child != NULL; child = __xml_next(child)) {
153 attr_msg(LOG_INFO,
" Value: %s \t(id=%s)",
161 *value = strdup(tmp);
173 const char *section,
const char *node_uuid,
const char *set_type,
174 const char *set_name,
const char *attr_id,
const char *attr_name,
175 const char *attr_value, gboolean to_console,
const char *user_name,
178 const char *tag = NULL;
180 xmlNode *xml_top = NULL;
181 xmlNode *xml_obj = NULL;
183 char *local_attr_id = NULL;
184 char *local_set_name = NULL;
186 CRM_CHECK(section != NULL,
return -EINVAL);
187 CRM_CHECK(attr_value != NULL,
return -EINVAL);
188 CRM_CHECK(attr_name != NULL || attr_id != NULL,
return -EINVAL);
191 attr_id, attr_name, to_console, &local_attr_id, user_name);
193 attr_id = local_attr_id;
196 }
else if (rc != -ENXIO) {
203 crm_trace(
"%s does not exist, create it", attr_name);
214 if (node_uuid == NULL) {
230 if (node_uuid == NULL) {
243 if (set_name == NULL) {
250 }
else if (node_uuid) {
251 local_set_name =
crm_concat(section, node_uuid,
'-');
254 char *tmp_set_name = local_set_name;
256 local_set_name =
crm_concat(tmp_set_name, set_type,
'-');
260 local_set_name =
crm_concat(section,
"options",
'-');
262 set_name = local_set_name;
265 if (attr_id == NULL) {
268 local_attr_id =
crm_concat(set_name, attr_name,
'-');
269 attr_id = local_attr_id;
272 for (lpc = 0; local_attr_id[lpc] != 0; lpc++) {
273 switch (local_attr_id[lpc]) {
275 local_attr_id[lpc] =
'.';
279 }
else if (attr_name == NULL) {
283 crm_trace(
"Creating %s/%s", section, tag);
287 if (xml_top == NULL) {
299 }
else if (set_type) {
307 if (xml_top == NULL) {
314 if (xml_top == NULL) {
327 attr_msg(LOG_ERR,
"Error setting %s=%s (section=%s, set=%s): %s",
332 free(local_set_name);
341 const char *section,
const char *node_uuid,
const char *set_type,
342 const char *set_name,
const char *attr_id,
const char *attr_name,
343 char **attr_value, gboolean to_console,
const char *user_name)
348 CRM_CHECK(section != NULL,
return -EINVAL);
349 CRM_CHECK(attr_name != NULL || attr_id != NULL,
return -EINVAL);
354 set_name, attr_id, attr_name, to_console, attr_value, user_name);
356 crm_trace(
"Query failed for attribute %s (section=%s, node=%s, set=%s): %s",
364 const char *section,
const char *node_uuid,
const char *set_type,
365 const char *set_name,
const char *attr_id,
const char *attr_name,
366 const char *attr_value, gboolean to_console,
const char *user_name)
369 xmlNode *xml_obj = NULL;
370 char *local_attr_id = NULL;
372 CRM_CHECK(section != NULL,
return -EINVAL);
373 CRM_CHECK(attr_name != NULL || attr_id != NULL,
return -EINVAL);
375 if (attr_id == NULL) {
377 set_name, attr_id, attr_name, to_console, &local_attr_id,
382 attr_id = local_attr_id;
394 attr_msg(LOG_DEBUG,
"Deleted %s %s: id=%s%s%s%s%s\n",
395 section, node_uuid ?
"attribute" :
"option", local_attr_id,
396 set_name ?
" set=" :
"", set_name ? set_name :
"",
397 attr_name ?
" name=" :
"", attr_name ? attr_name :
"");
406 found_remote_node_xpath(
cib_t *the_cib,
const char *xpath)
409 xmlNode *xml_search = NULL;
415 return rc ==
pcmk_ok ? TRUE : FALSE;
419 get_remote_node_uuid(
cib_t * the_cib,
const char *
uname,
char **uuid)
421 #define CONTAINER_REMOTE_NODE_XPATH "//" XML_CIB_TAG_NVPAIR \
422 "[@name='" XML_RSC_ATTR_REMOTE_NODE "'][@value='%s']"
424 #define BAREMETAL_REMOTE_NODE_XPATH "//" XML_CIB_TAG_RESOURCE "[@type='remote'][@provider='pacemaker'][@id='%s']"
426 #define ORPHAN_REMOTE_NODE_XPATH \
427 "//" XML_CIB_TAG_STATUS "//" XML_CIB_TAG_STATE \
428 "[@" XML_ATTR_UUID "='%s'][@" XML_NODE_IS_REMOTE "='true']"
430 int len = 128 + strlen(uname);
432 char *xpath_string = calloc(1, len);
435 if (found_remote_node_xpath(the_cib, xpath_string)) {
440 if (found_remote_node_xpath(the_cib, xpath_string)) {
445 if (found_remote_node_xpath(the_cib, xpath_string)) {
453 *uuid = xpath_string;
454 strcpy(*uuid, uname);
463 get_cluster_node_uuid(
cib_t * the_cib,
const char *uname,
char **uuid)
466 xmlNode *a_child = NULL;
467 xmlNode *xml_obj = NULL;
468 xmlNode *fragment = NULL;
469 const char *child_name = NULL;
485 for (a_child = __xml_first_child(xml_obj); a_child != NULL; a_child = __xml_next(a_child)) {
495 child_name =
ID(a_child);
496 if (child_name != NULL) {
497 *uuid = strdup(child_name);
517 if (is_remote_node) {
518 *is_remote_node = FALSE;
521 rc = get_cluster_node_uuid(the_cib, uname, uuid);
523 crm_debug(
"%s is not a cluster node, checking to see if remote-node", uname);
524 rc = get_remote_node_uuid(the_cib, uname, uuid);
526 crm_debug(
"%s is not a remote node either", uname);
528 }
else if (is_remote_node) {
529 *is_remote_node = TRUE;
536 crm_info(
"Mapped %s to %s", uname, *uuid);
546 xmlNode *a_child = NULL;
547 xmlNode *xml_obj = NULL;
548 xmlNode *fragment = NULL;
549 const char *child_name = NULL;
568 for (a_child = __xml_first_child(xml_obj); a_child != NULL; a_child = __xml_next(a_child)) {
570 child_name =
ID(a_child);
573 if (child_name != NULL) {
574 *uname = strdup(child_name);
587 set_standby(
cib_t * the_cib,
const char *uuid,
const char *scope,
const char *standby_value)
590 char *attr_id = NULL;
593 CRM_CHECK(standby_value != NULL,
return -EINVAL);
605 attr_id,
"standby", standby_value, TRUE, NULL, NULL);
int(* query)(cib_t *cib, const char *section, xmlNode **output_data, int call_options)
#define CRM_CHECK(expr, failure_action)
int read_attr_delegate(cib_t *the_cib, const char *section, const char *node_uuid, const char *set_type, const char *set_name, const char *attr_id, const char *attr_name, char **attr_value, gboolean to_console, const char *user_name)
gboolean safe_str_neq(const char *a, const char *b)
const char * pcmk_strerror(int rc)
int set_standby(cib_t *the_cib, const char *uuid, const char *scope, const char *standby_value)
int update_attr_delegate(cib_t *the_cib, int call_options, const char *section, const char *node_uuid, const char *set_type, const char *set_name, const char *attr_id, const char *attr_name, const char *attr_value, gboolean to_console, const char *user_name, const char *node_type)
int delete_attr_delegate(cib_t *the_cib, int options, const char *section, const char *node_uuid, const char *set_type, const char *set_name, const char *attr_id, const char *attr_name, const char *attr_value, gboolean to_console, const char *user_name)
#define XML_TAG_TRANSIENT_NODEATTRS
const char * get_object_path(const char *object_type)
#define XML_NVPAIR_ATTR_NAME
#define ORPHAN_REMOTE_NODE_XPATH
#define CRM_LOG_ASSERT(expr)
#define attr_snprintf(_str, _offset, _limit,...)
#define XML_CIB_TAG_NVPAIR
#define XML_CIB_TAG_NODES
int find_nvpair_attr_delegate(cib_t *the_cib, const char *attr, const char *section, const char *node_uuid, const char *attr_set_type, const char *set_name, const char *attr_id, const char *attr_name, gboolean to_console, char **value, const char *user_name)
#define XML_CIB_TAG_PROPSET
#define XML_TAG_ATTR_SETS
gboolean is_remote_node(node_t *node)
cib_api_operations_t * cmds
#define crm_debug(fmt, args...)
#define XML_CIB_TAG_STATE
#define crm_trace(fmt, args...)
#define crm_log_xml_debug(xml, text)
#define XML_TAG_META_SETS
Wrappers for and extensions to libxml2.
xmlNode * create_xml_node(xmlNode *parent, const char *name)
const char * crm_element_value(xmlNode *data, const char *name)
int query_node_uuid(cib_t *the_cib, const char *uname, char **uuid, int *is_remote_node)
#define CIB_OPTIONS_FIRST
void free_xml(xmlNode *child)
gboolean xml_has_children(const xmlNode *root)
gboolean crm_str_eq(const char *a, const char *b, gboolean use_case)
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
#define BAREMETAL_REMOTE_NODE_XPATH
#define XML_CIB_TAG_CRMCONFIG
#define XML_CIB_TAG_RSCCONFIG
#define crm_log_xml_info(xml, text)
#define XML_NVPAIR_ATTR_VALUE
#define attr_msg(level, fmt, args...)
#define XML_CIB_TAG_STATUS
#define crm_log_xml_trace(xml, text)
char * crm_concat(const char *prefix, const char *suffix, char join)
int cib_internal_op(cib_t *cib, const char *op, const char *host, const char *section, xmlNode *data, xmlNode **output_data, int call_options, const char *user_name)
#define safe_str_eq(a, b)
int query_node_uname(cib_t *the_cib, const char *uuid, char **uname)
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
#define XML_CIB_TAG_OPCONFIG
#define XML_CIB_TAG_TICKETS
#define crm_info(fmt, args...)
#define CONTAINER_REMOTE_NODE_XPATH