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)
   155     if ((search != NULL) && (search->children != NULL)) {
   156         xmlNode *child = NULL;
   158         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)",
   173                       const char *node_uuid, 
const char *set_type, 
const char *set_name,
   174                       const char *attr_id, 
const char *attr_name, 
const char *attr_value,
   175                       const char *user_name, 
const char *
node_type)
   177     const char *tag = NULL;
   179     xmlNode *xml_top = NULL;
   180     xmlNode *xml_obj = NULL;
   181     xmlNode *xml_search = NULL;
   183     char *local_attr_id = NULL;
   184     char *local_set_name = NULL;
   186     CRM_CHECK((out != NULL) && (cib != NULL) && (section != NULL)
   187               && ((attr_id != NULL) || (attr_name != NULL))
   188               && (attr_value != NULL), 
return EINVAL);
   190     rc = find_attr(cib, section, node_uuid, set_type, set_name, attr_id,
   191                    attr_name, user_name, &xml_search);
   194         if (handle_multiples(out, xml_search, attr_name) == 
ENOTUNIQ) {
   199             attr_id = local_attr_id;
   204     } 
else if (rc != ENXIO) {
   213         crm_trace(
"%s does not exist, create it", attr_name);
   224             if (node_uuid == NULL) {
   240             if (node_uuid == NULL) {
   253         if (set_name == NULL) {
   261             } 
else if (node_uuid) {
   265                     char *tmp_set_name = local_set_name;
   274             set_name = local_set_name;
   277         if (attr_id == NULL) {
   280             attr_id = local_attr_id;
   282         } 
else if (attr_name == NULL) {
   286         crm_trace(
"Creating %s/%s", section, tag);
   290             if (xml_top == NULL) {
   302         } 
else if (set_type) {
   310         if (xml_top == NULL) {
   317     if (xml_top == NULL) {
   323                          NULL, call_options, user_name);
   327         out->
err(out, 
"Error setting %s=%s (section=%s, set=%s): %s",
   328                  attr_name, attr_value, section, pcmk__s(set_name, 
"<null>"),
   335     free(local_set_name);
   344                     const char *node_uuid, 
const char *set_type, 
const char *set_name,
   345                     const char *attr_id, 
const char *attr_name, 
const char *user_name,
   351     CRM_CHECK(section != NULL, 
return EINVAL);
   355     rc = find_attr(cib, section, node_uuid, set_type, set_name, attr_id, attr_name,
   359         crm_trace(
"Query failed for attribute %s (section=%s node=%s set=%s): %s",
   360                   pcmk__s(attr_name, 
"with unspecified name"),
   361                   section, pcmk__s(set_name, 
"<null>"),
   370                       const char *node_uuid, 
const char *set_type, 
const char *set_name,
   371                       const char *attr_id, 
const char *attr_name, 
const char *attr_value,
   372                       const char *user_name)
   375     xmlNode *xml_obj = NULL;
   376     xmlNode *xml_search = NULL;
   377     char *local_attr_id = NULL;
   379     CRM_CHECK(section != NULL, 
return EINVAL);
   380     CRM_CHECK(attr_name != NULL || attr_id != NULL, 
return EINVAL);
   382     if (attr_id == NULL) {
   383         rc = find_attr(cib, section, node_uuid, set_type, set_name, attr_id,
   384                        attr_name, user_name, &xml_search);
   391             attr_id = local_attr_id;
   399                          NULL, options, user_name);
   404         out->
info(out, 
"Deleted %s %s: id=%s%s%s%s%s",
   405                   section, node_uuid ? 
"attribute" : 
"option", local_attr_id,
   406                   set_name ? 
" set=" : 
"", set_name ? set_name : 
"",
   407                   attr_name ? 
" name=" : 
"", attr_name ? attr_name : 
"");
   417                           const char *node_uuid, 
const char *attr_set_type, 
const char *set_name,
   418                           const char *attr_id, 
const char *attr_name, gboolean to_console,
   419                           char **value, 
const char *user_name)
   422     xmlNode *xml_search = NULL;
   425     out = new_output_object(to_console ? 
"text" : 
"log");
   430     rc = find_attr(cib, section, node_uuid, attr_set_type, set_name, attr_id,
   431                    attr_name, user_name, &xml_search);
   434         rc = handle_multiples(out, xml_search, attr_name);
   449                      const char *node_uuid, 
const char *set_type, 
const char *set_name,
   450                      const char *attr_id, 
const char *attr_name, 
const char *attr_value,
   451                      gboolean to_console, 
const char *user_name, 
const char *
node_type)
   456     out = new_output_object(to_console ? 
"text" : 
"log");
   462                                set_name, attr_id, attr_name, attr_value, user_name,
   472                    const char *set_type, 
const char *set_name, 
const char *attr_id,
   473                    const char *attr_name, 
char **attr_value, gboolean to_console,
   474                    const char *user_name)
   480     out = new_output_object(to_console ? 
"text" : 
"log");
   486                              attr_id, attr_name, user_name, &
result);
   489         if (
result->children == NULL) {
   504                      const char *set_type, 
const char *set_name, 
const char *attr_id,
   505                      const char *attr_name, 
const char *attr_value, gboolean to_console,
   506                      const char *user_name)
   511     out = new_output_object(to_console ? 
"text" : 
"log");
   517                                set_name, attr_id, attr_name, attr_value, user_name);
   535 get_uuid_from_result(
const xmlNode *
result, 
char **uuid, 
int *is_remote)
   539     const char *parsed_uuid = NULL;
   540     int parsed_is_remote = FALSE;
   547     tag = (
const char *) (
result->name);
   551         tag = (
const char *) (
result->name);
   559             parsed_is_remote = TRUE;
   562             parsed_is_remote = FALSE;
   569         parsed_is_remote = TRUE;
   575         parsed_is_remote = TRUE;
   582             parsed_is_remote = TRUE;
   588             *uuid = strdup(parsed_uuid);
   591             *is_remote = parsed_is_remote;
   605 #define XPATH_UPPER_TRANS "ABCDEFGHIJKLMNOPQRSTUVWXYZ"   606 #define XPATH_LOWER_TRANS "abcdefghijklmnopqrstuvwxyz"   608     "/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_NODES \   609         "/" XML_CIB_TAG_NODE "[translate(@" XML_ATTR_UNAME ",'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']" \   610     "|/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_RESOURCES \   611         "/" XML_CIB_TAG_RESOURCE \   612         "[@class='ocf'][@provider='pacemaker'][@type='remote'][translate(@id,'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']" \   613     "|/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_RESOURCES \   614         "/" XML_CIB_TAG_RESOURCE "/" XML_TAG_META_SETS "/" XML_CIB_TAG_NVPAIR \   615         "[@name='" XML_RSC_ATTR_REMOTE_NODE "'][translate(@value,'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']" \   616     "|/" XML_TAG_CIB "/" XML_CIB_TAG_STATUS "/" XML_CIB_TAG_STATE \   617         "[@" XML_NODE_IS_REMOTE "='true'][translate(@" XML_ATTR_ID ",'" XPATH_UPPER_TRANS "','" XPATH_LOWER_TRANS "') ='%s']"   624     xmlNode *xml_search = NULL;
   625     char *host_lowercase = NULL;
   629     host_lowercase = g_ascii_strdown(
uname, -1);
   634     if (is_remote_node) {
   635         *is_remote_node = FALSE;
   643         rc = get_uuid_from_result(xml_search, uuid, is_remote_node);
   649     g_free(host_lowercase);
   652         crm_debug(
"Could not map node name '%s' to a UUID: %s",
   655         crm_info(
"Mapped node name '%s' to UUID %s", 
uname, (uuid? *uuid : 
""));
   664     xmlNode *a_child = NULL;
   665     xmlNode *xml_obj = NULL;
   666     xmlNode *fragment = NULL;
   667     const char *child_name = NULL;
   685     for (a_child = pcmk__xml_first_child(xml_obj); a_child != NULL;
   686          a_child = pcmk__xml_next(a_child)) {
   690             child_name = 
ID(a_child);
   693                 if (child_name != NULL) {
   694                     *
uname = strdup(child_name);
   707 set_standby(
cib_t * the_cib, 
const char *uuid, 
const char *scope, 
const char *standby_value)
   710     char *attr_id = NULL;
   713     CRM_CHECK(standby_value != NULL, 
return -EINVAL);
   725                               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)
 
node_type
Possible node types. 
 
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)
 
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. 
 
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