From: rmccabe@sourceware.org <rmccabe@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] conga ./conga.spec.in.in ricci/modules/cluster ...
Date: 19 Mar 2008 14:45:35 -0000 [thread overview]
Message-ID: <20080319144535.18011.qmail@sourceware.org> (raw)
CVSROOT: /cvs/cluster
Module name: conga
Branch: RHEL5
Changes by: rmccabe at sourceware.org 2008-03-19 14:45:34
Modified files:
. : conga.spec.in.in
ricci/modules/cluster: ClusterModule.cpp Makefile Virt.cpp
Virt.h
Added files:
ricci/test_suite/cluster: vm_list.xml
Log message:
Fix bz206570: vm list from ricci
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/conga.spec.in.in.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.45.2.71&r2=1.45.2.72
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/ClusterModule.cpp.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.5.2.4&r2=1.5.2.5
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/Makefile.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.14.2.4&r2=1.14.2.5
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/Virt.cpp.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.1.2.3&r2=1.1.2.4
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/Virt.h.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.1.2.3&r2=1.1.2.4
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/test_suite/cluster/vm_list.xml.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=NONE&r2=1.1.2.1
--- conga/conga.spec.in.in 2008/03/12 15:13:12 1.45.2.71
+++ conga/conga.spec.in.in 2008/03/19 14:45:33 1.45.2.72
@@ -295,6 +295,7 @@
* Wed Feb 27 2008 Ryan McCabe <rmccabe@redhat.com> 0.12.0-6
- Fix bz434586 (Resource tree does not display multiple children of a parent correctly)
- Fix bz304931 (Rich Sybase resource agent configuration support)
+- Fix bz206570 (RFE: vm list from ricci)
* Tue Feb 12 2008 Ryan McCabe <rmccabe@redhat.com> 0.12.0-5
- Fix bz432533 (Do not attempt to install the cmirror package when shared storage is requested)
--- conga/ricci/modules/cluster/ClusterModule.cpp 2008/01/17 17:38:37 1.5.2.4
+++ conga/ricci/modules/cluster/ClusterModule.cpp 2008/03/19 14:45:33 1.5.2.5
@@ -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/17 17:38:37 1.14.2.4
+++ conga/ricci/modules/cluster/Makefile 2008/03/19 14:45:33 1.14.2.5
@@ -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/17 17:38:37 1.1.2.3
+++ conga/ricci/modules/cluster/Virt.cpp 2008/03/19 14:45:33 1.1.2.4
@@ -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,81 @@
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);
+ }
+
+ 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/17 17:38:37 1.1.2.3
+++ conga/ricci/modules/cluster/Virt.h 2008/03/19 14:45:33 1.1.2.4
@@ -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.2.1
--- conga/ricci/test_suite/cluster/vm_list.xml
+++ - 2008-03-19 14:45:35.123844000 +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>
+
next reply other threads:[~2008-03-19 14:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-19 14:45 rmccabe [this message]
-- strict thread matches above, loose matches on Subject: below --
2008-04-14 15:55 [Cluster-devel] conga ./conga.spec.in.in ricci/modules/cluster rmccabe
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=20080319144535.18011.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 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 NNTP newsgroup(s).