12 #include <sys/param.h>
17 #include <sys/types.h>
29 #define attr_msg(level, fmt, args...) do { \
31 printf(fmt"\n", ##args); \
33 do_crm_log(level, fmt , ##args); \
38 #define attr_snprintf(_str, _offset, _limit, ...) do { \
39 _offset += snprintf(_str + _offset, \
40 (_limit > _offset) ? _limit - _offset : 0, \
44 #define XPATH_MAX 1024
48 const char *node_uuid,
const char *attr_set_type,
const char *set_name,
49 const char *attr_id,
const char *attr_name, gboolean to_console,
50 char **value,
const char *user_name)
55 char *xpath_string = NULL;
56 xmlNode *xml_search = NULL;
57 const char *set_type = NULL;
61 set_type = attr_set_type;
83 }
else if (node_uuid == NULL) {
88 if (xpath_string == NULL) {
89 crm_perror(LOG_CRIT,
"Could not create xpath");
98 }
else if (node_uuid) {
134 crm_trace(
"Query failed for attribute %s (section=%s, node=%s, set=%s, xpath=%s): %s",
135 attr_name, section,
crm_str(node_uuid),
crm_str(set_name), xpath_string,
142 xmlNode *child = NULL;
145 attr_msg(LOG_WARNING,
"Multiple attributes match name=%s", attr_name);
147 for (child = __xml_first_child(xml_search); child != NULL; child = __xml_next(child)) {
148 attr_msg(LOG_INFO,
" Value: %s \t(id=%s)",
156 *value = strdup(tmp);
168 const char *section,
const char *node_uuid,
const char *set_type,
169 const char *set_name,
const char *attr_id,
const char *attr_name,
170 const char *attr_value, gboolean to_console,
const char *user_name,
173 const char *tag = NULL;
175 xmlNode *xml_top = NULL;
176 xmlNode *xml_obj = NULL;
178 char *local_attr_id = NULL;
179 char *local_set_name = NULL;
181 CRM_CHECK(section != NULL,
return -EINVAL);
182 CRM_CHECK(attr_value != NULL,
return -EINVAL);
183 CRM_CHECK(attr_name != NULL || attr_id != NULL,
return -EINVAL);
186 attr_id, attr_name, to_console, &local_attr_id, user_name);
188 attr_id = local_attr_id;
191 }
else if (rc != -ENXIO) {
198 crm_trace(
"%s does not exist, create it", attr_name);
209 if (node_uuid == NULL) {
225 if (node_uuid == NULL) {
238 if (set_name == NULL) {
246 }
else if (node_uuid) {
250 char *tmp_set_name = local_set_name;
259 set_name = local_set_name;
262 if (attr_id == NULL) {
265 attr_id = local_attr_id;
267 }
else if (attr_name == NULL) {
271 crm_trace(
"Creating %s/%s", section, tag);
275 if (xml_top == NULL) {
287 }
else if (set_type) {
295 if (xml_top == NULL) {
302 if (xml_top == NULL) {
311 attr_msg(LOG_ERR,
"Error setting %s=%s (section=%s, set=%s): %s",
316 free(local_set_name);
325 const char *section,
const char *node_uuid,
const char *set_type,
326 const char *set_name,
const char *attr_id,
const char *attr_name,
327 char **attr_value, gboolean to_console,
const char *user_name)
332 CRM_CHECK(section != NULL,
return -EINVAL);
333 CRM_CHECK(attr_name != NULL || attr_id != NULL,
return -EINVAL);
338 set_name, attr_id, attr_name, to_console, attr_value, user_name);
340 crm_trace(
"Query failed for attribute %s (section=%s, node=%s, set=%s): %s",
348 const char *section,
const char *node_uuid,
const char *set_type,
349 const char *set_name,
const char *attr_id,
const char *attr_name,
350 const char *attr_value, gboolean to_console,
const char *user_name)
353 xmlNode *xml_obj = NULL;
354 char *local_attr_id = NULL;
356 CRM_CHECK(section != NULL,
return -EINVAL);
357 CRM_CHECK(attr_name != NULL || attr_id != NULL,
return -EINVAL);
359 if (attr_id == NULL) {
361 set_name, attr_id, attr_name, to_console, &local_attr_id,
366 attr_id = local_attr_id;
375 attr_msg(LOG_DEBUG,
"Deleted %s %s: id=%s%s%s%s%s\n",
376 section, node_uuid ?
"attribute" :
"option", local_attr_id,
377 set_name ?
" set=" :
"", set_name ? set_name :
"",
378 attr_name ?
" name=" :
"", attr_name ? attr_name :
"");
397 get_uuid_from_result(xmlNode *result,
char **uuid,
int *is_remote)
401 const char *parsed_uuid = NULL;
402 int parsed_is_remote = FALSE;
404 if (result == NULL) {
409 tag = (
const char *) (result->name);
411 result = __xml_first_child(result);
413 tag = (
const char *) (result->name);
421 parsed_is_remote = TRUE;
423 parsed_uuid =
ID(result);
424 parsed_is_remote = FALSE;
430 parsed_uuid =
ID(result);
431 parsed_is_remote = TRUE;
437 parsed_is_remote = TRUE;
444 parsed_is_remote = TRUE;
450 *uuid = strdup(parsed_uuid);
453 *is_remote = parsed_is_remote;
467 #define XPATH_UPPER_TRANS "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
468 #define XPATH_LOWER_TRANS "abcdefghijklmnopqrstuvwxyz"
470 "/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_NODES \
471 "/" XML_CIB_TAG_NODE "[translate(@" XML_ATTR_UNAME ",'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']" \
472 "|/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_RESOURCES \
473 "/" XML_CIB_TAG_RESOURCE \
474 "[@class='ocf'][@provider='pacemaker'][@type='remote'][translate(@id,'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']" \
475 "|/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_RESOURCES \
476 "/" XML_CIB_TAG_RESOURCE "/" XML_TAG_META_SETS "/" XML_CIB_TAG_NVPAIR \
477 "[@name='" XML_RSC_ATTR_REMOTE_NODE "'][translate(@value,'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']" \
478 "|/" XML_TAG_CIB "/" XML_CIB_TAG_STATUS "/" XML_CIB_TAG_STATE \
479 "[@" XML_NODE_IS_REMOTE "='true'][translate(@" XML_ATTR_UUID ",'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']"
486 xmlNode *xml_search = NULL;
487 char *host_lowercase = g_ascii_strdown(uname, -1);
494 if (is_remote_node) {
495 *is_remote_node = FALSE;
502 rc = get_uuid_from_result(xml_search, uuid, is_remote_node);
508 g_free(host_lowercase);
511 crm_debug(
"Could not map node name '%s' to a UUID: %s",
514 crm_info(
"Mapped node name '%s' to UUID %s", uname, (uuid? *uuid :
""));
523 xmlNode *a_child = NULL;
524 xmlNode *xml_obj = NULL;
525 xmlNode *fragment = NULL;
526 const char *child_name = NULL;
545 for (a_child = __xml_first_child(xml_obj); a_child != NULL; a_child = __xml_next(a_child)) {
547 child_name =
ID(a_child);
550 if (child_name != NULL) {
551 *uname = strdup(child_name);
564 set_standby(
cib_t * the_cib,
const char *uuid,
const char *scope,
const char *standby_value)
567 char *attr_id = NULL;
570 CRM_CHECK(standby_value != NULL,
return -EINVAL);
582 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)
const char * pcmk_strerror(int rc)
gboolean safe_str_neq(const char *a, const char *b)
#define XML_TAG_TRANSIENT_NODEATTRS
const char * get_object_path(const char *object_type)
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
int query_node_uuid(cib_t *the_cib, const char *uname, char **uuid, int *is_remote_node)
int set_standby(cib_t *the_cib, const char *uuid, const char *scope, const char *standby_value)
#define CRM_LOG_ASSERT(expr)
#define attr_snprintf(_str, _offset, _limit,...)
#define XML_CIB_TAG_NVPAIR
#define XML_CIB_TAG_NODES
void crm_xml_sanitize_id(char *id)
Sanitize a string so it is usable as an XML ID.
#define XML_CIB_TAG_PROPSET
#define XML_TAG_ATTR_SETS
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)
int find_nvpair_attr_delegate(cib_t *the_cib, const char *attr, const char *section, const char *node_uuid, const char *set_type, const char *set_name, const char *attr_id, const char *attr_name, gboolean to_console, char **value, const char *user_name)
cib_api_operations_t * cmds
#define crm_debug(fmt, args...)
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
#define XML_CIB_TAG_RESOURCE
#define XML_CIB_TAG_STATE
int query_node_uname(cib_t *the_cib, const char *uuid, char **uname)
#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)
#define XML_NODE_IS_REMOTE
#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)
#define crm_perror(level, fmt, args...)
Send a system error message to both the log and stderr.
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_CIB_TAG_CRMCONFIG
#define XML_CIB_TAG_RSCCONFIG
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)
#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)
gboolean crm_is_true(const char *s)
xmlNode * crm_create_nvpair_xml(xmlNode *parent, const char *id, const char *name, const char *value)
Create an XML name/value pair.
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)
#define XML_CIB_TAG_OPCONFIG
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
#define XML_CIB_TAG_TICKETS
#define crm_info(fmt, args...)