public inbox for cluster-cvs@sourceware.org help / color / mirror / Atom feed
From: ccaulfield@sourceware.org To: cluster-cvs@sources.redhat.com, cluster-devel@redhat.com Subject: Cluster Project branch, master, updated. cluster-2.99.05-56-ge88a7d8 Date: Wed, 09 Jul 2008 14:20:00 -0000 [thread overview] Message-ID: <20080709141956.1762.qmail@sourceware.org> (raw) This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Cluster Project". http://sources.redhat.com/git/gitweb.cgi?p=cluster.git;a=commitdiff;h=e88a7d8044de44be39369f99d65bdb818e478c97 The branch, master has been updated via e88a7d8044de44be39369f99d65bdb818e478c97 (commit) from 6fb8dc9d73db3a5e48589ee274f1c34ee4bc76c5 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit e88a7d8044de44be39369f99d65bdb818e478c97 Author: Christine Caulfield <ccaulfie@redhat.com> Date: Wed Jul 9 15:18:09 2008 +0100 [CONFIG] Add ldap loader Add a new tool to load an existing cluster config into LDAP. This is as incomplete as the schema at the moment, but it will allow you to add nodes and some very basic fencing devices. It uses libconfdb so it can migrate either a running system or a cluster.conf file. Signed-off-by: Christine Caulfield <ccaulfie@redhat.com> ----------------------------------------------------------------------- Summary of changes: config/plugins/ldap/99cluster.ldif | 2 +- config/tools/{ccs_test => ldap}/Makefile | 8 +- config/tools/ldap/loadldap.c | 206 ++++++++++++++++++++++++++++++ 3 files changed, 211 insertions(+), 5 deletions(-) copy config/tools/{ccs_test => ldap}/Makefile (81%) create mode 100644 config/tools/ldap/loadldap.c diff --git a/config/plugins/ldap/99cluster.ldif b/config/plugins/ldap/99cluster.ldif index bd2d843..7b53a12 100644 --- a/config/plugins/ldap/99cluster.ldif +++ b/config/plugins/ldap/99cluster.ldif @@ -129,7 +129,7 @@ objectClasses: ( 1.3.6.1.4.1.2312.8.1.2.6 NAME 'rhcsFenceagent' SUP top STRUCTURAL DESC 'A Fence device' MUST ( name ) - MAY ( rhcsPort ) + MAY ( rhcsPort $ rhcsIpaddr ) ) objectClasses: ( 1.3.6.1.4.1.2312.8.1.2.7 NAME 'rhcsFencemethod' SUP top STRUCTURAL diff --git a/config/tools/ccs_test/Makefile b/config/tools/ldap/Makefile similarity index 81% copy from config/tools/ccs_test/Makefile copy to config/tools/ldap/Makefile index f0ebddc..dae9849 100644 --- a/config/tools/ccs_test/Makefile +++ b/config/tools/ldap/Makefile @@ -1,4 +1,4 @@ -TARGET= ccs_test +TARGET= loadldap SBINDIRT=$(TARGET) @@ -10,13 +10,13 @@ include $(OBJDIR)/make/clean.mk include $(OBJDIR)/make/install.mk include $(OBJDIR)/make/uninstall.mk -OBJS= ccs_test.o +OBJS= loadldap.o CFLAGS += -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -CFLAGS += -I${ccsincdir} +CFLAGS += -I${openaisincdir} CFLAGS += -I${incdir} -LDFLAGS += -L${ccslibdir} -lccs +LDFLAGS += -L${openaislibdir} -lconfdb ${TARGET}: ${OBJS} diff --git a/config/tools/ldap/loadldap.c b/config/tools/ldap/loadldap.c new file mode 100644 index 0000000..b25a3d6 --- /dev/null +++ b/config/tools/ldap/loadldap.c @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2008 Red Hat Inc + * + * All rights reserved. + * + * Author: Christine Caulfield <ccaulfie@redhat.com> + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <signal.h> +#include <unistd.h> +#include <string.h> +#include <sys/types.h> +#include <sys/un.h> + +#include <openais/saAis.h> +#include <openais/service/confdb.h> + +confdb_callbacks_t callbacks = { + .confdb_change_notify_fn = NULL, +}; + +/* This structure maps object parent names to object classes */ +struct objectclasses +{ + char *name; + char *class; +} objectclasses[] = +{ + { "cluster", "rhcsCluster" }, + { "cman", "rhcsCman" }, + { "totem", "rhcsTotem" }, + { "clusternode", "rhcsNode" }, + { "device", "rhcsFenceagent" }, + { "fencedevice", "rhcsFencedevice" }, + { "method", "rhcsFencemethod" }, +}; +/* TODO: Add more here as the schema gets filled in */ + + +static char *ldap_attr_name(char *attrname) +{ + static char newname[1024]; + int i; + + if (strcmp(attrname, "name") == 0) + return attrname; + + sprintf(newname, "rhcs"); + for (i=0; i<strlen(attrname)+1; i++) { + if (i == 0) + newname[4+i] = attrname[i] & 0x5F; + else + if (attrname[i] == '_') + newname[4+i] = '-'; + else + newname[4+i] = attrname[i]; + } + return newname; +} + + +/* Recursively dump the object tree */ +static void print_config_tree(confdb_handle_t handle, unsigned int parent_object_handle, char *dn, char *fulldn) +{ + unsigned int object_handle; + char object_name[1024]; + int object_name_len; + char key_name[1024]; + int key_name_len; + char key_value[1024]; + int key_value_len; + char cumulative_dn[4096]; + int res; + int i; + int keycount=0; + + printf("\ndn: %s\n", fulldn); + + /* Show the keys */ + res = confdb_key_iter_start(handle, parent_object_handle); + if (res != SA_AIS_OK) { + printf( "error resetting key iterator for object %d: %d\n", parent_object_handle, res); + return; + } + + while ( (res = confdb_key_iter(handle, parent_object_handle, key_name, &key_name_len, + key_value, &key_value_len)) == SA_AIS_OK) { + key_name[key_name_len] = '\0'; + key_value[key_value_len] = '\0'; + + printf("%s: %s\n", ldap_attr_name(key_name), key_value); + keycount++; + } + if (strncmp(fulldn, "cn=", 3) == 0) { + printf("cn: %s\n", dn); + } + + + /* Determine objectclass... */ + if (keycount == 0) { + printf("objectclass: nsContainer\n"); + } + else { + for (i = 0; i < sizeof(objectclasses)/sizeof(struct objectclasses); i++) { + if (strcmp(objectclasses[i].name, dn) == 0) + printf("objectclass: %s\n", objectclasses[i].class); + } + } + + /* Show sub-objects */ + res = confdb_object_iter_start(handle, parent_object_handle); + if (res != SA_AIS_OK) { + printf( "error resetting object iterator for object %d: %d\n", parent_object_handle, res); + return; + } + + while ( (res = confdb_object_iter(handle, parent_object_handle, &object_handle, object_name, &object_name_len)) == SA_AIS_OK) { + unsigned int parent; + + res = confdb_object_parent_get(handle, object_handle, &parent); + if (res != SA_AIS_OK) { + printf( "error getting parent for object %d: %d\n", object_handle, res); + return; + } + + object_name[object_name_len] = '\0'; + + /* Check for "name", and create dummy parent object */ + res = confdb_key_get(handle, object_handle, "name", strlen("name"), key_value, &key_value_len); + if (res == SA_AIS_OK) { + sprintf(cumulative_dn, "cn=%s,%s", object_name, fulldn); + printf("\n"); + printf("dn: %s\n", cumulative_dn); + printf("cn: %s\n", object_name); + printf("objectclass: %s\n", "nsContainer"); + + sprintf(cumulative_dn, "name=%s,cn=%s,%s", key_value, object_name, fulldn); + } + else { + sprintf(cumulative_dn, "cn=%s,%s", object_name, fulldn); + } + + /* Down we go ... */ + print_config_tree(handle, object_handle, object_name, cumulative_dn); + } +} + + +int main(int argc, char *argv[]) +{ + confdb_handle_t handle; + int result; + unsigned int cluster_handle; + char *clusterroot = "cluster"; + char basedn[1024]; + + if (argc == 1) { + fprintf(stderr, "usage: \n"); + fprintf(stderr, " %s <dn> [<objdb root>]\n", argv[0]); + fprintf(stderr, "\n"); + fprintf(stderr, " eg: \n"); + fprintf(stderr, " %s dc=mycompany,dc=com\n", argv[0]); + fprintf(stderr, " %s dc=mycompany,dc=com rhcluster\n", argv[0]); + fprintf(stderr, "\n"); + fprintf(stderr, "objdb root defaults to 'cn=cluster'\n"); + fprintf(stderr, "\n"); + return 0; + } + + if (argc > 2) { + clusterroot = argv[2]; + } + + result = confdb_initialize (&handle, &callbacks); + if (result != SA_AIS_OK) { + printf ("Could not initialize Cluster Configuration Database API instance error %d\n", result); + exit (1); + } + + /* Find the starting object ... this should be a param */ + + result = confdb_object_find_start(handle, OBJECT_PARENT_HANDLE); + if (result != SA_AIS_OK) { + printf ("Could not start object_find %d\n", result); + exit (1); + } + + result = confdb_object_find(handle, OBJECT_PARENT_HANDLE, "cluster", strlen("cluster"), &cluster_handle); + if (result != SA_AIS_OK) { + printf ("Could not object_find \"cluster\": %d\n", result); + exit (1); + } + + sprintf(basedn, "cn=%s,%s", clusterroot, argv[1]); + + /* Print the configuration */ + print_config_tree(handle, cluster_handle, clusterroot, basedn); + + + result = confdb_finalize (handle); + return (0); +} hooks/post-receive -- Cluster Project
reply other threads:[~2008-07-09 14:20 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20080709141956.1762.qmail@sourceware.org \ --to=ccaulfield@sourceware.org \ --cc=cluster-cvs@sources.redhat.com \ --cc=cluster-devel@redhat.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).