12 #include <sys/param.h> 17 #include <sys/types.h> 31 new_output_object(
const char *ty)
35 const char* argv[] = {
"", NULL };
53 find_attr(
cib_t *cib,
const char *section,
const char *node_uuid,
54 const char *attr_set_type,
const char *set_name,
const char *attr_id,
55 const char *attr_name,
const char *user_name, xmlNode **
result)
59 const char *xpath_base = NULL;
60 GString *xpath = NULL;
61 xmlNode *xml_search = NULL;
62 const char *set_type = NULL;
66 set_type = attr_set_type;
86 }
else if (node_uuid == NULL) {
91 if (xpath_base == NULL) {
92 crm_warn(
"%s CIB section not known", section);
96 xpath = g_string_sized_new(1024);
97 g_string_append(xpath, xpath_base);
102 }
else if (node_uuid) {
119 g_string_append(xpath,
"//nvpair");
121 if (attr_id && attr_name) {
126 }
else if (attr_id) {
129 }
else if (attr_name) {
134 (
const char *) xpath->str, NULL, &xml_search,
139 crm_trace(
"Query failed for attribute %s (section=%s, node=%s, set=%s, xpath=%s): %s",
140 attr_name, section, pcmk__s(node_uuid,
"<null>"),
141 pcmk__s(set_name,
"<null>"), (
const char *) xpath->str,
147 g_string_free(xpath, TRUE);
153 handle_multiples(
pcmk__output_t *out, xmlNode *search,
const char *attr_name)
155 if ((search != NULL) && (search->children != NULL)) {
165 const char *node_uuid,
const char *set_type,
const char *set_name,
166 const char *attr_id,
const char *attr_name,
const char *attr_value,
167 const char *user_name,
const char *
node_type)
169 const char *tag = NULL;
171 xmlNode *xml_top = NULL;
172 xmlNode *xml_obj = NULL;
173 xmlNode *xml_search = NULL;
175 char *local_attr_id = NULL;
176 char *local_set_name = NULL;
178 CRM_CHECK((out != NULL) && (cib != NULL) && (section != NULL)
179 && ((attr_id != NULL) || (attr_name != NULL))
180 && (attr_value != NULL),
return EINVAL);
182 rc = find_attr(cib, section, node_uuid, set_type, set_name, attr_id,
183 attr_name, user_name, &xml_search);
186 if (handle_multiples(out, xml_search, attr_name) ==
ENOTUNIQ) {
191 attr_id = local_attr_id;
196 }
else if (rc != ENXIO) {
205 crm_trace(
"%s does not exist, create it", attr_name);
216 if (node_uuid == NULL) {
232 if (node_uuid == NULL) {
245 if (set_name == NULL) {
255 }
else if (node_uuid) {
259 char *tmp_set_name = local_set_name;
268 set_name = local_set_name;
271 if (attr_id == NULL) {
274 attr_id = local_attr_id;
276 }
else if (attr_name == NULL) {
280 crm_trace(
"Creating %s/%s", section, tag);
284 if (xml_top == NULL) {
289 if ((node_uuid == NULL)
299 }
else if (set_type) {
307 if (xml_top == NULL) {
314 if (xml_top == NULL) {
320 NULL, call_options, user_name);
331 out->
err(out,
"Error setting %s=%s (section=%s, set=%s): %s",
332 attr_name, attr_value, section, pcmk__s(set_name,
"<null>"),
337 free(local_set_name);
346 const char *node_uuid,
const char *set_type,
const char *set_name,
347 const char *attr_id,
const char *attr_name,
const char *user_name,
353 CRM_CHECK(section != NULL,
return EINVAL);
357 rc = find_attr(cib, section, node_uuid, set_type, set_name, attr_id, attr_name,
361 crm_trace(
"Query failed for attribute %s (section=%s node=%s set=%s): %s",
362 pcmk__s(attr_name,
"with unspecified name"),
363 section, pcmk__s(set_name,
"<null>"),
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 xmlNode *xml_search = NULL;
379 char *local_attr_id = NULL;
381 CRM_CHECK(section != NULL,
return EINVAL);
382 CRM_CHECK(attr_name != NULL || attr_id != NULL,
return EINVAL);
384 if (attr_id == NULL) {
385 rc = find_attr(cib, section, node_uuid, set_type, set_name, attr_id,
386 attr_name, user_name, &xml_search);
393 attr_id = local_attr_id;
401 NULL, options, user_name);
412 out->
info(out,
"Deleted %s %s: id=%s%s%s%s%s",
413 section, node_uuid ?
"attribute" :
"option", local_attr_id,
414 set_name ?
" set=" :
"", set_name ? set_name :
"",
415 attr_name ?
" name=" :
"", attr_name ? attr_name :
"");
424 const char *node_uuid,
const char *attr_set_type,
const char *set_name,
425 const char *attr_id,
const char *attr_name, gboolean to_console,
426 char **value,
const char *user_name)
429 xmlNode *xml_search = NULL;
432 out = new_output_object(to_console ?
"text" :
"log");
437 rc = find_attr(cib, section, node_uuid, attr_set_type, set_name, attr_id,
438 attr_name, user_name, &xml_search);
441 rc = handle_multiples(out, xml_search, attr_name);
456 const char *node_uuid,
const char *set_type,
const char *set_name,
457 const char *attr_id,
const char *attr_name,
const char *attr_value,
458 gboolean to_console,
const char *user_name,
const char *
node_type)
463 out = new_output_object(to_console ?
"text" :
"log");
469 set_name, attr_id, attr_name, attr_value, user_name,
479 const char *set_type,
const char *set_name,
const char *attr_id,
480 const char *attr_name,
char **attr_value, gboolean to_console,
481 const char *user_name)
487 out = new_output_object(to_console ?
"text" :
"log");
493 attr_id, attr_name, user_name, &
result);
496 if (
result->children == NULL) {
512 const char *set_type,
const char *set_name,
const char *attr_id,
513 const char *attr_name,
const char *attr_value, gboolean to_console,
514 const char *user_name)
519 out = new_output_object(to_console ?
"text" :
"log");
525 set_name, attr_id, attr_name, attr_value, user_name);
543 get_uuid_from_result(
const xmlNode *
result,
char **uuid,
int *is_remote)
546 const char *parsed_uuid = NULL;
547 int parsed_is_remote = FALSE;
565 parsed_is_remote = TRUE;
567 parsed_uuid = pcmk__xe_id(
result);
568 parsed_is_remote = FALSE;
574 parsed_uuid = pcmk__xe_id(
result);
575 parsed_is_remote = TRUE;
583 parsed_is_remote = TRUE;
590 parsed_is_remote = TRUE;
596 *uuid = strdup(parsed_uuid);
599 *is_remote = parsed_is_remote;
613 #define XPATH_UPPER_TRANS "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 614 #define XPATH_LOWER_TRANS "abcdefghijklmnopqrstuvwxyz" 616 "/" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION "/" PCMK_XE_NODES \ 617 "/" PCMK_XE_NODE "[translate(@" PCMK_XA_UNAME ",'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']" \ 618 "|/" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION "/" PCMK_XE_RESOURCES \ 619 "/" PCMK_XE_PRIMITIVE \ 620 "[@class='ocf'][@provider='pacemaker'][@type='remote'][translate(@id,'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']" \ 621 "|/" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION "/" PCMK_XE_RESOURCES \ 622 "/" PCMK_XE_PRIMITIVE "/" PCMK_XE_META_ATTRIBUTES "/" PCMK_XE_NVPAIR \ 623 "[@name='" PCMK_META_REMOTE_NODE "'][translate(@value,'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']" \ 624 "|/" PCMK_XE_CIB "/" PCMK_XE_STATUS "/" PCMK__XE_NODE_STATE \ 625 "[@" PCMK_XA_REMOTE_NODE "='true'][translate(@" PCMK_XA_ID ",'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']" 632 xmlNode *xml_search = NULL;
633 char *host_lowercase = NULL;
637 host_lowercase = g_ascii_strdown(
uname, -1);
642 if (is_remote_node) {
643 *is_remote_node = FALSE;
651 rc = get_uuid_from_result(xml_search, uuid, is_remote_node);
657 g_free(host_lowercase);
660 crm_debug(
"Could not map node name '%s' to a UUID: %s",
663 crm_info(
"Mapped node name '%s' to UUID %s",
uname, (uuid? *uuid :
""));
677 xmlNode *a_child = NULL;
678 xmlNode *xml_obj = NULL;
679 xmlNode *fragment = NULL;
680 const char *child_name = NULL;
701 child_name = pcmk__xe_id(a_child);
705 if (child_name != NULL) {
706 *
uname = strdup(child_name);
718 set_standby(
cib_t * the_cib,
const char *uuid,
const char *scope,
const char *standby_value)
721 char *attr_id = NULL;
724 CRM_CHECK(standby_value != NULL,
return -EINVAL);
#define CRM_CHECK(expr, failure_action)
#define PCMK__SUPPORTED_FORMAT_LOG
const char * pcmk_strerror(int rc)
#define PCMK_XE_OP_DEFAULTS
int pcmk_rc2legacy(int rc)
#define PCMK_XA_REMOTE_NODE
bool pcmk__strcase_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
#define PCMK_XE_PRIMITIVE
#define PCMK__SUPPORTED_FORMAT_TEXT
#define PCMK__CIB_REQUEST_QUERY
#define PCMK_XE_RSC_DEFAULTS
int set_standby(cib_t *the_cib, const char *uuid, const char *scope, const char *standby_value)
#define PCMK__XE_XPATH_QUERY
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
int(* info)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
bool pcmk__xe_attr_is_true(const xmlNode *node, const char *name)
Deprecated Pacemaker configuration utilities.
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 crm_xml_sanitize_id(char *id)
Sanitize a string so it is usable as an XML ID.
#define PCMK__XE_TRANSIENT_ATTRIBUTES
int cib__get_node_attrs(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, const char *user_name, xmlNode **result)
#define crm_warn(fmt, args...)
Formatted output for pacemaker tools.
void pcmk__register_formats(GOptionGroup *group, const pcmk__supported_format_t *table)
cib_api_operations_t * cmds
#define crm_debug(fmt, args...)
char * crm_element_value_copy(const xmlNode *data, const char *name)
Retrieve a copy of the value of an XML attribute.
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
xmlNode * pcmk__xe_first_child(const xmlNode *parent, const char *node_name, const char *attr_n, const char *attr_v)
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...)
void pcmk__g_strcat(GString *buffer,...) G_GNUC_NULL_TERMINATED
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
int(*) int(*) void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
#define crm_log_xml_debug(xml, text)
#define PCMK_XE_CLUSTER_PROPERTY_SET
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)
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 PCMK_NODE_ATTR_STANDBY
void free_xml(xmlNode *child)
#define pcmk__str_copy(str)
#define PCMK_XE_META_ATTRIBUTES
void pcmk__output_free(pcmk__output_t *out)
const char * pcmk_cib_xpath_for(const char *element_name)
Get the relative XPath needed to find a specified CIB element name.
#define pcmk__assert(expr)
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 PCMK_VALUE_CIB_BOOTSTRAP_OPTIONS
#define crm_err(fmt, args...)
This structure contains everything that makes up a single output formatter.
#define crm_log_xml_info(xml, text)
#define PCMK__XE_NODE_STATE
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)
void pcmk__warn_multiple_name_matches(pcmk__output_t *out, xmlNode *search, const char *name)
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)
#define PCMK__CIB_REQUEST_MODIFY
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)
xmlNode * pcmk__xe_create(xmlNode *parent, const char *name)
#define PCMK_XE_INSTANCE_ATTRIBUTES
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)
xmlNode * pcmk__xe_next_same(const xmlNode *node)
#define PCMK_VALUE_REMOTE
#define crm_info(fmt, args...)
#define PCMK_XE_CRM_CONFIG
#define PCMK__CIB_REQUEST_DELETE