From 373f00b6e020b465bc6bd39c65cc52e8cc7c8221 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Mon, 22 Nov 2010 13:14:37 +0100 Subject: [PATCH 01/28] bug #394: added init scripts created by Dan Yocum and Damien Raude-Morvan --- share/etc/init.d/one.debian | 95 ++++++++++++++++ share/etc/init.d/one.ubuntu | 95 ++++++++++++++++ share/etc/init.d/oned.centos | 195 +++++++++++++++++++++++++++++++++ share/etc/init.d/oned.opensuse | 195 +++++++++++++++++++++++++++++++++ 4 files changed, 580 insertions(+) create mode 100755 share/etc/init.d/one.debian create mode 100755 share/etc/init.d/one.ubuntu create mode 100755 share/etc/init.d/oned.centos create mode 100755 share/etc/init.d/oned.opensuse diff --git a/share/etc/init.d/one.debian b/share/etc/init.d/one.debian new file mode 100755 index 0000000000..fe34910279 --- /dev/null +++ b/share/etc/init.d/one.debian @@ -0,0 +1,95 @@ +#! /bin/sh +### BEGIN INIT INFO +# Provides: opennebula +# Required-Start: $remote_fs +# Required-Stop: $remote_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: OpenNebula init script +# Description: OpenNebula cloud initialisation script +### END INIT INFO + +# Author: Soren Hansen + +PATH=/sbin:/usr/sbin:/bin:/usr/bin +DESC="OpenNebula cloud" +NAME=one +DAEMON=/usr/bin/$NAME +DAEMON_ARGS="" +PIDFILE=/var/run/$NAME.pid +SCRIPTNAME=/etc/init.d/$NAME + +# Exit if the package is not installed +[ -x "$DAEMON" ] || exit 0 + +# Load the VERBOSE setting and other rcS variables +. /lib/init/vars.sh + +# Define LSB log_* functions. +# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. +. /lib/lsb/init-functions + +# +# Function that starts the daemon/service +# +do_start() +{ + mkdir -p /var/run/one /var/lock/one + chown oneadmin /var/run/one /var/lock/one + su oneadmin -s /bin/sh -c 'one start' +} + +# +# Function that stops the daemon/service +# +do_stop() +{ + su oneadmin -s /bin/sh -c 'one stop' +} + +case "$1" in + start) + [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" + do_start + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + stop) + [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" + do_stop + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + restart|force-reload) + # + # If the "reload" option is implemented then remove the + # 'force-reload' alias + # + log_daemon_msg "Restarting $DESC" "$NAME" + do_stop + case "$?" in + 0|1) + do_start + case "$?" in + 0) log_end_msg 0 ;; + 1) log_end_msg 1 ;; # Old process is still running + *) log_end_msg 1 ;; # Failed to start + esac + ;; + *) + # Failed to stop + log_end_msg 1 + ;; + esac + ;; + *) + echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 + exit 3 + ;; +esac + +: diff --git a/share/etc/init.d/one.ubuntu b/share/etc/init.d/one.ubuntu new file mode 100755 index 0000000000..fe34910279 --- /dev/null +++ b/share/etc/init.d/one.ubuntu @@ -0,0 +1,95 @@ +#! /bin/sh +### BEGIN INIT INFO +# Provides: opennebula +# Required-Start: $remote_fs +# Required-Stop: $remote_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: OpenNebula init script +# Description: OpenNebula cloud initialisation script +### END INIT INFO + +# Author: Soren Hansen + +PATH=/sbin:/usr/sbin:/bin:/usr/bin +DESC="OpenNebula cloud" +NAME=one +DAEMON=/usr/bin/$NAME +DAEMON_ARGS="" +PIDFILE=/var/run/$NAME.pid +SCRIPTNAME=/etc/init.d/$NAME + +# Exit if the package is not installed +[ -x "$DAEMON" ] || exit 0 + +# Load the VERBOSE setting and other rcS variables +. /lib/init/vars.sh + +# Define LSB log_* functions. +# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. +. /lib/lsb/init-functions + +# +# Function that starts the daemon/service +# +do_start() +{ + mkdir -p /var/run/one /var/lock/one + chown oneadmin /var/run/one /var/lock/one + su oneadmin -s /bin/sh -c 'one start' +} + +# +# Function that stops the daemon/service +# +do_stop() +{ + su oneadmin -s /bin/sh -c 'one stop' +} + +case "$1" in + start) + [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" + do_start + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + stop) + [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" + do_stop + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + restart|force-reload) + # + # If the "reload" option is implemented then remove the + # 'force-reload' alias + # + log_daemon_msg "Restarting $DESC" "$NAME" + do_stop + case "$?" in + 0|1) + do_start + case "$?" in + 0) log_end_msg 0 ;; + 1) log_end_msg 1 ;; # Old process is still running + *) log_end_msg 1 ;; # Failed to start + esac + ;; + *) + # Failed to stop + log_end_msg 1 + ;; + esac + ;; + *) + echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 + exit 3 + ;; +esac + +: diff --git a/share/etc/init.d/oned.centos b/share/etc/init.d/oned.centos new file mode 100755 index 0000000000..883d29ac83 --- /dev/null +++ b/share/etc/init.d/oned.centos @@ -0,0 +1,195 @@ +#!/bin/bash +# +# oned This shell script takes care of starting and stopping +# the Opennebula subsystem (oned). +# +# chkconfig: - 65 35 +# description: oned cloud server. +# processname: oned +# config: /etc/one/oned.conf +# pidfile: /var/run/one/oned.pid + +# Source function library. +. /etc/rc.d/init.d/functions + +# Source networking configuration. +. /etc/sysconfig/network + +# Set the ONE_LOCATION +# ONE_LOCATION="/srv/cloud/one" +ONE_LOCATION="" + +prog="oned" + +if [ -z "$ONE_LOCATION" ]; then + ONE_PID=/var/run/one/oned.pid + ONE_SCHEDPID=/var/run/one/sched.pid + ONE_CONF=/etc/one/oned.conf + ONE_DB=/var/lib/one/one.db + + ONED=/usr/bin/oned + ONE_SCHEDULER=/usr/bin/mm_sched + + LOCK_FILE=/var/lock/one/one +else + ONE_PID=$ONE_LOCATION/var/oned.pid + ONE_SCHEDPID=$ONE_LOCATION/var/sched.pid + ONE_CONF=$ONE_LOCATION/etc/oned.conf + ONE_DB=$ONE_LOCATION/var/one.db + + ONED=$ONE_LOCATION/bin/oned + ONE_SCHEDULER=$ONE_LOCATION/bin/mm_sched + + LOCK_FILE=$ONE_LOCATION/var/.lock +fi + +setup() +{ + PORT=`cat $ONE_CONF | grep ^PORT= | cut -d= -f2` + + if [ $? -ne 0 ]; then + echo "Can not find PORT in $ONE_CONF." + exit 1 + fi + + if [ -f $LOCK_FILE ]; then + if [ -f $ONE_PID ]; then + ONEPID=`cat $ONE_PID` + ps $ONEPID > /dev/null 2>&1 + if [ $? -eq 0 ]; then + echo "ONE is still running (PID:$ONEPID). Please try 'one stop' first." + exit 1 + fi + fi + if [ -f $ONE_SCHEDPID ]; then + ONESCHEDPID=`cat $ONE_SCHEDPID` + ps $ONESCHEDPID > /dev/null 2>&1 + if [ $? -eq 0 ]; then + echo "The scheduler is still running (PID:$ONEPID). Please try 'one stop' first." + exit 1 + fi + fi + echo "Stale .lock detected. Erasing it." + rm $LOCK_FILE + fi +} + +start() +{ + if [ ! -x "$ONED" ]; then + echo "Can not find $ONED." + exit 1 + fi + + if [ ! -x "$ONE_SCHEDULER" ]; then + echo "Can not find $ONE_SCHEDULER." + exit 1 + fi + + if [ ! -f "$ONE_DB" ]; then + if [ -f "$HOME/.one/one_auth" ]; then + . $HOME/.one/one_auth + elif [ -z "$ONE_AUTH" ]; then + echo "You should have ONE_AUTH set the first time you start" + echo "OpenNebula as it is used to set the credentials for" + echo "the adminitrator user." + exit 1 + fi + fi + + # Start the one daemon + daemon --user=oneadmin $ONED -f 2>&1 & + + LASTRC=$? + LASTPID=$! + + if [ $LASTRC -ne 0 ]; then + echo "Error executing $ONED" + exit 1 + else + echo $LASTPID > $ONE_PID + fi + + sleep 1 + ps $LASTPID > /dev/null 2>&1 + + if [ $? -ne 0 ]; then + echo "Error executing $ONED." + exit 1 + fi + + # Start the scheduler + # The following command line arguments are supported by mm_shed: + # [-p port] to connect to oned - default: 2633 + # [-t timer] seconds between two scheduling actions - default: 30 + # [-m machines limit] max number of VMs managed in each scheduling action + # - default: 300 + # [-d dispatch limit] max number of VMs dispatched in each scheduling action + # - default: 30 + # [-h host dispatch] max number of VMs dispatched to a given host in each + # scheduling action - default: 1 + + daemon --user=oneadmin $ONE_SCHEDULER -p $PORT -t 30 -m 300 -d 30 -h 1& + + LASTRC=$? + LASTPID=$! + + if [ $LASTRC -ne 0 ]; then + echo "Error executing $ONE_SCHEDULER" + exit 1 + else + echo $LASTPID > $ONE_SCHEDPID + fi + + echo "oned and scheduler started" +} + +# +# Function that stops the daemon/service +# +stop() +{ + if [ ! -f $ONE_PID ]; then + echo "Couldn't find oned process pid." + exit 1 + fi + + if [ ! -f $ONE_SCHEDPID ]; then + echo "Couldn't find scheduler process pid." + exit 1 + fi + + # Kill the one daemon + + killproc oned + + # Kill the scheduler + + killproc mm_sched + + # Remove pid files + + rm -f $ONE_PID > /dev/null 2>&1 + rm -f $ONE_SCHEDPID > /dev/null 2>&1 + + echo "oned and scheduler stopped" +} + + +case "$1" in + start) + setup + start + ;; + stop) + stop + ;; + status) + status oned + status mm_sched + ;; + *) + echo "Usage: one {start|stop|status}" >&2 + exit 3 + ;; +esac diff --git a/share/etc/init.d/oned.opensuse b/share/etc/init.d/oned.opensuse new file mode 100755 index 0000000000..883d29ac83 --- /dev/null +++ b/share/etc/init.d/oned.opensuse @@ -0,0 +1,195 @@ +#!/bin/bash +# +# oned This shell script takes care of starting and stopping +# the Opennebula subsystem (oned). +# +# chkconfig: - 65 35 +# description: oned cloud server. +# processname: oned +# config: /etc/one/oned.conf +# pidfile: /var/run/one/oned.pid + +# Source function library. +. /etc/rc.d/init.d/functions + +# Source networking configuration. +. /etc/sysconfig/network + +# Set the ONE_LOCATION +# ONE_LOCATION="/srv/cloud/one" +ONE_LOCATION="" + +prog="oned" + +if [ -z "$ONE_LOCATION" ]; then + ONE_PID=/var/run/one/oned.pid + ONE_SCHEDPID=/var/run/one/sched.pid + ONE_CONF=/etc/one/oned.conf + ONE_DB=/var/lib/one/one.db + + ONED=/usr/bin/oned + ONE_SCHEDULER=/usr/bin/mm_sched + + LOCK_FILE=/var/lock/one/one +else + ONE_PID=$ONE_LOCATION/var/oned.pid + ONE_SCHEDPID=$ONE_LOCATION/var/sched.pid + ONE_CONF=$ONE_LOCATION/etc/oned.conf + ONE_DB=$ONE_LOCATION/var/one.db + + ONED=$ONE_LOCATION/bin/oned + ONE_SCHEDULER=$ONE_LOCATION/bin/mm_sched + + LOCK_FILE=$ONE_LOCATION/var/.lock +fi + +setup() +{ + PORT=`cat $ONE_CONF | grep ^PORT= | cut -d= -f2` + + if [ $? -ne 0 ]; then + echo "Can not find PORT in $ONE_CONF." + exit 1 + fi + + if [ -f $LOCK_FILE ]; then + if [ -f $ONE_PID ]; then + ONEPID=`cat $ONE_PID` + ps $ONEPID > /dev/null 2>&1 + if [ $? -eq 0 ]; then + echo "ONE is still running (PID:$ONEPID). Please try 'one stop' first." + exit 1 + fi + fi + if [ -f $ONE_SCHEDPID ]; then + ONESCHEDPID=`cat $ONE_SCHEDPID` + ps $ONESCHEDPID > /dev/null 2>&1 + if [ $? -eq 0 ]; then + echo "The scheduler is still running (PID:$ONEPID). Please try 'one stop' first." + exit 1 + fi + fi + echo "Stale .lock detected. Erasing it." + rm $LOCK_FILE + fi +} + +start() +{ + if [ ! -x "$ONED" ]; then + echo "Can not find $ONED." + exit 1 + fi + + if [ ! -x "$ONE_SCHEDULER" ]; then + echo "Can not find $ONE_SCHEDULER." + exit 1 + fi + + if [ ! -f "$ONE_DB" ]; then + if [ -f "$HOME/.one/one_auth" ]; then + . $HOME/.one/one_auth + elif [ -z "$ONE_AUTH" ]; then + echo "You should have ONE_AUTH set the first time you start" + echo "OpenNebula as it is used to set the credentials for" + echo "the adminitrator user." + exit 1 + fi + fi + + # Start the one daemon + daemon --user=oneadmin $ONED -f 2>&1 & + + LASTRC=$? + LASTPID=$! + + if [ $LASTRC -ne 0 ]; then + echo "Error executing $ONED" + exit 1 + else + echo $LASTPID > $ONE_PID + fi + + sleep 1 + ps $LASTPID > /dev/null 2>&1 + + if [ $? -ne 0 ]; then + echo "Error executing $ONED." + exit 1 + fi + + # Start the scheduler + # The following command line arguments are supported by mm_shed: + # [-p port] to connect to oned - default: 2633 + # [-t timer] seconds between two scheduling actions - default: 30 + # [-m machines limit] max number of VMs managed in each scheduling action + # - default: 300 + # [-d dispatch limit] max number of VMs dispatched in each scheduling action + # - default: 30 + # [-h host dispatch] max number of VMs dispatched to a given host in each + # scheduling action - default: 1 + + daemon --user=oneadmin $ONE_SCHEDULER -p $PORT -t 30 -m 300 -d 30 -h 1& + + LASTRC=$? + LASTPID=$! + + if [ $LASTRC -ne 0 ]; then + echo "Error executing $ONE_SCHEDULER" + exit 1 + else + echo $LASTPID > $ONE_SCHEDPID + fi + + echo "oned and scheduler started" +} + +# +# Function that stops the daemon/service +# +stop() +{ + if [ ! -f $ONE_PID ]; then + echo "Couldn't find oned process pid." + exit 1 + fi + + if [ ! -f $ONE_SCHEDPID ]; then + echo "Couldn't find scheduler process pid." + exit 1 + fi + + # Kill the one daemon + + killproc oned + + # Kill the scheduler + + killproc mm_sched + + # Remove pid files + + rm -f $ONE_PID > /dev/null 2>&1 + rm -f $ONE_SCHEDPID > /dev/null 2>&1 + + echo "oned and scheduler stopped" +} + + +case "$1" in + start) + setup + start + ;; + stop) + stop + ;; + status) + status oned + status mm_sched + ;; + *) + echo "Usage: one {start|stop|status}" >&2 + exit 3 + ;; +esac From 010a26d5cb5ebc9bc3b5f5c461b8248c83d80e62 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Mon, 22 Nov 2010 16:24:30 +0100 Subject: [PATCH 02/28] bug #394: changed chkconfig levels --- share/etc/init.d/oned.centos | 2 +- share/etc/init.d/oned.opensuse | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/share/etc/init.d/oned.centos b/share/etc/init.d/oned.centos index 883d29ac83..fa66e4a13b 100755 --- a/share/etc/init.d/oned.centos +++ b/share/etc/init.d/oned.centos @@ -3,7 +3,7 @@ # oned This shell script takes care of starting and stopping # the Opennebula subsystem (oned). # -# chkconfig: - 65 35 +# chkconfig: 2345 65 35 # description: oned cloud server. # processname: oned # config: /etc/one/oned.conf diff --git a/share/etc/init.d/oned.opensuse b/share/etc/init.d/oned.opensuse index 883d29ac83..fa66e4a13b 100755 --- a/share/etc/init.d/oned.opensuse +++ b/share/etc/init.d/oned.opensuse @@ -3,7 +3,7 @@ # oned This shell script takes care of starting and stopping # the Opennebula subsystem (oned). # -# chkconfig: - 65 35 +# chkconfig: 2345 65 35 # description: oned cloud server. # processname: oned # config: /etc/one/oned.conf From 6b6390667e4d8fbd7169ba1f70d6f768e3160e72 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Mon, 22 Nov 2010 18:01:50 +0100 Subject: [PATCH 03/28] bug #394: created opensuse init script from opensuse's skeleton --- share/etc/init.d/oned.opensuse | 268 +++++++++++---------------------- 1 file changed, 85 insertions(+), 183 deletions(-) diff --git a/share/etc/init.d/oned.opensuse b/share/etc/init.d/oned.opensuse index fa66e4a13b..1553b6a540 100755 --- a/share/etc/init.d/oned.opensuse +++ b/share/etc/init.d/oned.opensuse @@ -1,195 +1,97 @@ -#!/bin/bash -# -# oned This shell script takes care of starting and stopping -# the Opennebula subsystem (oned). -# -# chkconfig: 2345 65 35 -# description: oned cloud server. -# processname: oned -# config: /etc/one/oned.conf -# pidfile: /var/run/one/oned.pid +#!/bin/sh -# Source function library. -. /etc/rc.d/init.d/functions +# -------------------------------------------------------------------------- # +# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # -# Source networking configuration. -. /etc/sysconfig/network +### BEGIN INIT INFO +# Provides: ONE +# Required-Start: $remote_fs +# Required-Stop: $remote_fs +# Default-Start: 3 5 +# Default-Stop: 0 1 2 6 +# Short-Description: OpenNebula Init Script +# Description: OpenNebula Init Script +### END INIT INFO -# Set the ONE_LOCATION -# ONE_LOCATION="/srv/cloud/one" -ONE_LOCATION="" +ONE_BIN=/usr/bin/one -prog="oned" - -if [ -z "$ONE_LOCATION" ]; then - ONE_PID=/var/run/one/oned.pid - ONE_SCHEDPID=/var/run/one/sched.pid - ONE_CONF=/etc/one/oned.conf - ONE_DB=/var/lib/one/one.db - - ONED=/usr/bin/oned - ONE_SCHEDULER=/usr/bin/mm_sched - - LOCK_FILE=/var/lock/one/one -else - ONE_PID=$ONE_LOCATION/var/oned.pid - ONE_SCHEDPID=$ONE_LOCATION/var/sched.pid - ONE_CONF=$ONE_LOCATION/etc/oned.conf - ONE_DB=$ONE_LOCATION/var/one.db - - ONED=$ONE_LOCATION/bin/oned - ONE_SCHEDULER=$ONE_LOCATION/bin/mm_sched - - LOCK_FILE=$ONE_LOCATION/var/.lock -fi - -setup() -{ - PORT=`cat $ONE_CONF | grep ^PORT= | cut -d= -f2` - - if [ $? -ne 0 ]; then - echo "Can not find PORT in $ONE_CONF." - exit 1 - fi - - if [ -f $LOCK_FILE ]; then - if [ -f $ONE_PID ]; then - ONEPID=`cat $ONE_PID` - ps $ONEPID > /dev/null 2>&1 - if [ $? -eq 0 ]; then - echo "ONE is still running (PID:$ONEPID). Please try 'one stop' first." - exit 1 - fi - fi - if [ -f $ONE_SCHEDPID ]; then - ONESCHEDPID=`cat $ONE_SCHEDPID` - ps $ONESCHEDPID > /dev/null 2>&1 - if [ $? -eq 0 ]; then - echo "The scheduler is still running (PID:$ONEPID). Please try 'one stop' first." - exit 1 - fi - fi - echo "Stale .lock detected. Erasing it." - rm $LOCK_FILE - fi -} - -start() -{ - if [ ! -x "$ONED" ]; then - echo "Can not find $ONED." - exit 1 - fi - - if [ ! -x "$ONE_SCHEDULER" ]; then - echo "Can not find $ONE_SCHEDULER." - exit 1 - fi - - if [ ! -f "$ONE_DB" ]; then - if [ -f "$HOME/.one/one_auth" ]; then - . $HOME/.one/one_auth - elif [ -z "$ONE_AUTH" ]; then - echo "You should have ONE_AUTH set the first time you start" - echo "OpenNebula as it is used to set the credentials for" - echo "the adminitrator user." - exit 1 - fi - fi - - # Start the one daemon - daemon --user=oneadmin $ONED -f 2>&1 & - - LASTRC=$? - LASTPID=$! - - if [ $LASTRC -ne 0 ]; then - echo "Error executing $ONED" - exit 1 - else - echo $LASTPID > $ONE_PID - fi - - sleep 1 - ps $LASTPID > /dev/null 2>&1 - - if [ $? -ne 0 ]; then - echo "Error executing $ONED." - exit 1 - fi - - # Start the scheduler - # The following command line arguments are supported by mm_shed: - # [-p port] to connect to oned - default: 2633 - # [-t timer] seconds between two scheduling actions - default: 30 - # [-m machines limit] max number of VMs managed in each scheduling action - # - default: 300 - # [-d dispatch limit] max number of VMs dispatched in each scheduling action - # - default: 30 - # [-h host dispatch] max number of VMs dispatched to a given host in each - # scheduling action - default: 1 - - daemon --user=oneadmin $ONE_SCHEDULER -p $PORT -t 30 -m 300 -d 30 -h 1& - - LASTRC=$? - LASTPID=$! - - if [ $LASTRC -ne 0 ]; then - echo "Error executing $ONE_SCHEDULER" - exit 1 - else - echo $LASTPID > $ONE_SCHEDPID - fi - - echo "oned and scheduler started" -} - -# -# Function that stops the daemon/service -# -stop() -{ - if [ ! -f $ONE_PID ]; then - echo "Couldn't find oned process pid." - exit 1 - fi - - if [ ! -f $ONE_SCHEDPID ]; then - echo "Couldn't find scheduler process pid." - exit 1 - fi - - # Kill the one daemon - - killproc oned - - # Kill the scheduler - - killproc mm_sched - - # Remove pid files - - rm -f $ONE_PID > /dev/null 2>&1 - rm -f $ONE_SCHEDPID > /dev/null 2>&1 - - echo "oned and scheduler stopped" -} +. /etc/rc.status +rc_reset case "$1" in - start) - setup - start + start) + echo -n "Starting ONE " + /sbin/startproc -u oneadmin $ONE_BIN start + rc_status -v ;; - stop) - stop + stop) + echo -n "Shutting down ONE " + /sbin/startproc -u oneadmin $ONE_BIN stop + rc_status -v ;; - status) - status oned - status mm_sched + try-restart|condrestart) + if test "$1" = "condrestart"; then + echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}" + fi + $0 status + if test $? = 0; then + $0 restart + else + rc_reset # Not running is not a failure. + fi + # Remember status and be quiet + rc_status ;; - *) - echo "Usage: one {start|stop|status}" >&2 - exit 3 + restart) + $0 stop + $0 start + + rc_status + ;; + force-reload) + $0 try-restart + rc_status + ;; + reload) + rc_failed 3 + rc_status -v + ;; + status) + echo -n "Checking for service ONE " + ## Check status with checkproc(8), if process is running + ## checkproc will return with exit status 0. + + # Return value is slightly different for the status command: + # 0 - service up and running + # 1 - service dead, but /var/run/ pid file exists + # 2 - service dead, but /var/lock/ lock file exists + # 3 - service not running (unused) + # 4 - service status unknown :-( + # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.) + + # NOTE: checkproc returns LSB compliant status values. + /sbin/checkproc $ONE_BIN + # NOTE: rc_status knows that we called this init script with + # "status" option and adapts its messages accordingly. + rc_status -v + ;; + *) + echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}" + exit 1 ;; esac +rc_exit From 5fb6679242b22869d395d69c99f43f2cbfa69192 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Wed, 24 Nov 2010 12:58:45 +0100 Subject: [PATCH 04/28] bug #394: changed CentOS init script to rely on /usr/bin/one instead of starting oned and scheduler separately --- share/etc/init.d/oned.centos | 220 +++++++++-------------------------- 1 file changed, 54 insertions(+), 166 deletions(-) diff --git a/share/etc/init.d/oned.centos b/share/etc/init.d/oned.centos index fa66e4a13b..d556915e89 100755 --- a/share/etc/init.d/oned.centos +++ b/share/etc/init.d/oned.centos @@ -1,195 +1,83 @@ #!/bin/bash # -# oned This shell script takes care of starting and stopping -# the Opennebula subsystem (oned). +# /etc/rc.d/init.d/oned # -# chkconfig: 2345 65 35 -# description: oned cloud server. +# Starts the OpenNebula daemon +# +# chkconfig: 345 26 74 +# description: Starts the OpenNebula daemon # processname: oned -# config: /etc/one/oned.conf -# pidfile: /var/run/one/oned.pid + +### BEGIN INIT INFO +# Provides: oned +# Required-Start: $local_fs $remote_fs +# Required-Stop: $local_fs $remote_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: start and stop oned +# Description: start and stop oned +### END INIT INFO + +ONE_BIN=/usr/bin/one # Source function library. . /etc/rc.d/init.d/functions -# Source networking configuration. -. /etc/sysconfig/network +RETVAL=0 -# Set the ONE_LOCATION -# ONE_LOCATION="/srv/cloud/one" -ONE_LOCATION="" - -prog="oned" - -if [ -z "$ONE_LOCATION" ]; then - ONE_PID=/var/run/one/oned.pid - ONE_SCHEDPID=/var/run/one/sched.pid - ONE_CONF=/etc/one/oned.conf - ONE_DB=/var/lib/one/one.db - - ONED=/usr/bin/oned - ONE_SCHEDULER=/usr/bin/mm_sched - - LOCK_FILE=/var/lock/one/one -else - ONE_PID=$ONE_LOCATION/var/oned.pid - ONE_SCHEDPID=$ONE_LOCATION/var/sched.pid - ONE_CONF=$ONE_LOCATION/etc/oned.conf - ONE_DB=$ONE_LOCATION/var/one.db - - ONED=$ONE_LOCATION/bin/oned - ONE_SCHEDULER=$ONE_LOCATION/bin/mm_sched - - LOCK_FILE=$ONE_LOCATION/var/.lock -fi - -setup() -{ - PORT=`cat $ONE_CONF | grep ^PORT= | cut -d= -f2` - - if [ $? -ne 0 ]; then - echo "Can not find PORT in $ONE_CONF." - exit 1 - fi +check() { + # Check that we're a privileged user + [ `id -u` = 0 ] || exit 4 - if [ -f $LOCK_FILE ]; then - if [ -f $ONE_PID ]; then - ONEPID=`cat $ONE_PID` - ps $ONEPID > /dev/null 2>&1 - if [ $? -eq 0 ]; then - echo "ONE is still running (PID:$ONEPID). Please try 'one stop' first." - exit 1 - fi - fi - if [ -f $ONE_SCHEDPID ]; then - ONESCHEDPID=`cat $ONE_SCHEDPID` - ps $ONESCHEDPID > /dev/null 2>&1 - if [ $? -eq 0 ]; then - echo "The scheduler is still running (PID:$ONEPID). Please try 'one stop' first." - exit 1 - fi - fi - echo "Stale .lock detected. Erasing it." - rm $LOCK_FILE - fi + # Check if oned is executable + test -x $ONE_BIN || exit 5 } -start() -{ - if [ ! -x "$ONED" ]; then - echo "Can not find $ONED." - exit 1 - fi +start() { - if [ ! -x "$ONE_SCHEDULER" ]; then - echo "Can not find $ONE_SCHEDULER." - exit 1 - fi - - if [ ! -f "$ONE_DB" ]; then - if [ -f "$HOME/.one/one_auth" ]; then - . $HOME/.one/one_auth - elif [ -z "$ONE_AUTH" ]; then - echo "You should have ONE_AUTH set the first time you start" - echo "OpenNebula as it is used to set the credentials for" - echo "the adminitrator user." - exit 1 - fi - fi - - # Start the one daemon - daemon --user=oneadmin $ONED -f 2>&1 & + check - LASTRC=$? - LASTPID=$! - - if [ $LASTRC -ne 0 ]; then - echo "Error executing $ONED" - exit 1 - else - echo $LASTPID > $ONE_PID - fi - - sleep 1 - ps $LASTPID > /dev/null 2>&1 - - if [ $? -ne 0 ]; then - echo "Error executing $ONED." - exit 1 - fi - - # Start the scheduler - # The following command line arguments are supported by mm_shed: - # [-p port] to connect to oned - default: 2633 - # [-t timer] seconds between two scheduling actions - default: 30 - # [-m machines limit] max number of VMs managed in each scheduling action - # - default: 300 - # [-d dispatch limit] max number of VMs dispatched in each scheduling action - # - default: 30 - # [-h host dispatch] max number of VMs dispatched to a given host in each - # scheduling action - default: 1 - - daemon --user=oneadmin $ONE_SCHEDULER -p $PORT -t 30 -m 300 -d 30 -h 1& - - LASTRC=$? - LASTPID=$! - - if [ $LASTRC -ne 0 ]; then - echo "Error executing $ONE_SCHEDULER" - exit 1 - else - echo $LASTPID > $ONE_SCHEDPID - fi - - echo "oned and scheduler started" + echo -n $"Starting OpenNebula daemon: " + daemon --user oneadmin $ONE_BIN start + RETVAL=$? + echo + return $RETVAL } -# -# Function that stops the daemon/service -# -stop() -{ - if [ ! -f $ONE_PID ]; then - echo "Couldn't find oned process pid." - exit 1 - fi +stop() { - if [ ! -f $ONE_SCHEDPID ]; then - echo "Couldn't find scheduler process pid." - exit 1 - fi - - # Kill the one daemon - - killproc oned - - # Kill the scheduler + check - killproc mm_sched - - # Remove pid files - - rm -f $ONE_PID > /dev/null 2>&1 - rm -f $ONE_SCHEDPID > /dev/null 2>&1 - - echo "oned and scheduler stopped" + echo -n $"Stopping OpenNebula daemon: " + su oneadmin -s /bin/sh -c "$ONE_BIN stop" + RETVAL=$? + echo + return $RETVAL } +restart() { + stop + start +} + case "$1" in - start) - setup +start) start ;; - stop) +stop) stop ;; - status) +restart) + restart + ;; +status) status oned - status mm_sched - ;; - *) - echo "Usage: one {start|stop|status}" >&2 - exit 3 + RETVAL=$? ;; +*) + echo $"Usage: $0 {start|stop|status|restart}" + RETVAL=2 esac + +exit $RETVAL From c86d9a5ca7b4a07fa6fc596cb4f87d1ab3e8b7a4 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Wed, 24 Nov 2010 16:27:07 +0100 Subject: [PATCH 05/28] Copy the remotes to both the LIB and VAR directories (cherry picked from commit d29464875eedef7be1e5dfd07255ffb8e5b13441) --- install.sh | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/install.sh b/install.sh index 2834543290..04bbf41231 100755 --- a/install.sh +++ b/install.sh @@ -179,7 +179,13 @@ LIB_DIRS="$LIB_LOCATION/ruby \ $LIB_LOCATION/tm_commands/ssh \ $LIB_LOCATION/tm_commands/dummy \ $LIB_LOCATION/tm_commands/lvm \ - $LIB_LOCATION/mads" + $LIB_LOCATION/mads \ + $LIB_LOCATION/remotes \ + $LIB_LOCATION/remotes/im \ + $LIB_LOCATION/remotes/im/kvm.d \ + $LIB_LOCATION/remotes/im/xen.d \ + $LIB_LOCATION/remotes/vmm/xen \ + $LIB_LOCATION/remotes/vmm/kvm" VAR_DIRS="$VAR_LOCATION/remotes \ $VAR_LOCATION/remotes/im \ @@ -222,20 +228,25 @@ INSTALL_FILES[7]="IM_PROBES_KVM_FILES:$VAR_LOCATION/remotes/im/kvm.d" INSTALL_FILES[8]="IM_PROBES_XEN_FILES:$VAR_LOCATION/remotes/im/xen.d" INSTALL_FILES[9]="VMM_SSH_KVM_SCRIPTS:$VAR_LOCATION/remotes/vmm/kvm" INSTALL_FILES[10]="VMM_SSH_XEN_SCRIPTS:$VAR_LOCATION/remotes/vmm/xen" -INSTALL_FILES[11]="NFS_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/nfs" -INSTALL_FILES[12]="SSH_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/ssh" -INSTALL_FILES[13]="DUMMY_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/dummy" -INSTALL_FILES[14]="LVM_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/lvm" -INSTALL_FILES[15]="EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples" -INSTALL_FILES[16]="TM_EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples/tm" -INSTALL_FILES[17]="HOOK_SHARE_FILES:$SHARE_LOCATION/hooks" -INSTALL_FILES[18]="COMMON_CLOUD_LIB_FILES:$LIB_LOCATION/ruby/cloud" -INSTALL_FILES[19]="ECO_LIB_FILES:$LIB_LOCATION/ruby/cloud/econe" -INSTALL_FILES[20]="ECO_LIB_VIEW_FILES:$LIB_LOCATION/ruby/cloud/econe/views" -INSTALL_FILES[21]="ECO_BIN_FILES:$BIN_LOCATION" -INSTALL_FILES[22]="OCCI_LIB_FILES:$LIB_LOCATION/ruby/cloud/occi" -INSTALL_FILES[23]="OCCI_BIN_FILES:$BIN_LOCATION" -INSTALL_FILES[24]="MAN_FILES:$MAN_LOCATION" +INSTALL_FILES[11]="IM_PROBES_FILES:$LIB_LOCATION/remotes/im" +INSTALL_FILES[12]="IM_PROBES_KVM_FILES:$LIB_LOCATION/remotes/im/kvm.d" +INSTALL_FILES[13]="IM_PROBES_XEN_FILES:$LIB_LOCATION/remotes/im/xen.d" +INSTALL_FILES[14]="VMM_SSH_KVM_SCRIPTS:$LIB_LOCATION/remotes/vmm/kvm" +INSTALL_FILES[15]="VMM_SSH_XEN_SCRIPTS:$LIB_LOCATION/remotes/vmm/xen" +INSTALL_FILES[16]="NFS_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/nfs" +INSTALL_FILES[17]="SSH_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/ssh" +INSTALL_FILES[18]="DUMMY_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/dummy" +INSTALL_FILES[19]="LVM_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/lvm" +INSTALL_FILES[20]="EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples" +INSTALL_FILES[21]="TM_EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples/tm" +INSTALL_FILES[22]="HOOK_SHARE_FILES:$SHARE_LOCATION/hooks" +INSTALL_FILES[23]="COMMON_CLOUD_LIB_FILES:$LIB_LOCATION/ruby/cloud" +INSTALL_FILES[24]="ECO_LIB_FILES:$LIB_LOCATION/ruby/cloud/econe" +INSTALL_FILES[25]="ECO_LIB_VIEW_FILES:$LIB_LOCATION/ruby/cloud/econe/views" +INSTALL_FILES[26]="ECO_BIN_FILES:$BIN_LOCATION" +INSTALL_FILES[27]="OCCI_LIB_FILES:$LIB_LOCATION/ruby/cloud/occi" +INSTALL_FILES[28]="OCCI_BIN_FILES:$BIN_LOCATION" +INSTALL_FILES[29]="MAN_FILES:$MAN_LOCATION" INSTALL_ECO_CLIENT_FILES[0]="COMMON_CLOUD_CLIENT_LIB_FILES:$LIB_LOCATION/ruby/cloud" INSTALL_ECO_CLIENT_FILES[1]="ECO_LIB_CLIENT_FILES:$LIB_LOCATION/ruby/cloud/econe" From 5ef3bdc012bf3cdd966fe2d97e2a3570461a5fc1 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Wed, 24 Nov 2010 16:44:36 +0100 Subject: [PATCH 06/28] Fixed typo in oneuser command help (cherry picked from commit b4ff12f474f4721215642d07f9f0c09691d23ea7) --- src/cli/oneuser | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/oneuser b/src/cli/oneuser index 0ca2ad1a59..e2a68bc39f 100755 --- a/src/cli/oneuser +++ b/src/cli/oneuser @@ -98,7 +98,7 @@ Description: This command enables the OpenNebula administrator to manage users, adding, listing and deleting them. -The create and passwd commands accept the [-r, –read-file] option. Use this +The create and passwd commands accept the [-r, --read-file] option. Use this option to store the contents of a file (without hashing it) as the password. From f3e90d7f1abd0db874226f994e4c0c0fa79ccfa9 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Wed, 24 Nov 2010 17:57:28 +0100 Subject: [PATCH 07/28] bug in tm sed expressions (cherry picked from commit 94c436dbc5d24148eb4caf53d2d676dea20de92e) --- src/tm_mad/tm_common.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tm_mad/tm_common.sh b/src/tm_mad/tm_common.sh index 47a80cc29b..cb087cc23e 100644 --- a/src/tm_mad/tm_common.sh +++ b/src/tm_mad/tm_common.sh @@ -124,13 +124,13 @@ function error_message # Gets the host from an argument function arg_host { - echo $1 | $SED 's/^\([^:]*\):.*$/\1/' + echo $1 | $SED 's/^([^:]*):.*$/\1/' } # Gets the path from an argument function arg_path { - echo $1 | $SED 's/^[^:]*:\(.*\)$/\1/' + echo $1 | $SED 's/^[^:]*:(.*)$/\1/' } # Executes a command, if it fails return error message and exits From cc50668a4cf24b80c9ea0da4d5f2944faf281e77 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Thu, 25 Nov 2010 13:00:13 +0100 Subject: [PATCH 08/28] Add LICENSE headers to OCA(cherry picked from commit 59a2e5056f2d002de6a9720bd1de7c8f607525bf) --- src/oca/ruby/OpenNebula.rb | 16 ++++++++++++++++ src/oca/ruby/OpenNebula/Cluster.rb | 16 ++++++++++++++++ src/oca/ruby/OpenNebula/ClusterPool.rb | 16 ++++++++++++++++ src/oca/ruby/OpenNebula/Host.rb | 16 ++++++++++++++++ src/oca/ruby/OpenNebula/HostPool.rb | 16 ++++++++++++++++ src/oca/ruby/OpenNebula/Image.rb | 16 ++++++++++++++++ src/oca/ruby/OpenNebula/ImagePool.rb | 16 ++++++++++++++++ src/oca/ruby/OpenNebula/ImageRepository.rb | 16 ++++++++++++++++ src/oca/ruby/OpenNebula/Pool.rb | 15 +++++++++++++++ src/oca/ruby/OpenNebula/User.rb | 16 ++++++++++++++++ src/oca/ruby/OpenNebula/UserPool.rb | 16 ++++++++++++++++ src/oca/ruby/OpenNebula/VirtualMachine.rb | 16 ++++++++++++++++ src/oca/ruby/OpenNebula/VirtualMachinePool.rb | 16 ++++++++++++++++ src/oca/ruby/OpenNebula/VirtualNetwork.rb | 16 ++++++++++++++++ src/oca/ruby/OpenNebula/VirtualNetworkPool.rb | 16 ++++++++++++++++ src/oca/ruby/OpenNebula/XMLUtils.rb | 15 +++++++++++++++ 16 files changed, 254 insertions(+) diff --git a/src/oca/ruby/OpenNebula.rb b/src/oca/ruby/OpenNebula.rb index 6affea51ea..2aca81bf30 100644 --- a/src/oca/ruby/OpenNebula.rb +++ b/src/oca/ruby/OpenNebula.rb @@ -1,3 +1,19 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + begin # require 'rubygems' require 'rubygems' rescue Exception diff --git a/src/oca/ruby/OpenNebula/Cluster.rb b/src/oca/ruby/OpenNebula/Cluster.rb index 408e90afe8..2d76944e3f 100644 --- a/src/oca/ruby/OpenNebula/Cluster.rb +++ b/src/oca/ruby/OpenNebula/Cluster.rb @@ -1,3 +1,19 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' module OpenNebula diff --git a/src/oca/ruby/OpenNebula/ClusterPool.rb b/src/oca/ruby/OpenNebula/ClusterPool.rb index 561d84d0bc..eb05cf6c24 100644 --- a/src/oca/ruby/OpenNebula/ClusterPool.rb +++ b/src/oca/ruby/OpenNebula/ClusterPool.rb @@ -1,3 +1,19 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' module OpenNebula diff --git a/src/oca/ruby/OpenNebula/Host.rb b/src/oca/ruby/OpenNebula/Host.rb index 1af58430db..6589d7a302 100644 --- a/src/oca/ruby/OpenNebula/Host.rb +++ b/src/oca/ruby/OpenNebula/Host.rb @@ -1,3 +1,19 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' module OpenNebula diff --git a/src/oca/ruby/OpenNebula/HostPool.rb b/src/oca/ruby/OpenNebula/HostPool.rb index 6e4d03da84..fdfa0e32c1 100644 --- a/src/oca/ruby/OpenNebula/HostPool.rb +++ b/src/oca/ruby/OpenNebula/HostPool.rb @@ -1,3 +1,19 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' module OpenNebula diff --git a/src/oca/ruby/OpenNebula/Image.rb b/src/oca/ruby/OpenNebula/Image.rb index 965f4d333f..823a704329 100644 --- a/src/oca/ruby/OpenNebula/Image.rb +++ b/src/oca/ruby/OpenNebula/Image.rb @@ -1,3 +1,19 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' require 'fileutils' diff --git a/src/oca/ruby/OpenNebula/ImagePool.rb b/src/oca/ruby/OpenNebula/ImagePool.rb index 58c962a701..c0daed0318 100644 --- a/src/oca/ruby/OpenNebula/ImagePool.rb +++ b/src/oca/ruby/OpenNebula/ImagePool.rb @@ -1,3 +1,19 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' module OpenNebula diff --git a/src/oca/ruby/OpenNebula/ImageRepository.rb b/src/oca/ruby/OpenNebula/ImageRepository.rb index cb68350439..63c510bbbd 100644 --- a/src/oca/ruby/OpenNebula/ImageRepository.rb +++ b/src/oca/ruby/OpenNebula/ImageRepository.rb @@ -1,3 +1,19 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + require 'OpenNebula/Image' require 'fileutils' require 'CommandManager' diff --git a/src/oca/ruby/OpenNebula/Pool.rb b/src/oca/ruby/OpenNebula/Pool.rb index a271352232..0101df6917 100644 --- a/src/oca/ruby/OpenNebula/Pool.rb +++ b/src/oca/ruby/OpenNebula/Pool.rb @@ -1,3 +1,18 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # module OpenNebula # The Pool class represents a generic OpenNebula Pool in XML format diff --git a/src/oca/ruby/OpenNebula/User.rb b/src/oca/ruby/OpenNebula/User.rb index a444117498..5d6eecda2a 100644 --- a/src/oca/ruby/OpenNebula/User.rb +++ b/src/oca/ruby/OpenNebula/User.rb @@ -1,3 +1,19 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' module OpenNebula diff --git a/src/oca/ruby/OpenNebula/UserPool.rb b/src/oca/ruby/OpenNebula/UserPool.rb index 58bce9b618..b91ff7ad1e 100644 --- a/src/oca/ruby/OpenNebula/UserPool.rb +++ b/src/oca/ruby/OpenNebula/UserPool.rb @@ -1,3 +1,19 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' module OpenNebula diff --git a/src/oca/ruby/OpenNebula/VirtualMachine.rb b/src/oca/ruby/OpenNebula/VirtualMachine.rb index e9dc245ff0..8dcdb35764 100644 --- a/src/oca/ruby/OpenNebula/VirtualMachine.rb +++ b/src/oca/ruby/OpenNebula/VirtualMachine.rb @@ -1,3 +1,19 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' module OpenNebula diff --git a/src/oca/ruby/OpenNebula/VirtualMachinePool.rb b/src/oca/ruby/OpenNebula/VirtualMachinePool.rb index 0649f258ab..4a4fba39c6 100644 --- a/src/oca/ruby/OpenNebula/VirtualMachinePool.rb +++ b/src/oca/ruby/OpenNebula/VirtualMachinePool.rb @@ -1,3 +1,19 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' module OpenNebula diff --git a/src/oca/ruby/OpenNebula/VirtualNetwork.rb b/src/oca/ruby/OpenNebula/VirtualNetwork.rb index 4e10ebd7d6..ebda3c2502 100644 --- a/src/oca/ruby/OpenNebula/VirtualNetwork.rb +++ b/src/oca/ruby/OpenNebula/VirtualNetwork.rb @@ -1,3 +1,19 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' module OpenNebula diff --git a/src/oca/ruby/OpenNebula/VirtualNetworkPool.rb b/src/oca/ruby/OpenNebula/VirtualNetworkPool.rb index 1e66d33a6a..ed9f59c051 100644 --- a/src/oca/ruby/OpenNebula/VirtualNetworkPool.rb +++ b/src/oca/ruby/OpenNebula/VirtualNetworkPool.rb @@ -1,3 +1,19 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + require 'OpenNebula/Pool' module OpenNebula diff --git a/src/oca/ruby/OpenNebula/XMLUtils.rb b/src/oca/ruby/OpenNebula/XMLUtils.rb index 9444a4c098..9bb89f1194 100644 --- a/src/oca/ruby/OpenNebula/XMLUtils.rb +++ b/src/oca/ruby/OpenNebula/XMLUtils.rb @@ -1,3 +1,18 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # module OpenNebula From dbd4f14ab54b1148a85e2c56d3955af2b9f88d0d Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Thu, 25 Nov 2010 13:02:42 +0100 Subject: [PATCH 09/28] Load ruby libs path in ImageRepository(cherry picked from commit 52ff006835738b441e4e0a642a5dac6e73d32d3f) --- src/oca/ruby/OpenNebula/ImageRepository.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/oca/ruby/OpenNebula/ImageRepository.rb b/src/oca/ruby/OpenNebula/ImageRepository.rb index 63c510bbbd..5cec29761b 100644 --- a/src/oca/ruby/OpenNebula/ImageRepository.rb +++ b/src/oca/ruby/OpenNebula/ImageRepository.rb @@ -14,6 +14,16 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +ONE_LOCATION=ENV["ONE_LOCATION"] + +if !ONE_LOCATION + RUBY_LIB_LOCATION="/usr/lib/one/ruby" +else + RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" +end + +$: << RUBY_LIB_LOCATION + require 'OpenNebula/Image' require 'fileutils' require 'CommandManager' From fa71b4180ab87ee5b8626743439482e1a6b94134 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Fri, 26 Nov 2010 09:25:14 +0100 Subject: [PATCH 10/28] Revert "Load ruby libs path in ImageRepository(cherry picked from commit 52ff006835738b441e4e0a642a5dac6e73d32d3f)" This reverts commit dbd4f14ab54b1148a85e2c56d3955af2b9f88d0d. --- src/oca/ruby/OpenNebula/ImageRepository.rb | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/oca/ruby/OpenNebula/ImageRepository.rb b/src/oca/ruby/OpenNebula/ImageRepository.rb index 5cec29761b..63c510bbbd 100644 --- a/src/oca/ruby/OpenNebula/ImageRepository.rb +++ b/src/oca/ruby/OpenNebula/ImageRepository.rb @@ -14,16 +14,6 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -ONE_LOCATION=ENV["ONE_LOCATION"] - -if !ONE_LOCATION - RUBY_LIB_LOCATION="/usr/lib/one/ruby" -else - RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" -end - -$: << RUBY_LIB_LOCATION - require 'OpenNebula/Image' require 'fileutils' require 'CommandManager' From 2f57cb664793ab79964b7d4d216d604a17b0eaf1 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 26 Nov 2010 19:25:59 +0100 Subject: [PATCH 11/28] Better check of drop/delete actions result and XML-RPC return data. (cherry picked from commit f31fbb49bcd21c1109f51fdca7800b112f4d354f) --- src/rm/RequestManagerClusterDelete.cc | 4 ++-- src/rm/RequestManagerHostDelete.cc | 13 +++++++++++-- src/rm/RequestManagerImageDelete.cc | 17 ++++++++--------- src/rm/RequestManagerVirtualNetworkDelete.cc | 11 ++++++++++- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/rm/RequestManagerClusterDelete.cc b/src/rm/RequestManagerClusterDelete.cc index ddfcee56e3..5c1010be1c 100644 --- a/src/rm/RequestManagerClusterDelete.cc +++ b/src/rm/RequestManagerClusterDelete.cc @@ -32,7 +32,7 @@ void RequestManager::ClusterDelete::execute( int clid; ostringstream oss; int rc; - + const string method_name = "ClusterDelete"; /* -- RPC specific vars -- */ @@ -74,7 +74,7 @@ void RequestManager::ClusterDelete::execute( } // Return success - arrayData.push_back(xmlrpc_c::value_boolean( rc == 0 )); // SUCCESS + arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS arrayresult = new xmlrpc_c::value_array(arrayData); // Copy arrayresult into retval mem space diff --git a/src/rm/RequestManagerHostDelete.cc b/src/rm/RequestManagerHostDelete.cc index 0a453a8f56..662bf42c2a 100644 --- a/src/rm/RequestManagerHostDelete.cc +++ b/src/rm/RequestManagerHostDelete.cc @@ -33,7 +33,7 @@ void RequestManager::HostDelete::execute( Host * host; ostringstream oss; int rc; - + const string method_name = "HostDelete"; /* -- RPC specific vars -- */ @@ -79,8 +79,13 @@ void RequestManager::HostDelete::execute( host->unlock(); + if ( rc != 0 ) + { + goto error_host_drop; + } + // All nice, return the host info to the client - arrayData.push_back(xmlrpc_c::value_boolean( rc == 0 )); // SUCCESS + arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS arrayresult = new xmlrpc_c::value_array(arrayData); // Copy arrayresult into retval mem space @@ -102,6 +107,10 @@ error_host_get: oss.str(get_error(method_name, "HOST", hid)); goto error_common; +error_host_drop: + oss.str(action_error(method_name, "DELETE", "HOST", hid, rc)); + goto error_common; + error_common: NebulaLog::log ("Rem",Log::ERROR,oss); diff --git a/src/rm/RequestManagerImageDelete.cc b/src/rm/RequestManagerImageDelete.cc index 20875bf5f7..3c876de8ef 100644 --- a/src/rm/RequestManagerImageDelete.cc +++ b/src/rm/RequestManagerImageDelete.cc @@ -33,14 +33,14 @@ void RequestManager::ImageDelete::execute( int iid; int uid; int rc; - + int image_owner; bool is_public; Image * image; ostringstream oss; - + const string method_name = "ImageDelete"; vector arrayData; @@ -60,7 +60,7 @@ void RequestManager::ImageDelete::execute( { goto error_authenticate; } - + // Get image from the ImagePool image = ImageDelete::ipool->get(iid,true); @@ -68,12 +68,12 @@ void RequestManager::ImageDelete::execute( { goto error_image_get; } - + image_owner = image->get_uid(); is_public = image->isPublic(); - + image->unlock(); - + //Authorize the operation if ( uid != 0 ) // uid == 0 means oneadmin { @@ -101,14 +101,13 @@ void RequestManager::ImageDelete::execute( rc = ImageDelete::ipool->drop(image); + image->unlock(); + if ( rc < 0 ) { goto error_delete; - } - image->unlock(); - arrayData.push_back(xmlrpc_c::value_boolean(true)); arrayData.push_back(xmlrpc_c::value_int(iid)); diff --git a/src/rm/RequestManagerVirtualNetworkDelete.cc b/src/rm/RequestManagerVirtualNetworkDelete.cc index 4a44d445c2..184550fc12 100644 --- a/src/rm/RequestManagerVirtualNetworkDelete.cc +++ b/src/rm/RequestManagerVirtualNetworkDelete.cc @@ -105,8 +105,13 @@ void RequestManager::VirtualNetworkDelete::execute( vn->unlock(); + if ( rc != 0 ) + { + goto error_vn_drop; + } + // All nice, return the host info to the client - arrayData.push_back(xmlrpc_c::value_boolean( rc == 0 )); // SUCCESS + arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS arrayresult = new xmlrpc_c::value_array(arrayData); // Copy arrayresult into retval mem space @@ -128,6 +133,10 @@ error_vn_get: oss.str(get_error(method_name, "NET", nid)); goto error_common; +error_vn_drop: + oss.str(action_error(method_name, "DELETE", "NET",nid,rc)); + goto error_common; + error_common: NebulaLog::log ("ReM",Log::ERROR,oss); From 2b1f2170338ac285a07f04823d83638951a69feb Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Mon, 29 Nov 2010 19:02:46 +0100 Subject: [PATCH 12/28] Fix bug in RemotesCommand class (cherry picked from commit 55596e2c41092a12dd79eae399b8711c1c71ad79) --- src/mad/ruby/CommandManager.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mad/ruby/CommandManager.rb b/src/mad/ruby/CommandManager.rb index 0f3082d8fd..1d90fe44a9 100644 --- a/src/mad/ruby/CommandManager.rb +++ b/src/mad/ruby/CommandManager.rb @@ -160,7 +160,7 @@ class RemotesCommand < SSHCommand cmd.run if cmd.code == MAGIC_RC - self.update_remotes(host, remote_dir, logger) + cmd.update_remotes(host, remote_dir, logger) @command = command cmd.run @@ -169,7 +169,7 @@ class RemotesCommand < SSHCommand cmd end - def self.update_remotes(host, remote_dir, logger=nil) + def update_remotes(host, remote_dir, logger=nil) log("Remote worker node files not found") log("Updating remotes") From 2abede7d2bd2ff28871b5f099055ad109b0d3b41 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Tue, 30 Nov 2010 12:52:30 +0100 Subject: [PATCH 13/28] install OCCI common.erb file --- install.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 04bbf41231..58a01977b8 100755 --- a/install.sh +++ b/install.sh @@ -602,7 +602,8 @@ OCCI_BIN_CLIENT_FILES="src/cloud/occi/bin/occi-compute \ OCCI_ETC_FILES="src/cloud/occi/etc/occi-server.conf" -OCCI_ETC_TEMPLATE_FILES="src/cloud/occi/etc/templates/small.erb \ +OCCI_ETC_TEMPLATE_FILES="src/cloud/occi/etc/templates/common.erb \ + src/cloud/occi/etc/templates/small.erb \ src/cloud/occi/etc/templates/medium.erb \ src/cloud/occi/etc/templates/large.erb" From de8d62423ed3724212a7efb0df7af93efc9cede1 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Tue, 30 Nov 2010 18:47:32 +0100 Subject: [PATCH 14/28] Fix bug in common.erb (cherry picked from commit 694e38f8da6bfcca26b9e735c93c457cd6840eab) --- src/cloud/occi/etc/templates/common.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cloud/occi/etc/templates/common.erb b/src/cloud/occi/etc/templates/common.erb index 0a2756e5b3..2280a6b111 100644 --- a/src/cloud/occi/etc/templates/common.erb +++ b/src/cloud/occi/etc/templates/common.erb @@ -1,6 +1,6 @@ # # This template is processed by the OCCI Server to include specific data for the -# instance, you should not need to modify the <% ... %> compounds. +# instance, you should not need to modify the ruby code. # You can add common attributes for your cloud templates (e.g. OS) # From 18361ccfe643632aba5dd84e5128d8fbaa1774bb Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Tue, 30 Nov 2010 18:47:32 +0100 Subject: [PATCH 15/28] Fix bug in common.erb (cherry picked from commit 694e38f8da6bfcca26b9e735c93c457cd6840eab) --- src/cloud/occi/etc/templates/common.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cloud/occi/etc/templates/common.erb b/src/cloud/occi/etc/templates/common.erb index 0a2756e5b3..2280a6b111 100644 --- a/src/cloud/occi/etc/templates/common.erb +++ b/src/cloud/occi/etc/templates/common.erb @@ -1,6 +1,6 @@ # # This template is processed by the OCCI Server to include specific data for the -# instance, you should not need to modify the <% ... %> compounds. +# instance, you should not need to modify the ruby code. # You can add common attributes for your cloud templates (e.g. OS) # From d6f52231efa689ad332a7e01ca6546a59e987721 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Thu, 2 Dec 2010 19:16:16 +0100 Subject: [PATCH 16/28] Fix OCCI client REXML formatting compatibility with ruby 1.8.5 --- src/cloud/common/CloudClient.rb | 35 +++++++++++++++++++++++++++++++++ src/cloud/occi/bin/occi-compute | 24 +++++----------------- src/cloud/occi/bin/occi-network | 22 ++++----------------- src/cloud/occi/bin/occi-storage | 26 ++++++------------------ 4 files changed, 50 insertions(+), 57 deletions(-) diff --git a/src/cloud/common/CloudClient.rb b/src/cloud/common/CloudClient.rb index d047892e1f..f056dc619e 100644 --- a/src/cloud/common/CloudClient.rb +++ b/src/cloud/common/CloudClient.rb @@ -20,6 +20,15 @@ require 'uri' require 'digest/sha1' require 'net/https' +require "rexml/document" + +begin + require 'rexml/formatters/pretty' + REXML_FORMATTERS=true +rescue LoadError + REXML_FORMATTERS=false +end + begin require 'curb' CURL_LOADED=true @@ -131,6 +140,32 @@ end # Command line help functions module CloudCLI + def print_xml(xml_text) + begin + doc = REXML::Document.new(xml_text) + rescue REXML::ParseException => e + return e.message, -1 + end + + xml = doc.root + + if xml.nil? + return xml_text, -1 + end + + str = String.new + if REXML_FORMATTERS + formatter = REXML::Formatters::Pretty.new + formatter.compact = true + + formatter.write(xml,str) + else + str = xml.to_s + end + + return str, 0 + end + # Returns the command name def cmd_name File.basename($0) diff --git a/src/cloud/occi/bin/occi-compute b/src/cloud/occi/bin/occi-compute index 0332e48c48..a58be6c8b2 100755 --- a/src/cloud/occi/bin/occi-compute +++ b/src/cloud/occi/bin/occi-compute @@ -79,7 +79,6 @@ EOT require 'occi/OCCIClient' require 'getoptlong' -require "rexml/document" include CloudCLI @@ -151,7 +150,7 @@ case ARGV[0].downcase end rc = occi_client.post_vms(vm_xml) - + when 'show' vm_id = ARGV[1] @@ -189,23 +188,10 @@ end if CloudClient::is_error?(rc) puts rc.to_s() + exit(-1) else - begin - doc = REXML::Document.new(rc) - rescue REXML::ParseException => e - puts e.message - exit(-1) - end - - xml = doc.root - - if xml.nil? - puts rc - exit(-1) - end - - str = "" - REXML::Formatters::Pretty.new(4).write(xml,str) - puts "\n" + str + "\n " + str, code = print_xml(rc) + puts str + exit(code) end diff --git a/src/cloud/occi/bin/occi-network b/src/cloud/occi/bin/occi-network index 2d1387ed79..bdbeb3c57d 100755 --- a/src/cloud/occi/bin/occi-network +++ b/src/cloud/occi/bin/occi-network @@ -80,7 +80,6 @@ EOT require 'occi/OCCIClient' require 'CloudClient' require 'getoptlong' -require "rexml/document" include CloudCLI @@ -182,22 +181,9 @@ end if CloudClient::is_error?(rc) puts rc.to_s() + exit(-1) else - begin - doc = REXML::Document.new(rc) - rescue REXML::ParseException => e - puts e.message - exit(-1) - end - - xml = doc.root - - if xml.nil? - puts rc - exit(-1) - end - - str = "" - REXML::Formatters::Pretty.new(4).write(xml,str) - puts "\n" + str + "\n " + str, code = print_xml(rc) + puts str + exit(code) end diff --git a/src/cloud/occi/bin/occi-storage b/src/cloud/occi/bin/occi-storage index 5085656090..e2e0fd7aed 100755 --- a/src/cloud/occi/bin/occi-storage +++ b/src/cloud/occi/bin/occi-storage @@ -79,8 +79,7 @@ EOT require 'occi/OCCIClient' require 'CloudClient' require 'getoptlong' -require 'rexml/document' -require 'pp' + include CloudCLI opts = GetoptLong.new( @@ -184,22 +183,9 @@ end if CloudClient::is_error?(rc) puts rc.to_s() -else - begin - doc = REXML::Document.new(rc) - rescue REXML::ParseException => e - puts e.message - exit(-1) - end - - xml = doc.root - - if xml.nil? - puts rc - exit(-1) - end - - str = "" - REXML::Formatters::Pretty.new(4).write(xml,str) - puts "\n" + str + "\n " + exit(-1) +else + str, code = print_xml(rc) + puts str + exit(code) end From ed8ee81928a456a46e088552a547e292ceae22c6 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Thu, 2 Dec 2010 19:19:01 +0100 Subject: [PATCH 17/28] Add to OCCI fine grain resource spec, custom.erb --- install.sh | 1 + src/cloud/occi/etc/occi-server.conf | 1 + src/cloud/occi/etc/templates/custom.erb | 8 ++++++++ src/cloud/occi/lib/VirtualMachineOCCI.rb | 2 ++ 4 files changed, 12 insertions(+) create mode 100644 src/cloud/occi/etc/templates/custom.erb diff --git a/install.sh b/install.sh index 58a01977b8..98ac05f47b 100755 --- a/install.sh +++ b/install.sh @@ -603,6 +603,7 @@ OCCI_BIN_CLIENT_FILES="src/cloud/occi/bin/occi-compute \ OCCI_ETC_FILES="src/cloud/occi/etc/occi-server.conf" OCCI_ETC_TEMPLATE_FILES="src/cloud/occi/etc/templates/common.erb \ + src/cloud/occi/etc/templates/custom.erb \ src/cloud/occi/etc/templates/small.erb \ src/cloud/occi/etc/templates/medium.erb \ src/cloud/occi/etc/templates/large.erb" diff --git a/src/cloud/occi/etc/occi-server.conf b/src/cloud/occi/etc/occi-server.conf index 025dd492b1..8b216fb029 100644 --- a/src/cloud/occi/etc/occi-server.conf +++ b/src/cloud/occi/etc/occi-server.conf @@ -12,6 +12,7 @@ PORT=4567 BRIDGE= # VM types allowed and its template file (inside templates directory) +VM_TYPE=[NAME=custom, TEMPLATE=custom.erb] VM_TYPE=[NAME=small, TEMPLATE=small.erb] VM_TYPE=[NAME=medium, TEMPLATE=medium.erb] VM_TYPE=[NAME=large, TEMPLATE=large.erb] diff --git a/src/cloud/occi/etc/templates/custom.erb b/src/cloud/occi/etc/templates/custom.erb new file mode 100644 index 0000000000..2b91f543e6 --- /dev/null +++ b/src/cloud/occi/etc/templates/custom.erb @@ -0,0 +1,8 @@ +# +# Virtual Machine Template generated for custom instance types. +# The CPU and MEMORY parameters will be specified in the body of the request. +# You can also add specific attributes for your cloud in this file (e.g. OS). +# + +CPU = "<%= @vm_info['CPU'] %>" +MEMORY = "<%= @vm_info['MEMORY'] %>" \ No newline at end of file diff --git a/src/cloud/occi/lib/VirtualMachineOCCI.rb b/src/cloud/occi/lib/VirtualMachineOCCI.rb index c72c645525..2235d1fe27 100755 --- a/src/cloud/occi/lib/VirtualMachineOCCI.rb +++ b/src/cloud/occi/lib/VirtualMachineOCCI.rb @@ -22,6 +22,8 @@ class VirtualMachineOCCI < VirtualMachine OCCI_VM = %q{ <%= self.id.to_s%> + <%= self['TEMPLATE/CPU'] %> + <%= self['TEMPLATE/MEMORY'] %> <%= self.name%> <% if self['TEMPLATE/INSTANCE_TYPE'] %> <%= self['TEMPLATE/INSTANCE_TYPE'] %> From 1cd061babcb939cb79ea9f6d63bc68a0fb4b5e98 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Thu, 2 Dec 2010 19:19:59 +0100 Subject: [PATCH 18/28] Add description support to OCCI network --- src/cloud/occi/lib/VirtualNetworkOCCI.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cloud/occi/lib/VirtualNetworkOCCI.rb b/src/cloud/occi/lib/VirtualNetworkOCCI.rb index 9b0be1fb42..af3843be3c 100755 --- a/src/cloud/occi/lib/VirtualNetworkOCCI.rb +++ b/src/cloud/occi/lib/VirtualNetworkOCCI.rb @@ -23,6 +23,9 @@ class VirtualNetworkOCCI < VirtualNetwork <%= self.id.to_s %> <%= self.name %> + <% if self['TEMPLATE/DESCRIPTION'] != nil %> + <%= self['TEMPLATE/DESCRIPTION'] %> + <% end %>
<%= self['TEMPLATE/NETWORK_ADDRESS'] %>
<% if self['TEMPLATE/NETWORK_SIZE'] %> <%= self['TEMPLATE/NETWORK_SIZE'] %> @@ -33,6 +36,9 @@ class VirtualNetworkOCCI < VirtualNetwork ONE_NETWORK = %q{ NAME = "<%= @vnet_info['NAME'] %>" TYPE = RANGED + <% if @vnet_info['DESCRIPTION'] != nil %> + DESCRIPTION = "<%= @vnet_info['DESCRIPTION'] %>" + <% end %> <% if @bridge %> BRIDGE = <%= @bridge %> <% end %> From 40f282cd8a67936d535ce73cafa03839ca1a1154 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Thu, 2 Dec 2010 19:21:59 +0100 Subject: [PATCH 19/28] Add network publishing functionality to OCCI --- src/cloud/occi/bin/occi-network | 22 +++++++++++++--- src/cloud/occi/lib/OCCIClient.rb | 32 ++++++++++++++++++++++++ src/cloud/occi/lib/OCCIServer.rb | 28 +++++++++++++++++++++ src/cloud/occi/lib/VirtualNetworkOCCI.rb | 4 +++ src/cloud/occi/lib/occi-server.rb | 5 ++++ 5 files changed, 87 insertions(+), 4 deletions(-) diff --git a/src/cloud/occi/bin/occi-network b/src/cloud/occi/bin/occi-network index bdbeb3c57d..df53439be7 100755 --- a/src/cloud/occi/bin/occi-network +++ b/src/cloud/occi/bin/occi-network @@ -36,18 +36,22 @@ Usage: Commands: -create +* create creates a new virtual network described by the provided -list +* list lists available virtual networks -show +* show retrieves the OCCI XML representation of the virtual network identified by -delete +* update + updates the representation of the network resource represented by the + provided + +* delete deletes the virtual network idenfitied by @@ -164,6 +168,16 @@ case ARGV[0].downcase rc = occi_client.get_network(network_id) + when 'update' + network_xml = ARGV[1] + + if !network_xml || !File.exists?(network_xml) + puts "#{cmd_name} update: missing OCCI-XML or file not found" + exit -1 + end + + rc = occi_client.put_network(network_xml) + when 'delete' network_id = ARGV[1] diff --git a/src/cloud/occi/lib/OCCIClient.rb b/src/cloud/occi/lib/OCCIClient.rb index 3d8b1ba065..1188b33274 100755 --- a/src/cloud/occi/lib/OCCIClient.rb +++ b/src/cloud/occi/lib/OCCIClient.rb @@ -352,6 +352,38 @@ module OCCIClient end end + ###################################################################### + # Puts a new Network representation in order to change its state + # :xmlfile Network OCCI xml representation + ###################################################################### + def put_network(xmlfile) + xml = File.read(xmlfile) + vnet_info = REXML::Document.new(xml).root + + if vnet_info.elements['ID'] == nil + return CloudClient::Error.new("Can not find NETWORK_ID") + end + + vnet_id = vnet_info.elements['ID'].text + + url = URI.parse(@endpoint+'/network/' + vnet_id) + + req = Net::HTTP::Put.new(url.path) + req.body = xml + + req.basic_auth @occiauth[0], @occiauth[1] + + res = CloudClient::http_start(url, @timeout) do |http| + http.request(req) + end + + if CloudClient::is_error?(res) + return res + else + return res.body + end + end + ###################################################################### # :id VM identifier ###################################################################### diff --git a/src/cloud/occi/lib/OCCIServer.rb b/src/cloud/occi/lib/OCCIServer.rb index 6fd0a91290..4088ab6740 100755 --- a/src/cloud/occi/lib/OCCIServer.rb +++ b/src/cloud/occi/lib/OCCIServer.rb @@ -293,6 +293,34 @@ class OCCIServer < CloudServer return "", 204 end + + # Updates a NETWORK resource + # request:: _Hash_ hash containing the data of the request + # [return] _String_,_Integer_ Update confirmation msg or error, + # status code + def put_network(request, params) + xmldoc = XMLElement.build_xml(request.body, 'NETWORK') + vnet_info = XMLElement.new(xmldoc) if xmldoc != nil + + vnet = VirtualNetworkOCCI.new( + VirtualNetwork.build_xml(params[:id]), + get_client(request.env)) + + rc = vnet.info + return rc, 400 if OpenNebula.is_error?(rc) + + if vnet_info['PUBLIC'] == 'YES' + rc = vnet.publish + return rc, 400 if OpenNebula.is_error?(rc) + elsif vnet_info['PUBLIC'] == 'NO' + rc = vnet.unpublish + return rc, 400 if OpenNebula.is_error?(rc) + end + + # --- Prepare XML Response --- + vnet.info + return to_occi_xml(vnet, 202) + end ############################################################################ # STORAGE Methods diff --git a/src/cloud/occi/lib/VirtualNetworkOCCI.rb b/src/cloud/occi/lib/VirtualNetworkOCCI.rb index af3843be3c..7a0d765670 100755 --- a/src/cloud/occi/lib/VirtualNetworkOCCI.rb +++ b/src/cloud/occi/lib/VirtualNetworkOCCI.rb @@ -30,6 +30,7 @@ class VirtualNetworkOCCI < VirtualNetwork <% if self['TEMPLATE/NETWORK_SIZE'] %> <%= self['TEMPLATE/NETWORK_SIZE'] %> <% end %> + <%= self['PUBLIC'] == "0" ? "NO" : "YES"%> } @@ -39,6 +40,9 @@ class VirtualNetworkOCCI < VirtualNetwork <% if @vnet_info['DESCRIPTION'] != nil %> DESCRIPTION = "<%= @vnet_info['DESCRIPTION'] %>" <% end %> + <% if @vnet_info['PUBLIC'] != nil %> + PUBLIC = "<%= @vnet_info['PUBLIC'] %>" + <% end %> <% if @bridge %> BRIDGE = <%= @bridge %> <% end %> diff --git a/src/cloud/occi/lib/occi-server.rb b/src/cloud/occi/lib/occi-server.rb index 82624fdf94..bae43ac655 100755 --- a/src/cloud/occi/lib/occi-server.rb +++ b/src/cloud/occi/lib/occi-server.rb @@ -151,6 +151,11 @@ delete '/network/:id' do treat_response(result,rc) end +put '/network/:id' do + result,rc = $occi_server.put_network(request, params) + treat_response(result,rc) +end + get '/storage/:id' do result,rc = $occi_server.get_storage(request, params) treat_response(result,rc) From d38f7cc49bfaf127423ae89296c0937ffad6fc6c Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Thu, 2 Dec 2010 19:23:44 +0100 Subject: [PATCH 20/28] Add storage publishing and persistent functionality to OCCI --- src/cloud/occi/bin/occi-storage | 23 +++++++++++++++---- src/cloud/occi/lib/ImageOCCI.rb | 8 +++++++ src/cloud/occi/lib/OCCIClient.rb | 37 +++++++++++++++++++++++++++++++ src/cloud/occi/lib/OCCIServer.rb | 34 ++++++++++++++++++++++++++++ src/cloud/occi/lib/occi-server.rb | 5 +++++ 5 files changed, 103 insertions(+), 4 deletions(-) diff --git a/src/cloud/occi/bin/occi-storage b/src/cloud/occi/bin/occi-storage index e2e0fd7aed..b596e869ba 100755 --- a/src/cloud/occi/bin/occi-storage +++ b/src/cloud/occi/bin/occi-storage @@ -36,18 +36,23 @@ Usage: Commands: -create +* create creates a new storage resource described by the provided -list +* list lists available storage resources -show +* show retrieves the OCCI XML representation of the storage resource identified by -delete + +* update + updates the representation of the storage resource represented by the + provided + +* delete deletes the storage resource idenfitied by @@ -166,6 +171,16 @@ case ARGV[0].downcase rc = occi_client.get_image(image_id) + when 'update' + image_xml = ARGV[1] + + if !image_xml || !File.exists?(image_xml) + puts "#{cmd_name} update: missing OCCI-XML or file not found" + exit -1 + end + + rc = occi_client.put_image(image_xml) + when 'delete' image_id = ARGV[1] diff --git a/src/cloud/occi/lib/ImageOCCI.rb b/src/cloud/occi/lib/ImageOCCI.rb index e95768b582..60ca9daaaa 100755 --- a/src/cloud/occi/lib/ImageOCCI.rb +++ b/src/cloud/occi/lib/ImageOCCI.rb @@ -35,6 +35,8 @@ class ImageOCCI < Image <% if fstype != nil %> <%= fstype %> <% end %> + <%= self['PUBLIC'] == "0" ? "NO" : "YES"%> + <%= self['PERSISTENT'] == "0" ? "NO" : "YES"%> } @@ -44,6 +46,12 @@ class ImageOCCI < Image <% if @image_info['DESCRIPTION'] != nil %> DESCRIPTION = "<%= @image_info['DESCRIPTION'] %>" <% end %> + <% if @image_info['PUBLIC'] != nil %> + PUBLIC = "<%= @image_info['PUBLIC'] %>" + <% end %> + <% if @image_info['PERSISTENT'] != nil %> + PERSISTENT = "<%= @image_info['PERSISTENT'] %>" + <% end %> <% if @image_info['TYPE'] != nil %> TYPE = <%= @image_info['TYPE'] %> <% end %> diff --git a/src/cloud/occi/lib/OCCIClient.rb b/src/cloud/occi/lib/OCCIClient.rb index 1188b33274..b5fd1f9c4c 100755 --- a/src/cloud/occi/lib/OCCIClient.rb +++ b/src/cloud/occi/lib/OCCIClient.rb @@ -425,6 +425,43 @@ module OCCIClient end end + ###################################################################### + # Puts a new Storage representation in order to change its state + # :xmlfile Storage OCCI xml representation + ###################################################################### + def put_image(xmlfile) + xml = File.read(xmlfile) + begin + image_info = REXML::Document.new(xml).root + rescue Exception => e + error = OpenNebula::Error.new(e.message) + return error + end + + if image_info.elements['ID'] == nil + return CloudClient::Error.new("Can not find STORAGE_ID") + end + + image_id = image_info.elements['ID'].text + + url = URI.parse(@endpoint+'/storage/' + image_id) + + req = Net::HTTP::Put.new(url.path) + req.body = xml + + req.basic_auth @occiauth[0], @occiauth[1] + + res = CloudClient::http_start(url, @timeout) do |http| + http.request(req) + end + + if CloudClient::is_error?(res) + return res + else + return res.body + end + end + ###################################################################### # :id VM identifier ###################################################################### diff --git a/src/cloud/occi/lib/OCCIServer.rb b/src/cloud/occi/lib/OCCIServer.rb index 4088ab6740..beca4f628c 100755 --- a/src/cloud/occi/lib/OCCIServer.rb +++ b/src/cloud/occi/lib/OCCIServer.rb @@ -391,4 +391,38 @@ class OCCIServer < CloudServer return "", 204 end + + # Updates a STORAGE resource + # request:: _Hash_ hash containing the data of the request + # [return] _String_,_Integer_ Update confirmation msg or error, + # status code + def put_storage(request, params) + xmldoc = XMLElement.build_xml(request.body, 'STORAGE') + image_info = XMLElement.new(xmldoc) if xmldoc != nil + + image = ImageOCCI.new( + Image.build_xml(params[:id]), + get_client(request.env)) + + rc = image.info + return rc, 400 if OpenNebula.is_error?(rc) + + if image_info['PERSISTENT'] == 'YES' + rc = image.persistent + return rc, 400 if OpenNebula.is_error?(rc) + elsif image_info['PERSISTENT'] == 'NO' + rc = image.nonpersistent + return rc, 400 if OpenNebula.is_error?(rc) + elsif image_info['PUBLIC'] == 'YES' + rc = image.publish + return rc, 400 if OpenNebula.is_error?(rc) + elsif image_info['PUBLIC'] == 'NO' + rc = image.unpublish + return rc, 400 if OpenNebula.is_error?(rc) + end + + # --- Prepare XML Response --- + image.info + return to_occi_xml(image, 202) + end end diff --git a/src/cloud/occi/lib/occi-server.rb b/src/cloud/occi/lib/occi-server.rb index bae43ac655..8ac525d330 100755 --- a/src/cloud/occi/lib/occi-server.rb +++ b/src/cloud/occi/lib/occi-server.rb @@ -165,3 +165,8 @@ delete '/storage/:id' do result,rc = $occi_server.delete_storage(request, params) treat_response(result,rc) end + +put '/storage/:id' do + result,rc = $occi_server.put_storage(request, params) + treat_response(result,rc) +end From 3e9627c946bab060685b8eb81f53054532b4a444 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Thu, 2 Dec 2010 19:26:02 +0100 Subject: [PATCH 21/28] Add save_as functionality to OCCI --- src/cloud/occi/lib/OCCIServer.rb | 41 ++++++++++++++++++------ src/cloud/occi/lib/VirtualMachineOCCI.rb | 5 ++- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/cloud/occi/lib/OCCIServer.rb b/src/cloud/occi/lib/OCCIServer.rb index beca4f628c..9587d8e8e0 100755 --- a/src/cloud/occi/lib/OCCIServer.rb +++ b/src/cloud/occi/lib/OCCIServer.rb @@ -213,19 +213,40 @@ class OCCIServer < CloudServer xmldoc = XMLElement.build_xml(request.body, 'COMPUTE') vm_info = XMLElement.new(xmldoc) if xmldoc != nil - # --- Get the VM and Action on it --- - if vm_info['STATE'] != nil - vm = VirtualMachineOCCI.new( - VirtualMachine.build_xml(params[:id]), - get_client(request.env)) + vm = VirtualMachineOCCI.new( + VirtualMachine.build_xml(params[:id]), + get_client(request.env)) + + rc = vm.info + return rc, 400 if OpenNebula.is_error?(rc) + + if image_name = vm_info.attr('DISK/SAVE_AS', 'name') + # Get the disk id + disk_id = vm_info.attr('DISK/SAVE_AS/..', 'id') + if disk_id.nil? + error_msg = "DISK id attribute not specified" + return OpenNebula::Error.new(error_msg), 400 + else + disk_id = disk_id.to_i + end + + # Create a new Image to save the disk + template = "NAME=\"#{image_name}\"\n" + template << "TYPE=OS\n" - rc = vm.mk_action(vm_info['STATE']) + image = Image.new(Image.build_xml, one_client) + rc = image.allocate(template) + return rc, 400 if OpenNebula.is_error?(rc) + + rc = vm.save_as(disk_id, image.id) + if OpenNebula.is_error?(rc) + image.delete + return rc, 400 + end + elsif state = vm_info['STATE'] + rc = vm.mk_action(state) return rc, 400 if OpenNebula.is_error?(rc) - else - error_msg = "State not defined in the OCCI XML" - error = OpenNebula::Error.new(error_msg) - return error, 400 end # --- Prepare XML Response --- diff --git a/src/cloud/occi/lib/VirtualMachineOCCI.rb b/src/cloud/occi/lib/VirtualMachineOCCI.rb index 2235d1fe27..7abc9266e2 100755 --- a/src/cloud/occi/lib/VirtualMachineOCCI.rb +++ b/src/cloud/occi/lib/VirtualMachineOCCI.rb @@ -30,7 +30,10 @@ class VirtualMachineOCCI < VirtualMachine <% end %> <%= self.state_str %> <% self.each('TEMPLATE/DISK') do |disk| %> - + + <% if disk['SAVE_AS'] %> + + <% end %> <%= disk['TYPE'] %> <%= disk['TARGET'] %> From 17d9dd08c5fa3d16165168316f8e8932c33cc328 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Thu, 2 Dec 2010 19:29:49 +0100 Subject: [PATCH 22/28] Check malformed XML in OCCI Client --- src/cloud/occi/lib/OCCIClient.rb | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/cloud/occi/lib/OCCIClient.rb b/src/cloud/occi/lib/OCCIClient.rb index b5fd1f9c4c..47a9d27fec 100755 --- a/src/cloud/occi/lib/OCCIClient.rb +++ b/src/cloud/occi/lib/OCCIClient.rb @@ -162,7 +162,13 @@ module OCCIClient ###################################################################### def post_image(xmlfile, curb=true) xml = File.read(xmlfile) - image_info = REXML::Document.new(xml).root + + begin + image_info = REXML::Document.new(xml).root + rescue Exception => e + error = CloudClient::Error.new(e.message) + return error + end if image_info.elements['URL'] == nil return CloudClient::Error.new("Can not find URL") @@ -285,10 +291,16 @@ module OCCIClient ###################################################################### def put_vm(xmlfile) xml = File.read(xmlfile) - vm_info = REXML::Document.new(xml).root + + begin + vm_info = REXML::Document.new(xml).root + rescue Exception => e + error = CloudClient::Error.new(e.message) + return error + end if vm_info.elements['ID'] == nil - return CloudClient::Error.new("Can not find VM_ID") + return CloudClient::Error.new("Can not find COMPUTE_ID") end vm_id = vm_info.elements['ID'].text @@ -358,7 +370,13 @@ module OCCIClient ###################################################################### def put_network(xmlfile) xml = File.read(xmlfile) - vnet_info = REXML::Document.new(xml).root + + begin + vnet_info = REXML::Document.new(xml).root + rescue Exception => e + error = CloudClient::Error.new(e.message) + return error + end if vnet_info.elements['ID'] == nil return CloudClient::Error.new("Can not find NETWORK_ID") @@ -431,6 +449,7 @@ module OCCIClient ###################################################################### def put_image(xmlfile) xml = File.read(xmlfile) + begin image_info = REXML::Document.new(xml).root rescue Exception => e From 2250ec8f179568e9f221f956d76d41774bd80616 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Thu, 2 Dec 2010 19:38:41 +0100 Subject: [PATCH 23/28] Fix bug in XMLUtils attr with Nokogiri(cherry picked from commit 4f2ea6b9aaf45e7ec75f3137a45dd1d1dcb1863d) --- src/oca/ruby/OpenNebula/XMLUtils.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/oca/ruby/OpenNebula/XMLUtils.rb b/src/oca/ruby/OpenNebula/XMLUtils.rb index 9bb89f1194..898719b675 100644 --- a/src/oca/ruby/OpenNebula/XMLUtils.rb +++ b/src/oca/ruby/OpenNebula/XMLUtils.rb @@ -106,7 +106,9 @@ module OpenNebula return nil end - value = element[name] if element != nil + attribute = element.attr(name) + + value = attribute.text if attribute != nil else element=@xml.elements[key.to_s.upcase] From bf2b2b3a05243393fefe5ea5a6f41ec5a7babff7 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Thu, 2 Dec 2010 19:38:41 +0100 Subject: [PATCH 24/28] Fix bug in XMLUtils attr with Nokogiri(cherry picked from commit 4f2ea6b9aaf45e7ec75f3137a45dd1d1dcb1863d) (cherry picked from commit 2250ec8f179568e9f221f956d76d41774bd80616) --- src/oca/ruby/OpenNebula/XMLUtils.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/oca/ruby/OpenNebula/XMLUtils.rb b/src/oca/ruby/OpenNebula/XMLUtils.rb index 9bb89f1194..898719b675 100644 --- a/src/oca/ruby/OpenNebula/XMLUtils.rb +++ b/src/oca/ruby/OpenNebula/XMLUtils.rb @@ -106,7 +106,9 @@ module OpenNebula return nil end - value = element[name] if element != nil + attribute = element.attr(name) + + value = attribute.text if attribute != nil else element=@xml.elements[key.to_s.upcase] From 33d7eafc9c85db50dba6b32f49de6b8dff86aa1d Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Thu, 9 Dec 2010 17:23:58 +0100 Subject: [PATCH 25/28] Add default values to OCCI custom.erb --- src/cloud/occi/etc/templates/custom.erb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cloud/occi/etc/templates/custom.erb b/src/cloud/occi/etc/templates/custom.erb index 2b91f543e6..f000a411c1 100644 --- a/src/cloud/occi/etc/templates/custom.erb +++ b/src/cloud/occi/etc/templates/custom.erb @@ -4,5 +4,11 @@ # You can also add specific attributes for your cloud in this file (e.g. OS). # -CPU = "<%= @vm_info['CPU'] %>" -MEMORY = "<%= @vm_info['MEMORY'] %>" \ No newline at end of file +# Default values for VM capacity +<% + DEFAULT_CPU = 1 + DEFAULT_MEMORY = 128 +%> + +CPU = "<%= @vm_info['CPU'].nil? ? DEFAULT_CPU : @vm_info['CPU'] %>" +MEMORY = "<%= @vm_info['MEMORY'].nil? ? DEFAULT_MEMORY : @vm_info['MEMORY'] %>" From a51296a3ce0a144b52a0a2ede4313f460997805f Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Thu, 9 Dec 2010 17:29:47 +0100 Subject: [PATCH 26/28] Avoid more than one action per request and overwriting save_as in OCCI --- src/cloud/occi/lib/OCCIServer.rb | 41 +++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/src/cloud/occi/lib/OCCIServer.rb b/src/cloud/occi/lib/OCCIServer.rb index 9587d8e8e0..69c1d06a13 100755 --- a/src/cloud/occi/lib/OCCIServer.rb +++ b/src/cloud/occi/lib/OCCIServer.rb @@ -210,9 +210,6 @@ class OCCIServer < CloudServer # [return] _String_,_Integer_ Update confirmation msg or error, # status code def put_compute(request, params) - xmldoc = XMLElement.build_xml(request.body, 'COMPUTE') - vm_info = XMLElement.new(xmldoc) if xmldoc != nil - vm = VirtualMachineOCCI.new( VirtualMachine.build_xml(params[:id]), get_client(request.env)) @@ -220,14 +217,39 @@ class OCCIServer < CloudServer rc = vm.info return rc, 400 if OpenNebula.is_error?(rc) - if image_name = vm_info.attr('DISK/SAVE_AS', 'name') + xmldoc = XMLElement.build_xml(request.body, 'COMPUTE') + vm_info = XMLElement.new(xmldoc) if xmldoc != nil + + # Check the number of changes in the request + image_name = nil + image_type = nil + vm_info.each('DISK/SAVE_AS') { |disk| + if image_name + error_msg = "It is only allowed one save_as per request" + return OpenNebula::Error.new(error_msg), 400 + end + image_name = disk.attr('.', 'name') + image_type = disk.attr('.', 'type') + } + state = vm_info['STATE'] + + if image_name && state + error_msg = "It is only allowed to change the state and save_as" << + " a disk in the same request" + return OpenNebula::Error.new(error_msg), 400 + elsif image_name # Get the disk id disk_id = vm_info.attr('DISK/SAVE_AS/..', 'id') if disk_id.nil? error_msg = "DISK id attribute not specified" return OpenNebula::Error.new(error_msg), 400 - else - disk_id = disk_id.to_i + end + + disk_id = disk_id.to_i + if vm["TEMPLATE/DISK[DISK_ID=\"#{disk_id}\"]/SAVE_AS"] + error_msg = "The disk #{disk_id} is already" << + " suppossed to be saved" + return OpenNebula::Error.new(error_msg), 400 end # Create a new Image to save the disk @@ -244,7 +266,7 @@ class OCCIServer < CloudServer image.delete return rc, 400 end - elsif state = vm_info['STATE'] + elsif state rc = vm.mk_action(state) return rc, 400 if OpenNebula.is_error?(rc) end @@ -428,7 +450,10 @@ class OCCIServer < CloudServer rc = image.info return rc, 400 if OpenNebula.is_error?(rc) - if image_info['PERSISTENT'] == 'YES' + if image_info['PERSISTENT'] && image_info['PUBLIC'] + error_msg = "It is not allowed more than one change per request" + return OpenNebula::Error.new(error_msg), 400 + elsif image_info['PERSISTENT'] == 'YES' rc = image.persistent return rc, 400 if OpenNebula.is_error?(rc) elsif image_info['PERSISTENT'] == 'NO' From 1288fff17d3da505199953ee698de7d0882e1b3c Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Thu, 9 Dec 2010 17:30:49 +0100 Subject: [PATCH 27/28] Add custom image type to the OCCI save_as --- src/cloud/occi/lib/OCCIServer.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cloud/occi/lib/OCCIServer.rb b/src/cloud/occi/lib/OCCIServer.rb index 69c1d06a13..b7f2079f3a 100755 --- a/src/cloud/occi/lib/OCCIServer.rb +++ b/src/cloud/occi/lib/OCCIServer.rb @@ -254,7 +254,11 @@ class OCCIServer < CloudServer # Create a new Image to save the disk template = "NAME=\"#{image_name}\"\n" - template << "TYPE=OS\n" + if image_type + template << "TYPE=\"#{image_type}\"\n" + else + template << "TYPE=\"OS\"\n" + end image = Image.new(Image.build_xml, one_client) From ae71bd7b47d6574897c93793c1f08dee218083b8 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Thu, 9 Dec 2010 18:28:00 +0100 Subject: [PATCH 28/28] feature #421: Fix typo in error message --- src/cloud/occi/lib/OCCIServer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cloud/occi/lib/OCCIServer.rb b/src/cloud/occi/lib/OCCIServer.rb index b7f2079f3a..add4a47221 100755 --- a/src/cloud/occi/lib/OCCIServer.rb +++ b/src/cloud/occi/lib/OCCIServer.rb @@ -234,7 +234,7 @@ class OCCIServer < CloudServer state = vm_info['STATE'] if image_name && state - error_msg = "It is only allowed to change the state and save_as" << + error_msg = "It is not allowed to change the state and save_as" << " a disk in the same request" return OpenNebula::Error.new(error_msg), 400 elsif image_name