All of lore.kernel.org
 help / color / mirror / Atom feed
From: rmccabe@sourceware.org <rmccabe@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] conga/ricci make/defines.mk.in modules/cluster ...
Date: 14 Mar 2008 19:58:13 -0000	[thread overview]
Message-ID: <20080314195813.31724.qmail@sourceware.org> (raw)

CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	rmccabe at sourceware.org	2008-03-14 19:58:12

Modified files:
	ricci/make     : defines.mk.in 
	ricci/modules/cluster: ClusterModule.cpp Makefile Virt.cpp 
	                       Virt.h 
Added files:
	ricci/test_suite/cluster: vm_list.xml 

Log message:
	Add a call to list available VMs and provide their status (has to work around libvirt bz437216 for now)

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/make/defines.mk.in.diff?cvsroot=cluster&r1=1.10&r2=1.11
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/ClusterModule.cpp.diff?cvsroot=cluster&r1=1.11&r2=1.12
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/Makefile.diff?cvsroot=cluster&r1=1.20&r2=1.21
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/Virt.cpp.diff?cvsroot=cluster&r1=1.8&r2=1.9
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/Virt.h.diff?cvsroot=cluster&r1=1.6&r2=1.7
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/test_suite/cluster/vm_list.xml.diff?cvsroot=cluster&r1=NONE&r2=1.1

--- conga/ricci/make/defines.mk.in	2007/09/20 05:52:55	1.10
+++ conga/ricci/make/defines.mk.in	2008/03/14 19:58:12	1.11
@@ -33,7 +33,7 @@
 					`pkg-config --cflags libxml-2.0` \
 					`pkg-config --cflags openssl`
 CFLAGS			+= -Wall -Wno-unused -fPIC -O2 -g ${INCLUDE}
-CXXFLAGS		+= -Wall -Wno-unused -fPIC -O2 -g ${INCLUDE}
+CXXFLAGS		+= -Wall -Wno-unused -fPIC -O2 -g ${INCLUDE} -fpermissive
 LDFLAGS			+= -fPIC -lpthread \
 					`pkg-config --libs libxml-2.0` \
 					`pkg-config --libs openssl`
--- conga/ricci/modules/cluster/ClusterModule.cpp	2008/01/02 20:47:35	1.11
+++ conga/ricci/modules/cluster/ClusterModule.cpp	2008/03/14 19:58:12	1.12
@@ -50,6 +50,7 @@
 static VarMap set_xvm_key(const VarMap& args);
 static VarMap get_xvm_key(const VarMap& args);
 static VarMap generate_xvm_key(const VarMap& args);
+static VarMap list_vm(const VarMap& args);
 
 static ApiFcnMap build_fcn_map();
 
@@ -87,6 +88,7 @@
 	api_1_0["get_xvm_key"]			= get_xvm_key;
 	api_1_0["generate_xvm_key"]		= generate_xvm_key;
 	api_1_0["virt_guest"]			= virt_guest;
+	api_1_0["list_vm"]				= list_vm;
 
 
 	ApiFcnMap api_fcn_map;
@@ -233,6 +235,42 @@
 }
 
 VarMap
+list_vm(const VarMap& args)
+{
+	String hypervisor_uri = "";
+
+	try {
+		VarMap::const_iterator iter = args.find("hypervisor_uri");
+
+		if (iter != args.end())
+			hypervisor_uri = iter->second.get_string();
+	} catch ( String e ) {
+		throw APIerror(e);
+	}
+
+	if (!hypervisor_uri.size())
+		hypervisor_uri = String(DEFAULT_HV_URI);
+
+	std::map<String, String> vm_list = Virt::get_vm_list(hypervisor_uri);
+
+	list<XMLObject> ids_list;
+	for (	map<String,String>::iterator iter = vm_list.begin() ;
+			iter != vm_list.end();
+			iter++)
+	{
+		XMLObject id_xml("vm");
+		id_xml.set_attr("domain", String(iter->first));
+		id_xml.set_attr("status", String(iter->second));
+		ids_list.push_back(id_xml);
+	}
+
+	Variable var("vm_list", ids_list);
+	VarMap ret;
+	ret.insert(pair<String, Variable>(var.name(), var));
+	return ret;
+}
+
+VarMap
 delete_xvm_key(const VarMap& args) {
 	Virt::delete_xvm_key();
 	VarMap ret;
--- conga/ricci/modules/cluster/Makefile	2008/01/02 20:47:35	1.20
+++ conga/ricci/modules/cluster/Makefile	2008/03/14 19:58:12	1.21
@@ -27,6 +27,7 @@
 PARANOID=0
 INCLUDE += -I${top_srcdir}/common/
 CXXFLAGS += -DPARANOIA=$(PARANOID)
+LDFLAGS += -lvirt
 
 ifeq ($(PARANOID), 1)
 	LDFLAGS += ${top_srcdir}/common/paranoid/*.o
--- conga/ricci/modules/cluster/Virt.cpp	2008/01/02 20:47:35	1.8
+++ conga/ricci/modules/cluster/Virt.cpp	2008/03/14 19:58:12	1.9
@@ -17,15 +17,16 @@
 */
 
 extern "C" {
-#include <unistd.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <string.h>
-#include <errno.h>
+	#include <unistd.h>
+	#include <stdlib.h>
+	#include <fcntl.h>
+	#include <sys/stat.h>
+	#include <string.h>
+	#include <errno.h>
+	#include <libvirt/libvirt.h>
 
-#include "sys_util.h"
-#include "base64.h"
+	#include "sys_util.h"
+	#include "base64.h"
 }
 
 #include "Virt.h"
@@ -176,3 +177,86 @@
 		throw String("error retrieving key");
 	return (key_out);
 }
