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 if (xpath_string == NULL) {
97 crm_perror(LOG_CRIT,
"Could not create xpath");
104 attr_snprintf(xpath_string, offset, xpath_max,
"//%s", node_type);
106 }
else if (node_uuid) {
113 attr_snprintf(xpath_string, offset, xpath_max,
"//%s[@id='%s']", node_type,
118 attr_snprintf(xpath_string, offset, xpath_max,
"//%s[@id='%.128s']", set_type,
121 attr_snprintf(xpath_string, offset, xpath_max,
"//%s", set_type);
126 attr_snprintf(xpath_string, offset, xpath_max,
"@id='%s'", attr_id);
133 attr_snprintf(xpath_string, offset, xpath_max,
"@name='%.128s'", attr_name);
142 crm_trace(
"Query failed for attribute %s (section=%s, node=%s, set=%s, xpath=%s): %s",
143 attr_name, section,
crm_str(node_uuid),
crm_str(set_name), xpath_string,
150 xmlNode *child = NULL;
153 attr_msg(LOG_WARNING,
"Multiple attributes match name=%s", attr_name);
155 for (child = __xml_first_child(xml_search); child != NULL; child = __xml_next(child)) {
156 attr_msg(LOG_INFO,
" Value: %s \t(id=%s)",
164 *value = strdup(tmp);
176 const char *section,
const char *node_uuid,
const char *set_type,
177 const char *set_name,
const char *attr_id,
const char *attr_name,
178 const char *attr_value, gboolean to_console,
const char *user_name,
181 const char *tag = NULL;
183 xmlNode *xml_top = NULL;
184 xmlNode *xml_obj = NULL;
186 char *local_attr_id = NULL;
187 char *local_set_name = NULL;
189 CRM_CHECK(section != NULL,
return -EINVAL);
190 CRM_CHECK(attr_value != NULL,
return -EINVAL);
191 CRM_CHECK(attr_name != NULL || attr_id != NULL,
return -EINVAL);
194 attr_id, attr_name, to_console, &local_attr_id, user_name);
196 attr_id = local_attr_id;
199 }
else if (rc != -ENXIO) {
206 crm_trace(
"%s does not exist, create it", attr_name);
217 if (node_uuid == NULL) {
233 if (node_uuid == NULL) {
246 if (set_name == NULL) {
253 }
else if (node_uuid) {
254 local_set_name =
crm_concat(section, node_uuid,
'-');
257 char *tmp_set_name = local_set_name;
259 local_set_name =
crm_concat(tmp_set_name, set_type,
'-');
263 local_set_name =
crm_concat(section,
"options",
'-');
265 set_name = local_set_name;
268 if (attr_id == NULL) {
271 local_attr_id =
crm_concat(set_name, attr_name,
'-');
272 attr_id = local_attr_id;
275 for (lpc = 0; local_attr_id[lpc] != 0; lpc++) {
276 switch (local_attr_id[lpc]) {
278 local_attr_id[lpc] =
'.';
282 }
else if (attr_name == NULL) {
286 crm_trace(
"Creating %s/%s", section, tag);
290 if (xml_top == NULL) {
302 }
else if (set_type) {
310 if (xml_top == NULL) {
317 if (xml_top == NULL) {
330 attr_msg(LOG_ERR,
"Error setting %s=%s (section=%s, set=%s): %s",
335 free(local_set_name);
344 const char *section,
const char *node_uuid,
const char *set_type,
345 const char *set_name,
const char *attr_id,
const char *attr_name,
346 char **attr_value, gboolean to_console,
const char *user_name)
351 CRM_CHECK(section != NULL,
return -EINVAL);
352 CRM_CHECK(attr_name != NULL || attr_id != NULL,
return -EINVAL);
357 set_name, attr_id, attr_name, to_console, attr_value, user_name);
359 crm_trace(
"Query failed for attribute %s (section=%s, node=%s, set=%s): %s",
367 const char *section,
const char *node_uuid,
const char *set_type,
368 const char *set_name,
const char *attr_id,
const char *attr_name,
369 const char *attr_value, gboolean to_console,
const char *user_name)
372 xmlNode *xml_obj = NULL;
373 char *local_attr_id = NULL;
375 CRM_CHECK(section != NULL,
return -EINVAL);
376 CRM_CHECK(attr_name != NULL || attr_id != NULL,
return -EINVAL);
378 if (attr_id == NULL) {
380 set_name, attr_id, attr_name, to_console, &local_attr_id,
385 attr_id = local_attr_id;
397 attr_msg(LOG_DEBUG,
"Deleted %s %s: id=%s%s%s%s%s\n",
398 section, node_uuid ?
"attribute" :
"option", local_attr_id,
399 set_name ?
" set=" :
"", set_name ? set_name :
"",
400 attr_name ?
" name=" :
"", attr_name ? attr_name :
"");
409 found_remote_node_xpath(
cib_t *the_cib,
const char *xpath)
412 xmlNode *xml_search = NULL;
418 return rc ==
pcmk_ok ? TRUE : FALSE;
422 get_remote_node_uuid(
cib_t * the_cib,
const char *
uname,
char **uuid)
424 #define CONTAINER_REMOTE_NODE_XPATH "//" XML_CIB_TAG_NVPAIR \ 425 "[@name='" XML_RSC_ATTR_REMOTE_NODE "'][@value='%s']" 427 #define BAREMETAL_REMOTE_NODE_XPATH "//" XML_CIB_TAG_RESOURCE "[@type='remote'][@provider='pacemaker'][@id='%s']" 429 #define ORPHAN_REMOTE_NODE_XPATH \ 430 "//" XML_CIB_TAG_STATUS "//" XML_CIB_TAG_STATE \ 431 "[@" XML_ATTR_UUID "='%s'][@" XML_NODE_IS_REMOTE "='true']" 433 int len = 128 + strlen(
uname);
435 char *xpath_string = calloc(1, len);
438 if (found_remote_node_xpath(the_cib, xpath_string)) {
443 if (found_remote_node_xpath(the_cib, xpath_string)) {
448 if (found_remote_node_xpath(the_cib, xpath_string)) {
456 *uuid = xpath_string;
457 strcpy(*uuid,
uname);
466 get_cluster_node_uuid(
cib_t * the_cib,
const char *
uname,
char **uuid)
469 xmlNode *a_child = NULL;
470 xmlNode *xml_obj = NULL;
471 xmlNode *fragment = NULL;
472 const char *child_name = NULL;
488 for (a_child = __xml_first_child(xml_obj); a_child != NULL; a_child = __xml_next(a_child)) {
498 child_name =
ID(a_child);
499 if (child_name != NULL) {
500 *uuid = strdup(child_name);
520 if (is_remote_node) {
521 *is_remote_node = FALSE;
524 rc = get_cluster_node_uuid(the_cib, uname, uuid);
526 crm_debug(
"%s is not a cluster node, checking to see if remote-node", uname);
527 rc = get_remote_node_uuid(the_cib, uname, uuid);
529 crm_debug(
"%s is not a remote node either", uname);
531 }
else if (is_remote_node) {
532 *is_remote_node = TRUE;
539 crm_info(
"Mapped %s to %s", uname, *uuid);
549 xmlNode *a_child = NULL;
550 xmlNode *xml_obj = NULL;
551 xmlNode *fragment = NULL;
552 const char *child_name = NULL;
571 for (a_child = __xml_first_child(xml_obj); a_child != NULL; a_child = __xml_next(a_child)) {
573 child_name =
ID(a_child);
576 if (child_name != NULL) {
577 *uname = strdup(child_name);
590 set_standby(
cib_t * the_cib,
const char *uuid,
const char *scope,
const char *standby_value)
593 char *attr_id = NULL;
596 CRM_CHECK(standby_value != NULL,
return -EINVAL);
608 attr_id,
"standby", standby_value, TRUE, NULL, NULL);
#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)
int(* query)(cib_t *cib, const char *section, xmlNode **output_data, int call_options)
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 crm_perror(level, fmt, args...)
Log a system error message.
#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