]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Finish the integration of OpenNebula driver
authorDaniel Veillard <veillard@redhat.com>
Wed, 24 Jun 2009 17:32:56 +0000 (17:32 +0000)
committerDaniel Veillard <veillard@redhat.com>
Wed, 24 Jun 2009 17:32:56 +0000 (17:32 +0000)
* configure.in libvirt.spec.in src/Makefile.am
  src/opennebula/one_client.[ch] src/opennebula/one_conf.h
  src/opennebula/one_driver.[ch] : Finish the integration of OpenNebula,
  avoid dependancy on OpenNebula libraries, require xmlrpc-c-devel
  and build it by default, based on patch by Javier Fontan and DanB
  suggestions
Daniel

ChangeLog
configure.in
libvirt.spec.in
src/Makefile.am
src/opennebula/one_client.c [new file with mode: 0644]
src/opennebula/one_client.h [new file with mode: 0644]
src/opennebula/one_conf.h
src/opennebula/one_driver.c
src/opennebula/one_driver.h

index 2f3c87c495ad81d5540ac5f1f5353466d8a97ce2..96c42cb52f0aedac70f9e7167e9df7b7574774d0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Wed Jun 24 19:28:16 CEST 2009 Daniel Veillard <veillard@redhat.com>
+
+       * configure.in libvirt.spec.in src/Makefile.am
+         src/opennebula/one_client.[ch] src/opennebula/one_conf.h
+         src/opennebula/one_driver.[ch] : Finish the integration of OpenNebula,
+         avoid dependancy on OpenNebula libraries, require xmlrpc-c-devel
+         and build it by default, based on patch by Javier Fontan and DanB
+         suggestions
+
 Wed Jun 24 18:15:56 CEST 2009 Daniel Veillard <veillard@redhat.com>
 
        * src/opennebula/one_conf.c src/opennebula/one_driver.c: fix One
