12 #include <sys/param.h> 17 #include <sys/types.h> 30 #define attr_msg(level, fmt, args...) do { \ 32 printf(fmt"\n", ##args); \ 34 do_crm_log(level, fmt , ##args); \ 39 #define attr_snprintf(_str, _offset, _limit, ...) do { \ 40 _offset += snprintf(_str + _offset, \ 41 (_limit > _offset) ? _limit - _offset : 0, \ 45 #define XPATH_MAX 1024 49 const char *node_uuid,
const char *attr_set_type,
const char *set_name,
50 const char *attr_id,
const char *attr_name, gboolean to_console,
51 char **value,
const char *user_name)
56 char *xpath_string = NULL;
57 xmlNode *xml_search = NULL;
58 const char *set_type = NULL;
62 set_type = attr_set_type;
84 }
else if (node_uuid == NULL) {
89 if (xpath_string == NULL) {
90 crm_perror(LOG_CRIT,
"Could not create xpath");
99 }
else if (node_uuid) {
135 crm_trace(
"Query failed for attribute %s (section=%s, node=%s, set=%s, xpath=%s): %s",
136 attr_name, section,
crm_str(node_uuid),
crm_str(set_name), xpath_string,
143 xmlNode *child = NULL;
146 attr_msg(LOG_WARNING,
"Multiple attributes match name=%s", attr_name);
148 for (child = pcmk__xml_first_child(xml_search); child != NULL;
149 child = pcmk__xml_next(child)) {
150 attr_msg(LOG_INFO,
" Value: %s \t(id=%s)",
158 *value = strdup(tmp);
170 const char *section,
const char *node_uuid,
const char *set_type,
171 const char *set_name,
const char *attr_id,
const char *attr_name,
172 const char *attr_value, gboolean to_console,
const char *user_name,
175 const char *tag = NULL;
177 xmlNode *xml_top = NULL;
178 xmlNode *xml_obj = NULL;
180 char *local_attr_id = NULL;
181 char *local_set_name = NULL;
183 CRM_CHECK(section != NULL,
return -EINVAL);
184 CRM_CHECK(attr_value != NULL,
return -EINVAL);
185 CRM_CHECK(attr_name != NULL || attr_id != NULL,
return -EINVAL);
188 attr_id, attr_name, to_console, &local_attr_id, user_name);
190 attr_id = local_attr_id;
193 }
else if (
rc != -ENXIO) {
200 crm_trace(
"%s does not exist, create it", attr_name);
211 if (node_uuid == NULL) {
227 if (node_uuid == NULL) {
240 if (set_name == NULL) {
248 }
else if (node_uuid) {
252 char *tmp_set_name = local_set_name;
261 set_name = local_set_name;
264 if (attr_id == NULL) {
267 attr_id = local_attr_id;
269 }
else if (attr_name == NULL) {
273 crm_trace(
"Creating %s/%s", section, tag);
277 if (xml_top == NULL) {
289 }
else if (set_type) {
297 if (xml_top == NULL) {
304 if (xml_top == NULL) {
313 attr_msg(LOG_ERR,
"Error setting %s=%s (section=%s, set=%s): %s",
318 free(local_set_name);
327 const char *section,
const char *node_uuid,
const char *set_type,
328 const char *set_name,
const char *attr_id,
const char *attr_name,
329 char **attr_value, gboolean to_console,
const char *user_name)
334 CRM_CHECK(section != NULL,
return -EINVAL);
335 CRM_CHECK(attr_name != NULL || attr_id != NULL,
return -EINVAL);
340 set_name, attr_id, attr_name, to_console, attr_value, user_name);
342 crm_trace(
"Query failed for attribute %s (section=%s, node=%s, set=%s): %s",
350 const char *section,
const char *node_uuid,
const char *set_type,
351 const char *set_name,
const char *attr_id,
const char *attr_name,
352 const char *attr_value, gboolean to_console,
const char *user_name)
355 xmlNode *xml_obj = NULL;
356 char *local_attr_id = NULL;
358 CRM_CHECK(section != NULL,
return -EINVAL);
359 CRM_CHECK(attr_name != NULL || attr_id != NULL,
return -EINVAL);
361 if (attr_id == NULL) {
363 set_name, attr_id, attr_name, to_console, &local_attr_id,
368 attr_id = local_attr_id;
377 attr_msg(LOG_DEBUG,
"Deleted %s %s: id=%s%s%s%s%s\n",
378 section, node_uuid ?
"attribute" :
"option", local_attr_id,
379 set_name ?
" set=" :
"", set_name ? set_name :
"",
380 attr_name ?
" name=" :
"", attr_name ? attr_name :
"");
399 get_uuid_from_result(xmlNode *result,
char **uuid,
int *is_remote)
403 const char *parsed_uuid = NULL;
404 int parsed_is_remote = FALSE;
406 if (result == NULL) {
411 tag = (
const char *) (result->name);
413 result = pcmk__xml_first_child(result);
415 tag = (
const char *) (result->name);
423 parsed_is_remote = TRUE;
425 parsed_uuid =
ID(result);
426 parsed_is_remote = FALSE;
432 parsed_uuid =
ID(result);
433 parsed_is_remote = TRUE;
439 parsed_is_remote = TRUE;
446 parsed_is_remote = TRUE;
452 *uuid = strdup(parsed_uuid);
455 *is_remote = parsed_is_remote;
469 #define XPATH_UPPER_TRANS "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 470 #define XPATH_LOWER_TRANS "abcdefghijklmnopqrstuvwxyz" 472 "/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_NODES \ 473 "/" XML_CIB_TAG_NODE "[translate(@" XML_ATTR_UNAME ",'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']" \ 474 "|/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_RESOURCES \ 475 "/" XML_CIB_TAG_RESOURCE \ 476 "[@class='ocf'][@provider='pacemaker'][@type='remote'][translate(@id,'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']" \ 477 "|/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_RESOURCES \ 478 "/" XML_CIB_TAG_RESOURCE "/" XML_TAG_META_SETS "/" XML_CIB_TAG_NVPAIR \ 479 "[@name='" XML_RSC_ATTR_REMOTE_NODE "'][translate(@value,'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']" \ 480 "|/" XML_TAG_CIB "/" XML_CIB_TAG_STATUS "/" XML_CIB_TAG_STATE \ 481 "[@" XML_NODE_IS_REMOTE "='true'][translate(@" XML_ATTR_UUID ",'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']" 488 xmlNode *xml_search = NULL;
489 char *host_lowercase = g_ascii_strdown(
uname, -1);
496 if (is_remote_node) {
497 *is_remote_node = FALSE;
504 rc = get_uuid_from_result(xml_search, uuid, is_remote_node);
510 g_free(host_lowercase);
513 crm_debug(
"Could not map node name '%s' to a UUID: %s",
516 crm_info(
"Mapped node name '%s' to UUID %s",
uname, (uuid? *uuid :
""));
525 xmlNode *a_child = NULL;
526 xmlNode *xml_obj = NULL;
527 xmlNode *fragment = NULL;
528 const char *child_name = NULL;
548 for (a_child = pcmk__xml_first_child(xml_obj); a_child != NULL;
549 a_child = pcmk__xml_next(a_child)) {
553 child_name =
ID(a_child);
556 if (child_name != NULL) {
557 *
uname = strdup(child_name);
570 set_standby(
cib_t * the_cib,
const char *uuid,
const char *scope,
const char *standby_value)
573 char *attr_id = NULL;
576 CRM_CHECK(standby_value != NULL,
return -EINVAL);
588 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)
const char * pcmk_strerror(int rc)
bool pcmk__strcase_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
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)
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
#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)
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
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
#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)
int query_node_uuid(cib_t *the_cib, const char *uname, char **uuid, int *is_remote_node)
#define XML_NODE_IS_REMOTE
#define CIB_OPTIONS_FIRST
void free_xml(xmlNode *child)
gboolean xml_has_children(const xmlNode *root)
#define crm_perror(level, fmt, args...)
Send a system error message to both the log and stderr.
#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)
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)
int query_node_uname(cib_t *the_cib, const char *uuid, char **uname)
#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...)