From 06a53285657e4e1728ae6435f877edf516712dfc Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Mon, 23 Apr 2012 12:55:05 +0200 Subject: [PATCH 01/36] fix new jQuery 1.7.2 includes in UIs (cherry picked from commit 86d70574d8dd8c30226aa39087eb4bfc210c4a0b) --- src/cloud/occi/lib/ui/templates/login.html | 2 +- src/cloud/occi/lib/ui/views/index.erb | 2 +- src/ozones/Server/templates/index.html | 2 +- src/ozones/Server/templates/login.html | 2 +- src/sunstone/templates/login.html | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cloud/occi/lib/ui/templates/login.html b/src/cloud/occi/lib/ui/templates/login.html index 8bf6d0c005..7fb6b3e456 100644 --- a/src/cloud/occi/lib/ui/templates/login.html +++ b/src/cloud/occi/lib/ui/templates/login.html @@ -5,7 +5,7 @@ - + diff --git a/src/cloud/occi/lib/ui/views/index.erb b/src/cloud/occi/lib/ui/views/index.erb index 2ec20cb5cf..86dd776731 100644 --- a/src/cloud/occi/lib/ui/views/index.erb +++ b/src/cloud/occi/lib/ui/views/index.erb @@ -10,7 +10,7 @@ - + diff --git a/src/ozones/Server/templates/index.html b/src/ozones/Server/templates/index.html index afbc1c3039..cf434eab15 100644 --- a/src/ozones/Server/templates/index.html +++ b/src/ozones/Server/templates/index.html @@ -10,7 +10,7 @@ - + diff --git a/src/ozones/Server/templates/login.html b/src/ozones/Server/templates/login.html index d1001aaaa4..0624092c43 100644 --- a/src/ozones/Server/templates/login.html +++ b/src/ozones/Server/templates/login.html @@ -5,7 +5,7 @@ - + diff --git a/src/sunstone/templates/login.html b/src/sunstone/templates/login.html index 1dc5352d14..c708ec0ea5 100644 --- a/src/sunstone/templates/login.html +++ b/src/sunstone/templates/login.html @@ -6,7 +6,7 @@ - + From 65ecb979d4679e45eacae713405e028b714e50ea Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Tue, 24 Apr 2012 15:44:58 +0200 Subject: [PATCH 02/36] Feature #1222: Fix context scripts with variable number of arguments. --- src/tm_mad/common/context | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/tm_mad/common/context b/src/tm_mad/common/context index a37c4b7f07..913789c62e 100755 --- a/src/tm_mad/common/context +++ b/src/tm_mad/common/context @@ -23,13 +23,19 @@ # - vmid is the id of the VM # - 0 is the target datastore (system) -while (( "$#" )); do - if [ "$#" == "1" ]; then - DST=$1 +i=1 +for arg in "$@"; do + if [ $i -eq $# ]; then + DS_ID="$arg" + elif [ $i -eq $(($#-1)) ]; then + VM_ID="$arg" + elif [ $i -eq $(($#-2)) ]; then + DST="$arg" else - SRC="$SRC $1" + SRC="$SRC $arg" fi - shift + + let i=i+1 done if [ -z "${ONE_LOCATION}" ]; then From ec7c9106d6296b5fdb48df3a00b9f8811554fdab Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Wed, 18 Apr 2012 02:01:31 +0200 Subject: [PATCH 03/36] Feature #1240: Add LVM drivers adapted to the new datastore subsystem (cherry picked from commit 8379ac09aa56971f69e8f2986d6a61723ec23c43) Conflicts: src/datastore_mad/remotes/xpath.rb --- src/datastore_mad/remotes/lvm/cp | 104 +++++++++++++++++++++++++ src/datastore_mad/remotes/lvm/lvm.conf | 24 ++++++ src/datastore_mad/remotes/lvm/mkfs | 92 ++++++++++++++++++++++ src/datastore_mad/remotes/lvm/rm | 73 +++++++++++++++++ src/datastore_mad/remotes/xpath.rb | 18 ++++- src/tm_mad/lvm/clone | 89 +++++++++++++++++++++ src/tm_mad/lvm/delete | 64 +++++++++++++++ src/tm_mad/lvm/ln | 61 +++++++++++++++ src/tm_mad/lvm/mv | 19 +++++ src/tm_mad/lvm/mvds | 68 ++++++++++++++++ 10 files changed, 609 insertions(+), 3 deletions(-) create mode 100755 src/datastore_mad/remotes/lvm/cp create mode 100644 src/datastore_mad/remotes/lvm/lvm.conf create mode 100755 src/datastore_mad/remotes/lvm/mkfs create mode 100755 src/datastore_mad/remotes/lvm/rm create mode 100755 src/tm_mad/lvm/clone create mode 100755 src/tm_mad/lvm/delete create mode 100755 src/tm_mad/lvm/ln create mode 100755 src/tm_mad/lvm/mv create mode 100755 src/tm_mad/lvm/mvds diff --git a/src/datastore_mad/remotes/lvm/cp b/src/datastore_mad/remotes/lvm/cp new file mode 100755 index 0000000000..6c95b0c814 --- /dev/null +++ b/src/datastore_mad/remotes/lvm/cp @@ -0,0 +1,104 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# Copyright 2002-2012, 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. # +#--------------------------------------------------------------------------- # + +############################################################################### +# This script is used to copy a VM image (SRC) to the image repository as DST +# Several SRC types are supported +############################################################################### + +# -------- Set up the environment to source common tools & conf ------------ + +if [ -z "${ONE_LOCATION}" ]; then + LIB_LOCATION=/usr/lib/one +else + LIB_LOCATION=$ONE_LOCATION/lib +fi + +. $LIB_LOCATION/sh/scripts_common.sh + +DRIVER_PATH=$(dirname $0) +source ${DRIVER_PATH}/../libfs.sh +source ${DRIVER_PATH}/lvm.conf + +# -------- Get cp and datastore arguments from OpenNebula core ------------ + +DRV_ACTION=$1 +ID=$2 + +XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION" + +unset i XPATH_ELEMENTS + +while IFS= read -r -d '' element; do + XPATH_ELEMENTS[i++]="$element" +done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/BASE_PATH \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/RESTRICTED_DIRS \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/SAFE_DIRS \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/UMASK \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/HOST \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VG_NAME \ + /DS_DRIVER_ACTION_DATA/IMAGE/PATH) + +BASE_PATH="${XPATH_ELEMENTS[0]}" +RESTRICTED_DIRS="${XPATH_ELEMENTS[1]}" +SAFE_DIRS="${XPATH_ELEMENTS[2]}" +UMASK="${XPATH_ELEMENTS[3]}" +DST_HOST="${XPATH_ELEMENTS[4]:-$HOST}" +VG_NAME="${XPATH_ELEMENTS[5]:-$VG_NAME}" +SRC="${XPATH_ELEMENTS[6]}" + +set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK" + +SIZE=`fs_du $SRC` + +LV_NAME="lv-one-${ID}" +LVM_SOURCE="$DST_HOST:$VG_NAME.$LV_NAME" +DEV="/dev/$VG_NAME/$LV_NAME" + +REGISTER_CMD=$(cat < e @@ -42,7 +48,13 @@ end values = "" -tmp = Base64::decode64(tmp64) +case source +when :stdin + tmp = STDIN.read +when :b64 + tmp = Base64::decode64(tmp64) +end + xml = REXML::Document.new(tmp).root ARGV.each do |xpath| diff --git a/src/tm_mad/lvm/clone b/src/tm_mad/lvm/clone new file mode 100755 index 0000000000..a4a7ab9e92 --- /dev/null +++ b/src/tm_mad/lvm/clone @@ -0,0 +1,89 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# Copyright 2002-2012, 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. # +#--------------------------------------------------------------------------- # + +# clone fe:SOURCE host:remote_system_ds/disk.i size +# - fe is the front-end hostname +# - SOURCE is the path of the disk image in the form DS_BASE_PATH/disk +# - host is the target host to deploy the VM +# - remote_system_ds is the path for the system datastore in the host + +SRC=$1 +DST=$2 +VM_ID=$3 +DS_ID=$4 + +if [ -z "${ONE_LOCATION}" ]; then + TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh +else + TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh +fi + +DRIVER_PATH=$(dirname $0) + +source $TMCOMMON +source ${DRIVER_PATH}/../../datastore/lvm/lvm.conf + +#------------------------------------------------------------------------------- +# Set dst path and dir +#------------------------------------------------------------------------------- + +SRC_HOST=`arg_host $SRC` +SRC_PATH=`arg_path $SRC` + +DST_PATH=`arg_path $DST` +DST_HOST=`arg_host $DST` +DST_DIR=`dirname $DST_PATH` + +#------------------------------------------------------------------------------- +# Get SIZE through XPATH +#------------------------------------------------------------------------------- + +DISK_ID=$(echo $DST_PATH|awk -F. '{print $NF}') + +XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin" +XPATH="$XPATH /VM/TEMPLATE/DISK[DISK_ID='$DISK_ID']/SIZE" + +SIZE=$(onevm show -x $VM_ID | $XPATH ) +[ -z "$SIZE" ] && SIZE=$DEFAULT_SIZE + +#------------------------------------------------------------------------------- +# Get other LVM related fields +#------------------------------------------------------------------------------- + +LV_NAME=`echo $SRC_PATH|cut -d. -f2` +VG_NAME=`echo $SRC_PATH|cut -d. -f1` + +TARGET_DEV="/dev/$VG_NAME/$LV_NAME" +LV_SNAPSHOT="$LV_NAME-$VM_ID-$DISK_ID" +LV_SNAPSHOT_DEV="/dev/$VG_NAME/$LV_SNAPSHOT" + +#------------------------------------------------------------------------------- +# Create the snapshot and link it +#------------------------------------------------------------------------------- + +CLONE_CMD=$(cat < +# - host is the target host to deploy the VM +# - remote_system_ds is the path for the system datastore in the host + +DST=$1 +VM_ID=$2 +DS_ID=$3 + +if [ -z "${ONE_LOCATION}" ]; then + TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh +else + TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh +fi + +. $TMCOMMON + +#------------------------------------------------------------------------------- +# Return if deleting a disk, we will delete them when removing the +# remote_system_ds directory for the VM (remotely) +#------------------------------------------------------------------------------- +DST_PATH=`arg_path $DST` +DST_HOST=`arg_host $DST` + +# Delete the device if it's a clone (LVM snapshot) +DELETE_CMD=$(cat < Date: Tue, 24 Apr 2012 16:34:48 +0200 Subject: [PATCH 04/36] Feature #1240: Update install.sh for LVM drivers --- install.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/install.sh b/install.sh index 5db567dd3b..c668e02297 100755 --- a/install.sh +++ b/install.sh @@ -230,6 +230,7 @@ VAR_DIRS="$VAR_LOCATION/remotes \ $VAR_LOCATION/remotes/tm/ssh \ $VAR_LOCATION/remotes/tm/vmware \ $VAR_LOCATION/remotes/tm/iscsi \ + $VAR_LOCATION/remotes/tm/lvm \ $VAR_LOCATION/remotes/hooks \ $VAR_LOCATION/remotes/hooks/ft \ $VAR_LOCATION/remotes/datastore \ @@ -237,6 +238,7 @@ VAR_DIRS="$VAR_LOCATION/remotes \ $VAR_LOCATION/remotes/datastore/fs \ $VAR_LOCATION/remotes/datastore/vmware \ $VAR_LOCATION/remotes/datastore/iscsi \ + $VAR_LOCATION/remotes/datastore/lvm \ $VAR_LOCATION/remotes/auth \ $VAR_LOCATION/remotes/auth/plain \ $VAR_LOCATION/remotes/auth/ssh \ @@ -391,12 +393,14 @@ INSTALL_FILES=( TM_SSH_FILES:$VAR_LOCATION/remotes/tm/ssh TM_VMWARE_FILES:$VAR_LOCATION/remotes/tm/vmware TM_ISCSI_FILES:$VAR_LOCATION/remotes/tm/iscsi + TM_LVM_FILES:$VAR_LOCATION/remotes/tm/lvm TM_DUMMY_FILES:$VAR_LOCATION/remotes/tm/dummy DATASTORE_DRIVER_COMMON_SCRIPTS:$VAR_LOCATION/remotes/datastore/ DATASTORE_DRIVER_DUMMY_SCRIPTS:$VAR_LOCATION/remotes/datastore/dummy DATASTORE_DRIVER_FS_SCRIPTS:$VAR_LOCATION/remotes/datastore/fs DATASTORE_DRIVER_VMWARE_SCRIPTS:$VAR_LOCATION/remotes/datastore/vmware DATASTORE_DRIVER_ISCSI_SCRIPTS:$VAR_LOCATION/remotes/datastore/iscsi + DATASTORE_DRIVER_LVM_SCRIPTS:$VAR_LOCATION/remotes/datastore/lvm NETWORK_FILES:$VAR_LOCATION/remotes/vnm NETWORK_8021Q_FILES:$VAR_LOCATION/remotes/vnm/802.1Q NETWORK_DUMMY_FILES:$VAR_LOCATION/remotes/vnm/dummy @@ -769,6 +773,7 @@ NETWORK_VMWARE_FILES="src/vnm_mad/remotes/vmware/clean \ # - DUMMY TM, $VAR_LOCATION/tm/dummy # - VMWARE TM, $VAR_LOCATION/tm/vmware # - ISCSI TM, $VAR_LOCATION/tm/iscsi +# - LVM TM, $VAR_LOCATION/tm/lvm #------------------------------------------------------------------------------- TM_FILES="src/tm_mad/tm_common.sh" @@ -823,10 +828,20 @@ TM_ISCSI_FILES="src/tm_mad/iscsi/clone \ src/tm_mad/iscsi/mv \ src/tm_mad/iscsi/mvds \ src/tm_mad/iscsi/delete" + +TM_LVM_FILES="src/tm_mad/lvm/clone \ + src/tm_mad/lvm/ln \ + src/tm_mad/lvm/mv \ + src/tm_mad/lvm/mvds \ + src/tm_mad/lvm/delete" + #------------------------------------------------------------------------------- # Datastore drivers, to be installed under $REMOTES_LOCATION/datastore +# - Dummy Image Repository, $REMOTES_LOCATION/datastore/dummy # - FS based Image Repository, $REMOTES_LOCATION/datastore/fs # - VMware based Image Repository, $REMOTES_LOCATION/datastore/vmware +# - iSCSI based Image Repository, $REMOTES_LOCATION/datastore/iscsi +# - LVM based Image Repository, $REMOTES_LOCATION/datastore/lvm #------------------------------------------------------------------------------- DATASTORE_DRIVER_COMMON_SCRIPTS="src/datastore_mad/remotes/xpath.rb \ @@ -849,6 +864,11 @@ DATASTORE_DRIVER_ISCSI_SCRIPTS="src/datastore_mad/remotes/iscsi/cp \ src/datastore_mad/remotes/iscsi/rm \ src/datastore_mad/remotes/iscsi/iscsi.conf" +DATASTORE_DRIVER_LVM_SCRIPTS="src/datastore_mad/remotes/lvm/cp \ + src/datastore_mad/remotes/lvm/mkfs \ + src/datastore_mad/remotes/lvm/rm \ + src/datastore_mad/remotes/lvm/lvm.conf" + #------------------------------------------------------------------------------- # Migration scripts for onedb command, to be installed under $LIB_LOCATION #------------------------------------------------------------------------------- From 81a142374bebc0281f215b947cfa66cd4d2b3fda Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Tue, 24 Apr 2012 16:53:13 +0200 Subject: [PATCH 05/36] Fix occi-server script, +x is not required --- src/cloud/occi/bin/occi-server | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cloud/occi/bin/occi-server b/src/cloud/occi/bin/occi-server index e9615a2108..72625a1d61 100755 --- a/src/cloud/occi/bin/occi-server +++ b/src/cloud/occi/bin/occi-server @@ -54,7 +54,7 @@ setup() start() { - if [ ! -x "$OCCI_SERVER" ]; then + if [ ! -f "$OCCI_SERVER" ]; then echo "Cannot find $OCCI_SERVER." exit 1 fi From 2de23bbaffdc64ddbaf90cc0fbfb2682986107c6 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Tue, 24 Apr 2012 17:00:29 +0200 Subject: [PATCH 06/36] bug #1211: add retry and force_shutdown to scripts_common --- src/mad/sh/scripts_common.sh | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/mad/sh/scripts_common.sh b/src/mad/sh/scripts_common.sh index 9889741187..0f2b477e1c 100644 --- a/src/mad/sh/scripts_common.sh +++ b/src/mad/sh/scripts_common.sh @@ -176,6 +176,48 @@ function timeout_exec_and_log fi } +# Parameters are times (seconds) and monitoring command (or function). +# Executes monitoring command until it is successful (VM is no longer +# running) or the timeout is reached. +function retry +{ + times=$1 + function=$2 + + count=1 + + ret=$($function) + error=$? + + while [ $count -lt $times -a "$error" != "0" ]; do + sleep 1 + count=$(( $count + 1 )) + ret=$($function) + error=$? + done + + [ "x$error" = "x0" ] +} + +# Parameters are deploy_id and cancel command. If the last command is +# unsuccessful and $FORCE_DESTROY=yes then calls cancel command +function force_shutdown { + error=$? + deploy_id=$1 + command=$2 + + if [ "x$error" != "x0" ]; then + if [ "$FORCE_DESTROY" = "yes" ]; then + log_error "Timeout shutting down $deploy_id. Destroying it" + $($command) + sleep 2 + else + error_message "Timed out shutting down $deploy_id" + exit -1 + fi + fi +} + # This function will return a command that upon execution will format a # filesystem with its proper parameters based on the filesystem type function mkfs_command { From 19fe111fccd8a4371aebce630b9171d7e24c65c8 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Tue, 24 Apr 2012 17:23:02 +0200 Subject: [PATCH 07/36] bug #1211: change vmm/xen/shutdown to make use of retry and force_destroy --- src/vmm_mad/remotes/xen/shutdown | 27 +++++++++++++-------------- src/vmm_mad/remotes/xen/xenrc | 6 ++++++ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/vmm_mad/remotes/xen/shutdown b/src/vmm_mad/remotes/xen/shutdown index d7ed0a16c6..9ec12b8c87 100755 --- a/src/vmm_mad/remotes/xen/shutdown +++ b/src/vmm_mad/remotes/xen/shutdown @@ -21,24 +21,23 @@ source $(dirname $0)/../../scripts_common.sh deploy_id=$1 -function gdm { - $XM_LIST | grep "$deploy_id " +if [ -z "$SHUTDOWN_TIMEOUT" ]; then + TIMEOUT=120 +else + TIMEOUT=$SHUTDOWN_TIMEOUT +fi + +function monitor +{ + $XM_LIST "$deploy_id" > /dev/null + + [ "x$?" != "x0" ] } exec_and_log "$XM_SHUTDOWN $deploy_id" \ "Could not shutdown $deploy_id" -OUT=$(gdm) +retry $TIMEOUT monitor -while [ -n "$OUT" -a "$(echo $OUT | awk '{print $5}')" != "---s--" ]; do - sleep 1 - OUT=$(gdm) -done - -OUT=$(gdm) - -if [ -n "$OUT" ]; then - $XM_CANCEL "$deploy_id" -fi -sleep 2 +force_shutdown "$deploy_id" "$XM_CANCEL \"$deploy_id\"" diff --git a/src/vmm_mad/remotes/xen/xenrc b/src/vmm_mad/remotes/xen/xenrc index 694d9570c1..357a93478b 100644 --- a/src/vmm_mad/remotes/xen/xenrc +++ b/src/vmm_mad/remotes/xen/xenrc @@ -28,4 +28,10 @@ export XM_LIST="sudo $XM_PATH list" export XM_SHUTDOWN="sudo $XM_PATH shutdown" export XM_POLL="sudo /usr/sbin/xentop -bi2" +# Senconds to wait after shutdown until timeout +export SHUTDOWN_TIMEOUT=120 + +# Uncoment this line to force VM cancellation after shutdown timeout +#export FORCE_DESTROY=yes + From fda4161a6c6bc01eb3c9e9a6a898b8ed29113f44 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Mon, 23 Apr 2012 17:12:10 +0200 Subject: [PATCH 08/36] Sunstone: require image target when adding image to VM template. Autofill when attribute is present in image template. Include special input for target in image creation form. (cherry picked from commit c7721e814dac16b1f5d38e3ce603c854a060338f) --- src/sunstone/public/js/plugins/images-tab.js | 19 +++++++++++++++---- .../public/js/plugins/templates-tab.js | 11 ++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/sunstone/public/js/plugins/images-tab.js b/src/sunstone/public/js/plugins/images-tab.js index 4fe86d4051..d7a5ebe693 100644 --- a/src/sunstone/public/js/plugins/images-tab.js +++ b/src/sunstone/public/js/plugins/images-tab.js @@ -36,6 +36,7 @@ var images_tab_content = '\ '+tr("Persistent")+'\ '+tr("Status")+'\ '+tr("#VMS")+'\ + '+tr("Target")+'\ \ \ \ @@ -108,6 +109,11 @@ var create_image_tmpl = \
'+tr("Specific image mapping driver. KVM: raw, qcow2. XEN: tap:aio, file:")+'
\ \ +
\ + \ + \ +
'+tr("Target on which the image will be mounted at. For example: hda, sdb...")+'
\ +
\ \
\
\ @@ -544,7 +550,8 @@ function imageElementArray(image_json){ parseInt(image.PERSISTENT) ? '' : '', OpenNebula.Helper.resource_state("image",image.STATE), - image.RUNNING_VMS + image.RUNNING_VMS, + image.TEMPLATE.TARGET ? image.TEMPLATE.TARGET : '--' ]; } @@ -899,6 +906,10 @@ function setupCreateImageDialog(){ if (driver.length) img_json["DRIVER"] = driver; + var target = $('#img_target',this).val(); + if (target) + img_json["TARGET"] = target; + switch ($('#src_path_select input:checked',this).val()){ case "path": path = $('#img_path',this).val(); @@ -1144,10 +1155,10 @@ $(document).ready(function(){ "aoColumnDefs": [ { "bSortable": false, "aTargets": ["check"] }, { "sWidth": "60px", "aTargets": [0,2,3,9,10] }, - { "sWidth": "35px", "aTargets": [1,6,11] }, + { "sWidth": "35px", "aTargets": [1,6,11,12] }, { "sWidth": "100px", "aTargets": [5,7] }, { "sWidth": "150px", "aTargets": [8] }, - { "bVisible": false, "aTargets": [6,8]} + { "bVisible": false, "aTargets": [6,8,12]} ], "oLanguage": (datatable_lang != "") ? { @@ -1158,7 +1169,7 @@ $(document).ready(function(){ dataTable_images.fnClearTable(); addElement([ spinner, - '','','','','','','','','','',''],dataTable_images); + '','','','','','','','','','','',''],dataTable_images); Sunstone.runAction("Image.list"); setupCreateImageDialog(); diff --git a/src/sunstone/public/js/plugins/templates-tab.js b/src/sunstone/public/js/plugins/templates-tab.js index 993f3980fb..8411a95bd8 100644 --- a/src/sunstone/public/js/plugins/templates-tab.js +++ b/src/sunstone/public/js/plugins/templates-tab.js @@ -208,7 +208,7 @@ var create_template_tmpl = '
\ \
'+tr("Type of disk device to emulate: ide, scsi")+'
\
\ -
\ +
\ \ \
'+tr("Device to map image disk. If set, it will overwrite the default device mapping")+'
\ @@ -1405,6 +1405,11 @@ function setupCreateTemplateDialog(){ $('#IMAGE', section_disks).change(function(){ var uname = getValue($(this).val(),4,2,dataTable_images); $('input#IMAGE_UNAME',section_disks).val(uname); + var target = getValue($(this).val(),4,12,dataTable_images); + if (target && target != "--") + $('input#TARGET',section_disks).val(target); + else + $('input#TARGET',section_disks).val(''); }); //Depending on adding a disk or a image we need to show/hide @@ -1420,16 +1425,12 @@ function setupCreateTemplateDialog(){ $('.add_image',section_disks).attr('disabled','disabled'); $('.add_disk',section_disks).show(); $('.add_disk',section_disks).removeAttr('disabled'); - $('#TARGET',section_disks).parent().removeClass(opt_class); - $('#TARGET',section_disks).parent().addClass(man_class); break; case "image": $('.add_disk',section_disks).hide(); $('.add_disk',section_disks).attr('disabled','disabled'); $('.add_image',section_disks).show(); $('.add_image',section_disks).removeAttr('disabled'); - $('#TARGET',section_disks).parent().removeClass(man_class); - $('#TARGET',section_disks).parent().addClass(opt_class); break; } $('#SIZE',section_disks).parent().hide(); From fda520349f381aaf6acbde9e684d363ae5661de5 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Tue, 24 Apr 2012 12:44:21 +0200 Subject: [PATCH 09/36] Feature #1218: add IP column to compute list in Selfservice (cherry picked from commit 5fcb907a9ecfc8b561f125dfe10a55e1b4e204f4) --- .../occi/lib/ui/public/js/plugins/compute.js | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/cloud/occi/lib/ui/public/js/plugins/compute.js b/src/cloud/occi/lib/ui/public/js/plugins/compute.js index cedf1210e1..2f405ad7c7 100644 --- a/src/cloud/occi/lib/ui/public/js/plugins/compute.js +++ b/src/cloud/occi/lib/ui/public/js/plugins/compute.js @@ -63,6 +63,7 @@ var vms_tab_content = '+tr("All")+'\ '+tr("ID")+'\ '+tr("Name")+' / '+tr("State")+'\ + '+tr("IP")+'\ \ \ \ @@ -397,6 +398,20 @@ function str_start_time(vm){ return pretty_time(vm.STIME); } +function ip_str(vm){ + var nic = vm.NIC; + var ip = '--'; + if ($.isArray(nic)) { + ip = ''; + $.each(nic, function(index,value){ + ip += value.IP+'
'; + }); + } else if (nic && nic.IP) { + ip = nic.IP; + }; + return ip; +}; + // Returns an array formed by the information contained in the vm_json // and ready to be introduced in a dataTable function vMachineElementArray(vm_json){ @@ -416,7 +431,8 @@ function vMachineElementArray(vm_json){ return [ '', id, - VMStateBulletStr(vm_json) + name + VMStateBulletStr(vm_json) + name, + ip_str(vm) ]; } @@ -454,7 +470,7 @@ function addVMachineElement(request,vm_json){ var id = vm_json.COMPUTE.ID; var element = vMachineElementArray(vm_json); addElement(element,dataTable_vMachines); - Sunstone.runAction("VM.showstate",id); + Sunstone.runAction("VM.show",id); } @@ -1097,6 +1113,7 @@ $(document).ready(function(){ { "bSortable": false, "aTargets": ["check"] }, { "sWidth": "60px", "aTargets": [0] }, { "sWidth": "35px", "aTargets": [1] }, + { "sWidth": "110px", "aTargets": [3] }, ], "oLanguage": (datatable_lang != "") ? { @@ -1107,7 +1124,7 @@ $(document).ready(function(){ dataTable_vMachines.fnClearTable(); addElement([ spinner, - '',''],dataTable_vMachines); + '','',''],dataTable_vMachines); Sunstone.runAction("VM.list"); //setupCreateVMDialog(); From 6fc7eac554362ddcfc5f0ee990e1f0cf5d838249 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Tue, 24 Apr 2012 11:45:27 +0200 Subject: [PATCH 10/36] Bug #1043: Prevent VNC dialog from closing with ESC key in Sunstone and SelfService (cherry picked from commit 889249a6af8a78bd43452042302b7bd3b4405e31) --- src/cloud/occi/lib/ui/public/js/plugins/compute.js | 1 + src/sunstone/public/js/plugins/vms-tab.js | 1 + 2 files changed, 2 insertions(+) diff --git a/src/cloud/occi/lib/ui/public/js/plugins/compute.js b/src/cloud/occi/lib/ui/public/js/plugins/compute.js index 2f405ad7c7..5b99c81c9f 100644 --- a/src/cloud/occi/lib/ui/public/js/plugins/compute.js +++ b/src/cloud/occi/lib/ui/public/js/plugins/compute.js @@ -1013,6 +1013,7 @@ function setupVNC(){ modal:true, height:500, resizable:true, + closeOnEscape: false }); $('#sendCtrlAltDelButton',dialog).click(function(){ diff --git a/src/sunstone/public/js/plugins/vms-tab.js b/src/sunstone/public/js/plugins/vms-tab.js index 8a936c904a..e4ec4f57d8 100644 --- a/src/sunstone/public/js/plugins/vms-tab.js +++ b/src/sunstone/public/js/plugins/vms-tab.js @@ -1300,6 +1300,7 @@ function setupVNC(){ modal:true, height:500, resizable:true, + closeOnEscape: false }); $('#sendCtrlAltDelButton',dialog).click(function(){ From e024d57def62684a4e0cb846a6753b9cb4bd4f67 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Wed, 25 Apr 2012 10:33:46 +0200 Subject: [PATCH 11/36] Fix watch_client filtering (cherry picked from commit 590ba0e4eb25c126d59d4df91646f10ec2a5ec6a) --- src/acct/watch_client.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/acct/watch_client.rb b/src/acct/watch_client.rb index 7a63251a48..c3da4289bf 100644 --- a/src/acct/watch_client.rb +++ b/src/acct/watch_client.rb @@ -154,7 +154,7 @@ module OneWatchClient if filter[:uid] filter[:uid]==0 ? (hosts = pool) : (return nil) elsif filter[:gid] - filter[:uid]==0 ? (hosts = pool) : (return nil) + filter[:gid]==0 ? (hosts = pool) : (return nil) else hosts = pool end From 156d2ea9e08d1f0a551a36007d670e4ee24689d0 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Wed, 25 Apr 2012 11:59:59 +0200 Subject: [PATCH 12/36] Feature #1222: Improve readability of the context scripts --- src/tm_mad/common/context | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/tm_mad/common/context b/src/tm_mad/common/context index 913789c62e..d419cd60fa 100755 --- a/src/tm_mad/common/context +++ b/src/tm_mad/common/context @@ -23,20 +23,12 @@ # - vmid is the id of the VM # - 0 is the target datastore (system) -i=1 -for arg in "$@"; do - if [ $i -eq $# ]; then - DS_ID="$arg" - elif [ $i -eq $(($#-1)) ]; then - VM_ID="$arg" - elif [ $i -eq $(($#-2)) ]; then - DST="$arg" - else - SRC="$SRC $arg" - fi +ARGV=("$@") - let i=i+1 -done +DS_ID="${ARGV[$(($#-1))]}" +VM_ID="${ARGV[$(($#-2))]}" +DST="${ARGV[$(($#-3))]}" +SRC="${ARGV[@]:0:$(($#-3))}" if [ -z "${ONE_LOCATION}" ]; then TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh From 6c726bfe4e3145cf972ab4f81f23db018fbcf965 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Wed, 25 Apr 2012 13:13:17 +0200 Subject: [PATCH 13/36] Feature #1207: Add custom input field for host drivers and user auth driver (cherry picked from commit 01cef094183a0da70b19dcb730106950de85aa60) --- src/sunstone/public/js/plugins/hosts-tab.js | 67 ++++++++++++++++++--- src/sunstone/public/js/plugins/users-tab.js | 17 +++++- 2 files changed, 73 insertions(+), 11 deletions(-) diff --git a/src/sunstone/public/js/plugins/hosts-tab.js b/src/sunstone/public/js/plugins/hosts-tab.js index 1376a8566d..431985711f 100644 --- a/src/sunstone/public/js/plugins/hosts-tab.js +++ b/src/sunstone/public/js/plugins/hosts-tab.js @@ -84,7 +84,11 @@ var create_host_tmpl = \ \ \ + \ \ +
\ + \ +
\
\
\ \ @@ -94,18 +98,28 @@ var create_host_tmpl = \ \ \ + \ \ +
\ + \ + \ +
\
\
\ \ \ +
\ + \ + \ +
\
\
\ \ @@ -595,9 +609,35 @@ function setupCreateHostDialog(){ $('button',dialog).button(); + $('input[name="custom_vmm_mad"],'+ + 'input[name="custom_im_mad"],'+ + 'input[name="custom_vnm_mad"]',dialog).parent().hide(); + + $('select#vmm_mad',dialog).change(function(){ + if ($(this).val()=="custom") + $('input[name="custom_vmm_mad"]').parent().show(); + else + $('input[name="custom_vmm_mad"]').parent().hide(); + }); + + $('select#im_mad',dialog).change(function(){ + if ($(this).val()=="custom") + $('input[name="custom_im_mad"]').parent().show(); + else + $('input[name="custom_im_mad"]').parent().hide(); + }); + + $('select#vnm_mad',dialog).change(function(){ + if ($(this).val()=="custom") + $('input[name="custom_vnm_mad"]').parent().show(); + else + $('input[name="custom_vnm_mad"]').parent().hide(); + }); + //Handle the form submission $('#create_host_form',dialog).submit(function(){ - if (!($('#name',this).val().length)){ + var name = $('#name',this).val(); + if (!name){ notifyError(tr("Host name missing!")); return false; } @@ -605,12 +645,19 @@ function setupCreateHostDialog(){ var cluster_id = $('#host_cluster_id',this).val(); if (!cluster_id) cluster_id = "-1"; + var vmm_mad = $('select#vmm_mad',this).val(); + vmm_mad = vmm_mad == "custom" ? $('input[name="custom_vmm_mad"]').val() : vmm_mad; + var im_mad = $('select#im_mad',this).val(); + im_mad = im_mad == "custom" ? $('input[name="custom_im_mad"]').val() : im_mad; + var vnm_mad = $('select#vnm_mad',this).val(); + vnm_mad = vnm_mad == "custom" ? $('input[name="custom_vnm_mad"]').val() : vnm_mad; + var host_json = { "host": { - "name": $('#name',this).val(), - "vm_mad": $('#vmm_mad',this).val(), - "vnm_mad": $('#vnm_mad',this).val(), - "im_mad": $('#im_mad',this).val(), + "name": name, + "vm_mad": vmm_mad, + "vnm_mad": vnm_mad, + "im_mad": im_mad, "cluster_id": cluster_id } }; diff --git a/src/sunstone/public/js/plugins/users-tab.js b/src/sunstone/public/js/plugins/users-tab.js index 1585513a31..d1f4aa34ab 100644 --- a/src/sunstone/public/js/plugins/users-tab.js +++ b/src/sunstone/public/js/plugins/users-tab.js @@ -60,7 +60,12 @@ var create_user_tmpl = \ \ \ + \ \ +
\ + \ +
\ +
\
\
\
\ @@ -444,15 +449,25 @@ function setupCreateUserDialog(){ $('button',dialog).button(); + $('input[name="custom_auth"]',dialog).parent().hide(); + $('select#driver').change(function(){ + if ($(this).val() == "custom") + $('input[name="custom_auth"]',dialog).parent().show(); + else + $('input[name="custom_auth"]',dialog).parent().hide(); + }); + $('#create_user_form',dialog).submit(function(){ var user_name=$('#username',this).val(); var user_password=$('#pass',this).val(); var driver = $('#driver', this).val(); + if (driver == 'custom') + driver = $('input[name="custom_auth"]').val(); if (!user_name.length || !user_password.length){ notifyError(tr("User name and password must be filled in")); return false; - } + }; var user_json = { "user" : { "name" : user_name, From c8d8e1d1ccfee5db17fe464aacdb5336dd96b7bc Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Wed, 25 Apr 2012 16:12:46 +0200 Subject: [PATCH 14/36] bug #1211: change vmm/kvm/shutdown to make use of retry and force_destroy --- src/vmm_mad/remotes/kvm/kvmrc | 7 ++++ src/vmm_mad/remotes/kvm/shutdown | 59 +++++++++++++++----------------- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/vmm_mad/remotes/kvm/kvmrc b/src/vmm_mad/remotes/kvm/kvmrc index 3c4650a9cd..0cb2f2791f 100644 --- a/src/vmm_mad/remotes/kvm/kvmrc +++ b/src/vmm_mad/remotes/kvm/kvmrc @@ -19,3 +19,10 @@ export LANG=C export LIBVIRT_URI=qemu:///system export QEMU_PROTOCOL=qemu+ssh + +# Senconds to wait after shutdown until timeout +export SHUTDOWN_TIMEOUT=120 + +# Uncoment this line to force VM cancellation after shutdown timeout +#export FORCE_DESTROY=yes + diff --git a/src/vmm_mad/remotes/kvm/shutdown b/src/vmm_mad/remotes/kvm/shutdown index 86f82002c9..936f80cb71 100755 --- a/src/vmm_mad/remotes/kvm/shutdown +++ b/src/vmm_mad/remotes/kvm/shutdown @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash # -------------------------------------------------------------------------- # # Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # @@ -19,45 +19,42 @@ source $(dirname $0)/kvmrc source $(dirname $0)/../../scripts_common.sh -#------------------------------------------------------------------------------ -# Wait the VM to shutdown TIMEOUT (xPOLL_INTERVAL) seconds. -# Set to ~10min -#------------------------------------------------------------------------------ -POLL_INTERVAL=2 -TIMEOUT=300 -HALF_LOOP=$(($TIMEOUT/POLL_INTERVAL)) +count=0 deploy_id=$1 -virsh --connect $LIBVIRT_URI shutdown $deploy_id - -exit_code=$? - -if [ "$exit_code" != "0" ]; then - error_message "Could not shutdown $deploy_id" - exit $exit_code +if [ -z "$SHUTDOWN_TIMEOUT" ]; then + TIMEOUT=120 +else + TIMEOUT=$SHUTDOWN_TIMEOUT fi -count=0 -while [ $(virsh --connect $LIBVIRT_URI --readonly dominfo $deploy_id > /dev/null 2>&1; echo $?) = "0" ] -do - sleep $POLL_INTERVAL - if [ "$count" -gt "$TIMEOUT" ] - then - error_message "Timeout reached and VM $deploy_id is still alive" - echo "Timeout reached" >&2 - exit 1 - fi +HALF_LOOP=$(($TIMEOUT/2)) +function monitor +{ # Issue another shutdown to cover occasional libvirt lack of attention - if [ "$count" -eq "$HALF_LOOP" ] - then - virsh --connect $LIBVIRT_URI shutdown $deploy_id + if [ "$count" -eq "$HALF_LOOP" ] + then + virsh --connect $LIBVIRT_URI shutdown $deploy_id fi - let count=count+$POLL_INTERVAL -done + let count=count+1 + + export count + + virsh --connect $LIBVIRT_URI --readonly dominfo $deploy_id > /dev/null 2>&1 + + [ "x$?" != "x0" ] +} + +exec_and_log "virsh --connect $LIBVIRT_URI shutdown \"$deploy_id\"" \ + "Could not shutdown $deploy_id" + +retry $TIMEOUT monitor + +force_shutdown "$deploy_id" \ + "virsh --connect $LIBVIRT_URI destroy \"$deploy_id\"" sleep 4 -exit 0 From d364c3e57f67790e64547b81f63c0c18ed58745c Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Wed, 25 Apr 2012 16:44:00 +0200 Subject: [PATCH 15/36] bug #1211: default shutdown timeout is now 300 and typo fixing --- src/vmm_mad/remotes/kvm/kvmrc | 6 +++--- src/vmm_mad/remotes/xen/xenrc | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/vmm_mad/remotes/kvm/kvmrc b/src/vmm_mad/remotes/kvm/kvmrc index 0cb2f2791f..8f36a9b9a0 100644 --- a/src/vmm_mad/remotes/kvm/kvmrc +++ b/src/vmm_mad/remotes/kvm/kvmrc @@ -20,9 +20,9 @@ export LIBVIRT_URI=qemu:///system export QEMU_PROTOCOL=qemu+ssh -# Senconds to wait after shutdown until timeout -export SHUTDOWN_TIMEOUT=120 +# Seconds to wait after shutdown until timeout +export SHUTDOWN_TIMEOUT=300 -# Uncoment this line to force VM cancellation after shutdown timeout +# Uncomment this line to force VM cancellation after shutdown timeout #export FORCE_DESTROY=yes diff --git a/src/vmm_mad/remotes/xen/xenrc b/src/vmm_mad/remotes/xen/xenrc index 357a93478b..96a3dfb024 100644 --- a/src/vmm_mad/remotes/xen/xenrc +++ b/src/vmm_mad/remotes/xen/xenrc @@ -28,10 +28,10 @@ export XM_LIST="sudo $XM_PATH list" export XM_SHUTDOWN="sudo $XM_PATH shutdown" export XM_POLL="sudo /usr/sbin/xentop -bi2" -# Senconds to wait after shutdown until timeout -export SHUTDOWN_TIMEOUT=120 +# Seconds to wait after shutdown until timeout +export SHUTDOWN_TIMEOUT=300 -# Uncoment this line to force VM cancellation after shutdown timeout +# Uncomment this line to force VM cancellation after shutdown timeout #export FORCE_DESTROY=yes From 0775a43100c6e1d04f3409f2419bde96b19cedcb Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Thu, 26 Apr 2012 16:13:05 +0200 Subject: [PATCH 16/36] bug #1211: Remove unnecessary quotes in the shutdown script (cherry picked from commit 69cd251c9120cd4528900a186359b707b7951382) --- src/vmm_mad/remotes/kvm/shutdown | 4 ++-- src/vmm_mad/remotes/xen/shutdown | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/vmm_mad/remotes/kvm/shutdown b/src/vmm_mad/remotes/kvm/shutdown index 936f80cb71..2e6b1099c3 100755 --- a/src/vmm_mad/remotes/kvm/shutdown +++ b/src/vmm_mad/remotes/kvm/shutdown @@ -48,13 +48,13 @@ function monitor [ "x$?" != "x0" ] } -exec_and_log "virsh --connect $LIBVIRT_URI shutdown \"$deploy_id\"" \ +exec_and_log "virsh --connect $LIBVIRT_URI shutdown $deploy_id" \ "Could not shutdown $deploy_id" retry $TIMEOUT monitor force_shutdown "$deploy_id" \ - "virsh --connect $LIBVIRT_URI destroy \"$deploy_id\"" + "virsh --connect $LIBVIRT_URI destroy $deploy_id" sleep 4 diff --git a/src/vmm_mad/remotes/xen/shutdown b/src/vmm_mad/remotes/xen/shutdown index 9ec12b8c87..69aff84621 100755 --- a/src/vmm_mad/remotes/xen/shutdown +++ b/src/vmm_mad/remotes/xen/shutdown @@ -39,5 +39,5 @@ exec_and_log "$XM_SHUTDOWN $deploy_id" \ retry $TIMEOUT monitor -force_shutdown "$deploy_id" "$XM_CANCEL \"$deploy_id\"" +force_shutdown "$deploy_id" "$XM_CANCEL $deploy_id" From e9e5d95417327029bcdfaefc5b52f59fa2bff9fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 25 Apr 2012 16:47:00 +0200 Subject: [PATCH 17/36] Revert "bug #1232: Set default targets for EC2 API" This reverts commit 44af8c66076411d1728724801915ba122d8fbd2b. --- src/cloud/ec2/etc/templates/m1.small.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cloud/ec2/etc/templates/m1.small.erb b/src/cloud/ec2/etc/templates/m1.small.erb index 3f9ad0a8b8..57fbb2cfc2 100644 --- a/src/cloud/ec2/etc/templates/m1.small.erb +++ b/src/cloud/ec2/etc/templates/m1.small.erb @@ -11,7 +11,7 @@ MEMORY = 256 # root = sda1, # kernel_cmd = "ro xencons=tty console=tty1"] -DISK = [ IMAGE_ID = <%= erb_vm_info[:img_id] %>, TARGET = "hda" ] +DISK = [ IMAGE_ID = <%= erb_vm_info[:img_id] %> ] # Put here the ID of the VNET with the IPs for the EC2 VMs NIC=[NETWORK_ID=] @@ -22,6 +22,6 @@ INSTANCE_TYPE = <%= erb_vm_info[:instance_type ]%> <% if erb_vm_info[:user_data] %> CONTEXT = [ EC2_USER_DATA="<%= erb_vm_info[:user_data] %>", - TARGET="hdb" + TARGET="hdc" ] <% end %> From f0c1641fdcea04c3731e8ef4a777fddd207b546e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 25 Apr 2012 16:47:12 +0200 Subject: [PATCH 18/36] Revert "bug #1232: Only allow Datastore & volatile disks. Remove automatic target generation. Remove unneeded oned.conf attributes" This reverts commit e401b4900d99104d77c83f80c2a9e48daf668af5. --- include/Image.h | 15 ++-- include/ImagePool.h | 16 ++++ include/test/NebulaTest.h | 3 +- share/etc/oned.conf | 12 ++- src/image/Image.cc | 83 +++++++++++++++----- src/image/ImageManagerActions.cc | 1 - src/image/ImagePool.cc | 50 ++++++------ src/image/test/ImagePoolTest.cc | 129 ++++++++++++++++++++++++++++--- src/nebula/Nebula.cc | 11 ++- src/nebula/NebulaTemplate.cc | 6 ++ src/test/Nebula.cc | 4 +- src/test/NebulaTest.cc | 5 +- src/vm/VirtualMachine.cc | 74 ++++++++++++++++-- 13 files changed, 329 insertions(+), 80 deletions(-) diff --git a/include/Image.h b/include/Image.h index 871046a443..bdee93831a 100644 --- a/include/Image.h +++ b/include/Image.h @@ -329,13 +329,18 @@ public: * Modifies the given disk attribute adding the following attributes: * * SOURCE: the file-path. * * BUS: will only be set if the Image's definition includes it. - * * TARGET: if not set uses that in the image template + * * TARGET: the value set depends on: + * - OS images will be mounted at prefix + a: hda, sda. + * - Prefix + b is reserved for the contex cdrom. + * - CDROM images will be at prefix + c: hdc, sdc. + * - Several DATABLOCK images can be mounted, they will be set to + * prefix + (d + index) : hdd, hde, hdf... * @param disk attribute for the VM template - * - * @return -1 if there is no TARGET in the disk nor in the template, 0 - * otherwise + * @param index number of datablock images used by the same VM. Will be + * automatically increased. + * @param img_type will be set to the used image's type */ - int disk_attribute(VectorAttribute * disk); + int disk_attribute(VectorAttribute * disk, int* index, ImageType* img_type); /** * Factory method for image templates diff --git a/include/ImagePool.h b/include/ImagePool.h index e4792b6677..4fc8038f9b 100644 --- a/include/ImagePool.h +++ b/include/ImagePool.h @@ -40,6 +40,7 @@ public: ImagePool(SqlDB * db, const string& _default_type, + const string& _default_dev_prefix, vector& restricted_attrs); ~ImagePool(){}; @@ -135,6 +136,9 @@ public: * Generates a DISK attribute for VM templates using the Image metadata * @param disk the disk to be generated * @param disk_id the id for this disk + * @param index number of datablock images used by the same VM. Will be + * automatically increased. + * @param img_type will be set to the used image's type * @param uid of VM owner (to look for the image id within its images) * @param image_id on success returns the acquired image id * @param error_str string describing the error @@ -144,6 +148,8 @@ public: */ int disk_attribute(VectorAttribute * disk, int disk_id, + int * index, + Image::ImageType * img_type, int uid, int& image_id, string& error_str); @@ -160,6 +166,11 @@ public: return _default_type; }; + static const string& default_dev_prefix() + { + return _default_dev_prefix; + }; + private: //-------------------------------------------------------------------------- // Configuration Attributes for Images @@ -170,6 +181,11 @@ private: **/ static string _default_type; + /** + * Default device prefix + **/ + static string _default_dev_prefix; + //-------------------------------------------------------------------------- // Pool Attributes // ------------------------------------------------------------------------- diff --git a/include/test/NebulaTest.h b/include/test/NebulaTest.h index 754289367c..bd73d4f201 100644 --- a/include/test/NebulaTest.h +++ b/include/test/NebulaTest.h @@ -104,7 +104,8 @@ public: virtual UserPool* create_upool(SqlDB* db); - virtual ImagePool* create_ipool(SqlDB* db, + virtual ImagePool* create_ipool( SqlDB* db, + string default_image_type, string default_device_prefix); virtual VMTemplatePool* create_tpool(SqlDB* db); diff --git a/share/etc/oned.conf b/share/etc/oned.conf index c49a503ecd..0bf1cd0492 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -88,11 +88,19 @@ MAC_PREFIX = "02:00" # DEFAULT_IMAGE_TYPE: This can take values # OS Image file holding an operating system # CDROM Image file holding a CDROM -# DATABLOCK Image file holding a datablock, created as an empty block +# DATABLOCK Image file holding a datablock, +# always created as an empty block +# DEFAULT_DEVICE_PREFIX: This can be set to +# hd IDE prefix +# sd SCSI +# xvd XEN Virtual Disk +# vd KVM virtual disk #******************************************************************************* #DATASTORE_LOCATION = /var/lib/one/datastores -DEFAULT_IMAGE_TYPE = "OS" + +DEFAULT_IMAGE_TYPE = "OS" +DEFAULT_DEVICE_PREFIX = "hd" #******************************************************************************* # Information Driver Configuration diff --git a/src/image/Image.cc b/src/image/Image.cc index 389b7ef0fd..adcb40d64c 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -130,6 +130,17 @@ int Image::insert(SqlDB *db, string& error_str) persistent_img = (persistent_attr == "YES"); + // ------------ PREFIX -------------------- + + get_template_attribute("DEV_PREFIX", dev_prefix); + + if( dev_prefix.empty() ) + { + SingleAttribute * dev_att = new SingleAttribute("DEV_PREFIX", + ImagePool::default_dev_prefix()); + obj_template->set(dev_att); + } + // ------------ PATH & SOURCE -------------------- erase_template_attribute("PATH", path); @@ -426,15 +437,18 @@ int Image::from_xml(const string& xml) /* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */ -int Image::disk_attribute(VectorAttribute * disk) +int Image::disk_attribute( VectorAttribute * disk, + int * index, + ImageType* img_type) { - string bus; - string target; - string driver; - string disk_attr_type; + string bus; + string target; + string driver; + string disk_attr_type; - ostringstream iid; + ostringstream iid; + *img_type = type; bus = disk->vector_value("BUS"); target = disk->vector_value("TARGET"); driver = disk->vector_value("DRIVER"); @@ -442,30 +456,24 @@ int Image::disk_attribute(VectorAttribute * disk) string template_bus; string template_target; + string prefix; string template_driver; - get_template_attribute("BUS", template_bus); + get_template_attribute("BUS", template_bus); get_template_attribute("TARGET", template_target); get_template_attribute("DRIVER", template_driver); - //--------------------------------------------------------------------------- - // TARGET attribute - //--------------------------------------------------------------------------- - if (target.empty()) + get_template_attribute("DEV_PREFIX", prefix); + + if (prefix.empty())//Removed from image template, get it again from defaults { - if (!template_target.empty()) - { - disk->replace("TARGET", template_target); - } - else //No TARGET in DISK nor in Image (ERROR!) - { - return -1; - } + prefix = ImagePool::default_dev_prefix(); } //--------------------------------------------------------------------------- // BASE DISK ATTRIBUTES //--------------------------------------------------------------------------- + disk->replace("IMAGE", name); disk->replace("IMAGE_ID", iid.str()); disk->replace("SOURCE", source); @@ -483,6 +491,7 @@ int Image::disk_attribute(VectorAttribute * disk) //--------------------------------------------------------------------------- // TYPE, READONLY, CLONE, and SAVE attributes //--------------------------------------------------------------------------- + if ( persistent_img ) { disk->replace("CLONE","NO"); @@ -509,8 +518,42 @@ int Image::disk_attribute(VectorAttribute * disk) break; } + disk->replace("TYPE",disk_attr_type); - + + //--------------------------------------------------------------------------- + // TARGET attribute + //--------------------------------------------------------------------------- + + if (target.empty()) //No TARGET in DISK attribute + { + if (!template_target.empty()) + { + disk->replace("TARGET", template_target); + } + else + { + switch(type) + { + case OS: + prefix += "a"; + break; + + case CDROM: + prefix += "c"; // b is for context + break; + + case DATABLOCK: + prefix += static_cast(('e'+ *index)); + *index = *index + 1; + break; + + } + + disk->replace("TARGET", prefix); + } + } + return 0; } diff --git a/src/image/ImageManagerActions.cc b/src/image/ImageManagerActions.cc index 17f63c3f62..58f41d3d33 100644 --- a/src/image/ImageManagerActions.cc +++ b/src/image/ImageManagerActions.cc @@ -191,7 +191,6 @@ void ImageManager::release_image(int iid, bool failed) img->unlock(); break; - case Image::DISABLED: case Image::READY: case Image::ERROR: diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index 48ad8be838..3fde07920c 100644 --- a/src/image/ImagePool.cc +++ b/src/image/ImagePool.cc @@ -26,12 +26,14 @@ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ string ImagePool::_default_type; +string ImagePool::_default_dev_prefix; /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -ImagePool::ImagePool(SqlDB * db, - const string& __default_type, +ImagePool::ImagePool(SqlDB * db, + const string& __default_type, + const string& __default_dev_prefix, vector& restricted_attrs): PoolSQL(db, Image::table, true) { @@ -39,6 +41,7 @@ ImagePool::ImagePool(SqlDB * db, // Init static defaults _default_type = __default_type; + _default_dev_prefix = __default_dev_prefix; // Set default type if (_default_type != "OS" && @@ -213,6 +216,8 @@ static int get_disk_id(const string& id_s) int ImagePool::disk_attribute(VectorAttribute * disk, int disk_id, + int * index, + Image::ImageType * img_type, int uid, int& image_id, string& error_str) @@ -221,7 +226,6 @@ int ImagePool::disk_attribute(VectorAttribute * disk, Image * img = 0; int rc = 0; int datastore_id; - int iid; ostringstream oss; @@ -244,12 +248,10 @@ int ImagePool::disk_attribute(VectorAttribute * disk, { return -1; } - - iid = img->get_oid(); } else if (!(source = disk->vector_value("IMAGE_ID")).empty()) { - iid = get_disk_id(source); + int iid = get_disk_id(source); if ( iid == -1) { @@ -264,27 +266,28 @@ int ImagePool::disk_attribute(VectorAttribute * disk, return -1; } } - else //Not using the image repository (volatile DISK) + else //Not using the image repository { - string type = disk->vector_value("TYPE"); + string type; + + rc = -2; + type = disk->vector_value("TYPE"); transform(type.begin(),type.end(),type.begin(),(int(*)(int))toupper); - if ( type == "SWAP" || type == "FS" ) + if( type == "SWAP" ) { string target = disk->vector_value("TARGET"); if ( target.empty() ) { - error_str = "Missing target for disk of type " + type; - return -1; + string dev_prefix = _default_dev_prefix; + + dev_prefix += "d"; + + disk->replace("TARGET", dev_prefix); } } - else - { - error_str = "Unknown disk type " + type; - return -1; - } } if ( img != 0 ) @@ -292,29 +295,20 @@ int ImagePool::disk_attribute(VectorAttribute * disk, DatastorePool * ds_pool = nd.get_dspool(); Datastore * ds; - iid = img->get_oid(); - rc = img->disk_attribute(disk); + img->disk_attribute(disk, index, img_type); image_id = img->get_oid(); datastore_id = img->get_ds_id(); + update(img); + img->unlock(); - if (rc == -1) - { - imagem->release_image(iid, false); - error_str = "Missing TARGET in disk"; - - return -1; - } - ds = ds_pool->get(datastore_id, true); if ( ds == 0 ) { - imagem->release_image(iid, false); error_str = "Associated datastore for the image does not exist"; - return -1; } diff --git a/src/image/test/ImagePoolTest.cc b/src/image/test/ImagePoolTest.cc index ab63e93cf5..11f1d82003 100644 --- a/src/image/test/ImagePoolTest.cc +++ b/src/image/test/ImagePoolTest.cc @@ -90,10 +90,12 @@ class ImagePoolFriend : public ImagePool public: ImagePoolFriend(SqlDB * db, const string& _default_type, + const string& _default_dev_prefix, vector _restricted_attrs): ImagePool( db, _default_type, + _default_dev_prefix, _restricted_attrs){}; @@ -113,7 +115,7 @@ public: string gname = gnames[uid]; return ImagePool::allocate(uid, 1, uname, gname, - img_template, 0, "none", "", oid, err); + img_template, 0,"none", "", oid, err); } else { @@ -143,6 +145,7 @@ class ImagePoolTest : public PoolTest CPPUNIT_TEST ( duplicates ); CPPUNIT_TEST ( extra_attributes ); CPPUNIT_TEST ( wrong_templates ); + CPPUNIT_TEST ( target_generation ); CPPUNIT_TEST ( bus_source_assignment ); CPPUNIT_TEST ( persistence ); CPPUNIT_TEST ( imagepool_disk_attribute ); @@ -253,7 +256,7 @@ public: // Create a new pool, using the same DB. This new pool should read the // allocated images. vector restricted_attrs; - imp = new ImagePool(db,"OS", restricted_attrs); + imp = new ImagePool(db,"OS", "hd", restricted_attrs); img = imp->get(0, false); CPPUNIT_ASSERT( img != 0 ); @@ -424,6 +427,107 @@ public: } } +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + + void target_generation() + { + ImagePoolFriend * imp = static_cast(pool); + Image * img; + + VectorAttribute * disk; + int oid; + string value; + int index=0; + Image::ImageType img_type; + + disk = new VectorAttribute("DISK"); + + // Allocate an OS type image + oid = allocate(0); + img = imp->get(oid, false); + + CPPUNIT_ASSERT( img != 0 ); + CPPUNIT_ASSERT( oid == 0 ); + + img->set_state(Image::READY); + img->disk_attribute(disk, &index, &img_type); + + value = disk->vector_value("TARGET"); + + CPPUNIT_ASSERT( value == "hda" ); + CPPUNIT_ASSERT( img_type == Image::OS ); + + // clean up + delete disk; + value = ""; + + disk = new VectorAttribute("DISK"); + + // Allocate a CDROM type image + string templ = "NAME = \"name A\" TYPE = CDROM PATH = /tmp"; + imp->allocate(0, templ, &oid); + + CPPUNIT_ASSERT(oid >= 0); + + img = imp->get(oid, false); + CPPUNIT_ASSERT( img != 0 ); + + img->set_state(Image::READY); + img->disk_attribute(disk, &index, &img_type); + + value = disk->vector_value("TARGET"); + CPPUNIT_ASSERT(value == "hdc"); + CPPUNIT_ASSERT( img_type == Image::CDROM ); + + // clean up + delete disk; + value = ""; + + disk = new VectorAttribute("DISK"); + + // Allocate a DATABLOCK type image + templ = "NAME = \"name B\" TYPE = DATABLOCK PATH=\"/dev/null\""; + imp->allocate(0, templ, &oid); + + CPPUNIT_ASSERT(oid >= 0); + + img = imp->get(oid, false); + CPPUNIT_ASSERT( img != 0 ); + + img->set_state(Image::READY); + img->disk_attribute(disk, &index, &img_type); + + value = disk->vector_value("TARGET"); + CPPUNIT_ASSERT(value == "hde"); + CPPUNIT_ASSERT( img_type == Image::DATABLOCK ); + + // clean up + delete disk; + value = ""; + + disk = new VectorAttribute("DISK"); + + // Allocate a DATABLOCK type image + templ = "NAME = \"name C\" TYPE = DATABLOCK DEV_PREFIX = \"sd\"" + " SIZE=4 FSTYPE=ext3"; + imp->allocate(0, templ, &oid); + + CPPUNIT_ASSERT(oid >= 0); + + img = imp->get(oid, false); + CPPUNIT_ASSERT( img != 0 ); + + img->set_state(Image::READY); + img->disk_attribute(disk, &index, &img_type); + + value = disk->vector_value("TARGET"); + CPPUNIT_ASSERT(value == "sdf"); + + // clean up + delete disk; + } + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -500,10 +604,11 @@ public: // Allocate 2 images, with different dev_prefix string template_0 = "NAME = \"Image 0\"\n" - "TARGET = \"hdx\"\n" + "DEV_PREFIX = \"hd\"\n" "PATH = /dev/null\n"; string template_1 = "NAME = \"Image 1\"\n" + "DEV_PREFIX = \"sd\"\n" "PATH = /dev/null\n"; @@ -527,25 +632,29 @@ public: disk = new VectorAttribute("DISK"); disk->replace("IMAGE_ID", "0"); - ((ImagePool*)imp)->disk_attribute(disk, 0, 0, img_id,error); + ((ImagePool*)imp)->disk_attribute(disk, 0, &index, &img_type,0, img_id,error); value = ""; value = disk->vector_value("TARGET"); - CPPUNIT_ASSERT( value == "hdx" ); + CPPUNIT_ASSERT( value == "hda" ); - value = ""; - value = disk->vector_value("IMAGE"); - CPPUNIT_ASSERT( value == "Image 0" ); delete disk; + // Disk using image 1 index disk = new VectorAttribute("DISK"); disk->replace("IMAGE_ID", "1"); - int rc = ((ImagePool*)imp)->disk_attribute(disk, 0, 0, img_id,error); + ((ImagePool*)imp)->disk_attribute(disk, 0, &index, &img_type,0, img_id,error); - CPPUNIT_ASSERT( rc == -1 ); + value = ""; + value = disk->vector_value("TARGET"); + CPPUNIT_ASSERT( value == "sda" ); + + value = ""; + value = disk->vector_value("IMAGE"); + CPPUNIT_ASSERT( value == "Image 1" ); delete disk; } diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index d2cef5f284..7ccb90c74b 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -299,9 +299,16 @@ void Nebula::start() upool = new UserPool(db, expiration_time); nebula_configuration->get("DEFAULT_IMAGE_TYPE", default_image_type); - - ipool = new ImagePool(db, default_image_type, img_restricted_attrs); + nebula_configuration->get("DEFAULT_DEVICE_PREFIX", + default_device_prefix); + + ipool = new ImagePool(db, + default_image_type, + default_device_prefix, + img_restricted_attrs); + tpool = new VMTemplatePool(db); + dspool = new DatastorePool(db); } catch (exception&) diff --git a/src/nebula/NebulaTemplate.cc b/src/nebula/NebulaTemplate.cc index 4e216a105d..db998d2a17 100644 --- a/src/nebula/NebulaTemplate.cc +++ b/src/nebula/NebulaTemplate.cc @@ -179,6 +179,7 @@ void OpenNebulaTemplate::set_conf_default() #******************************************************************************* # DATASTORE_LOCATION # DEFAULT_IMAGE_TYPE +# DEFAULT_DEVICE_PREFIX #******************************************************************************* */ //DATASTORE_LOCATION @@ -192,6 +193,11 @@ void OpenNebulaTemplate::set_conf_default() attribute = new SingleAttribute("DEFAULT_IMAGE_TYPE",value); conf_default.insert(make_pair(attribute->name(),attribute)); + //DEFAULT_DEVICE_PREFIX + value = "hd"; + + attribute = new SingleAttribute("DEFAULT_DEVICE_PREFIX",value); + conf_default.insert(make_pair(attribute->name(),attribute)); /* #******************************************************************************* # Auth Manager Configuration diff --git a/src/test/Nebula.cc b/src/test/Nebula.cc index bd9a202997..14684ebe4e 100644 --- a/src/test/Nebula.cc +++ b/src/test/Nebula.cc @@ -243,7 +243,9 @@ void Nebula::start() if (tester->need_image_pool) { - ipool = tester->create_ipool(db, default_image_type); + ipool = tester->create_ipool(db, + default_image_type, + default_device_prefix); } if (tester->need_template_pool) diff --git a/src/test/NebulaTest.cc b/src/test/NebulaTest.cc index 0c1c9f04ae..1527e57982 100644 --- a/src/test/NebulaTest.cc +++ b/src/test/NebulaTest.cc @@ -44,11 +44,12 @@ UserPool* NebulaTest::create_upool(SqlDB* db) } ImagePool* NebulaTest::create_ipool( SqlDB* db, - string default_image_type) + string default_image_type, + string default_device_prefix) { vector restricted_attrs; - return new ImagePool(db, default_image_type, restricted_attrs); + return new ImagePool(db, default_image_type, default_device_prefix, restricted_attrs); } VMTemplatePool* NebulaTest::create_tpool(SqlDB* db) diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index d2bae041c9..6b530500b2 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -376,8 +376,13 @@ int VirtualMachine::parse_context(string& error_str) if ( target.empty() ) { - error_str = "Missing TARGET attribute in CONTEXT."; - return -1; + Nebula& nd = Nebula::instance(); + string dev_prefix; + + nd.get_configuration_attribute("DEFAULT_DEVICE_PREFIX",dev_prefix); + dev_prefix += "b"; + + context_parsed->replace("TARGET", dev_prefix); } obj_template->set(context_parsed); @@ -855,15 +860,21 @@ int VirtualMachine::get_disk_images(string& error_str) VectorAttribute * disk; vector acquired_images; - int image_id; - ostringstream oss; + int n_os = 0; // Number of OS images + int n_cd = 0; // Number of CDROMS + int n_db = 0; // Number of DATABLOCKS + string type; + int image_id; + + ostringstream oss; + Image::ImageType img_type; Nebula& nd = Nebula::instance(); ipool = nd.get_ipool(); num_disks = obj_template->get("DISK",disks); - for(int i=0; i(disks[i]); @@ -872,13 +883,48 @@ int VirtualMachine::get_disk_images(string& error_str) continue; } - rc = ipool->disk_attribute(disk, i, uid, image_id, error_str); - + rc = ipool->disk_attribute(disk, + i, + &index, + &img_type, + uid, + image_id, + error_str); if (rc == 0 ) { acquired_images.push_back(image_id); + + switch(img_type) + { + case Image::OS: + n_os++; + break; + case Image::CDROM: + n_cd++; + break; + case Image::DATABLOCK: + n_db++; + break; + default: + break; + } + + if( n_os > 1 ) // Max. number of OS images is 1 + { + goto error_max_os; + } + + if( n_cd > 1 ) // Max. number of CDROM images is 1 + { + goto error_max_cd; + } + + if( n_db > 10 ) // Max. number of DATABLOCK images is 10 + { + goto error_max_db; + } } - else + else if ( rc == -1 ) { goto error_common; } @@ -886,6 +932,18 @@ int VirtualMachine::get_disk_images(string& error_str) return 0; +error_max_os: + error_str = "VM cannot use more than one OS image."; + goto error_common; + +error_max_cd: + error_str = "VM cannot use more than one CDROM image."; + goto error_common; + +error_max_db: + error_str = "VM cannot use more than 10 DATABLOCK images."; + goto error_common; + error_common: ImageManager * imagem = nd.get_imagem(); From 7da6c9883e94543f145a24a1ce6ec08152ac75b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 25 Apr 2012 17:12:16 +0200 Subject: [PATCH 19/36] Bug #1232: Bring back part of commit:e401b49 : Only allow Datastore & volatile disks. --- src/image/Image.cc | 15 +++++------- src/image/ImageManagerActions.cc | 1 + src/image/ImagePool.cc | 41 ++++++++++++++++++++------------ 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/image/Image.cc b/src/image/Image.cc index adcb40d64c..1ac8275559 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -441,12 +441,12 @@ int Image::disk_attribute( VectorAttribute * disk, int * index, ImageType* img_type) { - string bus; - string target; - string driver; - string disk_attr_type; + string bus; + string target; + string driver; + string disk_attr_type; - ostringstream iid; + ostringstream iid; *img_type = type; bus = disk->vector_value("BUS"); @@ -459,7 +459,7 @@ int Image::disk_attribute( VectorAttribute * disk, string prefix; string template_driver; - get_template_attribute("BUS", template_bus); + get_template_attribute("BUS", template_bus); get_template_attribute("TARGET", template_target); get_template_attribute("DRIVER", template_driver); @@ -473,7 +473,6 @@ int Image::disk_attribute( VectorAttribute * disk, //--------------------------------------------------------------------------- // BASE DISK ATTRIBUTES //--------------------------------------------------------------------------- - disk->replace("IMAGE", name); disk->replace("IMAGE_ID", iid.str()); disk->replace("SOURCE", source); @@ -491,7 +490,6 @@ int Image::disk_attribute( VectorAttribute * disk, //--------------------------------------------------------------------------- // TYPE, READONLY, CLONE, and SAVE attributes //--------------------------------------------------------------------------- - if ( persistent_img ) { disk->replace("CLONE","NO"); @@ -518,7 +516,6 @@ int Image::disk_attribute( VectorAttribute * disk, break; } - disk->replace("TYPE",disk_attr_type); //--------------------------------------------------------------------------- diff --git a/src/image/ImageManagerActions.cc b/src/image/ImageManagerActions.cc index 58f41d3d33..17f63c3f62 100644 --- a/src/image/ImageManagerActions.cc +++ b/src/image/ImageManagerActions.cc @@ -191,6 +191,7 @@ void ImageManager::release_image(int iid, bool failed) img->unlock(); break; + case Image::DISABLED: case Image::READY: case Image::ERROR: diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index 3fde07920c..d32ac4a7f7 100644 --- a/src/image/ImagePool.cc +++ b/src/image/ImagePool.cc @@ -226,6 +226,7 @@ int ImagePool::disk_attribute(VectorAttribute * disk, Image * img = 0; int rc = 0; int datastore_id; + int iid; ostringstream oss; @@ -248,10 +249,12 @@ int ImagePool::disk_attribute(VectorAttribute * disk, { return -1; } + + iid = img->get_oid(); } else if (!(source = disk->vector_value("IMAGE_ID")).empty()) { - int iid = get_disk_id(source); + iid = get_disk_id(source); if ( iid == -1) { @@ -266,28 +269,27 @@ int ImagePool::disk_attribute(VectorAttribute * disk, return -1; } } - else //Not using the image repository + else //Not using the image repository (volatile DISK) { - string type; - - rc = -2; - type = disk->vector_value("TYPE"); + string type = disk->vector_value("TYPE"); transform(type.begin(),type.end(),type.begin(),(int(*)(int))toupper); - if( type == "SWAP" ) + if ( type == "SWAP" || type == "FS" ) { string target = disk->vector_value("TARGET"); if ( target.empty() ) { - string dev_prefix = _default_dev_prefix; - - dev_prefix += "d"; - - disk->replace("TARGET", dev_prefix); + error_str = "Missing target for disk of type " + type; + return -1; } } + else + { + error_str = "Unknown disk type " + type; + return -1; + } } if ( img != 0 ) @@ -295,20 +297,29 @@ int ImagePool::disk_attribute(VectorAttribute * disk, DatastorePool * ds_pool = nd.get_dspool(); Datastore * ds; - img->disk_attribute(disk, index, img_type); + iid = img->get_oid(); + rc = img->disk_attribute(disk, index, img_type); image_id = img->get_oid(); datastore_id = img->get_ds_id(); - update(img); - img->unlock(); + if (rc == -1) + { + imagem->release_image(iid, false); + error_str = "Missing TARGET in disk"; + + return -1; + } + ds = ds_pool->get(datastore_id, true); if ( ds == 0 ) { + imagem->release_image(iid, false); error_str = "Associated datastore for the image does not exist"; + return -1; } From c71a92d18a3168be939468cce114fb23ac8d6f12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 26 Apr 2012 16:53:11 +0200 Subject: [PATCH 20/36] Bug #1232: Improve automatic target assignment --- include/Image.h | 18 ++-- include/ImagePool.h | 12 +-- src/image/Image.cc | 46 +++------- src/image/ImagePool.cc | 15 ++-- src/vm/VirtualMachine.cc | 176 ++++++++++++++++++++++++++------------- 5 files changed, 149 insertions(+), 118 deletions(-) diff --git a/include/Image.h b/include/Image.h index bdee93831a..90cf694164 100644 --- a/include/Image.h +++ b/include/Image.h @@ -329,18 +329,18 @@ public: * Modifies the given disk attribute adding the following attributes: * * SOURCE: the file-path. * * BUS: will only be set if the Image's definition includes it. - * * TARGET: the value set depends on: - * - OS images will be mounted at prefix + a: hda, sda. - * - Prefix + b is reserved for the contex cdrom. - * - CDROM images will be at prefix + c: hdc, sdc. - * - Several DATABLOCK images can be mounted, they will be set to - * prefix + (d + index) : hdd, hde, hdf... + * * TARGET: will only be set if the Image's definition includes it. + * * @param disk attribute for the VM template - * @param index number of datablock images used by the same VM. Will be - * automatically increased. * @param img_type will be set to the used image's type + * @param dev_prefix will be set to the defined dev_prefix, + * or the default one + * + * @return 0 on success, -1 otherwise */ - int disk_attribute(VectorAttribute * disk, int* index, ImageType* img_type); + int disk_attribute( VectorAttribute * disk, + ImageType* img_type, + string& dev_prefix); /** * Factory method for image templates diff --git a/include/ImagePool.h b/include/ImagePool.h index 4fc8038f9b..c7526b787c 100644 --- a/include/ImagePool.h +++ b/include/ImagePool.h @@ -134,22 +134,22 @@ public: /** * Generates a DISK attribute for VM templates using the Image metadata + * * @param disk the disk to be generated * @param disk_id the id for this disk - * @param index number of datablock images used by the same VM. Will be - * automatically increased. * @param img_type will be set to the used image's type + * @param dev_prefix will be set to the image defined dev_prefix, + * or the default one * @param uid of VM owner (to look for the image id within its images) * @param image_id on success returns the acquired image id * @param error_str string describing the error - * @return 0 on success, - * -1 error, - * -2 not using the pool, + * + * @return 0 on success, -1 otherwise */ int disk_attribute(VectorAttribute * disk, int disk_id, - int * index, Image::ImageType * img_type, + string& dev_prefix, int uid, int& image_id, string& error_str); diff --git a/src/image/Image.cc b/src/image/Image.cc index 1ac8275559..4a41ccf850 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -438,8 +438,8 @@ int Image::from_xml(const string& xml) /* ------------------------------------------------------------------------ */ int Image::disk_attribute( VectorAttribute * disk, - int * index, - ImageType* img_type) + ImageType* img_type, + string& dev_prefix) { string bus; string target; @@ -456,18 +456,17 @@ int Image::disk_attribute( VectorAttribute * disk, string template_bus; string template_target; - string prefix; string template_driver; get_template_attribute("BUS", template_bus); get_template_attribute("TARGET", template_target); get_template_attribute("DRIVER", template_driver); - get_template_attribute("DEV_PREFIX", prefix); + get_template_attribute("DEV_PREFIX", dev_prefix); - if (prefix.empty())//Removed from image template, get it again from defaults + if (dev_prefix.empty())//Removed from image template, get it again from defaults { - prefix = ImagePool::default_dev_prefix(); + dev_prefix = ImagePool::default_dev_prefix(); } //--------------------------------------------------------------------------- @@ -518,37 +517,14 @@ int Image::disk_attribute( VectorAttribute * disk, disk->replace("TYPE",disk_attr_type); - //--------------------------------------------------------------------------- - // TARGET attribute - //--------------------------------------------------------------------------- + //--------------------------------------------------------------------------- + // TARGET attribute + //--------------------------------------------------------------------------- - if (target.empty()) //No TARGET in DISK attribute + // TARGET defined in the Image template, but not in the DISK attribute + if ( target.empty() && !template_target.empty() ) { - if (!template_target.empty()) - { - disk->replace("TARGET", template_target); - } - else - { - switch(type) - { - case OS: - prefix += "a"; - break; - - case CDROM: - prefix += "c"; // b is for context - break; - - case DATABLOCK: - prefix += static_cast(('e'+ *index)); - *index = *index + 1; - break; - - } - - disk->replace("TARGET", prefix); - } + disk->replace("TARGET", template_target); } return 0; diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index d32ac4a7f7..5f36f9666f 100644 --- a/src/image/ImagePool.cc +++ b/src/image/ImagePool.cc @@ -216,8 +216,8 @@ static int get_disk_id(const string& id_s) int ImagePool::disk_attribute(VectorAttribute * disk, int disk_id, - int * index, Image::ImageType * img_type, + string& dev_prefix, int uid, int& image_id, string& error_str) @@ -277,13 +277,8 @@ int ImagePool::disk_attribute(VectorAttribute * disk, if ( type == "SWAP" || type == "FS" ) { - string target = disk->vector_value("TARGET"); - - if ( target.empty() ) - { - error_str = "Missing target for disk of type " + type; - return -1; - } + dev_prefix = _default_dev_prefix; + *img_type = Image::DATABLOCK; } else { @@ -298,7 +293,7 @@ int ImagePool::disk_attribute(VectorAttribute * disk, Datastore * ds; iid = img->get_oid(); - rc = img->disk_attribute(disk, index, img_type); + rc = img->disk_attribute(disk, img_type, dev_prefix); image_id = img->get_oid(); datastore_id = img->get_ds_id(); @@ -308,7 +303,7 @@ int ImagePool::disk_attribute(VectorAttribute * disk, if (rc == -1) { imagem->release_image(iid, false); - error_str = "Missing TARGET in disk"; + error_str = "Unknown internal error"; return -1; } diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 6b530500b2..e4ad4d1537 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -22,6 +22,7 @@ #include #include +#include #include "VirtualMachine.h" #include "VirtualNetworkPool.h" @@ -371,20 +372,6 @@ int VirtualMachine::parse_context(string& error_str) context_parsed = new VectorAttribute("CONTEXT"); context_parsed->unmarshall(parsed," @^_^@ "); - - string target = context_parsed->vector_value("TARGET"); - - if ( target.empty() ) - { - Nebula& nd = Nebula::instance(); - string dev_prefix; - - nd.get_configuration_attribute("DEFAULT_DEVICE_PREFIX",dev_prefix); - dev_prefix += "b"; - - context_parsed->replace("TARGET", dev_prefix); - } - obj_template->set(context_parsed); } @@ -860,11 +847,22 @@ int VirtualMachine::get_disk_images(string& error_str) VectorAttribute * disk; vector acquired_images; - int n_os = 0; // Number of OS images - int n_cd = 0; // Number of CDROMS - int n_db = 0; // Number of DATABLOCKS - string type; int image_id; + string dev_prefix; + string target; + + queue< pair > os_disk; + queue< pair > cdrom_disks; + queue< pair > datablock_disks; + + queue< pair >* queues[3] = + {&os_disk, &cdrom_disks, &datablock_disks}; + + pair disk_pair; + set used_targets; + + bool inserted; + int index = 0; ostringstream oss; Image::ImageType img_type; @@ -872,9 +870,32 @@ int VirtualMachine::get_disk_images(string& error_str) Nebula& nd = Nebula::instance(); ipool = nd.get_ipool(); - num_disks = obj_template->get("DISK",disks); + // The context is the first of the cdroms + num_disks = obj_template->get("CONTEXT", disks); - for(int i=0, index=0; i 0 ) + { + disk = dynamic_cast(disks[0]); + + if ( disk != 0 ) + { + target = disk->vector_value("TARGET"); + + if ( !target.empty() ) + { + used_targets.insert(target).second; + } + else + { + cdrom_disks.push( make_pair(ipool->default_dev_prefix(), disk) ); + } + } + } + + disks.clear(); + num_disks = obj_template->get("DISK", disks); + + for(int i=0; i(disks[i]); @@ -883,66 +904,105 @@ int VirtualMachine::get_disk_images(string& error_str) continue; } + // This will set disk->target only if + // it is defined in the Image template rc = ipool->disk_attribute(disk, - i, - &index, - &img_type, + i, + &img_type, + dev_prefix, uid, image_id, error_str); + if (rc == 0 ) { acquired_images.push_back(image_id); - switch(img_type) - { - case Image::OS: - n_os++; - break; - case Image::CDROM: - n_cd++; - break; - case Image::DATABLOCK: - n_db++; - break; - default: - break; - } + // If the disk has TARGET defined, that one can't be used later + // in the automatic assignment - if( n_os > 1 ) // Max. number of OS images is 1 - { - goto error_max_os; - } + target = disk->vector_value("TARGET"); - if( n_cd > 1 ) // Max. number of CDROM images is 1 + if ( !target.empty() ) { - goto error_max_cd; - } + inserted = used_targets.insert(target).second; - if( n_db > 10 ) // Max. number of DATABLOCK images is 10 + if ( inserted == false ) + { + goto error_duplicated_target; + } + } + else { - goto error_max_db; + switch(img_type) + { + case Image::OS: + // The first OS disk gets the first device (a), + // if there are more than one, the rest will start after + // the cdroms, with the other datablock disks + + if ( os_disk.size() == 0 ) + { + os_disk.push( make_pair(dev_prefix, disk) ); + } + else + { + datablock_disks.push( make_pair(dev_prefix, disk) ); + } + break; + + case Image::CDROM: + cdrom_disks.push( make_pair(dev_prefix, disk) ); + break; + + case Image::DATABLOCK: + datablock_disks.push( make_pair(dev_prefix, disk) ); + break; + + default: + break; + } } } - else if ( rc == -1 ) + else { goto error_common; } } + // TODO: check that there is at least one OS disk + + for ( int i=0; i<3; i++ ) + { + queue< pair >* queue = queues[i]; + + while ( (*queue).size() > 0 ) + { + disk_pair = (*queue).front(); + + index = 0; + + do + { + target = disk_pair.first + static_cast(('a'+ index)); + index++; + } + while ( used_targets.count(target) > 0 && index < 26 ); + + // TODO: if index == 26, then all targets up to z are used + + disk_pair.second->replace("TARGET", target); + used_targets.insert(target); + + (*queue).pop(); + } + } + return 0; -error_max_os: - error_str = "VM cannot use more than one OS image."; - goto error_common; - -error_max_cd: - error_str = "VM cannot use more than one CDROM image."; - goto error_common; - -error_max_db: - error_str = "VM cannot use more than 10 DATABLOCK images."; - goto error_common; +error_duplicated_target: + oss << "Two disks have defined the same target " << target; + error_str = oss.str(); error_common: ImageManager * imagem = nd.get_imagem(); From a7ab6e4ce8e3ee304de85fc1fb31246c3a998582 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Thu, 26 Apr 2012 17:34:40 +0200 Subject: [PATCH 21/36] bug #1165: set correct state value for unknown state for vmm/poll --- src/vmm_mad/remotes/poll_xen_kvm.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vmm_mad/remotes/poll_xen_kvm.rb b/src/vmm_mad/remotes/poll_xen_kvm.rb index 1486d1dfb4..419dce0081 100755 --- a/src/vmm_mad/remotes/poll_xen_kvm.rb +++ b/src/vmm_mad/remotes/poll_xen_kvm.rb @@ -172,7 +172,7 @@ private when *%w{running blocked shutdown dying idle} 'a' when 'paused' - '-' + 'd' when 'crashed' 'e' else @@ -242,7 +242,7 @@ module XEN when *%w{r b s d} 'a' when 'p' - '-' + 'd' when 'c' 'e' else From 8ff221052d80f191eb7eabc7ddc8a6d994dfd54a Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 26 Apr 2012 19:06:49 +0200 Subject: [PATCH 22/36] feature #1243: Add resched flag to VMs. Includes associated logic to make it work: RM methods, OCA bindings, CLI commands. LCM updated to clear the resched flag when leaving the running state Fixes VM tests --- SConstruct | 30 ++++----- include/DispatchManager.h | 11 ++++ include/VirtualMachine.h | 21 +++++++ src/cli/one_helper/onevm_helper.rb | 7 ++- src/cli/onevm | 24 ++++++++ src/dm/DispatchManagerActions.cc | 46 ++++++++++++++ src/lcm/LifeCycleActions.cc | 19 +++++- src/lcm/LifeCycleStates.cc | 6 ++ .../opennebula/client/vm/VirtualMachine.java | 18 ++++++ src/oca/ruby/OpenNebula/VirtualMachine.rb | 10 +++ src/ozones/test/test.sh | 8 +-- src/rm/RequestManagerVirtualMachine.cc | 8 +++ src/test/Nebula.cc | 7 ++- src/vm/VirtualMachine.cc | 3 + src/vm/test/SConstruct | 13 +++- src/vm/test/VirtualMachinePoolTest.cc | 61 +++++++++++++++---- 16 files changed, 255 insertions(+), 37 deletions(-) diff --git a/SConstruct b/SConstruct index cf962f4d85..c5db663582 100644 --- a/SConstruct +++ b/SConstruct @@ -237,22 +237,22 @@ if testing=='yes': ]) build_scripts.extend([ - 'src/authm/test/SConstruct', - 'src/common/test/SConstruct', - 'src/host/test/SConstruct', - 'src/cluster/test/SConstruct', - 'src/datastore/test/SConstruct', - 'src/group/test/SConstruct', - 'src/image/test/SConstruct', - 'src/lcm/test/SConstruct', - 'src/pool/test/SConstruct', - 'src/template/test/SConstruct', - 'src/test/SConstruct', - 'src/um/test/SConstruct', +# 'src/authm/test/SConstruct', +# 'src/common/test/SConstruct', +# 'src/host/test/SConstruct', +# 'src/cluster/test/SConstruct', +# 'src/datastore/test/SConstruct', +# 'src/group/test/SConstruct', +# 'src/image/test/SConstruct', +# 'src/lcm/test/SConstruct', +# 'src/pool/test/SConstruct', +# 'src/template/test/SConstruct', +# 'src/test/SConstruct', +# 'src/um/test/SConstruct', 'src/vm/test/SConstruct', - 'src/vnm/test/SConstruct', - 'src/xml/test/SConstruct', - 'src/vm_template/test/SConstruct', +# 'src/vnm/test/SConstruct', +# 'src/xml/test/SConstruct', +# 'src/vm_template/test/SConstruct', ]) else: main_env.Append(testing='no') diff --git a/include/DispatchManager.h b/include/DispatchManager.h index 1bf3e4cf22..2ad6b03649 100644 --- a/include/DispatchManager.h +++ b/include/DispatchManager.h @@ -219,6 +219,17 @@ public: int reboot( int vid); + /** + * Set the re-scheduling flag for the VM (must be in RUNNING state) + * @param vid VirtualMachine identification + * @param do_resched set or unset the flag + * @return 0 on success, -1 if the VM does not exits or -2 if the VM is + * in a wrong a state + */ + int resched( + int vid, + bool do_resched); + private: /** * Thread id for the Dispatch Manager diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 9254ec2b4c..be2ba87c0f 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -586,6 +586,22 @@ public: lcm_state = s; }; + /** + * Sets the re-scheduling flag + * @param set or unset the re-schedule flag + */ + void set_resched(bool do_sched) + { + if ( do_sched == true ) + { + resched = 1; + } + else + { + resched = 0; + } + }; + // ------------------------------------------------------------------------ // Timers // ------------------------------------------------------------------------ @@ -720,6 +736,11 @@ private: */ LcmState lcm_state; + /** + * Marks the VM as to be re-scheduled + */ + int resched; + /** * Start time, the VM enter the nebula system (in epoch) */ diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index b772ce61bb..b7d32be70d 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -57,7 +57,11 @@ class OneVMHelper < OpenNebulaHelper::OneHelper column :NAME, "Name of the Virtual Machine", :left, :size=>15 do |d| - d["NAME"] + if d["RESCHED"] == "1" + "*#{d["NAME"]}" + else + d["NAME"] + end end column :USER, "Username of the Virtual Machine owner", :left, @@ -132,6 +136,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper puts str % ["GROUP", vm['GNAME']] puts str % ["STATE", vm.state_str] puts str % ["LCM_STATE", vm.lcm_state_str] + puts str % ["RESCHED", OpenNebulaHelper.boolean_to_str(vm['RESCHED'])] puts str % ["HOSTNAME", vm['/VM/HISTORY_RECORDS/HISTORY[last()]/HOSTNAME']] if %w{ACTIVE SUSPENDED}.include? vm.state_str diff --git a/src/cli/onevm b/src/cli/onevm index e8dd16b71f..ddf1d7d52f 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -354,6 +354,30 @@ cmd=CommandParser::CmdParser.new(ARGV) do end end + resched_desc = <<-EOT.unindent + Sets the rescheduling flag for the VM. + + States: RUNNING + EOT + + command :resched, resched_desc, [:range,:vmid_list] do + helper.perform_actions(args[0],options,"Setting resched flag") do |vm| + vm.resched + end + end + + unresched_desc = <<-EOT.unindent + Clears the rescheduling flag for the VM. + + States: RUNNING + EOT + + command :unresched, unresched_desc, [:range,:vmid_list] do + helper.perform_actions(args[0],options,"Clearing resched flag") do |vm| + vm.unresched + end + end + list_desc = <<-EOT.unindent Lists VMs in the pool EOT diff --git a/src/dm/DispatchManagerActions.cc b/src/dm/DispatchManagerActions.cc index 4907ed7194..f573c3218d 100644 --- a/src/dm/DispatchManagerActions.cc +++ b/src/dm/DispatchManagerActions.cc @@ -580,6 +580,52 @@ error: return -2; } + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int DispatchManager::resched(int vid, bool do_resched) +{ + VirtualMachine * vm; + ostringstream oss; + + vm = vmpool->get(vid,true); + + if ( vm == 0 ) + { + return -1; + } + + oss << "Setting rescheduling flag on VM " << vid; + NebulaLog::log("DiM",Log::DEBUG,oss); + + if (vm->get_state() == VirtualMachine::ACTIVE && + vm->get_lcm_state() == VirtualMachine::RUNNING ) + { + Nebula& nd = Nebula::instance(); + LifeCycleManager * lcm = nd.get_lcm(); + + vm->set_resched(do_resched); + vmpool->update(vm); + } + else + { + goto error; + } + + vm->unlock(); + + return 0; + +error: + oss.str(""); + oss << "Could not set rescheduling flag for VM " << vid << ", wrong state."; + NebulaLog::log("DiM",Log::ERROR,oss); + + vm->unlock(); + + return -2; +} /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/src/lcm/LifeCycleActions.cc b/src/lcm/LifeCycleActions.cc index 6b316d5f14..234e686a58 100644 --- a/src/lcm/LifeCycleActions.cc +++ b/src/lcm/LifeCycleActions.cc @@ -111,6 +111,8 @@ void LifeCycleManager::suspend_action(int vid) vm->set_state(VirtualMachine::SAVE_SUSPEND); + vm->set_resched(false); + vmpool->update(vm); vm->log("LCM", Log::INFO, "New VM state is SAVE_SUSPEND"); @@ -154,7 +156,9 @@ void LifeCycleManager::stop_action(int vid) //---------------------------------------------------- vm->set_state(VirtualMachine::SAVE_STOP); - + + vm->set_resched(false); + vmpool->update(vm); vm->log("LCM", Log::INFO, "New VM state is SAVE_STOP"); @@ -200,6 +204,8 @@ void LifeCycleManager::migrate_action(int vid) vm->set_state(VirtualMachine::SAVE_MIGRATE); + vm->set_resched(false); + vmpool->update(vm); vm->set_stime(time(0)); @@ -254,6 +260,8 @@ void LifeCycleManager::live_migrate_action(int vid) vm->set_state(VirtualMachine::MIGRATE); + vm->set_resched(false); + vmpool->update(vm); vm->set_stime(time(0)); @@ -306,6 +314,8 @@ void LifeCycleManager::shutdown_action(int vid) vm->set_state(VirtualMachine::SHUTDOWN); + vm->set_resched(false); + vmpool->update(vm); vm->log("LCM",Log::INFO,"New VM state is SHUTDOWN"); @@ -410,6 +420,8 @@ void LifeCycleManager::cancel_action(int vid) vm->set_state(VirtualMachine::CANCEL); + vm->set_resched(false); + vmpool->update(vm); vm->log("LCM", Log::INFO, "New state is CANCEL"); @@ -448,6 +460,10 @@ void LifeCycleManager::reboot_action(int vid) VirtualMachineManager * vmm = nd.get_vmm(); vmm->trigger(VirtualMachineManager::REBOOT,vid); + + vm->set_resched(false); //Rebooting cancel re-scheduling actions + + vmpool->update(vm); } else { @@ -595,6 +611,7 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm) int vid = vm->get_oid(); vm->set_state(VirtualMachine::CLEANUP); + vm->set_resched(false); vmpool->update(vm); vm->set_etime(the_time); diff --git a/src/lcm/LifeCycleStates.cc b/src/lcm/LifeCycleStates.cc index 391238680b..11cf2bd7be 100644 --- a/src/lcm/LifeCycleStates.cc +++ b/src/lcm/LifeCycleStates.cc @@ -719,6 +719,8 @@ void LifeCycleManager::monitor_suspend_action(int vid) vm->set_state(VirtualMachine::SAVE_SUSPEND); + vm->set_resched(false); + vmpool->update(vm); vm->set_running_etime(the_time); @@ -762,6 +764,8 @@ void LifeCycleManager::monitor_done_action(int vid) vm->set_state(VirtualMachine::UNKNOWN); + vm->set_resched(false); + vmpool->update(vm); vm->log("LCM", Log::INFO, "New VM state is UNKNOWN"); @@ -789,6 +793,8 @@ void LifeCycleManager::failure_action(VirtualMachine * vm) vm->set_state(VirtualMachine::FAILURE); + vm->set_resched(false); + vmpool->update(vm); vm->set_etime(the_time); diff --git a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java index 9cefefe188..ef10adbdb8 100644 --- a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java +++ b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java @@ -501,6 +501,24 @@ public class VirtualMachine extends PoolElement{ return action("resubmit"); } + /** + * Sets the re-scheduling flag for the VM + * @return If an error occurs the error message contains the reason. + */ + public OneResponse resched() + { + return action("resched"); + } + + /** + * Unsets the re-scheduling flag for the VM + * @return If an error occurs the error message contains the reason. + */ + public OneResponse unresched() + { + return action("unresched"); + } + /** * Migrates the virtual machine to the target host (hid). *
diff --git a/src/oca/ruby/OpenNebula/VirtualMachine.rb b/src/oca/ruby/OpenNebula/VirtualMachine.rb index a22726f330..d99f30712b 100644 --- a/src/oca/ruby/OpenNebula/VirtualMachine.rb +++ b/src/oca/ruby/OpenNebula/VirtualMachine.rb @@ -194,6 +194,16 @@ module OpenNebula action('resubmit') end + # Sets the re-scheduling flag for the VM + def resched + action('resched') + end + + # Unsets the re-scheduling flag for the VM + def unresched + action('unresched') + end + # Saves a running VM and starts it again in the specified host def migrate(host_id) return Error.new('ID not defined') if !@pe_id diff --git a/src/ozones/test/test.sh b/src/ozones/test/test.sh index d6de0d2f42..76dad892a2 100755 --- a/src/ozones/test/test.sh +++ b/src/ozones/test/test.sh @@ -38,9 +38,9 @@ for j in `ls ./spec/*_spec.rb` ; do ONE_LOCATION=$ONE_LOCATION_A rspec $j -f s CODE=$? - if [ $CODE != 0 ] ; then - break - fi +# if [ $CODE != 0 ] ; then +# break +# fi ONE_LOCATION=$ONE_LOCATION_A oneA/bin/one stop ONE_LOCATION=$ONE_LOCATION_B oneB/bin/one stop @@ -54,4 +54,4 @@ if (($CODE == 0)); then # Delete directories rm -rf oneA rm -rf oneB -fi \ No newline at end of file +fi diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index 1f3973c669..cc8d129704 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -233,6 +233,14 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList, { rc = dm->reboot(id); } + else if (action == "resched") + { + rc = dm->resched(id, true); + } + else if (action == "unresched") + { + rc = dm->resched(id, false); + } switch (rc) { diff --git a/src/test/Nebula.cc b/src/test/Nebula.cc index bd9a202997..6a867ee17c 100644 --- a/src/test/Nebula.cc +++ b/src/test/Nebula.cc @@ -166,11 +166,12 @@ void Nebula::start() hook_location = nebula_location + "hooks/"; remotes_location = nebula_location + "var/remotes/"; - if ( nebula_configuration != 0) + /*if ( nebula_configuration != 0) { delete nebula_configuration; - } - + }*/ + nebula_configuration = new OpenNebulaTemplate(etc_location, var_location); + xmlInitParser(); // ----------------------------------------------------------- diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index d2bae041c9..6810f01bcb 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -47,6 +47,7 @@ VirtualMachine::VirtualMachine(int id, last_poll(0), state(INIT), lcm_state(LCM_INIT), + resched(0), stime(time(0)), etime(0), deploy_id(""), @@ -1386,6 +1387,7 @@ string& VirtualMachine::to_xml_extended(string& xml, bool extended) const << "" << last_poll << "" << "" << state << "" << "" << lcm_state << "" + << "" << resched << "" << "" << stime << "" << "" << etime << "" << "" << deploy_id << "" @@ -1452,6 +1454,7 @@ int VirtualMachine::from_xml(const string &xml_str) rc += xpath(last_poll, "/VM/LAST_POLL", 0); rc += xpath(istate, "/VM/STATE", 0); rc += xpath(ilcmstate, "/VM/LCM_STATE", 0); + rc += xpath(resched, "/VM/RESCHED", 0); rc += xpath(stime, "/VM/STIME", 0); rc += xpath(etime, "/VM/ETIME", 0); diff --git a/src/vm/test/SConstruct b/src/vm/test/SConstruct index 98fd9ad244..06f2085cbb 100644 --- a/src/vm/test/SConstruct +++ b/src/vm/test/SConstruct @@ -17,6 +17,13 @@ Import('env') env.Prepend(LIBS=[ + 'nebula_core_test', + 'nebula_lcm', + 'nebula_tm', + 'nebula_vmm', + 'nebula_im', + 'nebula_rm', + 'nebula_dm', 'nebula_um', 'nebula_vm', 'nebula_hm', @@ -26,6 +33,8 @@ env.Prepend(LIBS=[ 'nebula_group', 'nebula_template', 'nebula_pool', + 'nebula_host', + 'nebula_vmtemplate', 'nebula_xml', 'nebula_image', 'nebula_datastore', @@ -39,4 +48,6 @@ env.Prepend(LIBS=[ 'crypto' ]) -env.Program('test','VirtualMachinePoolTest.cc') +nt = env.Object('NebulaTemplateTest.o', '../../nebula/NebulaTemplate.cc') + +env.Program('test',[nt,'VirtualMachinePoolTest.cc']) diff --git a/src/vm/test/VirtualMachinePoolTest.cc b/src/vm/test/VirtualMachinePoolTest.cc index 3a0ac90c90..8f5f7a9ac7 100644 --- a/src/vm/test/VirtualMachinePoolTest.cc +++ b/src/vm/test/VirtualMachinePoolTest.cc @@ -46,12 +46,12 @@ const string templates[] = const string xmls[] = { - "01231the_userusersVM one110000000010000000000000000", + "01231the_userusersVM one1100000000100000000000000000", - "12611the_userusersSecond VM110000000010000000000000000", + "12611the_userusersSecond VM1100000000100000000000000000", "01231the_userusersVM one01000000000000100000000000000000" @@ -60,16 +60,28 @@ const string xmls[] = // This xml dump result has the STIMEs modified to 0000000000 const string xml_dump = - "011the_userusersVM one110000000010000000000000000121the_userusersSecond VM110000000020000000000000000"; + "011the_userusersVM one1100000000100000000000000000121the_userusersSecond VM1100000000200000000000000000"; const string xml_dump_where = - "011the_userusersVM one110000000010000000000000000"; + "011the_userusersVM one1100000000100000000000000000"; const string xml_history_dump = - "001the_userusersVM one110000000010000000000000000101the_userusersSecond VM1100000000200000000000000000A_hostnameA_vm_dir000A_vmm_madA_vnm_mad0000000201the_userusersVM one1100000000200000000000000001C_hostnameC_vm_dir200C_vmm_madC_vnm_mad0000000311the_userusersVM one110000000060000000000000000"; + "001the_userusersVM one1100000000100000000000000000101the_userusersSecond VM11000000002000000000000000000A_hostname000A_vmm_madA_vnm_mad0000000201the_userusersVM one11000000002000000000000000001C_hostname200C_vmm_madC_vnm_mad0000000311the_userusersVM one1100000000600000000000000000"; /* ************************************************************************* */ /* ************************************************************************* */ +#include "NebulaTest.h" + +class NebulaTestVM: public NebulaTest +{ +public: + NebulaTestVM():NebulaTest() + { + NebulaTest::the_tester = this; + + need_vm_pool = true; + } +}; class VirtualMachinePoolFriend : public VirtualMachinePool { @@ -131,19 +143,18 @@ class VirtualMachinePoolTest : public PoolTest CPPUNIT_TEST_SUITE_END (); protected: + NebulaTestVM * tester; + VirtualMachinePool * vmpool; void bootstrap(SqlDB* db) { - VirtualMachinePool::bootstrap(db); + // setUp overwritten }; PoolSQL* create_pool(SqlDB* db) { - // The VM pool needs a vector containing the vm hooks - vector vm_hooks; - vector restricted_attrs; - - return new VirtualMachinePoolFriend(db, vm_hooks, restricted_attrs); + // setUp overwritten + return vmpool; }; int allocate(int index) @@ -181,6 +192,32 @@ public: ~VirtualMachinePoolTest(){xmlCleanupParser();}; + void setUp() + { + create_db(); + + tester = new NebulaTestVM(); + + Nebula& neb = Nebula::instance(); + neb.start(); + + vmpool = neb.get_vmpool(); + pool = vmpool; + }; + + void tearDown() + { + // ----------------------------------------------------------- + // Stop the managers & free resources + // ----------------------------------------------------------- + + //XML Library + xmlCleanupParser(); + + delete_db(); + + delete tester; + }; /* ********************************************************************* */ /* ********************************************************************* */ From ae6df524bb7f37956ca3c7af52f7ee833ea75433 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 27 Apr 2012 00:02:43 +0200 Subject: [PATCH 23/36] bug #1232: Work on the target assginment function --- src/vm/VirtualMachine.cc | 123 +++++++++++++++++++++------------------ 1 file changed, 67 insertions(+), 56 deletions(-) diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index e4ad4d1537..9204e68d70 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -839,30 +839,52 @@ void VirtualMachine::get_requirements (int& cpu, int& memory, int& disk) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +static void assign_disk_targets(queue >& _queue, + set& used_targets) +{ + int index = 0; + string target; + + pair disk_pair; + + while (_queue.size() > 0 ) + { + disk_pair = _queue.front(); + index = 0; + + do + { + target = disk_pair.first + static_cast(('a'+ index)); + index++; + } + while ( used_targets.count(target) > 0 && index < 26 ); + + disk_pair.second->replace("TARGET", target); + used_targets.insert(target); + + _queue.pop(); + } +} + +/* -------------------------------------------------------------------------- */ + int VirtualMachine::get_disk_images(string& error_str) { - int num_disks, rc; - vector disks; - ImagePool * ipool; - VectorAttribute * disk; - vector acquired_images; + int num_disks, rc; + vector disks; + ImagePool * ipool; + VectorAttribute * disk; + vector acquired_images; int image_id; string dev_prefix; string target; - queue< pair > os_disk; - queue< pair > cdrom_disks; - queue< pair > datablock_disks; + queue > os_disk; + queue > cdrom_disks; + queue > datablock_disks; - queue< pair >* queues[3] = - {&os_disk, &cdrom_disks, &datablock_disks}; - - pair disk_pair; - set used_targets; - - bool inserted; - int index = 0; + set used_targets; ostringstream oss; Image::ImageType img_type; @@ -870,7 +892,9 @@ int VirtualMachine::get_disk_images(string& error_str) Nebula& nd = Nebula::instance(); ipool = nd.get_ipool(); + // ------------------------------------------------------------------------- // The context is the first of the cdroms + // ------------------------------------------------------------------------- num_disks = obj_template->get("CONTEXT", disks); if ( num_disks > 0 ) @@ -883,18 +907,26 @@ int VirtualMachine::get_disk_images(string& error_str) if ( !target.empty() ) { - used_targets.insert(target).second; + used_targets.insert(target); } else { - cdrom_disks.push( make_pair(ipool->default_dev_prefix(), disk) ); + cdrom_disks.push(make_pair(ipool->default_dev_prefix(), disk)); } } } + // ------------------------------------------------------------------------- + // Set DISK attributes & Targets + // ------------------------------------------------------------------------- disks.clear(); num_disks = obj_template->get("DISK", disks); + if ( num_disks > 20 ) + { + goto error_max_disks; + } + for(int i=0; i(disks[i]); @@ -904,8 +936,6 @@ int VirtualMachine::get_disk_images(string& error_str) continue; } - // This will set disk->target only if - // it is defined in the Image template rc = ipool->disk_attribute(disk, i, &img_type, @@ -913,21 +943,15 @@ int VirtualMachine::get_disk_images(string& error_str) uid, image_id, error_str); - if (rc == 0 ) { acquired_images.push_back(image_id); - // If the disk has TARGET defined, that one can't be used later - // in the automatic assignment - target = disk->vector_value("TARGET"); if ( !target.empty() ) { - inserted = used_targets.insert(target).second; - - if ( inserted == false ) + if ( used_targets.insert(target).second == false ) { goto error_duplicated_target; } @@ -938,10 +962,8 @@ int VirtualMachine::get_disk_images(string& error_str) { case Image::OS: // The first OS disk gets the first device (a), - // if there are more than one, the rest will start after - // the cdroms, with the other datablock disks - - if ( os_disk.size() == 0 ) + // other OS's will be managed as DATABLOCK's + if ( os_disk.empty() ) { os_disk.push( make_pair(dev_prefix, disk) ); } @@ -970,36 +992,25 @@ int VirtualMachine::get_disk_images(string& error_str) } } - // TODO: check that there is at least one OS disk - - for ( int i=0; i<3; i++ ) + if (os_disk.empty()) { - queue< pair >* queue = queues[i]; - - while ( (*queue).size() > 0 ) - { - disk_pair = (*queue).front(); - - index = 0; - - do - { - target = disk_pair.first + static_cast(('a'+ index)); - index++; - } - while ( used_targets.count(target) > 0 && index < 26 ); - - // TODO: if index == 26, then all targets up to z are used - - disk_pair.second->replace("TARGET", target); - used_targets.insert(target); - - (*queue).pop(); - } + goto error_no_os; } + assign_disk_targets(os_disk, used_targets); + assign_disk_targets(cdrom_disks, used_targets); + assign_disk_targets(datablock_disks, used_targets); + return 0; +error_max_disks: + error_str = "Exceeded the maximum number of disks (20)"; + return -1; + +error_no_os: + error_str = "There is no OS image defined"; + goto error_common; + error_duplicated_target: oss << "Two disks have defined the same target " << target; error_str = oss.str(); From 71e4dc6967964eb56ea81f3182e5320aca47ffbc Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 27 Apr 2012 00:12:55 +0200 Subject: [PATCH 24/36] bug 1212: Pass references instead of pointers --- include/Image.h | 2 +- include/ImagePool.h | 2 +- src/image/Image.cc | 10 +++++----- src/image/ImagePool.cc | 16 ++++++++-------- src/vm/VirtualMachine.cc | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/include/Image.h b/include/Image.h index 90cf694164..3b4027b9bf 100644 --- a/include/Image.h +++ b/include/Image.h @@ -339,7 +339,7 @@ public: * @return 0 on success, -1 otherwise */ int disk_attribute( VectorAttribute * disk, - ImageType* img_type, + ImageType& img_type, string& dev_prefix); /** diff --git a/include/ImagePool.h b/include/ImagePool.h index c7526b787c..1bc30383cd 100644 --- a/include/ImagePool.h +++ b/include/ImagePool.h @@ -148,7 +148,7 @@ public: */ int disk_attribute(VectorAttribute * disk, int disk_id, - Image::ImageType * img_type, + Image::ImageType& img_type, string& dev_prefix, int uid, int& image_id, diff --git a/src/image/Image.cc b/src/image/Image.cc index 4a41ccf850..b0eb1b53a9 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -438,7 +438,7 @@ int Image::from_xml(const string& xml) /* ------------------------------------------------------------------------ */ int Image::disk_attribute( VectorAttribute * disk, - ImageType* img_type, + ImageType& img_type, string& dev_prefix) { string bus; @@ -448,10 +448,10 @@ int Image::disk_attribute( VectorAttribute * disk, ostringstream iid; - *img_type = type; - bus = disk->vector_value("BUS"); - target = disk->vector_value("TARGET"); - driver = disk->vector_value("DRIVER"); + img_type = type; + bus = disk->vector_value("BUS"); + target = disk->vector_value("TARGET"); + driver = disk->vector_value("DRIVER"); iid << oid; string template_bus; diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index 5f36f9666f..251c037a0e 100644 --- a/src/image/ImagePool.cc +++ b/src/image/ImagePool.cc @@ -214,13 +214,13 @@ static int get_disk_id(const string& id_s) /* -------------------------------------------------------------------------- */ -int ImagePool::disk_attribute(VectorAttribute * disk, - int disk_id, - Image::ImageType * img_type, - string& dev_prefix, - int uid, - int& image_id, - string& error_str) +int ImagePool::disk_attribute(VectorAttribute * disk, + int disk_id, + Image::ImageType& img_type, + string& dev_prefix, + int uid, + int& image_id, + string& error_str) { string source; Image * img = 0; @@ -278,7 +278,7 @@ int ImagePool::disk_attribute(VectorAttribute * disk, if ( type == "SWAP" || type == "FS" ) { dev_prefix = _default_dev_prefix; - *img_type = Image::DATABLOCK; + img_type = Image::DATABLOCK; } else { diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 9204e68d70..2dbb4ae787 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -938,7 +938,7 @@ int VirtualMachine::get_disk_images(string& error_str) rc = ipool->disk_attribute(disk, i, - &img_type, + img_type, dev_prefix, uid, image_id, From 804881e71350a019097d3043933fa7ba932a4e34 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Fri, 27 Apr 2012 11:55:32 +0200 Subject: [PATCH 25/36] Bug #1246: Add max cpu to host info view (cherry picked from commit 30fbadd5046c3ceb2da7370819a155c1e50960c7) --- src/sunstone/public/js/plugins/hosts-tab.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/sunstone/public/js/plugins/hosts-tab.js b/src/sunstone/public/js/plugins/hosts-tab.js index 431985711f..aec8889a19 100644 --- a/src/sunstone/public/js/plugins/hosts-tab.js +++ b/src/sunstone/public/js/plugins/hosts-tab.js @@ -549,6 +549,10 @@ function updateHostInfo(request,host){ ' + tr("Used Mem (allocated)") + '\ '+humanize_size(host_info.HOST_SHARE.MAX_USAGE)+'\ \ + \ + ' + tr("Max CPU") + '\ + '+host_info.HOST_SHARE.MAX_CPU+'\ + \ \ ' + tr("Used CPU (real)") + '\ '+host_info.HOST_SHARE.USED_CPU+'\ From a467bbc30ee26426a2df99f24b982c79022ebfe0 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Fri, 27 Apr 2012 11:57:09 +0200 Subject: [PATCH 26/36] Feature #1253: Ctrl + click select row for sunstone and selfservice (cherry picked from commit 0e02730af849d6c7cae1e6909385232784bd9104) --- .../occi/lib/ui/public/js/plugins/compute.js | 18 +---------------- .../occi/lib/ui/public/js/plugins/network.js | 18 +---------------- .../occi/lib/ui/public/js/plugins/storage.js | 20 +------------------ .../Server/public/js/plugins/vdcs-tab.js | 16 +-------------- .../Server/public/js/plugins/zones-tab.js | 16 +-------------- 5 files changed, 5 insertions(+), 83 deletions(-) diff --git a/src/cloud/occi/lib/ui/public/js/plugins/compute.js b/src/cloud/occi/lib/ui/public/js/plugins/compute.js index 5b99c81c9f..dabafb3edc 100644 --- a/src/cloud/occi/lib/ui/public/js/plugins/compute.js +++ b/src/cloud/occi/lib/ui/public/js/plugins/compute.js @@ -437,22 +437,6 @@ function vMachineElementArray(vm_json){ } -//Creates a listener for the TDs of the VM table -function vMachineInfoListener(){ - - $('#tbodyvmachines tr',dataTable_vMachines).live("click", function(e){ - if ($(e.target).is('input') || $(e.target).is('a img')) {return true;} - - var aData = dataTable_vMachines.fnGetData(this); - var id = $(aData[0]).val(); - if (!id) return true; - - popDialogLoading(); - Sunstone.runAction("VM.showinfo",id); - return false; - }); -} - // Callback to refresh a single element from the list function updateVMachineElement(request, vm_json){ var id = vm_json.COMPUTE.ID; @@ -1135,7 +1119,7 @@ $(document).ready(function(){ initCheckAllBoxes(dataTable_vMachines); tableCheckboxesListener(dataTable_vMachines); - vMachineInfoListener(); + infoListener(dataTable_vMachines,'VM.showinfo'); $('#li_vms_tab').click(function(){ popUpVMDashboard(); diff --git a/src/cloud/occi/lib/ui/public/js/plugins/network.js b/src/cloud/occi/lib/ui/public/js/plugins/network.js index b909d84d68..a19f9046bc 100644 --- a/src/cloud/occi/lib/ui/public/js/plugins/network.js +++ b/src/cloud/occi/lib/ui/public/js/plugins/network.js @@ -233,22 +233,6 @@ function vNetworkElementArray(vn_json){ }; -//Adds a listener to show the extended info when clicking on a row -function vNetworkInfoListener(){ - - $('#tbodyvnetworks tr',dataTable_vNetworks).live("click", function(e){ - if ($(e.target).is('input')) {return true;}; - - var aData = dataTable_vNetworks.fnGetData(this); - var id = $(aData[0]).val(); - if (!id) return true; - - popDialogLoading(); - Sunstone.runAction("Network.showinfo",id); - return false; - }); -} - //Callback to update a vnet element after an action on it function updateVNetworkElement(request, vn_json){ id = vn_json.NETWORK.ID; @@ -443,7 +427,7 @@ $(document).ready(function(){ initCheckAllBoxes(dataTable_vNetworks); tableCheckboxesListener(dataTable_vNetworks); - vNetworkInfoListener(); + infoListener(dataTable_vNetworks,'Network.showinfo'); $('#li_vnets_tab').click(function(){ popUpVNetDashboard(); diff --git a/src/cloud/occi/lib/ui/public/js/plugins/storage.js b/src/cloud/occi/lib/ui/public/js/plugins/storage.js index d21f7b285a..c42a3ab7dc 100644 --- a/src/cloud/occi/lib/ui/public/js/plugins/storage.js +++ b/src/cloud/occi/lib/ui/public/js/plugins/storage.js @@ -300,24 +300,6 @@ function imageElementArray(image_json){ ]; } -// Set up the listener on the table TDs to show the info panel -function imageInfoListener(){ - $('#tbodyimages tr',dataTable_images).live("click",function(e){ - var target = $(e.target); - - if (target.is('input') || target.is('select') || target.is('option')) - return true; - - var aData = dataTable_images.fnGetData(this); - var id = $(aData[0]).val(); - if (!id) return true; - - popDialogLoading(); - Sunstone.runAction("Image.showinfo",id); - return false; - }); -} - // Callback to update an element in the dataTable function updateImageElement(request, image_json){ var id = image_json.STORAGE.ID; @@ -629,7 +611,7 @@ $(document).ready(function(){ initCheckAllBoxes(dataTable_images); tableCheckboxesListener(dataTable_images); - imageInfoListener(); + infoListener(dataTable_images, 'Image.showinfo'); $('#li_images_tab').click(function(){ popUpImageDashboard(); diff --git a/src/ozones/Server/public/js/plugins/vdcs-tab.js b/src/ozones/Server/public/js/plugins/vdcs-tab.js index 29bf077e10..773417ab31 100644 --- a/src/ozones/Server/public/js/plugins/vdcs-tab.js +++ b/src/ozones/Server/public/js/plugins/vdcs-tab.js @@ -307,20 +307,6 @@ function vdcElementArray(vdc_json){ ]; } -function vdcInfoListener() { - $("#tbodyvdcs tr").live("click", function(e){ - if ($(e.target).is('input')) {return true;} - - var aData = dataTable_vdcs.fnGetData(this); - var id = $(aData[0]).val(); - if (!id) return true; - - popDialogLoading(); - Sunstone.runAction("VDC.showinfo",id); - return false; - }); -} - function deleteVDCElement(req){ deleteElement(dataTable_vdcs,'#vdc_'+req.request.data); } @@ -930,5 +916,5 @@ $(document).ready(function(){ setVDCAutorefresh(); initCheckAllBoxes(dataTable_vdcs); tableCheckboxesListener(dataTable_vdcs); - vdcInfoListener(); + infoListener(dataTable_vdcs,'VDC.showinfo'); }); \ No newline at end of file diff --git a/src/ozones/Server/public/js/plugins/zones-tab.js b/src/ozones/Server/public/js/plugins/zones-tab.js index 54b1049694..8402f2f5d4 100644 --- a/src/ozones/Server/public/js/plugins/zones-tab.js +++ b/src/ozones/Server/public/js/plugins/zones-tab.js @@ -275,20 +275,6 @@ function zoneElementArray(zone_json){ ]; } -function zoneInfoListener(){ - $("#tbodyzones tr").live("click", function(e){ - if ($(e.target).is('input')) {return true;} - - var aData = dataTable_zones.fnGetData(this); - var id = $(aData[0]).val(); - if (!id) return true; - - popDialogLoading(); - Sunstone.runAction("Zone.showinfo",id); - return false; - }); -} - function updateZoneSelect(){ zones_select = makeSelectOptions(dataTable_zones,1,2,-1,"",-1); } @@ -744,5 +730,5 @@ $(document).ready(function(){ initCheckAllBoxes(dataTable_zones); tableCheckboxesListener(dataTable_zones); - zoneInfoListener(); + infoListener(dataTable_zones,'Zone.showinfo'); }); \ No newline at end of file From a344dbdd573648c5c5d057cb2b0502565f534d32 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Thu, 26 Apr 2012 17:04:20 +0200 Subject: [PATCH 27/36] Feature #1253: Modify row click behaviour in Sunstone When clicking on a row with CTRL it will be checked/unchecked. When >= 1 rows are already selected, subsequent clicks on rows will (un)select them instead of triggering the info dialog. (cherry picked from commit 6cf2c019ff0fec234beb668fcf20e9d3611837c3) --- src/sunstone/public/js/plugins/acls-tab.js | 1 + .../public/js/plugins/clusters-tab.js | 2 +- .../public/js/plugins/datastores-tab.js | 17 +----------- src/sunstone/public/js/plugins/groups-tab.js | 12 +-------- src/sunstone/public/js/plugins/hosts-tab.js | 18 +------------ src/sunstone/public/js/plugins/images-tab.js | 20 +------------- .../public/js/plugins/templates-tab.js | 17 +----------- src/sunstone/public/js/plugins/users-tab.js | 16 +---------- src/sunstone/public/js/plugins/vms-tab.js | 18 +------------ src/sunstone/public/js/plugins/vnets-tab.js | 19 +------------ src/sunstone/public/js/sunstone-util.js | 27 +++++++++++++++++++ 11 files changed, 37 insertions(+), 130 deletions(-) diff --git a/src/sunstone/public/js/plugins/acls-tab.js b/src/sunstone/public/js/plugins/acls-tab.js index a61ca0082d..d53b4f81f7 100644 --- a/src/sunstone/public/js/plugins/acls-tab.js +++ b/src/sunstone/public/js/plugins/acls-tab.js @@ -517,4 +517,5 @@ $(document).ready(function(){ tableCheckboxesListener(dataTable_acls); //shortenedInfoFields('#datatable_acls'); + infoListener(dataTable_acls); }) diff --git a/src/sunstone/public/js/plugins/clusters-tab.js b/src/sunstone/public/js/plugins/clusters-tab.js index f08e6ab9ad..e2d9d1e400 100644 --- a/src/sunstone/public/js/plugins/clusters-tab.js +++ b/src/sunstone/public/js/plugins/clusters-tab.js @@ -864,5 +864,5 @@ $(document).ready(function(){ initCheckAllBoxes(dataTable_clusters); tableCheckboxesListener(dataTable_clusters); -// clusterInfoListener(); + infoListener(dataTable_clusters); }); diff --git a/src/sunstone/public/js/plugins/datastores-tab.js b/src/sunstone/public/js/plugins/datastores-tab.js index 996a85ba3c..80f760a018 100644 --- a/src/sunstone/public/js/plugins/datastores-tab.js +++ b/src/sunstone/public/js/plugins/datastores-tab.js @@ -356,21 +356,6 @@ function datastoreElementArray(element_json){ ]; } -function datastoreInfoListener(){ - - $('#tbodydatastores tr',dataTable_datastores).live("click", function(e){ - if ($(e.target).is('input') || $(e.target).is('a img')) {return true;} - - var aData = dataTable_datastores.fnGetData(this); - var id = $(aData[0]).val(); - if (!id) return true; - - popDialogLoading(); - Sunstone.runAction("Datastore.showinfo",id); - return false; - }); -}; - function updateDatastoreSelect(){ datastores_select = makeSelectOptions(dataTable_datastores, 1, @@ -703,7 +688,7 @@ $(document).ready(function(){ initCheckAllBoxes(dataTable_datastores); tableCheckboxesListener(dataTable_datastores); - datastoreInfoListener(); + infoListener(dataTable_datastores,'Datastore.showinfo'); $('div#menu li#li_datastores_tab').live('click',function(){ dataTable_datastores.fnFilter('',5); diff --git a/src/sunstone/public/js/plugins/groups-tab.js b/src/sunstone/public/js/plugins/groups-tab.js index 5689390462..8f6152ae29 100644 --- a/src/sunstone/public/js/plugins/groups-tab.js +++ b/src/sunstone/public/js/plugins/groups-tab.js @@ -179,17 +179,6 @@ function groupElementArray(group_json){ users_str ]; } -// function groupInfoListener(){ -// $('#groups_tab #tbodygroups tr',main_tabs_context).live("click",function(e){ -// //do nothing if we are clicking a checkbox! -// if ($(e.target).is('input')) {return true;} -// var aData = dataTable_groups.fnGetData(this); -// var id = $(aData[0]).val(); -// Sunstone.runAction("Group.showinfo",id); -// return false; -// }); -// } - function updateGroupSelect(){ groups_select = makeSelectOptions(dataTable_groups, 1,//id_col @@ -302,4 +291,5 @@ $(document).ready(function(){ initCheckAllBoxes(dataTable_groups); tableCheckboxesListener(dataTable_groups); + infoListener(dataTable_groups); }) diff --git a/src/sunstone/public/js/plugins/hosts-tab.js b/src/sunstone/public/js/plugins/hosts-tab.js index aec8889a19..2c482ea121 100644 --- a/src/sunstone/public/js/plugins/hosts-tab.js +++ b/src/sunstone/public/js/plugins/hosts-tab.js @@ -425,22 +425,6 @@ function hostElementArray(host_json){ ]; } -//Listen to clicks on the tds of the tables and shows the info dialogs. -function hostInfoListener(){ - $('#tbodyhosts tr',dataTable_hosts).live("click",function(e){ - //do nothing if we are clicking a checkbox! - if ($(e.target).is('input')) {return true;} - - var aData = dataTable_hosts.fnGetData(this); - var id = $(aData[0]).val(); - if (!id) return true; - - popDialogLoading(); - Sunstone.runAction("Host.showinfo",id); - return false; - }); -} - //updates the host select by refreshing the options in it function updateHostSelect(){ hosts_select = makeSelectOptions(dataTable_hosts, @@ -743,7 +727,7 @@ $(document).ready(function(){ initCheckAllBoxes(dataTable_hosts); tableCheckboxesListener(dataTable_hosts); - hostInfoListener(); + infoListener(dataTable_hosts, "Host.showinfo"); $('div#menu li#li_hosts_tab').live('click',function(){ dataTable_hosts.fnFilter('',3); diff --git a/src/sunstone/public/js/plugins/images-tab.js b/src/sunstone/public/js/plugins/images-tab.js index d7a5ebe693..ade3f02c2a 100644 --- a/src/sunstone/public/js/plugins/images-tab.js +++ b/src/sunstone/public/js/plugins/images-tab.js @@ -555,24 +555,6 @@ function imageElementArray(image_json){ ]; } -// Set up the listener on the table TDs to show the info panel -function imageInfoListener(){ - $('#tbodyimages tr',dataTable_images).live("click",function(e){ - var target = $(e.target); - - if (target.is('input') || target.is('select') || target.is('option')) - return true; - - var aData = dataTable_images.fnGetData(this); - var id = $(aData[0]).val(); - if (!id) return true; - - popDialogLoading(); - Sunstone.runAction("Image.showinfo",id); - return false; - }); -} - // Callback to update an element in the dataTable function updateImageElement(request, image_json){ var id = image_json.IMAGE.ID; @@ -1180,5 +1162,5 @@ $(document).ready(function(){ initCheckAllBoxes(dataTable_images); tableCheckboxesListener(dataTable_images); - imageInfoListener(); + infoListener(dataTable_images,'Image.showinfo'); }); diff --git a/src/sunstone/public/js/plugins/templates-tab.js b/src/sunstone/public/js/plugins/templates-tab.js index 8411a95bd8..84be66f5fd 100644 --- a/src/sunstone/public/js/plugins/templates-tab.js +++ b/src/sunstone/public/js/plugins/templates-tab.js @@ -857,21 +857,6 @@ function templateElementArray(template_json){ ]; } -// Set up the listener on the table TDs to show the info panel -function templateInfoListener(){ - $('#tbodytemplates tr',dataTable_templates).live("click",function(e){ - if ($(e.target).is('input')) {return true;} - - var aData = dataTable_templates.fnGetData(this); - var id = $(aData[0]).val(); - if (!id) return true; - - popDialogLoading(); - Sunstone.runAction("Template.showinfo",id); - return false; - }); -} - //Updates the select input field with an option for each template function updateTemplateSelect(){ var templates_select = @@ -2178,5 +2163,5 @@ $(document).ready(function(){ initCheckAllBoxes(dataTable_templates); tableCheckboxesListener(dataTable_templates); - templateInfoListener(); + infoListener(dataTable_templates,'Template.showinfo'); }); diff --git a/src/sunstone/public/js/plugins/users-tab.js b/src/sunstone/public/js/plugins/users-tab.js index d1f4aa34ab..02ba240c94 100644 --- a/src/sunstone/public/js/plugins/users-tab.js +++ b/src/sunstone/public/js/plugins/users-tab.js @@ -342,20 +342,6 @@ function userElementArray(user_json){ ] }; -function userInfoListener(){ - $('#tbodyusers tr',dataTable_users).live("click",function(e){ - //do nothing if we are clicking a checkbox! - if ($(e.target).is('input')) return true; - var aData = dataTable_users.fnGetData(this); - var id = $(aData[0]).val(); - if (!id) return true; - - popDialogLoading(); - Sunstone.runAction("User.showinfo",id); - return false; - }); -}; - function updateUserSelect(){ users_select = makeSelectOptions(dataTable_users, 1,//id_col @@ -571,5 +557,5 @@ $(document).ready(function(){ initCheckAllBoxes(dataTable_users); tableCheckboxesListener(dataTable_users); //shortenedInfoFields('#datatable_users'); - userInfoListener(); + infoListener(dataTable_users,'User.showinfo'); }); diff --git a/src/sunstone/public/js/plugins/vms-tab.js b/src/sunstone/public/js/plugins/vms-tab.js index e4ec4f57d8..3f621dbe2f 100644 --- a/src/sunstone/public/js/plugins/vms-tab.js +++ b/src/sunstone/public/js/plugins/vms-tab.js @@ -683,22 +683,6 @@ function vMachineElementArray(vm_json){ }; -//Creates a listener for the TDs of the VM table -function vMachineInfoListener(){ - - $('#tbodyvmachines tr',dataTable_vMachines).live("click", function(e){ - if ($(e.target).is('input') || $(e.target).is('a img')) {return true;} - - var aData = dataTable_vMachines.fnGetData(this); - var id = $(aData[0]).val(); - if (!id) return true; - - popDialogLoading(); - Sunstone.runAction("VM.showinfo",id); - return false; - }); -} - // Callback to refresh a single element from the list function updateVMachineElement(request, vm_json){ var id = vm_json.VM.ID; @@ -1410,5 +1394,5 @@ $(document).ready(function(){ initCheckAllBoxes(dataTable_vMachines); tableCheckboxesListener(dataTable_vMachines); - vMachineInfoListener(); + infoListener(dataTable_vMachines,'VM.showinfo'); }) \ No newline at end of file diff --git a/src/sunstone/public/js/plugins/vnets-tab.js b/src/sunstone/public/js/plugins/vnets-tab.js index 4b0f497747..8ef88a8811 100644 --- a/src/sunstone/public/js/plugins/vnets-tab.js +++ b/src/sunstone/public/js/plugins/vnets-tab.js @@ -496,23 +496,6 @@ function vNetworkElementArray(vn_json){ network.TOTAL_LEASES ]; } - -//Adds a listener to show the extended info when clicking on a row -function vNetworkInfoListener(){ - - $('#tbodyvnetworks tr',dataTable_vNetworks).live("click", function(e){ - if ($(e.target).is('input')) {return true;} - - var aData = dataTable_vNetworks.fnGetData(this); - var id = $(aData[0]).val(); - if (!id) return true; - - popDialogLoading(); - Sunstone.runAction("Network.showinfo",id); - return false; - }); -} - //Callback to update a vnet element after an action on it function updateVNetworkElement(request, vn_json){ id = vn_json.VNET.ID; @@ -1209,7 +1192,7 @@ $(document).ready(function(){ initCheckAllBoxes(dataTable_vNetworks); tableCheckboxesListener(dataTable_vNetworks); - vNetworkInfoListener(); + infoListener(dataTable_vNetworks,'Network.showinfo'); $('div#menu li#li_vnets_tab').live('click',function(){ dataTable_vNetworks.fnFilter('',5); diff --git a/src/sunstone/public/js/sunstone-util.js b/src/sunstone/public/js/sunstone-util.js index 39fae61534..7a066f4b48 100644 --- a/src/sunstone/public/js/sunstone-util.js +++ b/src/sunstone/public/js/sunstone-util.js @@ -787,6 +787,33 @@ function popUpTemplateUpdateDialog(elem_str,select_items,sel_elems){ return false; } + +//Shows run a custom action when clicking on rows. +function infoListener(dataTable, info_action){ + $('tbody tr',dataTable).live("click",function(e){ + if ($(e.target).is('input')) {return true;} + + var aData = dataTable.fnGetData(this); + var id = $(aData[0]).val(); + if (!id) return true; + + var count = $('tbody .check_item:checked', dataTable).length; + + if (info_action){ + if (e.ctrlKey || count >= 1) + $('.check_item',this).trigger('click'); + else { + popDialogLoading(); + Sunstone.runAction(info_action,id) + }; + } else { + $('.check_item',this).trigger('click'); + }; + + return false; + }); +} + function mustBeAdmin(){ return gid == 0; } From 63b4dd8467434e64fc1d156323a3745fb935a0b3 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Thu, 26 Apr 2012 17:07:39 +0200 Subject: [PATCH 28/36] Feature #1256: Show graphics section in template creation for vmware (cherry picked from commit 50bc0711a5a2cc8d459daec00228a5aa8c97b457) --- src/sunstone/public/js/plugins/templates-tab.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/sunstone/public/js/plugins/templates-tab.js b/src/sunstone/public/js/plugins/templates-tab.js index 84be66f5fd..dcf42eb96c 100644 --- a/src/sunstone/public/js/plugins/templates-tab.js +++ b/src/sunstone/public/js/plugins/templates-tab.js @@ -435,31 +435,31 @@ var create_template_tmpl = '
\

'+tr("Add Graphics")+'

\
\
'+tr("Graphics")+'\ -
\ +
\ \ \ -
\ +
'+tr("VMware supports VNC only")+'
\
\ -
\ +
\ \ \
'+tr("IP to listen on")+'
\
\ -
\ +
\ \ \
'+tr("Port for the VNC server")+'
\
\ -
\ +
\ \ \
'+tr("Password for the VNC server")+'
\
\ -
\ +
\ \ \
'+tr("Keyboard configuration locale to use in the VNC display")+'
\ @@ -997,7 +997,6 @@ function setupCreateTemplateDialog(){ //hide non common sections $(section_inputs).hide(); - $(section_graphics).hide(); switch(ui.index){ case 0: @@ -1085,7 +1084,6 @@ function setupCreateTemplateDialog(){ $('input#TYPE', section_raw).val("kvm"); $(section_inputs).show(); - $(section_graphics).show(); }; // Using XEN wizard. @@ -1121,7 +1119,6 @@ function setupCreateTemplateDialog(){ $('select#BUS',section_disks).html(bus_opts); $('input#TYPE', section_raw).val("xen"); - $(section_graphics).show(); }; //VMWare wizard From d209fbfee6a20dd4c1f8e2d9014987b8ffb51f71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 27 Apr 2012 15:01:29 +0200 Subject: [PATCH 29/36] Bug #1232: Remove the constraint to have at least one OS image --- src/vm/VirtualMachine.cc | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 2dbb4ae787..6603a9c4af 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -992,11 +992,6 @@ int VirtualMachine::get_disk_images(string& error_str) } } - if (os_disk.empty()) - { - goto error_no_os; - } - assign_disk_targets(os_disk, used_targets); assign_disk_targets(cdrom_disks, used_targets); assign_disk_targets(datablock_disks, used_targets); @@ -1007,10 +1002,6 @@ error_max_disks: error_str = "Exceeded the maximum number of disks (20)"; return -1; -error_no_os: - error_str = "There is no OS image defined"; - goto error_common; - error_duplicated_target: oss << "Two disks have defined the same target " << target; error_str = oss.str(); From 97cf299f70ef0a99060b1bb03b5166d187da83ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 27 Apr 2012 15:16:23 +0200 Subject: [PATCH 30/36] Bug #1232: Remove context/target att. from ec2 template --- src/cloud/ec2/etc/templates/m1.small.erb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/cloud/ec2/etc/templates/m1.small.erb b/src/cloud/ec2/etc/templates/m1.small.erb index 57fbb2cfc2..4883e539fd 100644 --- a/src/cloud/ec2/etc/templates/m1.small.erb +++ b/src/cloud/ec2/etc/templates/m1.small.erb @@ -20,8 +20,5 @@ IMAGE_ID = <%= erb_vm_info[:ec2_img_id] %> INSTANCE_TYPE = <%= erb_vm_info[:instance_type ]%> <% if erb_vm_info[:user_data] %> -CONTEXT = [ - EC2_USER_DATA="<%= erb_vm_info[:user_data] %>", - TARGET="hdc" - ] +CONTEXT = [ EC2_USER_DATA="<%= erb_vm_info[:user_data] %>" ] <% end %> From f2105549a7f5d60b4c0be3012adcd8585e1739a9 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 28 Apr 2012 02:33:18 +0200 Subject: [PATCH 31/36] feature #1243: Scheduler makes use of the resched flag. Needs to get live/cold migration type from config --- src/scheduler/include/VirtualMachinePoolXML.h | 5 +- src/scheduler/include/VirtualMachineXML.h | 17 ++++++- src/scheduler/src/pool/HostPoolXML.cc | 2 +- .../src/pool/VirtualMachinePoolXML.cc | 51 ++++++++++++++----- src/scheduler/src/pool/VirtualMachineXML.cc | 33 ++++++++++-- src/scheduler/src/sched/Scheduler.cc | 13 +++-- 6 files changed, 91 insertions(+), 30 deletions(-) diff --git a/src/scheduler/include/VirtualMachinePoolXML.h b/src/scheduler/include/VirtualMachinePoolXML.h index 3fa2901812..e8c9f5e485 100644 --- a/src/scheduler/include/VirtualMachinePoolXML.h +++ b/src/scheduler/include/VirtualMachinePoolXML.h @@ -47,13 +47,14 @@ public: return static_cast(PoolXML::get(oid)); }; - int dispatch(int vid, int hid) const; + int dispatch(int vid, int hid, bool resched) const; protected: int get_suitable_nodes(vector& content) { - return get_nodes("/VM_POOL/VM", content); + return get_nodes("/VM_POOL/VM[STATE=1 or (LCM_STATE=3 and RESCHED=1)]", + content); }; virtual void add_object(xmlNodePtr node); diff --git a/src/scheduler/include/VirtualMachineXML.h b/src/scheduler/include/VirtualMachineXML.h index f677ae9671..befb264083 100644 --- a/src/scheduler/include/VirtualMachineXML.h +++ b/src/scheduler/include/VirtualMachineXML.h @@ -56,10 +56,19 @@ public: return gid; }; + int get_hid() const + { + return hid; + }; + + bool is_resched() const + { + return (resched == 1); + } + /** - * Adds a new share to the map of suitable shares to start this VM + * Adds a new host to the list of suitable hosts to start this VM * @param hid of the selected host - * @param hsid of the selected host share */ void add_host(int hid); @@ -151,6 +160,10 @@ protected: int uid; int gid; + int hid; + + int resched; + int memory; float cpu; diff --git a/src/scheduler/src/pool/HostPoolXML.cc b/src/scheduler/src/pool/HostPoolXML.cc index 5c6ab100eb..316cca5a2d 100644 --- a/src/scheduler/src/pool/HostPoolXML.cc +++ b/src/scheduler/src/pool/HostPoolXML.cc @@ -27,7 +27,7 @@ int HostPoolXML::set_up() if ( rc == 0 ) { oss.str(""); - oss << "Discovered Hosts (enabled):"; + oss << "Discovered Hosts (enabled):" << endl; map::iterator it; diff --git a/src/scheduler/src/pool/VirtualMachinePoolXML.cc b/src/scheduler/src/pool/VirtualMachinePoolXML.cc index 8dedf4fe8e..2428b41154 100644 --- a/src/scheduler/src/pool/VirtualMachinePoolXML.cc +++ b/src/scheduler/src/pool/VirtualMachinePoolXML.cc @@ -21,11 +21,13 @@ int VirtualMachinePoolXML::set_up() { ostringstream oss; int rc; + rc = PoolXML::set_up(); + if ( rc == 0 ) { oss.str(""); - oss << "Pending virtual machines :"; + oss << "Pending and rescheduling VMs:" << endl; map::iterator it; @@ -72,7 +74,7 @@ int VirtualMachinePoolXML::load_info(xmlrpc_c::value &result) -2, // VM from all users -1, // start_id (none) -1, // end_id (none) - 1); // in pending state + -1); // not in DONE state return 0; } catch (exception const& e) @@ -90,27 +92,48 @@ int VirtualMachinePoolXML::load_info(xmlrpc_c::value &result) /* -------------------------------------------------------------------------- */ -int VirtualMachinePoolXML::dispatch(int vid, int hid) const +int VirtualMachinePoolXML::dispatch(int vid, int hid, bool resched) const { ostringstream oss; xmlrpc_c::value deploy_result; - oss.str(""); - oss << "Dispatching virtual machine " << vid - << " to HID: " << hid; + if (resched == true) + { + oss << "Rescheduling "; + } + else + { + oss << "Dispatching "; + } + + oss << "virtual machine " << vid << " to host " << hid; NebulaLog::log("VM",Log::INFO,oss); try { - client->call( client->get_endpoint(), // serverUrl - "one.vm.deploy", // methodName - "sii", // arguments format - &deploy_result, // resultP - client->get_oneauth().c_str(), // argument 0 - vid, // argument 1 - hid // argument 2 - ); + //TODO Get live migration from config file + if (resched == true) + { + client->call(client->get_endpoint(), // serverUrl + "one.vm.migrate", // methodName + "siib", // arguments format + &deploy_result, // resultP + client->get_oneauth().c_str(), // argument 0 (AUTH) + vid, // argument 1 (VM) + hid, // argument 2 (HOST) + true); // argument 3 (LIVE) + } + else + { + client->call(client->get_endpoint(), // serverUrl + "one.vm.deploy", // methodName + "sii", // arguments format + &deploy_result, // resultP + client->get_oneauth().c_str(), // argument 0 (AUTH) + vid, // argument 1 (VM) + hid); // argument 2 (HOST) + } } catch (exception const& e) { diff --git a/src/scheduler/src/pool/VirtualMachineXML.cc b/src/scheduler/src/pool/VirtualMachineXML.cc index f4c0137ba1..2fd1ca2702 100644 --- a/src/scheduler/src/pool/VirtualMachineXML.cc +++ b/src/scheduler/src/pool/VirtualMachineXML.cc @@ -66,7 +66,29 @@ void VirtualMachineXML::init_attributes() else { requirements = ""; + } + + result = ((*this)["/VM/HISTORY_RECORDS/HISTORY/HID"]); + + if (result.size() > 0) + { + hid = atoi(result[0].c_str()); } + else + { + hid = -1; + } + + result = ((*this)["/VM/RESCHED"]); + + if (result.size() > 0) + { + resched = atoi(result[0].c_str()); + } + else + { + resched = 0; + } } /* -------------------------------------------------------------------------- */ @@ -87,13 +109,16 @@ VirtualMachineXML::~VirtualMachineXML() /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void VirtualMachineXML::add_host(int hid) +void VirtualMachineXML::add_host(int host_id) { - VirtualMachineXML::Host * ss; + if (( resched == 1 && host_id != hid ) || ( resched == 0 )) + { + VirtualMachineXML::Host * ss; - ss = new VirtualMachineXML::Host(hid); + ss = new VirtualMachineXML::Host(host_id); - hosts.push_back(ss); + hosts.push_back(ss); + } } /* -------------------------------------------------------------------------- */ diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index 03a5cea226..9f1dfbdcb8 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -329,7 +329,6 @@ void Scheduler::match() const map pending_vms = vmpool->get_objects(); const map hosts = hpool->get_objects(); - for (vm_it=pending_vms.begin(); vm_it != pending_vms.end(); vm_it++) { vm = static_cast(vm_it->second); @@ -516,15 +515,15 @@ void Scheduler::dispatch() map host_vms; - oss << "Select hosts" << endl; - oss << "\tPRI\tHID" << endl; - oss << "\t-------------------" << endl; + oss << "Selected hosts:" << endl; for (vm_it=pending_vms.begin(); vm_it != pending_vms.end(); vm_it++) { vm = static_cast(vm_it->second); - oss << "Virtual Machine: " << vm->get_oid() << "\n" << *vm << endl; + oss << "\t PRI\tHID VM: " << vm->get_oid() << endl + << "\t-----------------------" << endl + << *vm << endl; } NebulaLog::log("SCHED",Log::INFO,oss); @@ -541,9 +540,9 @@ void Scheduler::dispatch() if (rc == 0) { - rc = vmpool->dispatch(vm_it->first,hid); + rc = vmpool->dispatch(vm_it->first, hid, vm->is_resched()); - if (rc == 0) + if (rc == 0 && !vm->is_resched()) { dispatched_vms++; } From 38c5992cd85533f717bae096ef9fcc3d93ee8dea Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sun, 29 Apr 2012 23:38:40 +0200 Subject: [PATCH 32/36] feature #1243: Add configuration option to select the rescheduling type --- src/scheduler/etc/sched.conf | 4 ++++ src/scheduler/include/Scheduler.h | 5 +++++ src/scheduler/include/VirtualMachinePoolXML.h | 17 +++++++++++++---- src/scheduler/src/pool/VirtualMachinePoolXML.cc | 2 +- src/scheduler/src/sched/Scheduler.cc | 7 +++++-- src/scheduler/src/sched/SchedulerTemplate.cc | 7 +++++++ 6 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/scheduler/etc/sched.conf b/src/scheduler/etc/sched.conf index b72f48dd37..73a4a91c6d 100644 --- a/src/scheduler/etc/sched.conf +++ b/src/scheduler/etc/sched.conf @@ -18,6 +18,8 @@ # MAX_HOST: Maximum number of Virtual Machines dispatched to a given host in # each scheduling action # +# LIVE_RESCHEDS: Perform live (1) or cold migrations (0) when rescheduling a VM +# # DEFAULT_SCHED: Definition of the default scheduling algorithm # - policy: # 0 = Packing. Heuristic that minimizes the number of hosts in use by @@ -41,6 +43,8 @@ MAX_DISPATCH = 30 MAX_HOST = 1 +LIVE_RESCHEDS = 0 + DEFAULT_SCHED = [ policy = 1 ] diff --git a/src/scheduler/include/Scheduler.h b/src/scheduler/include/Scheduler.h index 454f62fddd..6c7c09d8f7 100644 --- a/src/scheduler/include/Scheduler.h +++ b/src/scheduler/include/Scheduler.h @@ -155,6 +155,11 @@ private: */ unsigned int host_dispatch_limit; + /** + * Type of migrations when rescheduling a VM: 0 cold, 1 live + */ + unsigned int live_rescheds; + /** * Threshold value to round up freecpu */ diff --git a/src/scheduler/include/VirtualMachinePoolXML.h b/src/scheduler/include/VirtualMachinePoolXML.h index e8c9f5e485..b2b97e169b 100644 --- a/src/scheduler/include/VirtualMachinePoolXML.h +++ b/src/scheduler/include/VirtualMachinePoolXML.h @@ -27,10 +27,10 @@ class VirtualMachinePoolXML : public PoolXML { public: - VirtualMachinePoolXML( - Client* client, - unsigned int machines_limit - ):PoolXML(client, machines_limit){}; + VirtualMachinePoolXML(Client* client, + unsigned int machines_limit, + bool _live_resched): + PoolXML(client, machines_limit), live_resched(_live_resched){}; ~VirtualMachinePoolXML(){}; @@ -47,6 +47,12 @@ public: return static_cast(PoolXML::get(oid)); }; + /** + * Dispatch a VM to the given host + * @param vid the VM id + * @param hid the id of the target host + * @param resched the machine is going to be rescheduled + */ int dispatch(int vid, int hid, bool resched) const; protected: @@ -60,6 +66,9 @@ protected: virtual void add_object(xmlNodePtr node); virtual int load_info(xmlrpc_c::value &result); + + /* Do live migrations to resched VMs*/ + bool live_resched; }; #endif /* VM_POOL_XML_H_ */ diff --git a/src/scheduler/src/pool/VirtualMachinePoolXML.cc b/src/scheduler/src/pool/VirtualMachinePoolXML.cc index 2428b41154..1b4852cb69 100644 --- a/src/scheduler/src/pool/VirtualMachinePoolXML.cc +++ b/src/scheduler/src/pool/VirtualMachinePoolXML.cc @@ -122,7 +122,7 @@ int VirtualMachinePoolXML::dispatch(int vid, int hid, bool resched) const client->get_oneauth().c_str(), // argument 0 (AUTH) vid, // argument 1 (VM) hid, // argument 2 (HOST) - true); // argument 3 (LIVE) + live_resched); // argument 3 (LIVE) } else { diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index 9f1dfbdcb8..28fd93725a 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -136,6 +136,8 @@ void Scheduler::start() conf.get("MAX_DISPATCH", dispatch_limit); conf.get("MAX_HOST", host_dispatch_limit); + + conf.get("LIVE_RESCHEDS", live_rescheds); oss.str(""); @@ -169,8 +171,9 @@ void Scheduler::start() // ----------------------------------------------------------- hpool = new HostPoolXML(client); - vmpool = new VirtualMachinePoolXML(client, machines_limit); - + vmpool = new VirtualMachinePoolXML(client, + machines_limit, + (live_rescheds == 1)); acls = new AclXML(client); // ----------------------------------------------------------- diff --git a/src/scheduler/src/sched/SchedulerTemplate.cc b/src/scheduler/src/sched/SchedulerTemplate.cc index 6e2c72f83a..c6aa61fc7d 100644 --- a/src/scheduler/src/sched/SchedulerTemplate.cc +++ b/src/scheduler/src/sched/SchedulerTemplate.cc @@ -40,6 +40,7 @@ void SchedulerTemplate::set_conf_default() # MAX_DISPATCH # MAX_HOST # DEFAULT_SCHED +# LIVE_RESCHEDS #------------------------------------------------------------------------------- */ // ONED_PORT @@ -71,6 +72,12 @@ void SchedulerTemplate::set_conf_default() attribute = new SingleAttribute("MAX_HOST",value); conf_default.insert(make_pair(attribute->name(),attribute)); + + //LIVE_RESCHEDS + value = "0"; + + attribute = new SingleAttribute("LIVE_RESCHEDS",value); + conf_default.insert(make_pair(attribute->name(),attribute)); //DEFAULT_SCHED map vvalue; From f64fccdaad5755249116832d89b8c9e029da5389 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sun, 29 Apr 2012 23:41:34 +0200 Subject: [PATCH 33/36] feature #1243: Do not store uneeded vars in Scheduler class --- src/scheduler/include/Scheduler.h | 5 ----- src/scheduler/src/sched/Scheduler.cc | 8 +++++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/scheduler/include/Scheduler.h b/src/scheduler/include/Scheduler.h index 6c7c09d8f7..454f62fddd 100644 --- a/src/scheduler/include/Scheduler.h +++ b/src/scheduler/include/Scheduler.h @@ -155,11 +155,6 @@ private: */ unsigned int host_dispatch_limit; - /** - * Type of migrations when rescheduling a VM: 0 cold, 1 live - */ - unsigned int live_rescheds; - /** * Threshold value to round up freecpu */ diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index 28fd93725a..d40bb1740b 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -65,15 +65,17 @@ extern "C" void * scheduler_action_loop(void *arg) void Scheduler::start() { - int rc; + int rc; ifstream file; ostringstream oss; string etc_path; - int oned_port; - pthread_attr_t pattr; + int oned_port; + unsigned int live_rescheds; + + pthread_attr_t pattr; // ----------------------------------------------------------- // Log system & Configuration File From 0c60e38f2890e37bebede38c2db37a4bfbba6751 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Mon, 30 Apr 2012 18:35:16 +0200 Subject: [PATCH 34/36] feature #1247: Enable VMware console access --- src/vmm/LibVirtDriverVMware.cc | 61 ++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/vmm/LibVirtDriverVMware.cc b/src/vmm/LibVirtDriverVMware.cc index 076c864ed8..5161011caf 100644 --- a/src/vmm/LibVirtDriverVMware.cc +++ b/src/vmm/LibVirtDriverVMware.cc @@ -1,3 +1,5 @@ + + /* -------------------------------------------------------------------------- */ /* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) */ /* */ @@ -64,6 +66,13 @@ int LibVirtDriver::deployment_description_vmware( string script = ""; string model = ""; + const VectorAttribute * graphics; + + string listen = ""; + string port = ""; + string passwd = ""; + string keymap = ""; + const VectorAttribute * raw; string data; @@ -358,6 +367,58 @@ int LibVirtDriver::deployment_description_vmware( attrs.clear(); + // ------------------------------------------------------------------------ + // Graphics + // ------------------------------------------------------------------------ + + if ( vm->get_template_attribute("GRAPHICS",attrs) > 0 ) + { + graphics = dynamic_cast(attrs[0]); + + if ( graphics != 0 ) + { + type = graphics->vector_value("TYPE"); + listen = graphics->vector_value("LISTEN"); + port = graphics->vector_value("PORT"); + passwd = graphics->vector_value("PASSWD"); + keymap = graphics->vector_value("KEYMAP"); + + if ( type == "vnc" || type == "VNC" ) + { + file << "\t\t" << endl; + } + else + { + vm->log("VMM", Log::WARNING, + "Not supported graphics type, ignored."); + } + } + } + + attrs.clear(); + file << "\t" << endl; // ------------------------------------------------------------------------ From 00b09519fd6c72413526488b93dc11facea65c84 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Tue, 1 May 2012 23:17:22 +0200 Subject: [PATCH 35/36] feature #1243: Seting/Clearing resched flag requires ADMIN permissions. Bring back Sconstruct tests. --- SConstruct | 30 +++++++++++++------------- include/RequestManagerVirtualMachine.h | 11 ++++++---- src/rm/RequestManagerVirtualMachine.cc | 26 ++++++++++++++-------- 3 files changed, 39 insertions(+), 28 deletions(-) diff --git a/SConstruct b/SConstruct index c5db663582..cf962f4d85 100644 --- a/SConstruct +++ b/SConstruct @@ -237,22 +237,22 @@ if testing=='yes': ]) build_scripts.extend([ -# 'src/authm/test/SConstruct', -# 'src/common/test/SConstruct', -# 'src/host/test/SConstruct', -# 'src/cluster/test/SConstruct', -# 'src/datastore/test/SConstruct', -# 'src/group/test/SConstruct', -# 'src/image/test/SConstruct', -# 'src/lcm/test/SConstruct', -# 'src/pool/test/SConstruct', -# 'src/template/test/SConstruct', -# 'src/test/SConstruct', -# 'src/um/test/SConstruct', + 'src/authm/test/SConstruct', + 'src/common/test/SConstruct', + 'src/host/test/SConstruct', + 'src/cluster/test/SConstruct', + 'src/datastore/test/SConstruct', + 'src/group/test/SConstruct', + 'src/image/test/SConstruct', + 'src/lcm/test/SConstruct', + 'src/pool/test/SConstruct', + 'src/template/test/SConstruct', + 'src/test/SConstruct', + 'src/um/test/SConstruct', 'src/vm/test/SConstruct', -# 'src/vnm/test/SConstruct', -# 'src/xml/test/SConstruct', -# 'src/vm_template/test/SConstruct', + 'src/vnm/test/SConstruct', + 'src/xml/test/SConstruct', + 'src/vm_template/test/SConstruct', ]) else: main_env.Append(testing='no') diff --git a/include/RequestManagerVirtualMachine.h b/include/RequestManagerVirtualMachine.h index 6b5472807e..2955bbd79b 100644 --- a/include/RequestManagerVirtualMachine.h +++ b/include/RequestManagerVirtualMachine.h @@ -49,10 +49,11 @@ protected: RequestAttributes& att) = 0; bool vm_authorization(int id, - ImageTemplate * tmpl, - RequestAttributes& att, - PoolObjectAuth * host_perms, - PoolObjectAuth * ds_perm); + ImageTemplate * tmpl, + RequestAttributes& att, + PoolObjectAuth * host_perms, + PoolObjectAuth * ds_perm, + AuthRequest::Operation op); int get_host_information(int hid, string& name, string& vmm, string& vnm, RequestAttributes& att, PoolObjectAuth& host_perms); @@ -73,6 +74,8 @@ protected: class VirtualMachineAction : public RequestManagerVirtualMachine { public: + //auth_op is MANAGE for all actions but "resched" and "unresched" + //this is dynamically set for each request in the execute method VirtualMachineAction(): RequestManagerVirtualMachine("VirtualMachineAction", "Performs an action on a virtual machine", diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index cc8d129704..b252330b84 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -22,10 +22,11 @@ /* -------------------------------------------------------------------------- */ bool RequestManagerVirtualMachine::vm_authorization(int oid, - ImageTemplate * tmpl, - RequestAttributes& att, - PoolObjectAuth * host_perm, - PoolObjectAuth * ds_perm) + ImageTemplate * tmpl, + RequestAttributes& att, + PoolObjectAuth * host_perm, + PoolObjectAuth * ds_perm, + AuthRequest::Operation op) { PoolObjectSQL * object; PoolObjectAuth vm_perms; @@ -52,7 +53,7 @@ bool RequestManagerVirtualMachine::vm_authorization(int oid, AuthRequest ar(att.uid, att.gid); - ar.add_auth(auth_op, vm_perms); + ar.add_auth(op, vm_perms); if (host_perm != 0) { @@ -184,7 +185,14 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList, Nebula& nd = Nebula::instance(); DispatchManager * dm = nd.get_dm(); - if ( vm_authorization(id, 0, att, 0, 0) == false ) + AuthRequest::Operation op = auth_op; + + if (action == "resched" || action == "unresched") + { + op = AuthRequest::ADMIN; + } + + if ( vm_authorization(id, 0, att, 0, 0, op) == false ) { return; } @@ -297,7 +305,7 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, return; } - auth = vm_authorization(id, 0, att, &host_perms, 0); + auth = vm_authorization(id, 0, att, &host_perms, 0, auth_op); if ( auth == false ) { @@ -359,7 +367,7 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList return; } - auth = vm_authorization(id, 0, att, &host_perms, 0); + auth = vm_authorization(id, 0, att, &host_perms, 0, auth_op); if ( auth == false ) { @@ -531,7 +539,7 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis // Authorize the operation // ------------------------------------------------------------------------- - if ( vm_authorization(id, itemplate, att, 0, &ds_perms) == false ) + if ( vm_authorization(id, itemplate, att, 0, &ds_perms, auth_op) == false ) { delete itemplate; return; From 42872f9c447225e807682d81d5acf6c9225565ec Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Thu, 3 May 2012 18:58:15 +0200 Subject: [PATCH 36/36] Add --plain option to occi commands --- src/cloud/occi/bin/occi-compute | 8 ++++++-- src/cloud/occi/bin/occi-instance-type | 11 +++++++++-- src/cloud/occi/bin/occi-network | 11 +++++++++-- src/cloud/occi/bin/occi-storage | 11 +++++++++-- src/cloud/occi/lib/OCCIClient.rb | 4 ++-- 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/cloud/occi/bin/occi-compute b/src/cloud/occi/bin/occi-compute index 85277961e4..722ee2a91c 100755 --- a/src/cloud/occi/bin/occi-compute +++ b/src/cloud/occi/bin/occi-compute @@ -93,7 +93,8 @@ opts = GetoptLong.new( ['--url', '-R',GetoptLong::REQUIRED_ARGUMENT], ['--timeout', '-T',GetoptLong::REQUIRED_ARGUMENT], ['--debug', '-D',GetoptLong::NO_ARGUMENT], - ['--verbose', GetoptLong::NO_ARGUMENT] + ['--verbose', GetoptLong::NO_ARGUMENT], + ['--plain', GetoptLong::NO_ARGUMENT] ) url = nil @@ -103,6 +104,7 @@ auth = nil timeout = nil debug = false verbose = false +plain = false begin opts.each do |opt, arg| @@ -125,6 +127,8 @@ begin debug = true when '--verbose' verbose = true + when '--plain' + plain = true end end rescue Exception => e @@ -132,7 +136,7 @@ rescue Exception => e end begin - occi_client = OCCIClient::Client.new(url,username,password, timeout, debug) + occi_client = OCCIClient::Client.new(url,username,password, timeout, debug, plain) rescue Exception => e puts "#{cmd_name}: #{e.message}" exit(-1) diff --git a/src/cloud/occi/bin/occi-instance-type b/src/cloud/occi/bin/occi-instance-type index f4482fabc9..a05294b13a 100755 --- a/src/cloud/occi/bin/occi-instance-type +++ b/src/cloud/occi/bin/occi-instance-type @@ -62,6 +62,9 @@ Options: --verbose Show resources in verbose mode +--plain + The password provided will not be hashed + EOT require 'occi/OCCIClient' @@ -77,7 +80,8 @@ opts = GetoptLong.new( ['--url', '-R',GetoptLong::REQUIRED_ARGUMENT], ['--timeout', '-T',GetoptLong::REQUIRED_ARGUMENT], ['--debug', '-D',GetoptLong::NO_ARGUMENT], - ['--verbose', GetoptLong::NO_ARGUMENT] + ['--verbose', GetoptLong::NO_ARGUMENT], + ['--plain', GetoptLong::NO_ARGUMENT] ) url = nil @@ -87,6 +91,7 @@ auth = nil timeout = nil debug = false verbose = false +plain = false begin opts.each do |opt, arg| @@ -109,6 +114,8 @@ begin debug = true when '--verbose' verbose = true + when '--plain' + plain = true end end rescue Exception => e @@ -116,7 +123,7 @@ rescue Exception => e end begin - occi_client = OCCIClient::Client.new(url,username,password, timeout, debug) + occi_client = OCCIClient::Client.new(url,username,password, timeout, debug,plain) rescue Exception => e puts "#{cmd_name}: #{e.message}" exit(-1) diff --git a/src/cloud/occi/bin/occi-network b/src/cloud/occi/bin/occi-network index d2377bb31c..e2af20c6fb 100755 --- a/src/cloud/occi/bin/occi-network +++ b/src/cloud/occi/bin/occi-network @@ -79,6 +79,9 @@ Options: --verbose Show resources in verbose mode +--plain + The password provided will not be hashed + EOT require 'occi/OCCIClient' @@ -94,7 +97,8 @@ opts = GetoptLong.new( ['--url', '-R',GetoptLong::REQUIRED_ARGUMENT], ['--timeout', '-T',GetoptLong::REQUIRED_ARGUMENT], ['--debug', '-D',GetoptLong::NO_ARGUMENT], - ['--verbose', GetoptLong::NO_ARGUMENT] + ['--verbose', GetoptLong::NO_ARGUMENT], + ['--plain', GetoptLong::NO_ARGUMENT] ) url = nil @@ -104,6 +108,7 @@ auth = nil timeout = nil debug = false verbose = false +plain = false begin opts.each do |opt, arg| @@ -126,6 +131,8 @@ begin debug = true when '--verbose' verbose = true + when '--plain' + plain = true end end rescue Exception => e @@ -133,7 +140,7 @@ rescue Exception => e end begin - occi_client = OCCIClient::Client.new(url,username,password,timeout,debug) + occi_client = OCCIClient::Client.new(url,username,password,timeout,debug,plain) rescue Exception => e puts "#{cmd_name}: #{e.message}" exit(-1) diff --git a/src/cloud/occi/bin/occi-storage b/src/cloud/occi/bin/occi-storage index fb9eddb375..ad70987f71 100755 --- a/src/cloud/occi/bin/occi-storage +++ b/src/cloud/occi/bin/occi-storage @@ -82,6 +82,9 @@ Options: --verbose Show resources in verbose mode +--plain + The password provided will not be hashed + EOT require 'occi/OCCIClient' @@ -99,7 +102,8 @@ opts = GetoptLong.new( ['--debug', '-D',GetoptLong::NO_ARGUMENT], ['--timeout', '-T',GetoptLong::REQUIRED_ARGUMENT], ['--multipart', '-M',GetoptLong::NO_ARGUMENT], - ['--verbose', GetoptLong::NO_ARGUMENT] + ['--verbose', GetoptLong::NO_ARGUMENT], + ['--plain', GetoptLong::NO_ARGUMENT] ) url = nil @@ -110,6 +114,7 @@ timeout = nil debug = false curb = true verbose = false +plain = false begin opts.each do |opt, arg| @@ -134,6 +139,8 @@ begin curb = false when '--verbose' verbose = true + when '--plain' + plain = true end end rescue Exception => e @@ -148,7 +155,7 @@ end begin - occi_client = OCCIClient::Client.new(url,username,password,timeout,debug) + occi_client = OCCIClient::Client.new(url,username,password,timeout,debug,plain) rescue Exception => e puts "#{cmd_name}: #{e.message}" exit(-1) diff --git a/src/cloud/occi/lib/OCCIClient.rb b/src/cloud/occi/lib/OCCIClient.rb index 1844d90e58..9b1ffbf600 100755 --- a/src/cloud/occi/lib/OCCIClient.rb +++ b/src/cloud/occi/lib/OCCIClient.rb @@ -36,7 +36,7 @@ module OCCIClient # Initialize client library ###################################################################### def initialize(endpoint_str=nil, user=nil, pass=nil, - timeout=nil, debug_flag=true) + timeout=nil, debug_flag=true, plain=false) @debug = debug_flag @timeout = timeout @@ -60,7 +60,7 @@ module OCCIClient raise "No authorization data present" end - @occiauth[1] = Digest::SHA1.hexdigest(@occiauth[1]) + @occiauth[1] = Digest::SHA1.hexdigest(@occiauth[1]) unless plain end #################################