index 552c76157e7549a185fab1a52be90d2de9f8b1cc..2c20f5717c43eb21ed18b2fa66d3b1036b25d66f 100644 (file)
@@ -191,7 +191,7 @@ AC_ARG_WITH([vbox],
 AC_ARG_WITH([lxc],
 [  --with-lxc              add Linux Container support (on)],[],[with_lxc=yes])
 AC_ARG_WITH([one],
-[  --with-one              add ONE support (on)],[],[with_one=no])
+[  --with-one              add ONE support (on)],[],[with_one=check])
 AC_ARG_WITH([test],
 [  --with-test             add test driver support (on)],[],[with_test=yes])
 AC_ARG_WITH([remote],
@@ -420,11 +420,30 @@ AC_CHECK_HEADERS([linux/kvm.h])
 dnl OpenNebula driver Compilation setting
 dnl
 
-if test "$with_one" = "yes" ; then
- CFLAGS="$CFLAGS -I$ONE_LOCATION/include"
- ONE_LIBS="-L/usr/local/lib -lxmlrpc_client++ -lxmlrpc -lxmlrpc_util -lxmlrpc_xmlparse -lxmlrpc_xmltok -lxmlrpc++ -lxmlrpc_client -L$ONE_LOCATION/lib -loneapi"
- AC_SUBST([ONE_LIBS])
+XMLRPC_REQUIRED=1.14.0
+
+XMLRPC_CFLAGS=
+XMLRPC_LIBS=
+if test "x$with_one" = "xyes" -o "x$with_one" = "xcheck"; then
+    PKG_CHECK_MODULES(XMLRPC, xmlrpc_client >= $XMLRPC_REQUIRED,
+      [with_one=yes], [
+      if test "x$with_one" = "xcheck" ; then
+          with_one=no
+      else
+          AC_MSG_ERROR(
+            [You must install XMLRPC-C >= $XMLRPC_REQUIRED to compile libvirt ONE driver])
+      fi
+    ])
+    if test "x$with_one" = "xyes" ; then
+        AC_DEFINE_UNQUOTED([HAVE_XMLRPC], 1,
+          [whether One is used to broadcast server presence])
+    fi
 fi
+AM_CONDITIONAL([HAVE_XMLRPC], [test "x$with_one" = "xyes"])
+AM_CONDITIONAL([WITH_ONE], [test "x$with_one" = "xyes"])
+AC_SUBST([XMLRPC_CFLAGS])
+AC_SUBST([XMLRPC_LIBS])
+
 
 dnl Need to test if pkg-config exists
 PKG_PROG_PKG_CONFIG
@@ -1493,6 +1512,11 @@ AC_MSG_NOTICE([   netcf: $NETCF_CFLAGS $NETCF_LIBS])
 else
 AC_MSG_NOTICE([   netcf: no])
 fi
+if test "$with_one" = "yes" ; then
+AC_MSG_NOTICE([  xmlrpc: $XMLRPC_CFLAGS $XMLRPC_LIBS])
+else
+AC_MSG_NOTICE([  xmlrpc: no])
+fi
 AC_MSG_NOTICE([])
 AC_MSG_NOTICE([Test suite])
 AC_MSG_NOTICE([])
index 1e8a8ef192761ce10fe365331a6f717d53236ea9..6ba5405bc2d70d5d214553a4e21db6e3f30bb806 100644 (file)
@@ -11,6 +11,7 @@
 %define with_python        0%{!?_without_python:1}
 %define with_libvirtd      0%{!?_without_libvirtd:1}
 %define with_uml           0%{!?_without_uml:1}
+%define with_one           0%{!?_without_uml:1}
 %define with_network       0%{!?_without_network:1}
 %define with_storage_fs    0%{!?_without_storage_fs:1}
 %define with_storage_lvm   0%{!?_without_storage_lvm:1}
 
 #
 # If building on RHEL switch on the specific support
-# for the specific Xen version
 #
 %if 0%{?fedora}
-%define with_rhel5 0
+%define with_rhel5  0
 %else
-%define with_rhel5 1
+%define with_rhel5  1
 %define with_polkit 0
+%define with_one    0
 %endif
 
 
@@ -111,6 +112,9 @@ Requires: parted
 %if %{with_xen}
 BuildRequires: xen-devel
 %endif
+%if %{with_one}
+BuildRequires: xmlrpc-c-devel >= 1.14.0
+%endif
 BuildRequires: libxml2-devel
 BuildRequires: xhtml1-dtds
 BuildRequires: readline-devel
@@ -243,6 +247,10 @@ of recent versions of Linux (and other OSes).
 %define _without_uml --without-uml
 %endif
 
+%if ! %{with_one}
+%define _without_one --without-one
+%endif
+
 %if %{with_rhel5}
 %define _with_rhel5_api --with-rhel5-api
 %endif
@@ -281,6 +289,7 @@ of recent versions of Linux (and other OSes).
            %{?_without_python} \
            %{?_without_libvirtd} \
            %{?_without_uml} \
+           %{?_without_one} \
            %{?_without_network} \
            %{?_with_rhel5_api} \
            %{?_without_storage_fs} \
index f65e7ad08c813853340737a4f80e06342213dd7b..83d083340ddc0b613ed07bddbb3da4259e8ff6ac 100644 (file)
@@ -149,7 +149,9 @@ ONE_DRIVER_SOURCES =                                        \
                ./opennebula/one_conf.c                 \
                ./opennebula/one_conf.h                 \
                ./opennebula/one_driver.c               \
-               ./opennebula/one_driver.h
+               ./opennebula/one_driver.h               \
+               ./opennebula/one_client.c               \
+               ./opennebula/one_client.h
 
 NETWORK_DRIVER_SOURCES =                                       \
                network_driver.h network_driver.c
@@ -355,6 +357,7 @@ noinst_LTLIBRARIES += libvirt_driver_one.la
 # Stateful, so linked to daemon instead
 #libvirt_la_LIBADD  += libvirt_driver_one.la
 endif
+libvirt_driver_one_la_CFLAGS = $(ONE_LIBS)
 libvirt_driver_one_la_LDFLAGS = $(ONE_LIBS)
 #libvirt_driver_one_la_CFLAGS  = "-DWITH_ONE"
 if WITH_DRIVER_MODULES
diff --git a/src/opennebula/one_client.c b/src/opennebula/one_client.c
new file mode 100644 (file)
index 0000000..6d0fc6c
--- /dev/null
@@ -0,0 +1,249 @@
+/* Copyright 2002-2009, Distributed Systems Architecture Group, Universidad
+ * Complutense de Madrid (dsa-research.org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ */
+
+#include <config.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include "one_client.h"
+
+oneClient one_client;
+
+void c_oneStart()
+{
+    xmlrpc_env_init(&one_client.env);
+    xmlrpc_client_init2(&one_client.env, XMLRPC_CLIENT_NO_FLAGS,
+        "OpenNebula API Client", "1.2", NULL, 0);
+
+    one_client.error=0;
+
+#ifdef ONED_PORT
+    one_client.url=(char *)malloc(64);
+    snprintf(one_client.url, 63, "http://localhost:%d/RPC2", ONED_PORT);
+#else
+    one_client.url=(char *)"http://localhost:2633/RPC2";
+#endif
+
+    one_client.session=(char *)"one-session";
+};
+
+
+int c_oneReturnCode(xmlrpc_value *resultP);
+
+int c_oneReturnCode(xmlrpc_value *resultP)
+{
+    int return_code;
+    char *return_string;
+
+    xmlrpc_decompose_value(&one_client.env, resultP, "(bs)",
+        &return_code, &return_string);
+
+    if( return_code )
+    {
+        xmlrpc_DECREF(resultP);
+        free(return_string);
+        return 0;
+    }
+    else
+    {
+        free(one_client.error);
+
+        one_client.error=return_string;
+        return -1;
+    }
+}
+
+int c_oneDeploy(int vmid, int hid)
+{
+    xmlrpc_value *resultP;
+
+    resultP = xmlrpc_client_call(&one_client.env, one_client.url,
+        "one.vmdeploy", "(sii)", one_client.session, (xmlrpc_int32)vmid,
+        (xmlrpc_int32)hid);
+
+    return c_oneReturnCode(resultP);
+}
+
+int c_oneMigrate(int vmid, int hid, int flag)
+{
+    xmlrpc_value *resultP;
+
+    resultP = xmlrpc_client_call(&one_client.env, one_client.url,
+        "one.vmmigrate", "(siib)", one_client.session, (xmlrpc_int32)vmid,
+        (xmlrpc_int32)hid,
+        (xmlrpc_bool)flag);
+
+    return c_oneReturnCode(resultP);
+}
+
+int c_oneAllocate(char* template_file)
+{
+    int file;
+    int size;
+    int bytes_read;
+    char *file_text;
+    int return_code;
+
+    file=open(template_file, O_RDONLY);
+    size=lseek(file, 0, SEEK_END);
+    lseek(file, 0, SEEK_SET);
+
+    file_text=(char *)malloc(size+1);
+    bytes_read=read(file, file_text, size);
+    close(file);
+
+    if(bytes_read==size) {
+        file_text[size]=0;
+
+        return_code=c_oneAllocateTemplate(file_text);
+        free(file_text);
+
+        return return_code;
+    } else {
+        free(file_text);
+        return -1;
+    }
+}
+
+int c_oneAllocateTemplate(char* vm_template)
+{
+    xmlrpc_value *resultP;
+    xmlrpc_value *valueP;
+    int return_code;
+    char *return_string;
+    int vmid;
+
+
+    resultP = xmlrpc_client_call(&one_client.env, one_client.url,
+        "one.vmallocate", "(ss)", one_client.session, vm_template);
+
+    xmlrpc_array_read_item(&one_client.env, resultP, 0, &valueP);
+    xmlrpc_read_bool(&one_client.env, valueP, &return_code);
+
+    if( return_code )
+    {
+        xmlrpc_DECREF(valueP);
+        xmlrpc_array_read_item(&one_client.env, resultP, 1, &valueP);
+        xmlrpc_read_int(&one_client.env, valueP, &vmid);
+
+        xmlrpc_DECREF(valueP);
+        xmlrpc_DECREF(resultP);
+
+        return vmid;
+    }
+    else
+    {
+        xmlrpc_DECREF(valueP);
+        xmlrpc_array_read_item(&one_client.env, resultP, 1, &valueP);
+        xmlrpc_read_string(&one_client.env, valueP,
+            (const char **)&return_string);
+
+        xmlrpc_DECREF(valueP);
+        xmlrpc_DECREF(resultP);
+
+        free(one_client.error);
+
+        one_client.error=return_string;
+        return -1;
+    }
+}
+
+int c_oneAction(int vmid, char* action)
+{
+    xmlrpc_value *resultP;
+
+    resultP = xmlrpc_client_call(&one_client.env, one_client.url,
+        "one.vmaction", "(ssi)", one_client.session, action,
+        (xmlrpc_int32)vmid);
+
+    return c_oneReturnCode(resultP);
+}
+
+int c_oneShutdown(int vmid)
+{
+    return c_oneAction(vmid, (char *)"shutdown");
+}
+
+int c_oneSuspend(int vmid)
+{
+    return c_oneAction(vmid, (char *)"suspend");
+}
+
+int c_oneStop(int vmid)
+{
+    return c_oneAction(vmid, (char *)"stop");
+}
+
+int c_oneResume(int vmid)
+{
+    return c_oneAction(vmid, (char *)"resume");
+}
+
+int c_oneCancel(int vmid)
+{
+    return c_oneAction(vmid, (char *)"cancel");
+}
+
+int c_oneFinalize(int vmid)
+{
+    return c_oneAction(vmid, (char *)"finalize");
+}
+
+int c_oneVmInfo(int vmid, char* ret_info,int length)
+{
+    xmlrpc_value *resultP;
+    int return_code;
+    char *return_string;
+
+    resultP = xmlrpc_client_call(&one_client.env, one_client.url,
+        "one.vmget_info", "(si)", one_client.session, vmid);
+
+    xmlrpc_decompose_value(&one_client.env, resultP, "(bs)",
+        &return_code, &return_string);
+
+    if( return_code )
+    {
+        strncpy(ret_info, return_string, length-1);
+
+        xmlrpc_DECREF(resultP);
+        free(return_string);
+
+        return 0;
+    }
+    else
+    {
+        xmlrpc_DECREF(resultP);
+        free(return_string);
+
+        return -1;
+    }
+}
+
+void c_oneFree()
+{
+    xmlrpc_env_clean(&one_client.env);
+    xmlrpc_client_cleanup();
+#ifdef ONE_PORT
+    free(one_client.url);
+#endif
+}
+
+
diff --git a/src/opennebula/one_client.h b/src/opennebula/one_client.h
new file mode 100644 (file)
index 0000000..238d1a6
--- /dev/null
@@ -0,0 +1,66 @@
+/* Copyright 2002-2009, Distributed Systems Architecture Group, Universidad
+ * Complutense de Madrid (dsa-research.org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ */
+
+#ifndef ONE_CLIENT_H_
+#define ONE_CLIENT_H_
+
+#include <xmlrpc-c/base.h>
+#include <xmlrpc-c/client.h>
+
+struct _oneClient {
+    xmlrpc_env env;
+    char *url;
+    char *session;
+    char *error;
+};
+
+typedef struct _oneClient oneClient;
+typedef oneClient *oneClientPtr;
+
+void c_oneStart(void);
+
+int c_oneDeploy(int vmid, int hid);
+
+int c_oneMigrate(int vmid, int hid, int flag);
+
+int c_oneAllocate(char* template_file);
+
+int c_oneAllocateTemplate(char* vm_template);
+
+int c_oneAction(int vmid,char* action);
+
+int c_oneShutdown(int vmid);
+
+int c_oneSuspend(int vmid);
+
+int c_oneStop(int vmid);
+
+int c_oneResume(int vmid);
+
+int c_oneCancel(int vmid);
+
+int c_oneFinalize(int vmid);
+
+int c_oneVmInfo(int vmid, char* ret_info,int leng);
+
+void c_oneFree(void);
+
+
+#endif /* ONE_CLIENT_H_ */
+
+
index b80922099e65a09e8ca912b3d155fffb3aa7d9cf..06917f4a7d32bbe42cc0a0ddc2f7b6a7d75ea28a 100644 (file)
@@ -27,6 +27,7 @@
 #include "domain_conf.h"
 #include "capabilities.h"
 #include "threads.h"
+#include "one_client.h"
 
 struct one_driver{
     virMutex lock;
index 5e24dbf6cd0742a21cac1f1bbd4fe96deb0d8091..0950458a302838c6ba3acf6611d786736712c810 100644 (file)
@@ -45,7 +45,7 @@
 
 #define VIR_FROM_THIS VIR_FROM_ONE
 
-static int oneStartup(void);
+static int oneStartup(int privileged);
 static int oneShutdown(void);
 static int oneActive(void);
 
@@ -628,7 +628,7 @@ return_point:
     return ret;
 };
 
-static int oneStartup(void){
+static int oneStartup(int privileged ATTRIBUTE_UNUSED){
 
     if (VIR_ALLOC(one_driver) < 0) {
         return -1;
index 393edc6259ec46ab3dd410c3dcf75447053b58d3..e30a59f9b297a4cd5c73dc246c2d31c4251d519a 100644 (file)
@@ -23,7 +23,7 @@
 #define ONE_DRIVER_H
 
 #include <config.h>
-#include <OneClient.h>
+#include "one_client.h"
 
 int oneRegister(void);