Skip to content

Commit 601b91f

Browse files
committed
pacemaker: Use libpacemaker to load ticket state.
The function itself is very simple. The rest of the work is in save_attributes, where it needs to understand both the libpacemaker XML result as well as the result of calling crm_ticket directly. It's still pretty simple, though - just digging around in the XML to set a node pointer correctly. Fixes #136
1 parent dfd274a commit 601b91f

File tree

1 file changed

+64
-2
lines changed

1 file changed

+64
-2
lines changed

src/pacemaker.c

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,51 @@ static int save_attributes(struct ticket_config *tk, xmlDocPtr doc)
485485
tk_log_error("crm_ticket xml output empty");
486486
return -EINVAL;
487487
}
488-
if (xmlStrcmp(n->name, (const xmlChar *)"ticket_state")) {
488+
489+
if (xmlStrcmp(n->name, (const xmlChar *) PCMK_XE_PACEMAKER_RESULT) == 0) {
490+
xmlNode *tickets_node = NULL;
491+
xmlNode *ticket_node = NULL;
492+
493+
/* This is XML from a libpacemaker API call. Move the node pointer to
494+
* the ticket element containing the attributes we want to copy.
495+
*/
496+
497+
/* Look for a child node named <tickets>. */
498+
for (xmlNode *child = n->children; child != NULL; child = child->next) {
499+
if (xmlStrcmp(child->name, (const xmlChar *) PCMK_XE_TICKETS) == 0) {
500+
tickets_node = child;
501+
break;
502+
}
503+
}
504+
505+
if (tickets_node == NULL) {
506+
tk_log_error("API result does not match expected");
507+
return -EINVAL;
508+
}
509+
510+
/* Under that should be a single <ticket> node containing the attributes
511+
* we want to copy. libpacemaker should only return one node because we
512+
* asked for a specific ticket, but just to be safe...
513+
*/
514+
for (xmlNode *child = tickets_node->children; child != NULL; child = child->next) {
515+
if (xmlStrcmp(child->name, (const xmlChar *) PCMK_XE_TICKET) == 0) {
516+
ticket_node = child;
517+
break;
518+
}
519+
}
520+
521+
if (ticket_node == NULL) {
522+
tk_log_error("API result does not match expected");
523+
return -EINVAL;
524+
}
525+
526+
n = ticket_node;
527+
} else if (xmlStrcmp(n->name, (const xmlChar *) "ticket_state") != 0) {
528+
/* This isn't any XML we expect */
489529
tk_log_error("crm_ticket xml root element not ticket_state");
490530
return -EINVAL;
491-
}
531+
}
532+
492533
for (attr = n->properties; attr; attr = attr->next) {
493534
v = xmlGetProp(n, attr->name);
494535
for (atp = attr_handlers; atp->name; atp++) {
@@ -512,6 +553,26 @@ static int save_attributes(struct ticket_config *tk, xmlDocPtr doc)
512553
}
513554

514555

556+
#ifdef LIBPACEMAKER
557+
static int pcmk_load_ticket(struct ticket_config *tk)
558+
{
559+
xmlNode *xml = NULL;
560+
int rv;
561+
562+
rv = pcmk_ticket_state(&xml, tk->name);
563+
564+
if (rv == pcmk_rc_ok) {
565+
rv = save_attributes(tk, xml->doc);
566+
} else {
567+
log_error("pcmk_load_ticket: %s", pcmk_rc_str(rv));
568+
rv = -1;
569+
}
570+
571+
xmlFreeNode(xml);
572+
return rv;
573+
}
574+
#else
575+
515576
#define CHUNK_SIZE 256
516577

517578
static int read_ticket_state(struct ticket_config *tk, xmlDocPtr *doc, FILE *p)
@@ -617,6 +678,7 @@ static int pcmk_load_ticket(struct ticket_config *tk)
617678
}
618679
return rv | pipe_rv;
619680
}
681+
#endif
620682

621683

622684
struct ticket_handler pcmk_handler = {

0 commit comments

Comments
 (0)