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, \
53 #define XPATH_MAX 1024
57 const char *node_uuid,
const char *attr_set_type,
const char *set_name,
58 const char *attr_id,
const char *attr_name, gboolean to_console,
59 char **value,
const char *user_name)
64 char *xpath_string = NULL;
65 xmlNode *xml_search = NULL;
66 const char *set_type = NULL;
70 set_type = attr_set_type;
92 }
else if (node_uuid == NULL) {
97 if (xpath_string == NULL) {
98 crm_perror(LOG_CRIT,
"Could not create xpath");
107 }
else if (node_uuid) {
143 crm_trace(
"Query failed for attribute %s (section=%s, node=%s, set=%s, xpath=%s): %s",
144 attr_name, section,
crm_str(node_uuid),
crm_str(set_name), xpath_string,
151 xmlNode *child = NULL;
154 attr_msg(LOG_WARNING,
"Multiple attributes match name=%s", attr_name);
156 for (child = __xml_first_child(xml_search); child != NULL; child = __xml_next(child)) {
157 attr_msg(LOG_INFO,
" Value: %s \t(id=%s)",
165 *value = strdup(tmp);
177 const char *section,
const char *node_uuid,
const char *set_type,
178 const char *set_name,
const char *attr_id,
const char *attr_name,
179 const char *attr_value, gboolean to_console,
const char *user_name,
182 const char *tag = NULL;
184 xmlNode *xml_top = NULL;
185 xmlNode *xml_obj = NULL;
187 char *local_attr_id = NULL;
188 char *local_set_name = NULL;
190 CRM_CHECK(section != NULL,
return -EINVAL);
191 CRM_CHECK(attr_value != NULL,
return -EINVAL);
192 CRM_CHECK(attr_name != NULL || attr_id != NULL,
return -EINVAL);
195 attr_id, attr_name, to_console, &local_attr_id, user_name);
197 attr_id = local_attr_id;
200 }
else if (rc != -ENXIO) {
207 crm_trace(
"%s does not exist, create it", attr_name);
218 if (node_uuid == NULL) {
234 if (node_uuid == NULL) {
247 if (set_name == NULL) {
254 }
else if (node_uuid) {
255 local_set_name =
crm_concat(section, node_uuid,
'-');
258 char *tmp_set_name = local_set_name;
260 local_set_name =
crm_concat(tmp_set_name, set_type,
'-');
264 local_set_name =
crm_concat(section,
"options",
'-');
266 set_name = local_set_name;
269 if (attr_id == NULL) {
270 local_attr_id =
crm_concat(set_name, attr_name,
'-');
272 attr_id = local_attr_id;
274 }
else if (attr_name == NULL) {
278 crm_trace(
"Creating %s/%s", section, tag);
282 if (xml_top == NULL) {
294 }
else if (set_type) {
302 if (xml_top == NULL) {
309 if (xml_top == NULL) {
318 attr_msg(LOG_ERR,
"Error setting %s=%s (section=%s, set=%s): %s",
323 free(local_set_name);
332 const char *section,
const char *node_uuid,
const char *set_type,
333 const char *set_name,
const char *attr_id,
const char *attr_name,
334 char **attr_value, gboolean to_console,
const char *user_name)
339 CRM_CHECK(section != NULL,
return -EINVAL);
340 CRM_CHECK(attr_name != NULL || attr_id != NULL,
return -EINVAL);
345 set_name, attr_id, attr_name, to_console, attr_value, user_name);
347 crm_trace(
"Query failed for attribute %s (section=%s, node=%s, set=%s): %s",
355 const char *section,
const char *node_uuid,
const char *set_type,
356 const char *set_name,
const char *attr_id,
const char *attr_name,
357 const char *attr_value, gboolean to_console,
const char *user_name)
360 xmlNode *xml_obj = NULL;
361 char *local_attr_id = NULL;
363 CRM_CHECK(section != NULL,
return -EINVAL);
364 CRM_CHECK(attr_name != NULL || attr_id != NULL,
return -EINVAL);
366 if (attr_id == NULL) {
368 set_name, attr_id, attr_name, to_console, &local_attr_id,
373 attr_id = local_attr_id;
382 attr_msg(LOG_DEBUG,
"Deleted %s %s: id=%s%s%s%s%s\n",
383 section, node_uuid ?
"attribute" :
"option", local_attr_id,
384 set_name ?
" set=" :
"", set_name ? set_name :
"",
385 attr_name ?
" name=" :
"", attr_name ? attr_name :
"");
404 get_uuid_from_result(xmlNode *result,
char **uuid,
int *is_remote)
408 const char *parsed_uuid = NULL;
409 int parsed_is_remote = FALSE;
411 if (result == NULL) {
416 tag = (
const char *) (result->name);
418 result = __xml_first_child(result);
420 tag = (
const char *) (result->name);
428 parsed_is_remote = TRUE;
430 parsed_uuid =
ID(result);
431 parsed_is_remote = FALSE;
437 parsed_uuid =
ID(result);
438 parsed_is_remote = TRUE;
444 parsed_is_remote = TRUE;
451 parsed_is_remote = TRUE;
457 *uuid = strdup(parsed_uuid);
460 *is_remote = parsed_is_remote;
475 "/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_NODES \
476 "/" XML_CIB_TAG_NODE "[@" XML_ATTR_UNAME "='%s']" \
477 "|/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_RESOURCES \
478 "/" XML_CIB_TAG_RESOURCE \
479 "[@class='ocf'][@provider='pacemaker'][@type='remote'][@id='%s']" \
480 "|/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_RESOURCES \
481 "/" XML_CIB_TAG_RESOURCE "/" XML_TAG_META_SETS "/" XML_CIB_TAG_NVPAIR \
482 "[@name='" XML_RSC_ATTR_REMOTE_NODE "'][@value='%s']" \
483 "|/" XML_TAG_CIB "/" XML_CIB_TAG_STATUS "/" XML_CIB_TAG_STATE \
484 "[@" XML_NODE_IS_REMOTE "='true'][@" XML_ATTR_UUID "='%s']"
491 xmlNode *xml_search = NULL;
498 if (is_remote_node) {
499 *is_remote_node = FALSE;
506 rc = get_uuid_from_result(xml_search, uuid, is_remote_node);
514 crm_debug(
"Could not map node name '%s' to a UUID: %s",
517 crm_info(
"Mapped node name '%s' to UUID %s", uname, (uuid? *uuid :
""));
526 xmlNode *a_child = NULL;
527 xmlNode *xml_obj = NULL;
528 xmlNode *fragment = NULL;
529 const char *child_name = NULL;
548 for (a_child = __xml_first_child(xml_obj); a_child != NULL; a_child = __xml_next(a_child)) {
550 child_name =
ID(a_child);
553 if (child_name != NULL) {
554 *uname = strdup(child_name);
567 set_standby(
cib_t * the_cib,
const char *uuid,
const char *scope,
const char *standby_value)
570 char *attr_id = NULL;
573 CRM_CHECK(standby_value != NULL,
return -EINVAL);
585 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)
gboolean safe_str_neq(const char *a, const char *b)
const char * pcmk_strerror(int rc)
#define XML_TAG_TRANSIENT_NODEATTRS
const char * get_object_path(const char *object_type)
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
gboolean is_remote_node(node_t *node)
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...)
#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)
const char * crm_element_value(xmlNode *data, 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)
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
#define crm_perror(level, fmt, args...)
Log a system error message.
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
xmlNode * crm_create_nvpair_xml(xmlNode *parent, const char *id, const char *name, const char *value)
Create an XML name/value pair.
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)
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)
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...)