Finish the integration of OpenNebula driver

* 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
This commit is contained in:
Daniel Veillard 2009-06-24 17:32:56 +00:00
parent 31bd8cb6d0
commit b547201561
9 changed files with 373 additions and 12 deletions

View File

@ -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

View 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([])

View 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}
@ -40,13 +41,13 @@
#
# 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} \

View 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

249
src/opennebula/one_client.c Normal file
View File

@ -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
}

View File

@ -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_ */

View File

@ -27,6 +27,7 @@
#include "domain_conf.h"
#include "capabilities.h"
#include "threads.h"
#include "one_client.h"
struct one_driver{
virMutex lock;

View 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;

View File

@ -23,7 +23,7 @@
#define ONE_DRIVER_H
#include <config.h>
#include <OneClient.h>
#include "one_client.h"
int oneRegister(void);