diff --git a/install.sh b/install.sh index 2834543290..98ac05f47b 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" @@ -591,7 +602,9 @@ 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/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/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..d556915e89 --- /dev/null +++ b/share/etc/init.d/oned.centos @@ -0,0 +1,83 @@ +#!/bin/bash +# +# /etc/rc.d/init.d/oned +# +# Starts the OpenNebula daemon +# +# chkconfig: 345 26 74 +# description: Starts the OpenNebula daemon +# processname: oned + +### 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 + +RETVAL=0 + +check() { + # Check that we're a privileged user + [ `id -u` = 0 ] || exit 4 + + # Check if oned is executable + test -x $ONE_BIN || exit 5 +} + +start() { + + check + + echo -n $"Starting OpenNebula daemon: " + daemon --user oneadmin $ONE_BIN start + RETVAL=$? + echo + return $RETVAL +} + +stop() { + + check + + 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) + start + ;; +stop) + stop + ;; +restart) + restart + ;; +status) + status oned + RETVAL=$? + ;; +*) + echo $"Usage: $0 {start|stop|status|restart}" + RETVAL=2 +esac + +exit $RETVAL diff --git a/share/etc/init.d/oned.opensuse b/share/etc/init.d/oned.opensuse new file mode 100755 index 0000000000..1553b6a540 --- /dev/null +++ b/share/etc/init.d/oned.opensuse @@ -0,0 +1,97 @@ +#!/bin/sh + +# -------------------------------------------------------------------------- # +# 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 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 + +ONE_BIN=/usr/bin/one + +. /etc/rc.status + +rc_reset + +case "$1" in + start) + echo -n "Starting ONE " + /sbin/startproc -u oneadmin $ONE_BIN start + rc_status -v + ;; + stop) + echo -n "Shutting down ONE " + /sbin/startproc -u oneadmin $ONE_BIN stop + rc_status -v + ;; + 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 + ;; + 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 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. 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..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 @@ -80,7 +84,6 @@ EOT require 'occi/OCCIClient' require 'CloudClient' require 'getoptlong' -require "rexml/document" include CloudCLI @@ -165,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] @@ -182,22 +195,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..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 @@ -79,8 +84,7 @@ EOT require 'occi/OCCIClient' require 'CloudClient' require 'getoptlong' -require 'rexml/document' -require 'pp' + include CloudCLI opts = GetoptLong.new( @@ -167,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] @@ -184,22 +198,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 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/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) # diff --git a/src/cloud/occi/etc/templates/custom.erb b/src/cloud/occi/etc/templates/custom.erb new file mode 100644 index 0000000000..f000a411c1 --- /dev/null +++ b/src/cloud/occi/etc/templates/custom.erb @@ -0,0 +1,14 @@ +# +# 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). +# + +# 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'] %>" 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 3d8b1ba065..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 @@ -352,6 +364,44 @@ 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) + + 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") + 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 ###################################################################### @@ -393,6 +443,44 @@ 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 6fd0a91290..add4a47221 100755 --- a/src/cloud/occi/lib/OCCIServer.rb +++ b/src/cloud/occi/lib/OCCIServer.rb @@ -210,22 +210,69 @@ class OCCIServer < CloudServer # [return] _String_,_Integer_ Update confirmation msg or error, # status code def put_compute(request, params) + vm = VirtualMachineOCCI.new( + VirtualMachine.build_xml(params[:id]), + get_client(request.env)) + + rc = vm.info + return rc, 400 if OpenNebula.is_error?(rc) + 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 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 + # 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 + end - # --- Get the VM and Action on it --- - if vm_info['STATE'] != nil - vm = VirtualMachineOCCI.new( - VirtualMachine.build_xml(params[:id]), - get_client(request.env)) + 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 + template = "NAME=\"#{image_name}\"\n" + if image_type + template << "TYPE=\"#{image_type}\"\n" + else + template << "TYPE=\"OS\"\n" + end - 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 + 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 --- @@ -293,6 +340,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 @@ -363,4 +438,41 @@ 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'] && 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' + 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/VirtualMachineOCCI.rb b/src/cloud/occi/lib/VirtualMachineOCCI.rb index c72c645525..7abc9266e2 100755 --- a/src/cloud/occi/lib/VirtualMachineOCCI.rb +++ b/src/cloud/occi/lib/VirtualMachineOCCI.rb @@ -22,13 +22,18 @@ 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'] %> <% end %> <%= self.state_str %> <% self.each('TEMPLATE/DISK') do |disk| %> - + + <% if disk['SAVE_AS'] %> + + <% end %> <%= disk['TYPE'] %> <%= disk['TARGET'] %> diff --git a/src/cloud/occi/lib/VirtualNetworkOCCI.rb b/src/cloud/occi/lib/VirtualNetworkOCCI.rb index 9b0be1fb42..7a0d765670 100755 --- a/src/cloud/occi/lib/VirtualNetworkOCCI.rb +++ b/src/cloud/occi/lib/VirtualNetworkOCCI.rb @@ -23,16 +23,26 @@ 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'] %> <% end %> + <%= self['PUBLIC'] == "0" ? "NO" : "YES"%>
} ONE_NETWORK = %q{ NAME = "<%= @vnet_info['NAME'] %>" TYPE = RANGED + <% 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..8ac525d330 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) @@ -160,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 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") 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..898719b675 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 @@ -91,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] 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); 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