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) {
269 local_attr_id =
crm_concat(set_name, attr_name,
'-');
271 attr_id = local_attr_id;
273 }
else if (attr_name == NULL) {
277 crm_trace(
"Creating %s/%s", section, tag);
281 if (xml_top == NULL) {
293 }
else if (set_type) {
301 if (xml_top == NULL) {
308 if (xml_top == NULL) {
321 attr_msg(LOG_ERR,
"Error setting %s=%s (section=%s, set=%s): %s",
326 free(local_set_name);
335 const char *section,
const char *node_uuid,
const char *set_type,
336 const char *set_name,
const char *attr_id,
const char *attr_name,
337 char **attr_value, gboolean to_console,
const char *user_name)
342 CRM_CHECK(section != NULL,
return -EINVAL);
343 CRM_CHECK(attr_name != NULL || attr_id != NULL,
return -EINVAL);
348 set_name, attr_id, attr_name, to_console, attr_value, user_name);
350 crm_trace(
"Query failed for attribute %s (section=%s, node=%s, set=%s): %s",
358 const char *section,
const char *node_uuid,
const char *set_type,
359 const char *set_name,
const char *attr_id,
const char *attr_name,
360 const char *attr_value, gboolean to_console,
const char *user_name)
363 xmlNode *xml_obj = NULL;
364 char *local_attr_id = NULL;
366 CRM_CHECK(section != NULL,
return -EINVAL);
367 CRM_CHECK(attr_name != NULL || attr_id != NULL,
return -EINVAL);
369 if (attr_id == NULL) {
371 set_name, attr_id, attr_name, to_console, &local_attr_id,
376 attr_id = local_attr_id;
388 attr_msg(LOG_DEBUG,
"Deleted %s %s: id=%s%s%s%s%s\n",
389 section, node_uuid ?
"attribute" :
"option", local_attr_id,
390 set_name ?
" set=" :
"", set_name ? set_name :
"",
391 attr_name ?
" name=" :
"", attr_name ? attr_name :
"");
410 get_uuid_from_result(xmlNode *result,
char **uuid,
int *is_remote)
414 const char *parsed_uuid = NULL;
415 int parsed_is_remote = FALSE;
417 if (result == NULL) {
422 tag = (
const char *) (result->name);
424 result = __xml_first_child(result);
425 tag = (
const char *) (result->name);
433 parsed_is_remote = TRUE;
435 parsed_uuid =
ID(result);
436 parsed_is_remote = FALSE;
442 parsed_uuid =
ID(result);
443 parsed_is_remote = TRUE;
449 parsed_is_remote = TRUE;
456 parsed_is_remote = TRUE;
462 *uuid = strdup(parsed_uuid);
465 *is_remote = parsed_is_remote;
480 "/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_NODES \ 481 "/" XML_CIB_TAG_NODE "[@" XML_ATTR_UNAME "='%s']" \ 482 "|/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_RESOURCES \ 483 "/" XML_CIB_TAG_RESOURCE \ 484 "[@class='ocf'][@provider='pacemaker'][@type='remote'][@id='%s']" \ 485 "|/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_RESOURCES \ 486 "/" XML_CIB_TAG_RESOURCE "/" XML_TAG_META_SETS "/" XML_CIB_TAG_NVPAIR \ 487 "[@name='" XML_RSC_ATTR_REMOTE_NODE "'][@value='%s']" \ 488 "|/" XML_TAG_CIB "/" XML_CIB_TAG_STATUS "/" XML_CIB_TAG_STATE \ 489 "[@" XML_NODE_IS_REMOTE "='true'][@" XML_ATTR_UUID "='%s']" 496 xmlNode *xml_search = NULL;
503 if (is_remote_node) {
504 *is_remote_node = FALSE;
511 rc = get_uuid_from_result(xml_search, uuid, is_remote_node);
519 crm_debug(
"Could not map node name '%s' to a UUID: %s",
522 crm_info(
"Mapped node name '%s' to UUID %s", uname, (uuid? *uuid :
""));
531 xmlNode *a_child = NULL;
532 xmlNode *xml_obj = NULL;
533 xmlNode *fragment = NULL;
534 const char *child_name = NULL;
553 for (a_child = __xml_first_child(xml_obj); a_child != NULL; a_child = __xml_next(a_child)) {
555 child_name =
ID(a_child);
558 if (child_name != NULL) {
559 *uname = strdup(child_name);
572 set_standby(
cib_t * the_cib,
const char *uuid,
const char *scope,
const char *standby_value)
575 char *attr_id = NULL;
578 CRM_CHECK(standby_value != NULL,
return -EINVAL);
590 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 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
gboolean is_remote_node(node_t *node)
cib_api_operations_t * cmds
#define crm_debug(fmt, args...)
#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)
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 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.
#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)
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...)