12 #include <sys/param.h> 17 #include <sys/types.h> 32 new_output_object(
const char *ty)
36 const char* argv[] = {
"", NULL };
54 find_attr(
cib_t *cib,
const char *section,
const char *node_uuid,
55 const char *attr_set_type,
const char *set_name,
const char *attr_id,
56 const char *attr_name,
const char *user_name, xmlNode **
result)
60 const char *xpath_base = NULL;
61 GString *xpath = NULL;
62 xmlNode *xml_search = NULL;
63 const char *set_type = NULL;
67 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,
138 crm_trace(
"Query failed for attribute %s (section=%s, node=%s, set=%s, xpath=%s): %s",
139 attr_name, section, pcmk__s(node_uuid,
"<null>"),
140 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)
156 xmlNode *child = NULL;
157 out->
info(out,
"Multiple attributes match name=%s", attr_name);
159 for (child = pcmk__xml_first_child(search); child != NULL;
160 child = pcmk__xml_next(child)) {
161 out->
info(out,
" Value: %s \t(id=%s)",
174 const char *node_uuid,
const char *set_type,
const char *set_name,
175 const char *attr_id,
const char *attr_name,
const char *attr_value,
176 const char *user_name,
const char *
node_type)
178 const char *tag = NULL;
180 xmlNode *xml_top = NULL;
181 xmlNode *xml_obj = NULL;
182 xmlNode *xml_search = NULL;
184 char *local_attr_id = NULL;
185 char *local_set_name = NULL;
187 CRM_CHECK(section != NULL,
return EINVAL);
188 CRM_CHECK(attr_value != NULL,
return EINVAL);
189 CRM_CHECK(attr_name != NULL || attr_id != NULL,
return EINVAL);
191 rc = find_attr(cib, section, node_uuid, set_type, set_name, attr_id,
192 attr_name, user_name, &xml_search);
195 if (handle_multiples(out, xml_search, attr_name) ==
ENOTUNIQ) {
200 attr_id = local_attr_id;
205 }
else if (rc != ENXIO) {
214 crm_trace(
"%s does not exist, create it", attr_name);
225 if (node_uuid == NULL) {
241 if (node_uuid == NULL) {
254 if (set_name == NULL) {
262 }
else if (node_uuid) {
266 char *tmp_set_name = local_set_name;
275 set_name = local_set_name;
278 if (attr_id == NULL) {
281 attr_id = local_attr_id;
283 }
else if (attr_name == NULL) {
287 crm_trace(
"Creating %s/%s", section, tag);
291 if (xml_top == NULL) {
303 }
else if (set_type) {
311 if (xml_top == NULL) {
318 if (xml_top == NULL) {
324 NULL, call_options, user_name);
328 out->
err(out,
"Error setting %s=%s (section=%s, set=%s): %s",
329 attr_name, attr_value, section, pcmk__s(set_name,
"<null>"),
336 free(local_set_name);
345 const char *node_uuid,
const char *set_type,
const char *set_name,
346 const char *attr_id,
const char *attr_name,
const char *user_name,
352 CRM_CHECK(section != NULL,
return EINVAL);
356 rc = find_attr(cib, section, node_uuid, set_type, set_name, attr_id, attr_name,
360 crm_trace(
"Query failed for attribute %s (section=%s node=%s set=%s): %s",
361 pcmk__s(attr_name,
"with unspecified name"),
362 section, pcmk__s(set_name,
"<null>"),
371 const char *node_uuid,
const char *set_type,
const char *set_name,
372 const char *attr_id,
const char *attr_name,
const char *attr_value,
373 const char *user_name)
376 xmlNode *xml_obj = NULL;
377 xmlNode *xml_search = 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(cib, section, node_uuid, set_type, set_name, attr_id,
385 attr_name, user_name, &xml_search);
392 attr_id = local_attr_id;
400 NULL, options, user_name);
405 out->
info(out,
"Deleted %s %s: id=%s%s%s%s%s",
406 section, node_uuid ?
"attribute" :
"option", local_attr_id,
407 set_name ?
" set=" :
"", set_name ? set_name :
"",
408 attr_name ?
" name=" :
"", attr_name ? attr_name :
"");
418 const char *node_uuid,
const char *attr_set_type,
const char *set_name,
419 const char *attr_id,
const char *attr_name, gboolean to_console,
420 char **value,
const char *user_name)
423 xmlNode *xml_search = NULL;
426 out = new_output_object(to_console ?
"text" :
"log");
431 rc = find_attr(cib, section, node_uuid, attr_set_type, set_name, attr_id,
432 attr_name, user_name, &xml_search);
435 rc = handle_multiples(out, xml_search, attr_name);
450 const char *node_uuid,
const char *set_type,
const char *set_name,
451 const char *attr_id,
const char *attr_name,
const char *attr_value,
452 gboolean to_console,
const char *user_name,
const char *
node_type)
457 out = new_output_object(to_console ?
"text" :
"log");
463 set_name, attr_id, attr_name, attr_value, user_name,
473 const char *set_type,
const char *set_name,
const char *attr_id,
474 const char *attr_name,
char **attr_value, gboolean to_console,
475 const char *user_name)
481 out = new_output_object(to_console ?
"text" :
"log");
487 attr_id, attr_name, user_name, &
result);
505 const char *set_type,
const char *set_name,
const char *attr_id,
506 const char *attr_name,
const char *attr_value, gboolean to_console,
507 const char *user_name)
512 out = new_output_object(to_console ?
"text" :
"log");
518 set_name, attr_id, attr_name, attr_value, user_name);
536 get_uuid_from_result(
const xmlNode *
result,
char **uuid,
int *is_remote)
540 const char *parsed_uuid = NULL;
541 int parsed_is_remote = FALSE;
548 tag = (
const char *) (
result->name);
552 tag = (
const char *) (
result->name);
560 parsed_is_remote = TRUE;
563 parsed_is_remote = FALSE;
570 parsed_is_remote = TRUE;
576 parsed_is_remote = TRUE;
583 parsed_is_remote = TRUE;
589 *uuid = strdup(parsed_uuid);
592 *is_remote = parsed_is_remote;
606 #define XPATH_UPPER_TRANS "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 607 #define XPATH_LOWER_TRANS "abcdefghijklmnopqrstuvwxyz" 609 "/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_NODES \ 610 "/" XML_CIB_TAG_NODE "[translate(@" XML_ATTR_UNAME ",'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']" \ 611 "|/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_RESOURCES \ 612 "/" XML_CIB_TAG_RESOURCE \ 613 "[@class='ocf'][@provider='pacemaker'][@type='remote'][translate(@id,'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']" \ 614 "|/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_RESOURCES \ 615 "/" XML_CIB_TAG_RESOURCE "/" XML_TAG_META_SETS "/" XML_CIB_TAG_NVPAIR \ 616 "[@name='" XML_RSC_ATTR_REMOTE_NODE "'][translate(@value,'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']" \ 617 "|/" XML_TAG_CIB "/" XML_CIB_TAG_STATUS "/" XML_CIB_TAG_STATE \ 618 "[@" XML_NODE_IS_REMOTE "='true'][translate(@" XML_ATTR_ID ",'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']" 625 xmlNode *xml_search = NULL;
626 char *host_lowercase = NULL;
630 host_lowercase = g_ascii_strdown(
uname, -1);
635 if (is_remote_node) {
636 *is_remote_node = FALSE;
644 rc = get_uuid_from_result(xml_search, uuid, is_remote_node);
650 g_free(host_lowercase);
653 crm_debug(
"Could not map node name '%s' to a UUID: %s",
656 crm_info(
"Mapped node name '%s' to UUID %s",
uname, (uuid? *uuid :
""));
665 xmlNode *a_child = NULL;
666 xmlNode *xml_obj = NULL;
667 xmlNode *fragment = NULL;
668 const char *child_name = NULL;
688 for (a_child = pcmk__xml_first_child(xml_obj); a_child != NULL;
689 a_child = pcmk__xml_next(a_child)) {
693 child_name =
ID(a_child);
696 if (child_name != NULL) {
697 *
uname = strdup(child_name);
710 set_standby(
cib_t * the_cib,
const char *uuid,
const char *scope,
const char *standby_value)
713 char *attr_id = NULL;
716 CRM_CHECK(standby_value != NULL,
return -EINVAL);
728 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
#define PCMK__CIB_REQUEST_QUERY
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.
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)
#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)
#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
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 XML_TAG_ATTR_SETS
#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...)
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...)
void pcmk__g_strcat(GString *buffer,...) G_GNUC_NULL_TERMINATED
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
int(*) int(*) void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
#define crm_log_xml_debug(xml, text)
#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_err(fmt, args...)
#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)
#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)
#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...)
#define PCMK__CIB_REQUEST_DELETE