12 #include <sys/param.h> 17 #include <sys/types.h> 32 #define attr_snprintf(_str, _offset, _limit, ...) do { \ 33 _offset += snprintf(_str + _offset, \ 34 (_limit > _offset) ? _limit - _offset : 0, \ 38 #define XPATH_MAX 1024 41 new_output_object(
const char *ty)
45 const char* argv[] = {
"", NULL };
64 const char *node_uuid,
const char *attr_set_type,
const char *set_name,
65 const char *attr_id,
const char *attr_name,
char **value,
66 const char *user_name)
71 const char *xpath_base = NULL;
72 char *xpath_string = NULL;
73 xmlNode *xml_search = NULL;
74 const char *set_type = NULL;
78 set_type = attr_set_type;
100 }
else if (node_uuid == NULL) {
105 if (xpath_base == NULL) {
106 crm_warn(
"%s CIB section not known", section);
111 if (xpath_string == NULL) {
112 crm_perror(LOG_CRIT,
"Could not create xpath");
120 }
else if (node_uuid) {
156 crm_trace(
"Query failed for attribute %s (section=%s, node=%s, set=%s, xpath=%s): %s",
157 attr_name, section,
crm_str(node_uuid),
crm_str(set_name), xpath_string,
166 xmlNode *child = NULL;
169 out->
info(out,
"Multiple attributes match name=%s", attr_name);
171 for (child = pcmk__xml_first_child(xml_search); child != NULL;
172 child = pcmk__xml_next(child)) {
173 out->
info(out,
" Value: %s \t(id=%s)",
189 const char *node_uuid,
const char *set_type,
const char *set_name,
190 const char *attr_id,
const char *attr_name,
const char *attr_value,
191 const char *user_name,
const char *
node_type)
193 const char *tag = NULL;
195 xmlNode *xml_top = NULL;
196 xmlNode *xml_obj = NULL;
198 char *local_attr_id = NULL;
199 char *local_set_name = NULL;
201 CRM_CHECK(section != NULL,
return EINVAL);
202 CRM_CHECK(attr_value != NULL,
return EINVAL);
203 CRM_CHECK(attr_name != NULL || attr_id != NULL,
return EINVAL);
205 rc = find_attr(out, cib,
XML_ATTR_ID, section, node_uuid, set_type, set_name,
206 attr_id, attr_name, &local_attr_id, user_name);
208 attr_id = local_attr_id;
211 }
else if (rc != ENXIO) {
218 crm_trace(
"%s does not exist, create it", attr_name);
229 if (node_uuid == NULL) {
245 if (node_uuid == NULL) {
258 if (set_name == NULL) {
266 }
else if (node_uuid) {
270 char *tmp_set_name = local_set_name;
279 set_name = local_set_name;
282 if (attr_id == NULL) {
285 attr_id = local_attr_id;
287 }
else if (attr_name == NULL) {
291 crm_trace(
"Creating %s/%s", section, tag);
295 if (xml_top == NULL) {
307 }
else if (set_type) {
315 if (xml_top == NULL) {
322 if (xml_top == NULL) {
332 out->
err(out,
"Error setting %s=%s (section=%s, set=%s): %s",
339 free(local_set_name);
348 const char *node_uuid,
const char *set_type,
const char *set_name,
349 const char *attr_id,
const char *attr_name,
char **attr_value,
350 const char *user_name)
355 CRM_CHECK(section != NULL,
return EINVAL);
356 CRM_CHECK(attr_name != NULL || attr_id != NULL,
return EINVAL);
361 set_name, attr_id, attr_name, attr_value, user_name);
363 crm_trace(
"Query failed for attribute %s (section=%s, node=%s, set=%s): %s",
372 const char *node_uuid,
const char *set_type,
const char *set_name,
373 const char *attr_id,
const char *attr_name,
const char *attr_value,
374 const char *user_name)
377 xmlNode *xml_obj = NULL;
378 char *local_attr_id = NULL;
380 CRM_CHECK(section != NULL,
return EINVAL);
381 CRM_CHECK(attr_name != NULL || attr_id != NULL,
return EINVAL);
383 if (attr_id == NULL) {
384 rc = find_attr(out, cib,
XML_ATTR_ID, section, node_uuid, set_type,
385 set_name, attr_id, attr_name, &local_attr_id,
390 attr_id = local_attr_id;
401 out->
info(out,
"Deleted %s %s: id=%s%s%s%s%s",
402 section, node_uuid ?
"attribute" :
"option", local_attr_id,
403 set_name ?
" set=" :
"", set_name ? set_name :
"",
404 attr_name ?
" name=" :
"", attr_name ? attr_name :
"");
414 const char *node_uuid,
const char *attr_set_type,
const char *set_name,
415 const char *attr_id,
const char *attr_name, gboolean to_console,
416 char **value,
const char *user_name)
421 out = new_output_object(to_console ?
"text" :
"log");
426 rc = find_attr(out, cib, attr, section, node_uuid, attr_set_type,
427 set_name, attr_id, attr_name, value, user_name);
436 const char *node_uuid,
const char *set_type,
const char *set_name,
437 const char *attr_id,
const char *attr_name,
const char *attr_value,
438 gboolean to_console,
const char *user_name,
const char *
node_type)
443 out = new_output_object(to_console ?
"text" :
"log");
449 set_name, attr_id, attr_name, attr_value, user_name,
459 const char *set_type,
const char *set_name,
const char *attr_id,
460 const char *attr_name,
char **attr_value, gboolean to_console,
461 const char *user_name)
466 out = new_output_object(to_console ?
"text" :
"log");
472 attr_id, attr_name, attr_value, user_name);
481 const char *set_type,
const char *set_name,
const char *attr_id,
482 const char *attr_name,
const char *attr_value, gboolean to_console,
483 const char *user_name)
488 out = new_output_object(to_console ?
"text" :
"log");
494 set_name, attr_id, attr_name, attr_value, user_name);
512 get_uuid_from_result(xmlNode *
result,
char **uuid,
int *is_remote)
516 const char *parsed_uuid = NULL;
517 int parsed_is_remote = FALSE;
524 tag = (
const char *) (
result->name);
528 tag = (
const char *) (
result->name);
536 parsed_is_remote = TRUE;
539 parsed_is_remote = FALSE;
546 parsed_is_remote = TRUE;
552 parsed_is_remote = TRUE;
559 parsed_is_remote = TRUE;
565 *uuid = strdup(parsed_uuid);
568 *is_remote = parsed_is_remote;
582 #define XPATH_UPPER_TRANS "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 583 #define XPATH_LOWER_TRANS "abcdefghijklmnopqrstuvwxyz" 585 "/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_NODES \ 586 "/" XML_CIB_TAG_NODE "[translate(@" XML_ATTR_UNAME ",'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']" \ 587 "|/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_RESOURCES \ 588 "/" XML_CIB_TAG_RESOURCE \ 589 "[@class='ocf'][@provider='pacemaker'][@type='remote'][translate(@id,'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']" \ 590 "|/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_RESOURCES \ 591 "/" XML_CIB_TAG_RESOURCE "/" XML_TAG_META_SETS "/" XML_CIB_TAG_NVPAIR \ 592 "[@name='" XML_RSC_ATTR_REMOTE_NODE "'][translate(@value,'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']" \ 593 "|/" XML_TAG_CIB "/" XML_CIB_TAG_STATUS "/" XML_CIB_TAG_STATE \ 594 "[@" XML_NODE_IS_REMOTE "='true'][translate(@" XML_ATTR_UUID ",'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']" 601 xmlNode *xml_search = NULL;
602 char *host_lowercase = NULL;
606 host_lowercase = g_ascii_strdown(
uname, -1);
611 if (is_remote_node) {
612 *is_remote_node = FALSE;
619 rc = get_uuid_from_result(xml_search, uuid, is_remote_node);
625 g_free(host_lowercase);
628 crm_debug(
"Could not map node name '%s' to a UUID: %s",
631 crm_info(
"Mapped node name '%s' to UUID %s",
uname, (uuid? *uuid :
""));
640 xmlNode *a_child = NULL;
641 xmlNode *xml_obj = NULL;
642 xmlNode *fragment = NULL;
643 const char *child_name = NULL;
663 for (a_child = pcmk__xml_first_child(xml_obj); a_child != NULL;
664 a_child = pcmk__xml_next(a_child)) {
668 child_name =
ID(a_child);
671 if (child_name != NULL) {
672 *
uname = strdup(child_name);
685 set_standby(
cib_t * the_cib,
const char *uuid,
const char *scope,
const char *standby_value)
688 char *attr_id = NULL;
691 CRM_CHECK(standby_value != NULL,
return -EINVAL);
703 attr_id,
"standby", standby_value, TRUE, NULL, NULL);
#define CRM_CHECK(expr, failure_action)
#define PCMK__SUPPORTED_FORMAT_LOG
const char * pcmk_strerror(int rc)
int pcmk_rc2legacy(int rc)
bool pcmk__strcase_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
#define PCMK__SUPPORTED_FORMAT_TEXT
int set_standby(cib_t *the_cib, const char *uuid, const char *scope, const char *standby_value)
#define XML_TAG_TRANSIENT_NODEATTRS
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)
int(* info)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
#define attr_snprintf(_str, _offset, _limit,...)
#define XML_CIB_TAG_NVPAIR
const char * pcmk_rc_str(int rc)
Get a user-friendly description of a return code.
int cib__delete_node_attr(pcmk__output_t *out, cib_t *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, const char *user_name)
void pcmk__register_formats(GOptionGroup *group, pcmk__supported_format_t *table)
#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
#define crm_warn(fmt, args...)
Formatted output for pacemaker tools.
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 find_nvpair_attr_delegate(cib_t *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 crm_trace(fmt, args...)
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
#define crm_log_xml_debug(xml, text)
int(*) void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
#define XML_TAG_META_SETS
void pcmk__str_update(char **str, const char *value)
Wrappers for and extensions to libxml2.
void(* finish)(pcmk__output_t *out, crm_exit_t exit_status, bool print, void **copy_dest)
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)
int pcmk_legacy2rc(int legacy_rc)
#define XML_NODE_IS_REMOTE
#define CIB_OPTIONS_FIRST
void free_xml(xmlNode *child)
gboolean xml_has_children(const xmlNode *root)
void pcmk__output_free(pcmk__output_t *out)
const char * pcmk_cib_xpath_for(const char *element_name)
Get the XPath needed to find a specified CIB element name.
int update_attr_delegate(cib_t *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)
pcmk__action_result_t result
#define crm_perror(level, fmt, args...)
Send a system error message to both the log and stderr.
#define crm_err(fmt, args...)
int cib__read_node_attr(pcmk__output_t *out, cib_t *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, const char *user_name)
#define XML_CIB_TAG_CRMCONFIG
#define XML_CIB_TAG_RSCCONFIG
This structure contains everything that makes up a single output formatter.
#define crm_log_xml_info(xml, text)
#define XML_NVPAIR_ATTR_VALUE
int read_attr_delegate(cib_t *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)
#define XML_CIB_TAG_STATUS
int pcmk__output_new(pcmk__output_t **out, const char *fmt_name, const char *filename, char **argv)
#define crm_log_xml_trace(xml, text)
int delete_attr_delegate(cib_t *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)
bool pcmk__xe_attr_is_true(xmlNodePtr node, const char *name)
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
int cib__update_node_attr(pcmk__output_t *out, cib_t *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, const char *user_name, const char *node_type)
#define XML_CIB_TAG_TICKETS
#define crm_info(fmt, args...)