Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to using libpacemaker for managing tickets #144

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
pacemaker: Use libpacemaker for setting and removing attributes.
libpacemaker provides a public API for managing tickets.  A first step
towards using this API is just the setting and removing code, which is
pretty straightforward.  We can ignore the XML result portion of the API
because in these cases it doesn't contain anything more useful than just
the return code.
clumens committed Oct 1, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 82b117d262781119f1a5d87fc46f68dde76bad0e
56 changes: 56 additions & 0 deletions src/pcmk.c
Original file line number Diff line number Diff line change
@@ -33,6 +33,10 @@
#include "pcmk.h"
#include "inline-fn.h"

#ifdef LIBPACEMAKER
#include <crm/common/results.h>
#include <pacemaker.h>
#endif

#define COMMAND_MAX 2048

@@ -101,6 +105,57 @@ static int pcmk_revoke_ticket(struct ticket_config *tk)
}


#ifdef LIBPACEMAKER
static int pcmk_set_attr(struct ticket_config *tk, const char *attr, const char *val)
{
GHashTable *attrs = NULL;
xmlNode *xml = NULL;
int rv;

attrs = g_hash_table_new(g_str_hash, g_str_equal);
if (attrs == NULL) {
log_error("out of memory");
return -1;
}

g_hash_table_insert(attrs, (gpointer) attr, (gpointer) val);

rv = pcmk_ticket_set_attr(&xml, tk->name, attrs, false);
g_hash_table_destroy(attrs);
xmlFreeNode(xml);

if (rv != pcmk_rc_ok) {
log_error("pcmk_set_attr: %s", pcmk_rc_str(rv));
return -1;
}

return 0;
}

static int pcmk_del_attr(struct ticket_config *tk, const char *attr)
{
GList *attrs = NULL;
xmlNode *xml = NULL;
int rv;

attrs = g_list_append(attrs, (gpointer) attr);
if (attrs == NULL) {
log_error("out of memory");
return -1;
}

rv = pcmk_ticket_remove_attr(&xml, tk->name, attrs, false);
g_list_free(attrs);
xmlFreeNode(xml);

if (rv != pcmk_rc_ok) {
log_error("pcmk_del_attr: %s", pcmk_rc_str(rv));
return -1;
}

return 0;
}
#else
static int _run_crm_ticket(char *cmd)
{
int i, rv;
@@ -148,6 +203,7 @@ static int pcmk_del_attr(struct ticket_config *tk, const char *attr)

return _run_crm_ticket(cmd);
}
#endif


typedef int (*attr_f)(struct booth_config *conf, struct ticket_config *tk,