 |
pacemaker
2.0.1-9e909a5bdd
Scalable High-Availability cluster resource manager
|
Go to the documentation of this file.
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;
474 #define XPATH_UPPER_TRANS "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
475 #define XPATH_LOWER_TRANS "abcdefghijklmnopqrstuvwxyz"
477 "/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_NODES \
478 "/" XML_CIB_TAG_NODE "[translate(@" XML_ATTR_UNAME ",'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']" \
479 "|/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_RESOURCES \
480 "/" XML_CIB_TAG_RESOURCE \
481 "[@class='ocf'][@provider='pacemaker'][@type='remote'][translate(@id,'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']" \
482 "|/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_RESOURCES \
483 "/" XML_CIB_TAG_RESOURCE "/" XML_TAG_META_SETS "/" XML_CIB_TAG_NVPAIR \
484 "[@name='" XML_RSC_ATTR_REMOTE_NODE "'][translate(@value,'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']" \
485 "|/" XML_TAG_CIB "/" XML_CIB_TAG_STATUS "/" XML_CIB_TAG_STATE \
486 "[@" XML_NODE_IS_REMOTE "='true'][translate(@" XML_ATTR_UUID ",'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']"
493 xmlNode *xml_search = NULL;
494 char *host_lowercase = g_ascii_strdown(
uname, -1);
515 free(host_lowercase);
518 crm_debug(
"Could not map node name '%s' to a UUID: %s",
521 crm_info(
"Mapped node name '%s' to UUID %s",
uname, (uuid? *uuid :
""));
530 xmlNode *a_child = NULL;
531 xmlNode *xml_obj = NULL;
532 xmlNode *fragment = NULL;
533 const char *child_name = NULL;
552 for (a_child = __xml_first_child(xml_obj); a_child != NULL; a_child = __xml_next(a_child)) {
554 child_name =
ID(a_child);
557 if (child_name != NULL) {
558 *
uname = strdup(child_name);
571 set_standby(
cib_t * the_cib,
const char *uuid,
const char *scope,
const char *standby_value)
574 char *attr_id = NULL;
577 CRM_CHECK(standby_value != NULL,
return -EINVAL);
589 attr_id,
"standby", standby_value, TRUE, NULL, NULL);
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 crm_str_eq(const char *a, const char *b, gboolean use_case)
cib_api_operations_t * cmds
#define XML_CIB_TAG_TICKETS
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)
xmlNode * create_xml_node(xmlNode *parent, const char *name)
#define XML_CIB_TAG_STATE
#define XML_CIB_TAG_OPCONFIG
const char * pcmk_strerror(int rc)
#define CRM_CHECK(expr, failure_action)
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)
int set_standby(cib_t *the_cib, const char *uuid, const char *scope, const char *standby_value)
#define crm_trace(fmt, args...)
#define safe_str_eq(a, b)
#define XML_NVPAIR_ATTR_VALUE
#define XML_TAG_ATTR_SETS
void free_xml(xmlNode *child)
#define XML_TAG_TRANSIENT_NODEATTRS
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_RSCCONFIG
Wrappers for and extensions to libxml2.
gboolean crm_is_true(const char *s)
gboolean xml_has_children(const xmlNode *root)
#define XML_CIB_TAG_STATUS
#define XML_CIB_TAG_RESOURCE
gboolean is_remote_node(node_t *node)
#define XML_CIB_TAG_NODES
#define XML_NODE_IS_REMOTE
#define attr_snprintf(_str, _offset, _limit,...)
#define crm_info(fmt, args...)
#define CRM_LOG_ASSERT(expr)
#define XML_CIB_TAG_PROPSET
xmlNode * crm_create_nvpair_xml(xmlNode *parent, const char *id, const char *name, const char *value)
Create an XML name/value pair.
#define CIB_OPTIONS_FIRST
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
#define crm_debug(fmt, args...)
const char * get_object_path(const char *object_type)
int query_node_uname(cib_t *the_cib, const char *uuid, char **uname)
#define crm_log_xml_trace(xml, text)
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
#define crm_log_xml_info(xml, text)
int(* query)(cib_t *cib, const char *section, xmlNode **output_data, int call_options)
#define XML_TAG_META_SETS
#define crm_log_xml_debug(xml, text)
#define XML_CIB_TAG_CRMCONFIG
#define crm_perror(level, fmt, args...)
Log a system error message.
gboolean safe_str_neq(const char *a, const char *b)
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_uuid(cib_t *the_cib, const char *uname, char **uuid, int *is_remote_node)
#define XML_CIB_TAG_NVPAIR
void crm_xml_sanitize_id(char *id)
Sanitize a string so it is usable as an XML ID.
#define attr_msg(level, fmt, args...)