+
+map<String, String> Virt::get_vm_list(const String &hvURI) {
+	std::map<String, String> vm_list;
+	int i;
+	int ret;
+	int num_doms;
+	virConnectPtr con = NULL;
+
+	con = virConnectOpenReadOnly(hvURI.c_str());
+	if (con == NULL)
+		throw String("unable to connect to virtual machine manager");
+
+
+	num_doms = virConnectNumOfDefinedDomains(con);
+	if (num_doms < 1) {
+		virConnectClose(con);
+		throw String("Unable to get the number of defined domains");
+	}
+
+	if (num_doms > 0) {
+		char **dom = (char **) calloc(num_doms, sizeof(char *));
+		if (!dom) {
+			virConnectClose(con);
+			throw String("Out of memory");
+		}
+
+		ret = virConnectListDefinedDomains(con, dom, num_doms);
+		if (ret < 0) {
+			free(dom);
+			virConnectClose(con);
+			throw String("Unable to list defined domains");
+		}
+
+		for (i = 0 ; i < ret ; i++) {
+			if (dom[i] != NULL) {
+				vm_list.insert(
+					pair<String,String>(String(dom[i]), String("inactive")));
+				free(dom[i]);
+			}
+		}
+
+		free(dom);
+	}
+
+	/*
+	** As of libvirt-0.3.3-5, active domains aren't returned in the list
+	** of results from 'virConnectListDefinedDomains', so ask for them
+	** explicitly below.
+	*/
+	num_doms = virConnectNumOfDomains(con);
+	if (num_doms < 0) {
+		virConnectClose(con);
+		throw String("Unable to get the number of defined domains");
+	}
+
+	if (num_doms > 0) {
+		int *active_doms = (int *) calloc(sizeof(int), num_doms);
+		ret = virConnectListDomains(con, active_doms, num_doms);
+		if (ret > 0) {
+			for (i = 0 ; i < ret ; i++) {
+				const char *name;
+				if (active_doms[i] == 0) {
+					/* Skip dom0 */
+					continue;
+				}
+
+				virDomainPtr vdp = virDomainLookupByID(con, active_doms[i]);
+				if (vdp == NULL)
+					continue;
+
+				name = virDomainGetName(vdp);
+				if (name != NULL) {
+					vm_list.insert(
+						pair<String,String>(String(name), String("active")));
+				}
+			}
+		}
+		free(active_doms);
+	}
+
+	virConnectClose(con);
+	return vm_list;
+}
--- conga/ricci/modules/cluster/Virt.h	2008/01/02 20:47:35	1.6
+++ conga/ricci/modules/cluster/Virt.h	2008/03/14 19:58:12	1.7
@@ -20,6 +20,7 @@
 #define __CONGA_MODCLUSTER_VIRT_H
 
 #include "String.h"
+#include <map>
 
 #define XVM_KEY_PATH			"/etc/cluster/fence_xvm.key"
 #define XVM_KEY_MAX_SIZE		4096
@@ -27,9 +28,11 @@
 #define XVM_KEY_DEFAULT_SIZE	4096
 
 #define DMIDECODE_PATH			"/usr/sbin/dmidecode"
+#define DEFAULT_HV_URI			"xen:///"
 
 class Virt {
 	public:
+		static std::map<String, String> get_vm_list(const String& hvURI);
 		static bool virt_guest(void);
 		static bool delete_xvm_key(void);
 		static bool set_xvm_key(const char *key_base64);
/cvs/cluster/conga/ricci/test_suite/cluster/vm_list.xml,v  -->  standard output
revision 1.1
--- conga/ricci/test_suite/cluster/vm_list.xml
+++ -	2008-03-14 19:58:13.597973000 +0000
@@ -0,0 +1,13 @@
+<?xml version="1.0" ?>
+<ricci version="1.0" function="process_batch" async="false">
+<batch>
+
+<module name="cluster">
+<request sequence="1254" API_version="1.0">
+<function_call name="list_vm" />
+</request>
+</module>
+
+</batch>
+</ricci>
+



                 reply	other threads:[~2008-03-14 19:58 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=20080314195813.31724.qmail@sourceware.org \
    --to=rmccabe@sourceware.org \
    /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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.