Skip to content

Commit 0affd58

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 7a94c72 commit 0affd58

File tree

1 file changed

+64
-2
lines changed

1 file changed

+64
-2
lines changed

src/pcmk.c

+64-2
Original file line numberDiff line numberDiff line change
@@ -500,10 +500,51 @@ static int save_attributes(struct booth_config *conf, struct ticket_config *tk,
500500
tk_log_error("crm_ticket xml output empty");
501501
return -EINVAL;
502502
}
503-
if (xmlStrcmp(n->name, (const xmlChar *)"ticket_state")) {
503+
504+
if (xmlStrcmp(n->name, (const xmlChar *) PCMK_XE_PACEMAKER_RESULT) == 0) {
505+
xmlNode *tickets_node = NULL;
506+
xmlNode *ticket_node = NULL;
507+
508+
/* This is XML from a libpacemaker API call. Move the node pointer to
509+
* the ticket element containing the attributes we want to copy.
510+
*/
511+
512+
/* Look for a child node named <tickets>. */
513+
for (xmlNode *child = n->children; child != NULL; child = child->next) {
514+
if (xmlStrcmp(child->name, (const xmlChar *) PCMK_XE_TICKETS) == 0) {
515+
tickets_node = child;
516+
break;
517+
}
518+
}
519+
520+
if (tickets_node == NULL) {
521+
tk_log_error("API result does not match expected");
522+
return -EINVAL;
523+
}
524+
525+
/* Under that should be a single <ticket> node containing the attributes
526+
* we want to copy. libpacemaker should only return one node because we
527+
* asked for a specific ticket, but just to be safe...
528+
*/
529+
for (xmlNode *child = tickets_node->children; child != NULL; child = child->next) {
530+
if (xmlStrcmp(child->name, (const xmlChar *) PCMK_XE_TICKET) == 0) {
531+
ticket_node = child;
532+
break;
533+
}
534+
}
535+
536+
if (ticket_node == NULL) {
537+
tk_log_error("API result does not match expected");
538+
return -EINVAL;
539+
}
540+
541+
n = ticket_node;
542+
} else if (xmlStrcmp(n->name, (const xmlChar *) "ticket_state") != 0) {
543+
/* This isn't any XML we expect */
504544
tk_log_error("crm_ticket xml root element not ticket_state");
505545
return -EINVAL;
506-
}
546+
}
547+
507548
for (attr = n->properties; attr; attr = attr->next) {
508549
v = xmlGetProp(n, attr->name);
509550
for (atp = attr_handlers; atp->name; atp++) {
@@ -528,6 +569,26 @@ static int save_attributes(struct booth_config *conf, struct ticket_config *tk,
528569
}
529570

530571

572+
#ifdef LIBPACEMAKER
573+
static int pcmk_load_ticket(struct ticket_config *tk)
574+
{
575+
xmlNode *xml = NULL;
576+
int rv;
577+
578+
rv = pcmk_ticket_state(&xml, tk->name);
579+
580+
if (rv == pcmk_rc_ok) {
581+
rv = save_attributes(tk, xml->doc);
582+
} else {
583+
log_error("pcmk_load_ticket: %s", pcmk_rc_str(rv));
584+
rv = -1;
585+
}
586+
587+
xmlFreeNode(xml);
588+
return rv;
589+
}
590+
#else
591+
531592
#define CHUNK_SIZE 256
532593

533594
static int read_ticket_state(struct booth_config *conf, struct ticket_config *tk,
@@ -634,6 +695,7 @@ static int pcmk_load_ticket(struct booth_config *conf, struct ticket_config *tk)
634695
}
635696
return rv | pipe_rv;
636697
}
698+
#endif
637699

638700

639701
struct ticket_handler pcmk_handler = {

0 commit comments

Comments
 (0)