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],
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
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([])
--- /dev/null
+/* 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
+}
+
+
--- /dev/null
+/* 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_ */
+
+