Make uuids work with libvirt-qpid

Signed-off-by: Lon Hohberger <lon@users.sourceforge.net>
This commit is contained in:
Lon Hohberger 2009-11-06 13:16:42 -05:00
parent decab46dda
commit 33c16854eb
5 changed files with 88 additions and 6 deletions

5
TODO
View File

@ -11,12 +11,13 @@ High Priority / Blockers for v1.0;
fence who (for example, "vm1 vm2 vm3" can all fence each other, while
none may fence "vm4 vm5 vm6" since they are in a different cluster).
* libvirt-qpid security model: mirror what is done in libvirt-qpid
for authentication.
Future Stuff:
* oVirt backend
* libvirt-qpid backend
* libccs configuration plugin
* clean up development bits so third parties can develop plugins

View File

@ -39,6 +39,7 @@ MODULE_PATH=${libdir}/${PACKAGE_NAME}
fence_virtd_SOURCES = main.c plugin.c
libvirt_so_SOURCES = libvirt.c
null_so_SOURCES = null.c
libvirt_qpid_so_SOURCES = uuid-test.c
libvirt_qpid_cxx_so_SOURCES = libvirt-qpid.cpp
multicast_so_SOURCES = mcast.c history.c
checkpoint_so_SOURCES = virt.c vm_states.c history.c checkpoint.c cpg.c
@ -90,6 +91,7 @@ fence_virtd_SOURCES+=${checkpoint_so_SOURCES}
LIBS+=$(AIS_LIBS) $(COROSYNC_LIBS) $(CMAN_LIBS)
endif
ifneq ($(mod_libvirt_qpid),no)
fence_virtd_SOURCES+=${libvirt_qpid_so_SOURCES}
fence_virtd_cxx_SOURCES+=${libvirt_qpid_cxx_so_SOURCES}
LIBS+=$(VIRT_QPID)
endif
@ -116,7 +118,7 @@ multicast.so: ${multicast_so_SOURCES:.c=.o}
libvirt.so: ${libvirt_so_SOURCES:.c=.o}
$(CC) -o $@ $^ $(LIBS) -shared $(VIRT_LIBS)
libvirt-qpid.so: ${libvirt_qpid_cxx_so_SOURCES:.cpp=.opp}
libvirt-qpid.so: ${libvirt_qpid_so_SOURCES:.c=.o} ${libvirt_qpid_cxx_so_SOURCES:.cpp=.opp}
$(CXX) -o $@ $^ $(LIBS) -shared $(VIRT_QPID)
null.so: ${null_so_SOURCES:.c=.o}

View File

@ -27,6 +27,7 @@
#include <string.h>
#include <malloc.h>
#include <errno.h>
#include "uuid-test.h"
#include <qpid/console/SessionManager.h>
@ -45,7 +46,6 @@ struct lq_info {
int pad;
char *host;
uint16_t port;
};
#define VALIDATE(arg) \
@ -65,8 +65,13 @@ do_lq_request(const char *vm_name, const char *action)
SessionManager::NameVector names;
Object::Vector domains;
Object *domain = NULL;
const char *property = "name";
unsigned i, tries = 0, found = 0;
if (is_uuid(vm_name) == 1) {
property = "uuid";
}
cs.host = "127.0.0.1";
cs.port = 5672;
@ -105,7 +110,7 @@ do_lq_request(const char *vm_name, const char *action)
c = domains[i].getSchema();
#endif
if (strcmp(domains[i].attrString("name").c_str(),
if (strcmp(domains[i].attrString(property).c_str(),
vm_name)) {
continue;
}
@ -134,7 +139,7 @@ do_lq_request(const char *vm_name, const char *action)
Object::AttributeMap attrs;
MethodResponse result;
std::cout << domain->attrString("name") << " "
std::cout << domain->attrString(property) << " "
<< domain->attrString("state") << std::endl;
domain->invokeMethod(action, attrs, result);

60
server/uuid-test.c Normal file
View File

@ -0,0 +1,60 @@
#include <uuid/uuid.h>
#include <errno.h>
#include <string.h>
int
is_uuid(const char *value)
{
uuid_t id;
char test_value[37];
if (strlen(value) < 36) {
return 0;
}
if (uuid_is_null(id) < 0) {
errno = EINVAL;
return -1;
}
if (uuid_parse(value, id) < 0) {
return 0;
}
memset(test_value, 0, sizeof(test_value));
uuid_unparse(id, test_value);
if (strcasecmp(value, test_value)) {
return 0;
}
return 1;
}
#ifdef STANDALONE
#include <stdio.h>
int
main(int argc, char **argv)
{
int ret;
if (argc < 2) {
printf("Usage: uuidtest <value>\n");
return 1;
}
ret = is_uuid(argv[1]);
if (ret == 0) {
printf("%s is NOT a uuid\n", argv[1]);
} else if (ret == 1) {
printf("%s is a uuid\n", argv[1]);
} else {
printf("Error: %s\n", strerror(errno));
return 1;
}
return 0;
}
#endif

14
server/uuid-test.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef __UIID_TEST_H
#define __UUID_TEST_H
#ifdef __cplusplus
extern "C" {
#endif
int is_uuid(const char *value);
#ifdef __cplusplus
}
#endif
#endif