diff --git a/src/authm_mad/remotes/ldap/ldap_auth.rb b/src/authm_mad/remotes/ldap/ldap_auth.rb index 9a7ac5220c..091e91b3fb 100644 --- a/src/authm_mad/remotes/ldap/ldap_auth.rb +++ b/src/authm_mad/remotes/ldap/ldap_auth.rb @@ -66,6 +66,11 @@ class OpenNebula::LdapAuth @options[:attributes] << @options[:user_field] end + # fetch the user group field only if we need that + if @options[:group] or !@options[:rfc2307bis] + @options[:attributes] << @options[:user_group_field] + end + ops[:host]=@options[:host] if @options[:host] ops[:port]=@options[:port].to_i if @options[:port] ops[:encryption]=@options[:encryption] if @options[:encryption] diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index 138bfc3bd0..3c9dce4fd6 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -417,8 +417,8 @@ EOT else sync = true end - - @@client=OpenNebula::Client.new(secret, endpoint, :sync => sync) + options[:sync] = sync + @@client=OpenNebula::Client.new(secret, endpoint, options) end end diff --git a/src/cli/one_helper/onezone_helper.rb b/src/cli/one_helper/onezone_helper.rb index 8a1f0212ab..aef3c644c9 100644 --- a/src/cli/one_helper/onezone_helper.rb +++ b/src/cli/one_helper/onezone_helper.rb @@ -124,7 +124,8 @@ class OneZoneHelper < OpenNebulaHelper::OneHelper next if endpoint.nil? - client = OpenNebula::Client.new(nil, endpoint) + options[:timeout] = 5 #5 sec + client = OpenNebula::Client.new(nil, endpoint, options) xml_doc = client.call("zone.raftstatus") diff --git a/src/cli/onegroup b/src/cli/onegroup index 38f073e051..9444d3e8bc 100755 --- a/src/cli/onegroup +++ b/src/cli/onegroup @@ -87,13 +87,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do command :create, create_desc, [:group_name, nil], :options => OpenNebulaHelper::GROUP_OPTIONS do - - if !args[0] && options.empty? - STDERR.puts "Please use either a group name or command arguments."<< - " Run onegroup create -h for more information" - next -1 - end - if options && options[:admin_user] if !options[:admin_password] STDERR.puts "Admin user needs password" @@ -108,11 +101,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do options[:group_admin] = admin_user end - if !options.empty? - helper.create_complete_resource(options) - elsif args[0] + if args[0] options[:name] = args[0] helper.create_complete_resource(options) + elsif options[:name] + helper.create_complete_resource(options) + else + STDERR.puts "Please use either a group name or command arguments."<< + " Run onegroup create -h for more information" + next -1 end end diff --git a/src/cli/oneshowback b/src/cli/oneshowback index faae345c40..425934fe28 100755 --- a/src/cli/oneshowback +++ b/src/cli/oneshowback @@ -43,6 +43,7 @@ cmd = CommandParser::CmdParser.new(ARGV) do helper=OpenNebulaHelper::OneHelper.new before_proc do + options[:timeout] = 60 #60 sec helper.set_client(options) end diff --git a/src/datastore_mad/remotes/common/stat b/src/datastore_mad/remotes/common/stat index 07adcaca51..af41fb3ed7 100755 --- a/src/datastore_mad/remotes/common/stat +++ b/src/datastore_mad/remotes/common/stat @@ -45,15 +45,21 @@ unset i XPATH_ELEMENTS while IFS= read -r -d '' element; do XPATH_ELEMENTS[i++]="$element" -done < <($XPATH /DS_DRIVER_ACTION_DATA/IMAGE/PATH) +done < <($XPATH /DS_DRIVER_ACTION_DATA/IMAGE/PATH \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/NO_DECOMPRESS \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/LIMIT_TRANSFER_BW) -SRC="${XPATH_ELEMENTS[0]}" +unset i + +SRC="${XPATH_ELEMENTS[i++]}" +NO_DECOMPRESS="${XPATH_ELEMENTS[i++]}" +LIMIT_TRANSFER_BW="${XPATH_ELEMENTS[i++]}" # ------------------------------------------------------------------------------ # Compute the size # ------------------------------------------------------------------------------ -SIZE=`fs_size $SRC` +SIZE=`fs_size "${SRC}" "${NO_DECOMPRESS}" "${LIMIT_TRANSFER_BW}"` if [ "$SIZE" = "0" ]; then log_error "Cannot determine size for $SRC" diff --git a/src/datastore_mad/remotes/downloader.sh b/src/datastore_mad/remotes/downloader.sh index 827db89c9b..285b5762ff 100755 --- a/src/datastore_mad/remotes/downloader.sh +++ b/src/datastore_mad/remotes/downloader.sh @@ -43,7 +43,7 @@ function get_type else command=$1 - ( $command | head -n 1024 | file -b --mime-type - ) 2>/dev/null + ( eval "$command" | head -n 1024 | file -b --mime-type - ) 2>/dev/null fi } @@ -57,7 +57,10 @@ function get_decompressor echo "gunzip -c -" ;; "application/x-bzip2") - echo "bunzip2 -c -" + echo "bunzip2 -qc -" + ;; + "application/x-xz") + echo "unxz -c -" ;; *) echo "cat" @@ -221,7 +224,7 @@ function get_rbd_cmd echo "ssh '$(esc_sq "$DST_HOST")' \"$RBD export '$(esc_sq "$SOURCE")' -\"" } -TEMP=`getopt -o m:s:l:n -l md5:,sha1:,limit:,nodecomp -- "$@"` +TEMP=`getopt -o m:s:l:c:n -l md5:,sha1:,limit:,max-size:,nodecomp -- "$@"` if [ $? != 0 ] ; then echo "Arguments error" @@ -250,6 +253,10 @@ while true; do export LIMIT_RATE="$2" shift 2 ;; + -c|--max-size) + export MAX_SIZE="$2" + shift 2 + ;; --) shift break @@ -263,8 +270,13 @@ done FROM="$1" TO="$2" -# File used by the hasher function to store the resulting hash -export HASH_FILE="/tmp/downloader.hash.$$" +if [ -n "${HASH_TYPE}" -a -n "${MAX_SIZE}" ]; then + echo "Hash check not supported for partial downloads" >&2 + exit -1 +else + # File used by the hasher function to store the resulting hash + export HASH_FILE="/tmp/downloader.hash.$$" +fi GLOBAL_CURL_ARGS="--fail -sS -k -L" @@ -324,11 +336,48 @@ esac file_type=$(get_type "$command") decompressor=$(get_decompressor "$file_type") -eval "$command" | tee >( hasher $HASH_TYPE) | decompress "$decompressor" "$TO" +if [ -z "${MAX_SIZE}" ]; then + eval "$command" | \ + tee >( hasher $HASH_TYPE) | \ + decompress "$decompressor" "$TO" -if [ "$?" != "0" -o "$PIPESTATUS" != "0" ]; then - echo "Error copying" >&2 - exit -1 + if [ "$?" != "0" -o "$PIPESTATUS" != "0" ]; then + echo "Error copying" >&2 + exit -1 + fi +else + # Order of the 'head' command is here on purpose: + # 1. We want to download more bytes than needed to get a requested + # number of bytes on the output. Decompressor may need more + # data to decompress the stream. + # 2. Decompressor command is also misused to detect SIGPIPE error. + eval "$command" | \ + decompress "$decompressor" "$TO" 2>/dev/null | \ + head -c "${MAX_SIZE}" + + # Following table shows exit codes of each command + # in the pipe for various scenarios: + # + # ---------------------------------------------------- + # | $COMMAND | TYPE | PIPESTATUS | BEHAVIOUR + # ---------------------------------------------------- + # | cat | partial | 141 141 0 | OK + # | cat | full | 0 0 0 | OK + # | cat | error | 1 0 0 | fail + # | curl | partial | 23 141 0 | OK + # | curl | full | 0 0 0 | OK + # | curl | error | 22 0 0 | fail + # | ssh | partial | 255 141 0 | OK + # | ssh | full | 0 0 0 | OK + # | ssh | error ssh | 255 0 0 | fail + # | ssh | error ssh cat | 1 0 0 | fail + if [ \( "${PIPESTATUS[0]}" != '0' -a "${PIPESTATUS[1]}" = '0' \) \ + -o \( "${PIPESTATUS[1]}" != '0' -a "${PIPESTATUS[1]}" != '141' \) \ + -o \( "${PIPESTATUS[2]}" != "0" \) ]; + then + echo "Error copying" >&2 + exit -1 + fi fi if [ -n "$HASH_TYPE" ]; then @@ -344,4 +393,3 @@ fi if [ "$TO" != "-" ]; then unarchive "$TO" fi - diff --git a/src/datastore_mad/remotes/libfs.sh b/src/datastore_mad/remotes/libfs.sh index b477945584..16ada366ee 100644 --- a/src/datastore_mad/remotes/libfs.sh +++ b/src/datastore_mad/remotes/libfs.sh @@ -60,6 +60,14 @@ function image_format { echo "$($QEMU_IMG info $1 2>/dev/null | grep -Po '(?<=file format: )\w+')" } +#------------------------------------------------------------------------------- +# Get image virtual size using qemu-img +# @return string representation of the format, empty if error +#------------------------------------------------------------------------------- +function image_vsize { + echo "$($QEMU_IMG info "${1}" 2>/dev/null | sed -n 's/.*(\([0-9]*\) bytes).*/\1/p')" +} + #------------------------------------------------------------------------------- # Generates an unique image hash. Requires ID to be set # @return hash for the image (empty if error) @@ -118,7 +126,7 @@ function set_downloader_args { HASHES="$HASHES --sha1 $2" fi - if [ "$3" = "yes" -o "$3" = "Yes" -o "$3" = "YES" ]; then + if [ "x$(echo "$3" | tr A-Z a-z)" = "xyes" ]; then HASHES="$HASHES --nodecomp" fi @@ -149,6 +157,17 @@ function file_size { $STAT_CMD "$*" } + +#------------------------------------------------------------------------------ +# Gets the MIME type of a file +# @param $1 - Path to the image +# @return MIME type +#------------------------------------------------------------------------------ + +function file_type { + file -b --mime-type "${1}" | tr A-Z a-z +} + #------------------------------------------------------------------------------ # Gets the size in bytes of a gzipped file # @param $1 - Path to the image @@ -159,58 +178,195 @@ function gzip_file_size { gzip -l "$1" | tail -n 1 | awk '{print $2}' } +#------------------------------------------------------------------------------ +# Gets the size in bytes of a xzipped file +# @param $1 - Path to the image +# @return size of the image in bytes +#------------------------------------------------------------------------------ + +function xz_file_size { + xz -l --robot "$1" | tail -n 1 | awk '{print $5}' +} + +#------------------------------------------------------------------------------ +# Gets the size in bytes of a bzipped file +# @param $1 - Path to the image +# @return size of the image in bytes +#------------------------------------------------------------------------------ + +function bzip_file_size { + bunzip2 -c "${1}" | wc -c +} + #------------------------------------------------------------------------------- # Computes the size of an image # @param $1 - Path to the image +# @param $2 - NO_DECOMPRESS +# @param $3 - BW LIMIT # @return size of the image in Mb #------------------------------------------------------------------------------- function fs_size { + SRC=$1 + NO_DECOMPRESS=$(echo "$2" | tr A-Z a-z) + LIMIT_TRANSFER_BW=$3 - case $1 in - http://*|https://*) - HEADERS=`curl -LIk --max-time 60 "${1}" 2>&1` + DOWNLOADER_ARGS=`set_downloader_args '' '' "${NO_DECOMPRESS}" "${LIMIT_TRANSFER_BW}"` - if echo "$HEADERS" | grep -i -q "OpenNebula-AppMarket-Size"; then - # An AppMarket/Marketplace URL - SIZE=$(echo "$HEADERS" | grep -i "^OpenNebula-AppMarket-Size:" | tail -n1 | cut -d: -f2) + if [ -z "${UTILS_PATH}" ] && [ -n "${DRIVER_PATH}" ]; then + UTILS_PATH="${DRIVER_PATH}/../../datastore" + fi + + if ! [ -d "${UTILS_PATH}" ]; then + log_error "Failed to detect downloader.sh location" + exit 1 + fi + + error=1 + + # limit only on local or remote http(s) + if [ -d "${SRC}" ]; then + SIZE=`du -sb "${SRC}" | cut -f1` + error=$? + elif [ -f "${SRC}" ] || (echo "${SRC}" | grep -qe '^https\?://'); then + IMAGE=$(mktemp) + + # try first download only a part of image + $UTILS_PATH/downloader.sh ${DOWNLOADER_ARGS} -c 65536 "${SRC}" - >"${IMAGE}" 2>/dev/null + error=$? + if [ $error -ne 0 ]; then + # better fail here ... + log_error "Failed to download image head" + echo '0' + return + fi + + TYPE=$(image_format "${IMAGE}") + + # raw images requires special handling, as there is no image header + # with size available and we can't predict image virtual size just + # from a part of the file + if [ "${TYPE}" = 'raw' ]; then + $UTILS_PATH/downloader.sh ${DOWNLOADER_ARGS} --nodecomp -c 65536 "${SRC}" - >"${IMAGE}" 2>/dev/null error=$? - else - # Not an AppMarket/Marketplace URL - SIZE=$(echo "$HEADERS" | grep -i "^Content-Length:" | tail -n1 | cut -d: -f2 | tr -d "\r") - error=$? - - # Try to download the image head and inspect via qemu-img - IMAGE=$(mktemp) - curl -Lk --max-time 60 "${1}" 2>/dev/null | head -c 65536 >${IMAGE} - QSIZE=$($QEMU_IMG info "${IMAGE}" | sed -n 's/.*(\([0-9]*\) bytes).*/\1/p') - rm "${IMAGE}" 2>/dev/null - - if [ "${QSIZE}" -gt "${SIZE}" ]; then - SIZE="${QSIZE}" + if [ $error -ne 0 ]; then + # better fail here ... + log_error "Failed to download image head" + echo '0' + return + fi + + ORIG_TYPE=$(file_type "${IMAGE}") + + # if NO_DECOMPRESS=yes is configured on the datastore, + # treat the downloaded data as image as is + if [ "${NO_DECOMPRESS}" = 'yes' ]; then + ORIG_TYPE='application/octet-stream' + fi + + if [ -f "${SRC}" ] ; then + # for local raw images: + # - compressed: use decompressor on local file + # - uncompressed: get file size + case ${ORIG_TYPE} in + "application/x-gzip"|"application/gzip") + SIZE=$(gzip_file_size "${SRC}") + error=$? + ;; + "application/x-xz") + SIZE=$(xz_file_size "${SRC}") + error=$? + ;; + "application/x-bzip2") + SIZE=$(bzip_file_size "${SRC}") + error=$? + ;; + *) + SIZE=$(image_vsize "${SRC}") + error=$? + ;; + esac + else + # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + # code which allows downloading is experimental for future use, + # longer downloads may result in image import failure, as + # the datastore stat operation is synchronous with import call + # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + ALLOW_DOWNLOADS='no' + + # for remote raw images + # - compressed: complete download and use decompressor + # - uncompressed: get size from HTTP headers or complete download + case ${ORIG_TYPE} in + "application/x-gzip"|"application/gzip") + if [ "${ALLOW_DOWNLOADS}" = 'yes' ]; then + $UTILS_PATH/downloader.sh ${DOWNLOADER_ARGS} --nodecomp "${SRC}" - >"${IMAGE}" 2>/dev/null + error=$? + if [ $error -eq 0 ]; then + SIZE=$(gzip_file_size "${IMAGE}") + error=$? + fi + else + log_error 'Unsupported remote image format' + error=1 + fi + ;; + "application/x-xz") + if [ "${ALLOW_DOWNLOADS}" = 'yes' ]; then + $UTILS_PATH/downloader.sh ${DOWNLOADER_ARGS} --nodecomp "${SRC}" - >"${IMAGE}" 2>/dev/null + error=$? + if [ $error -eq 0 ]; then + SIZE=$(xz_file_size "${IMAGE}") + error=$? + fi + else + log_error 'Unsupported remote image format' + error=1 + fi + ;; + "application/x-bzip2") + if [ "${ALLOW_DOWNLOADS}" = 'yes' ]; then + $UTILS_PATH/downloader.sh ${DOWNLOADER_ARGS} "${SRC}" - >"${IMAGE}" 2>/dev/null + error=$? + if [ $error -eq 0 ]; then + SIZE=$(image_vsize "${IMAGE}") + error=$? + fi + else + log_error 'Unsupported remote image format' + error=1 + fi + ;; + *) + HEADERS=`curl -LIk --max-time 60 "${SRC}" 2>&1` + error=$? + SIZE=$(echo "$HEADERS" | grep -i "^Content-Length:" | tail -n1 | cut -d: -f2 | tr -d "\r") + + if [ -z "${SIZE}" ]; then + if [ "${ALLOW_DOWNLOADS}" = 'yes' ]; then + $UTILS_PATH/downloader.sh ${DOWNLOADER_ARGS} "${SRC}" - >"${IMAGE}" 2>/dev/null + error=$? + if [ $error -eq 0 ]; then + SIZE=$(image_vsize "${IMAGE}") + error=$? + fi + else + log_error 'Unsupported remote image format' + error=1 + fi + fi + ;; + esac fi - fi - ;; - *) - if [ -d "$1" ]; then - SIZE=`du -sb "$1" | cut -f1` - error=$? else - TYPE=$(cat "$1" | head -n 1024 | file -b - | tr A-Z a-z) - case "$TYPE" in - *gzip*) - SIZE=$(gzip_file_size "$1") - ;; - *qcow*) - SIZE=$($QEMU_IMG info "$1" | sed -n 's/.*(\([0-9]*\) bytes).*/\1/p') - ;; - *) - SIZE=$(file_size "$1") - ;; - esac - error=$? + SIZE=$(image_vsize "${IMAGE}") fi - ;; - esac + + if [ -f "${IMAGE}" ]; then + unlink "${IMAGE}" 2>/dev/null + fi + fi + + ##### SIZE=$(echo $SIZE | tr -d "\r") diff --git a/src/ipamm_mad/remotes/dummy/get_address b/src/ipamm_mad/remotes/dummy/get_address index e191b1a3b8..d2c2224a8b 100755 --- a/src/ipamm_mad/remotes/dummy/get_address +++ b/src/ipamm_mad/remotes/dummy/get_address @@ -103,6 +103,7 @@ ADDR_SIZE="${XPATH_ELEMENTS[i++]}" BASE_IP=$(echo $AR_IP | cut -d'.' -f-3) HOST_ID=$RANDOM let "HOST_ID %= $AR_SIZE" +HOST_ID=$(($HOST_ID+1)) cat << EOT ADDRESS = [ IP=$BASE_IP.$HOST_ID, SIZE=$ADDR_SIZE ] diff --git a/src/ipamm_mad/remotes/dummy/register_address_range b/src/ipamm_mad/remotes/dummy/register_address_range index 026897873d..5b5b61033c 100755 --- a/src/ipamm_mad/remotes/dummy/register_address_range +++ b/src/ipamm_mad/remotes/dummy/register_address_range @@ -121,7 +121,7 @@ else AR=$(cat <= 2 diff --git a/src/oca/ruby/opennebula/error.rb b/src/oca/ruby/opennebula/error.rb index 41ac9e927a..e287b75950 100644 --- a/src/oca/ruby/opennebula/error.rb +++ b/src/oca/ruby/opennebula/error.rb @@ -31,7 +31,7 @@ module OpenNebula EALLOCATE = 0x4000 ENOTDEFINED = 0xF001 EXML_RPC_CALL = 0xF002 - + attr_reader :message, :errno # +message+ Description of the error diff --git a/src/onedb/fsck/network.rb b/src/onedb/fsck/network.rb index 3802c0edce..4e085a47d7 100644 --- a/src/onedb/fsck/network.rb +++ b/src/onedb/fsck/network.rb @@ -170,9 +170,8 @@ module OneDBFsck counter_no_ar = counters[:vnet][row[:oid]][:no_ar_leases] + error = false counters[:vnet][row[:oid]][:ar_leases].each do |ar_id, counter_ar| - error = false - net_ar = doc.root.at_xpath("AR_POOL/AR[AR_ID=#{ar_id}]") if (net_ar.nil?) diff --git a/src/onedb/onedb b/src/onedb/onedb index 16ddf60db7..462ab409c5 100755 --- a/src/onedb/onedb +++ b/src/onedb/onedb @@ -570,7 +570,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do * --id: vm id, example: 156 * --seq: sequence number of the record, example: 0 - The new value for this elemente is set in the third parameter. + The new value for this elemente is set in the third parameter. Change the the hostname of first record: diff --git a/src/onedb/onedb_live.rb b/src/onedb/onedb_live.rb index bd1f97bc42..a1d4610c13 100644 --- a/src/onedb/onedb_live.rb +++ b/src/onedb/onedb_live.rb @@ -87,13 +87,18 @@ class OneDBLive OpenNebula::XMLElement.build_xml(res, '/SQL_COMMAND')) hash = element.to_hash + row = hash['SQL_COMMAND']['RESULT']['ROW'] rescue nil + + if !row + raise "Empty SQL query result: " + end - row = hash['SQL_COMMAND']['RESULT']['ROW'] rescue nil [row].flatten.compact end def db_query(sql, error_msg) rc = system_db.sql_query_command(sql) + if OpenNebula.is_error?(rc) raise "#{error_msg}: #{rc.message}" end @@ -370,22 +375,24 @@ class OneDBLive def change_body(object, xpath, value, options = {}) table, object, federate = get_pool_config(object) + found_id = false if !value && !options[:delete] raise "A value or --delete should specified" end - object.info_all + rc = object.info_all + raise rc.message if OpenNebula.is_error?(rc) object.each do |o| if options[:id] - next unless o.id.to_s.strip == options[:id].to_s + found_id = o.id.to_s.strip == options[:id].to_s + next unless found_id elsif options[:xpath] next unless o[options[:xpath]] elsif options[:expr] next unless check_expr(o, options[:expr]) end - # Get body from the database begin db_data = select(table, "oid = #{o.id}") @@ -423,7 +430,9 @@ class OneDBLive next end end + break if found_id end + raise "Object with id #{options[:id]} not found" if options[:id] && !found_id end def editor_body(body_xml) diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index ec03ea1f28..2f6a0b5763 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -1088,7 +1088,7 @@ bool VirtualRouterAllocate::allocate_authorization( if (quota_authorization(tmpl, Quotas::VIRTUALROUTER, att, att.resp_msg) == false) { - return AUTHORIZATION; + return false; } return true; diff --git a/src/rm/RequestManagerVMTemplate.cc b/src/rm/RequestManagerVMTemplate.cc index 68b854a8fb..6c49a2ea5e 100644 --- a/src/rm/RequestManagerVMTemplate.cc +++ b/src/rm/RequestManagerVMTemplate.cc @@ -255,10 +255,7 @@ Request::ErrorCode VMTemplateInstantiate::merge( const string &str_uattrs, RequestAttributes& att) { - if (str_uattrs.empty()) - { - return SUCCESS; - } + int rc; @@ -270,11 +267,15 @@ Request::ErrorCode VMTemplateInstantiate::merge( if ( rc != 0 ) { return INTERNAL; + } + else if (uattrs.empty()) + { + return SUCCESS; } if (att.uid!=UserPool::ONEADMIN_ID && att.gid!=GroupPool::ONEADMIN_ID) { - if (uattrs.check_restricted(aname, tmpl)) + if (uattrs.check_restricted(aname, tmpl)) { att.resp_msg ="User Template includes a restricted attribute " + aname; diff --git a/src/rm/RequestManagerVirtualRouter.cc b/src/rm/RequestManagerVirtualRouter.cc index 435c037afa..e95ce711d1 100644 --- a/src/rm/RequestManagerVirtualRouter.cc +++ b/src/rm/RequestManagerVirtualRouter.cc @@ -293,13 +293,10 @@ void VirtualRouterAttachNic::request_execute( { failure_response(ACTION, att); - delete nic; return; } } - delete nic; - success_response(vrid, att); } diff --git a/src/sunstone/public/app/sunstone.js b/src/sunstone/public/app/sunstone.js index f0877366de..eb17c435bf 100644 --- a/src/sunstone/public/app/sunstone.js +++ b/src/sunstone/public/app/sunstone.js @@ -15,24 +15,24 @@ /* -------------------------------------------------------------------------- */ define(function(require) { - require('jquery'); + require("jquery"); //require('foundation.reveal'); //require('foundation.tab'); //require('foundation.dropdown'); - var Config = require('sunstone-config'); - var Locale = require('utils/locale'); - var Notifier = require('utils/notifier'); - var Menu = require('utils/menu'); - var Tips = require('utils/tips'); - var Navigo = require('Navigo'); + var Config = require("sunstone-config"); + var Locale = require("utils/locale"); + var Notifier = require("utils/notifier"); + var Menu = require("utils/menu"); + var Tips = require("utils/tips"); + var Navigo = require("Navigo"); var router; var TOP_INTERVAL = 10000; //ms - var CONFIRM_DIALOG_ID = require('utils/dialogs/confirm/dialogId'); - var CONFIRM_WITH_SELECT_DIALOG_ID = require('utils/dialogs/confirm-with-select/dialogId'); - var DASHBOARD_TAB_ID = require('tabs/dashboard-tab/tabId'); + var CONFIRM_DIALOG_ID = require("utils/dialogs/confirm/dialogId"); + var CONFIRM_WITH_SELECT_DIALOG_ID = require("utils/dialogs/confirm-with-select/dialogId"); + var DASHBOARD_TAB_ID = require("tabs/dashboard-tab/tabId"); var SunstoneCfg = { "actions" : {}, @@ -45,14 +45,14 @@ define(function(require) { _addActions(); $.each(Config.enabledTabs, function(i, tabName){ - var name = './tabs/' + tabName; + var name = "./tabs/" + tabName; var tabObj = require(name); var _tabId = tabObj.tabId; SunstoneCfg["tabs"][_tabId] = tabObj; var panels = tabObj.panels; if (panels) { - _addPanels(_tabId, panels) + _addPanels(_tabId, panels); } var panelsHooks = tabObj.panelsHooks; @@ -67,19 +67,19 @@ define(function(require) { var dialogs = tabObj.dialogs; if (dialogs) { - _addDialogs(dialogs) + _addDialogs(dialogs); } var formPanels = tabObj.formPanels; if (formPanels) { - _addFormPanels(_tabId, formPanels) + _addFormPanels(_tabId, formPanels); } }); - } + }; var _addActions = function() { $.each(Config.allTabs(), function(i, tabName){ - var name = './tabs/' + tabName; + var name = "./tabs/" + tabName; var tabObj = require(name); var actions = tabObj.actions; @@ -89,43 +89,43 @@ define(function(require) { }); } }); - } + }; var _addDialogs = function(dialogs) { $.each(dialogs, function(index, dialog) { - SunstoneCfg['dialogs'][dialog.DIALOG_ID] = dialog - }) + SunstoneCfg["dialogs"][dialog.DIALOG_ID] = dialog; + }); return false; - } + }; var _addPanelsHooks = function(tabId, hooks) { - SunstoneCfg["tabs"][tabId]['panelsHooks'] = hooks; + SunstoneCfg["tabs"][tabId]["panelsHooks"] = hooks; return false; - } + }; var _addInitHooks = function(tabId, hooks) { - SunstoneCfg["tabs"][tabId]['initHooks'] = hooks; + SunstoneCfg["tabs"][tabId]["initHooks"] = hooks; return false; - } + }; var _addPanels = function(tabId, panels) { - var indexedPanels = {} + var indexedPanels = {}; $.each(panels, function(index, panel) { - indexedPanels[panel.PANEL_ID] = panel - }) - SunstoneCfg["tabs"][tabId]['panels'] = indexedPanels; + indexedPanels[panel.PANEL_ID] = panel; + }); + SunstoneCfg["tabs"][tabId]["panels"] = indexedPanels; return false; - } + }; var _addFormPanels = function(tabId, formPanels) { - var indexedFormPanels = {} + var indexedFormPanels = {}; $.each(formPanels, function(index, formPanel) { - indexedFormPanels[formPanel.FORM_PANEL_ID] = formPanel - }) - SunstoneCfg["tabs"][tabId]['formPanels'] = indexedFormPanels; - SunstoneCfg["tabs"][tabId]['formPanelInstances'] = {}; + indexedFormPanels[formPanel.FORM_PANEL_ID] = formPanel; + }); + SunstoneCfg["tabs"][tabId]["formPanels"] = indexedFormPanels; + SunstoneCfg["tabs"][tabId]["formPanelInstances"] = {}; return false; - } + }; //Inserts all main tabs in the DOM var _insertTabs = function() { @@ -134,7 +134,7 @@ define(function(require) { _insertButtonsInTab(tabName); _setupDataTable(tabName); - var hooks = SunstoneCfg['tabs'][tabName].initHooks; + var hooks = SunstoneCfg["tabs"][tabName].initHooks; if (hooks) { $.each(hooks, function(i, hook){ @@ -155,61 +155,61 @@ define(function(require) { } _setupTabs(); - } + }; var _setupDataTable = function(tabName) { - var dataTable = SunstoneCfg['tabs'][tabName].dataTable; + var dataTable = SunstoneCfg["tabs"][tabName].dataTable; if (dataTable) { dataTable.initialize(); } - } + }; //Inserts a main tab in the DOM. This is done by //adding the content to the proper div and by adding a list item //link to the navigation menu var _insertTab = function(tabName) { - var tabInfo = SunstoneCfg['tabs'][tabName]; - var condition = tabInfo['condition']; - var tabClass = tabInfo['tabClass'] ? tabInfo['tabClass'] : 'topTab'; - var parent = tabInfo['parentTab'] ? tabInfo['parentTab'] : ''; + var tabInfo = SunstoneCfg["tabs"][tabName]; + var condition = tabInfo["condition"]; + var tabClass = tabInfo["tabClass"] ? tabInfo["tabClass"] : "topTab"; + var parent = tabInfo["parentTab"] ? tabInfo["parentTab"] : ""; //skip this tab if we do not meet the condition if (condition && !condition()) {return;} if (tabInfo.no_content === true) { - tabClass += " tab_with_no_content is-accordion-submenu-parent" + tabClass += " tab_with_no_content is-accordion-submenu-parent"; } else { - tabInfo['tabName'] = tabName; - var TabTemplate = require('hbs!sunstone/tab') - $('div.sunstone-content').append(TabTemplate(tabInfo)); + tabInfo["tabName"] = tabName; + var TabTemplate = require("hbs!sunstone/tab"); + $("div.sunstone-content").append(TabTemplate(tabInfo)); } var liItem; - var title = ''; + var title = ""; if (tabInfo.icon) { - title += ' '; + title += " "; } title += tabInfo.title; - if (parent !== '') { - liItem = '
  • ' + - '' + title + '' + - '
  • '; + if (parent !== "") { + liItem = "
  • " + + "" + title + "" + + "
  • "; - if ($('#menu ul#navigation #li_' + parent + ' .menu').length > 0) { - $('#menu ul#navigation #li_' + parent + ' .menu').append(liItem); + if ($("#menu ul#navigation #li_" + parent + " .menu").length > 0) { + $("#menu ul#navigation #li_" + parent + " .menu").append(liItem); } else { - $('#menu ul#navigation #li_' + parent).append( - '"); } } else { - liItem = '
  • ' + - '' + title + '' + - '
  • '; + liItem = "
  • " + + "" + title + "" + + "
  • "; - $('div#menu ul#navigation').append(liItem); + $("div#menu ul#navigation").append(liItem); } //if this is a submenu... @@ -224,12 +224,12 @@ define(function(require) { if (tabInfo.forms) { $.each(tabInfo.forms, function(key, value) { - Sunstone.addFormPanel(tabName, key, value) - }) + Sunstone.addFormPanel(tabName, key, value); + }); } if (tabInfo.setup) { - var context = $('div#' + tabName, $('div.sunstone-content')); + var context = $("div#" + tabName, $("div.sunstone-content")); tabInfo.setup(context); } @@ -248,14 +248,14 @@ define(function(require) { context = customContext; } else { customId = tabName; - context = $('div#' + tabName, $('div.sunstone-content')); + context = $("div#" + tabName, $("div.sunstone-content")); } - var actionBlock = $('div.action_blocks', context) + var actionBlock = $("div.action_blocks", context); if (actionBlock.length) { - var ButtonsTemplate = require('hbs!./sunstone/buttons') + var ButtonsTemplate = require("hbs!./sunstone/buttons"); var buttonsRow = $(ButtonsTemplate({customId: customId, customContext: customContext})); //for every button defined for this tab... @@ -268,20 +268,20 @@ define(function(require) { continue; } - var type = button.type + '_button'; - var strClass = [type] + var type = button.type + "_button"; + var strClass = [type]; switch (button.type) { case "select": break; case "image": - strClass.push("action_button") + strClass.push("action_button"); break; case "create_dialog": - strClass.push("action_button") - strClass.push("top_button") + strClass.push("action_button"); + strClass.push("top_button"); break; default: - strClass.push("top_button") + strClass.push("top_button"); } if (button.alwaysActive) { @@ -297,92 +297,92 @@ define(function(require) { switch (button.layout) { case "create": buttonContext = $("#" + customId + "create_buttons", buttonsRow); - icon = button.icon ? button.icon : ''; - text = button.text ? icon + ' ' + button.text : icon; + icon = button.icon ? button.icon : ""; + text = button.text ? icon + " " + button.text : icon; strClass.push("success", "button"); - buttonCode = ''; + buttonCode = ""; break; case "refresh": buttonContext = $("#" + customId + "refresh_buttons", buttonsRow); - icon = button.icon ? button.icon : ''; - text = button.text ? icon + ' ' + button.text : icon; + icon = button.icon ? button.icon : ""; + text = button.text ? icon + " " + button.text : icon; strClass.push("refresh", "button", "secondary"); - buttonCode = ''; + buttonCode = ""; break; case "top": buttonContext = $("#" + customId + "refresh_buttons", buttonsRow); - text = '' + - '' + - '' + - ''; + text = "" + + "" + + "" + + ""; strClass.push("toggle_top_button", "only-sunstone-list", "button", "hollow"); - buttonCode = '' + text + ''; + buttonCode = "" + text + ""; break; case "main": buttonContext = $("#" + customId + "main_buttons", buttonsRow); text = button.text; strClass.push("button"); - buttonCode = ''; + buttonCode = ""; break; case "vmsplay_buttons": buttonContext = $("#" + customId + "vmsplay_buttons", buttonsRow); text = button.text; strClass.push("button"); - buttonCode = ''; + buttonCode = ""; break; case "vmspause_buttons": buttonContext = $("#" + customId + "vmspause_buttons", buttonsRow); text = button.text; - buttonCode = '
  • ' + text + '
  • '; + buttonCode = "
  • " + text + "
  • "; break; case "vmsstop_buttons": buttonContext = $("#" + customId + "vmsstop_buttons", buttonsRow); text = button.text; - buttonCode = '
  • ' + text + '
  • '; + buttonCode = "
  • " + text + "
  • "; break; case "vmsrepeat_buttons": buttonContext = $("#" + customId + "vmsrepeat_buttons", buttonsRow); text = button.text; - buttonCode = '
  • ' + text + '
  • '; + buttonCode = "
  • " + text + "
  • "; break; case "vmsdelete_buttons": buttonContext = $("#" + customId + "vmsdelete_buttons", buttonsRow); text = button.text; - buttonCode = '
  • ' + text + '
  • '; + buttonCode = "
  • " + text + "
  • "; break; case "vmsplanification_buttons": buttonContext = $("#" + customId + "vmsplanification_buttons", buttonsRow); text = button.text; - buttonCode = '
  • ' + text + '
  • '; + buttonCode = "
  • " + text + "
  • "; break; case "more_select": buttonContext = $("#" + customId + "more_buttons", buttonsRow); text = button.text; - buttonCode = '
  • ' + text + '
  • '; + buttonCode = "
  • " + text + "
  • "; break; case "user_select": buttonContext = $("#" + customId + "user_buttons", buttonsRow); text = button.text; - buttonCode = '
  • ' + text + '
  • '; + buttonCode = "
  • " + text + "
  • "; break; case "del": buttonContext = $("#" + customId + "delete_buttons", buttonsRow); - text = ' '; + text = " "; strClass.push("alert", "button"); - buttonCode = ''; + buttonCode = ""; break; case "labels": buttonContext = $("#" + customId + "labels_buttons", buttonsRow); - text = ''; + text = ""; strClass.push("only-sunstone-info", "only-sunstone-list", "top_button", "secondary", "button", "dropdown"); - buttonCode = ''; + buttonCode = ""; break; default: buttonContext = $("#" + customId + "main_buttons", buttonsRow); text = button.text; strClass.push("button"); - buttonCode = ''; + buttonCode = ""; } buttonContext.append(buttonCode); @@ -392,78 +392,78 @@ define(function(require) { actionBlock.append(buttonsRow); //actionBlock.foundation(); - Foundation.reflow(actionBlock, 'dropdown'); + Foundation.reflow(actionBlock, "dropdown"); Tips.setup(actionBlock); if ($("#" + customId + "more_buttons li", actionBlock).length == 0) { - $("button[data-toggle=" + customId + "more_buttons]", actionBlock).remove() + $("button[data-toggle=" + customId + "more_buttons]", actionBlock).remove(); } if ($("#" + customId + "user_buttons li", actionBlock).length == 0) { - $("button[data-toggle=" + customId + "user_buttons]", actionBlock).remove() + $("button[data-toggle=" + customId + "user_buttons]", actionBlock).remove(); } if ($("#" + customId + "vmsplanification_buttons li", actionBlock).length == 0) { - $("button[data-toggle=" + customId + "vmsplanification_buttons]", actionBlock).remove() + $("button[data-toggle=" + customId + "vmsplanification_buttons]", actionBlock).remove(); } if ($("#" + customId + "vmsdelete_buttons li", actionBlock).length == 0) { - $("button[data-toggle=" + customId + "vmsdelete_buttons]", actionBlock).remove() + $("button[data-toggle=" + customId + "vmsdelete_buttons]", actionBlock).remove(); } if ($("#" + customId + "vmsstop_buttons li", actionBlock).length == 0) { - $("button[data-toggle=" + customId + "vmsstop_buttons]", actionBlock).remove() + $("button[data-toggle=" + customId + "vmsstop_buttons]", actionBlock).remove(); } if ($("#" + customId + "vmspause_buttons li", actionBlock).length == 0) { - $("button[data-toggle=" + customId + "vmspause_buttons]", actionBlock).remove() + $("button[data-toggle=" + customId + "vmspause_buttons]", actionBlock).remove(); } if ($("#" + customId + "vmsrepeat_buttons li", actionBlock).length == 0) { - $("button[data-toggle=" + customId + "vmsrepeat_buttons]", actionBlock).remove() + $("button[data-toggle=" + customId + "vmsrepeat_buttons]", actionBlock).remove(); } if ($("#" + customId + "user_buttons li", actionBlock).length == 0) { - $("button[data-toggle=" + customId + "user_buttons]", actionBlock).remove() + $("button[data-toggle=" + customId + "user_buttons]", actionBlock).remove(); } if ($("#" + customId + "labels_buttons button", buttonsRow).length != 0) { - $('#' + customId + 'labels_buttons').append( - ''); + $("#" + customId + "labels_buttons").append( + "
    "); } - $('#' + customId + 'labels_buttons').foundation(); + $("#" + customId + "labels_buttons").foundation(); //actionBlock.foundationButtons(); - $('.top_button, .list_button', actionBlock).prop('disabled', false); - $('.top_button, .list_button', actionBlock).prop('disabled', true); - $('.create_dialog_button', actionBlock).prop('disabled', false).removeAttr('disabled'); - $('.alwaysActive', actionBlock).prop('disabled', false).removeAttr('disabled'); + $(".top_button, .list_button", actionBlock).prop("disabled", false); + $(".top_button, .list_button", actionBlock).prop("disabled", true); + $(".create_dialog_button", actionBlock).prop("disabled", false).removeAttr("disabled"); + $(".alwaysActive", actionBlock).prop("disabled", false).removeAttr("disabled"); - $('#' + customId + 'reset_button', actionBlock).on("click", function() { + $("#" + customId + "reset_button", actionBlock).on("click", function() { _resetFormPanel(tabName); return false; - }) + }); - $('.submit_button', actionBlock).on("click", function() { + $(".submit_button", actionBlock).on("click", function() { _submitFormPanel(tabName); return false; - }) + }); }//if tab exists - } + }; var _setupButtons = function() { //Listen for .action_buttons //An action buttons runs a predefined action. If it has type //"multiple" it runs that action on the elements of a datatable. - $(document).on("click", '.action_button', function() { + $(document).on("click", ".action_button", function() { var error = 0; - var value = $(this).val() + var value = $(this).val(); if ($.isEmptyObject(value)) { - value = $(this).attr('href'); + value = $(this).attr("href"); } - $('.dropdown-pane').foundation('close'); + $(".dropdown-pane").foundation("close"); var action = SunstoneCfg["actions"][value]; if (!action) { @@ -485,23 +485,23 @@ define(function(require) { //Listen .confirm_buttons. These buttons show a confirmation dialog //before running the action. - $(document).on("click", '.confirm_button', function() { - var dialogInstance = _getDialogInstance(CONFIRM_DIALOG_ID) + $(document).on("click", ".confirm_button", function() { + var dialogInstance = _getDialogInstance(CONFIRM_DIALOG_ID); dialogInstance.reset(); - $('#' + CONFIRM_DIALOG_ID).data('buttonAction', $(this).attr('href')); - $('#' + CONFIRM_DIALOG_ID).data('buttonTab', $(this).parents('.tab').attr('id')); + $("#" + CONFIRM_DIALOG_ID).data("buttonAction", $(this).attr("href")); + $("#" + CONFIRM_DIALOG_ID).data("buttonTab", $(this).parents(".tab").attr("id")); dialogInstance.show(); return false; }); //Listen .confirm_buttons. These buttons show a confirmation dialog //with a select box before running the action. - $(document).on("click", '.confirm_with_select_button', function() { + $(document).on("click", ".confirm_with_select_button", function() { var dialogInstance = _getDialogInstance(CONFIRM_WITH_SELECT_DIALOG_ID); dialogInstance.setParams({ - 'buttonAction' : $(this).attr('href'), - 'buttonTab' : $(this).parents('.tab').attr('id') + "buttonAction" : $(this).attr("href"), + "buttonTab" : $(this).parents(".tab").attr("id") }); dialogInstance.reset(); @@ -517,26 +517,26 @@ define(function(require) { window.history.back(); e.preventDefault(); }); - } + }; var _setupTabs = function() { - Foundation.reflow($('#menu'), 'accordion-menu'); - Foundation.reflow($('div.sunstone-content'), 'sticky') + Foundation.reflow($("#menu"), "accordion-menu"); + Foundation.reflow($("div.sunstone-content"), "sticky"); var topTabs = $(".sunstone-menu-content ul li.topTab"); var subTabs = $(".sunstone-menu-content ul li.subTab > a"); subTabs.on("click", function() { - if ($(this).closest('li').hasClass('topTab')) { + if ($(this).closest("li").hasClass("topTab")) { return false; } else { - var tabName = $(this).closest('li').attr('id').substring(3); + var tabName = $(this).closest("li").attr("id").substring(3); _showTab(tabName); return false; } }); topTabs.on("click", function(e) { - var tabName = $(this).attr('id').substring(3); + var tabName = $(this).attr("id").substring(3); if ($(this).hasClass("tab_with_no_content")) { //Subtabs have a class with the name of this tab @@ -553,7 +553,7 @@ define(function(require) { }; var _showRighList = function(tabName) { - var tab = $('#' + tabName); + var tab = $("#" + tabName); $(".tab").hide(); tab.show(); @@ -563,11 +563,11 @@ define(function(require) { $(".only-sunstone-info", tab).hide(); $(".only-sunstone-form", tab).hide(); $(".only-sunstone-list", tab).fadeIn(); - $('.action_blocks', tab).removeClass('large-12').addClass('large-9'); + $(".action_blocks", tab).removeClass("large-12").addClass("large-9"); }; var _showRighInfo = function(tabName) { - var tab = $('#' + tabName); + var tab = $("#" + tabName); $(".tab").hide(); tab.show(); @@ -577,8 +577,8 @@ define(function(require) { $(".only-sunstone-list", tab).hide(); $(".only-sunstone-form", tab).hide(); $(".only-sunstone-info", tab).fadeIn(); - $('.action_blocks', tab).removeClass('large-9').addClass('large-12'); - } + $(".action_blocks", tab).removeClass("large-9").addClass("large-12"); + }; var _showTab = function(tabName) { if (_getTab() == tabName && _rightListVisible()){ @@ -590,12 +590,12 @@ define(function(require) { _routerShowTab(tabName); } } - } + }; var _routerShowTab = function(tabName) { - $('.labels-tree', '#navigation').remove(); + $(".labels-tree", "#navigation").remove(); - if (!SunstoneCfg['tabs'][tabName]) { + if (!SunstoneCfg["tabs"][tabName]) { return false; } @@ -605,7 +605,7 @@ define(function(require) { // TODO check if necessary // last_selected_row = null; - if (tabName.indexOf('#') == 0) { + if (tabName.indexOf("#") == 0) { tabName = tabName.substring(1); } @@ -613,24 +613,29 @@ define(function(require) { $("#navigation li").removeClass("navigation-active-li"); $("#navigation li#li_" + tabName).addClass("navigation-active-li"); - var tab = $('#' + tabName); + var tab = $("#" + tabName); //show tab _showRighList(tabName); - var dataTable = SunstoneCfg['tabs'][tabName]['dataTable']; + var dataTable = SunstoneCfg["tabs"][tabName]["dataTable"]; if (dataTable) { dataTable.recountCheckboxes(); } - var res = SunstoneCfg['tabs'][tabName]['resource'] + var hashRes = ["Dashboard", "Settings", "NetworkTopology"]; + var res = SunstoneCfg["tabs"][tabName]["resource"]; if (res) { - Sunstone.runAction(res + ".refresh"); + if (!hashRes.includes(res)){ + Sunstone.runAction(res + ".list"); + } else { + Sunstone.runAction(res + ".refresh"); + } } - } + }; var _getTab = function() { return $(".tab:visible").attr("id"); - } + }; var _showElement = function(tabName, elementId) { if(!Config.isTabEnabled(tabName)){ @@ -642,7 +647,7 @@ define(function(require) { }else{ _routerShowElement(tabName, elementId); } - } + }; var _routerShowElement = function(tabName, elementId) { var resource = SunstoneCfg["tabs"][tabName].resource; @@ -655,39 +660,39 @@ define(function(require) { _routerShowTab(tabName); - var context = $('#' + tabName); + var context = $("#" + tabName); $(".resource-id", context).html(elementId); $(".resource-info-header", context).text(""); - var loading = '
    loading...
    '; + var loading = "
    \"loading...\"
    "; $(".sunstone-info", context).html(loading); _showRighInfo(tabName); Sunstone.runAction(infoAction, elementId); //enable action buttons - $('.top_button, .list_button', context).attr('disabled', false); - } + $(".top_button, .list_button", context).attr("disabled", false); + }; // Returns the element that is currently shown in the right info var _getElementRightInfo = function(tabName, context) { var context = context || $(".sunstone-info", $("#" + tabName)); - return context.data('element'); - } + return context.data("element"); + }; var _insertPanels = function(tabName, info, contextTabId, context) { var context = context || $(".sunstone-info", $("#" + tabName)); - context.data('element', info[Object.keys(info)[0]]); + context.data("element", info[Object.keys(info)[0]]); - var containerId = tabName + '-panels'; + var containerId = tabName + "-panels"; var activaTab = $("li.is-active a", $("#" + containerId)); if (activaTab) { - var activaTabHref = activaTab.attr('href'); + var activaTabHref = activaTab.attr("href"); } var isRefresh = (activaTabHref != undefined); - var prevPanelInstances = SunstoneCfg['tabs'][tabName]["panelInstances"]; + var prevPanelInstances = SunstoneCfg["tabs"][tabName]["panelInstances"]; var prevPanelStates = {}; if(isRefresh && prevPanelInstances != undefined){ @@ -698,7 +703,7 @@ define(function(require) { }); } - var hooks = SunstoneCfg['tabs'][tabName].panelsHooks; + var hooks = SunstoneCfg["tabs"][tabName].panelsHooks; if (hooks) { $.each(hooks, function(i, hook){ @@ -706,10 +711,10 @@ define(function(require) { }); } - var panels = SunstoneCfg['tabs'][tabName].panels; + var panels = SunstoneCfg["tabs"][tabName].panels; var active = false; - var templatePanelsParams = [] - SunstoneCfg['tabs'][tabName]["panelInstances"] = {}; + var templatePanelsParams = []; + SunstoneCfg["tabs"][tabName]["panelInstances"] = {}; $.each(panels, function(panelName, Panel) { if (Config.isTabPanelEnabled((contextTabId||tabName), panelName)) { @@ -718,20 +723,20 @@ define(function(require) { active = true; } } else { - activaTabHref = "#" + panelName + activaTabHref = "#" + panelName; active = true; } try { var panelInstance = new Panel(info, contextTabId); - SunstoneCfg['tabs'][tabName]["panelInstances"][panelName] = panelInstance; + SunstoneCfg["tabs"][tabName]["panelInstances"][panelName] = panelInstance; templatePanelsParams.push({ - 'panelName': panelName, - 'icon': panelInstance.icon, - 'title': panelInstance.title, - 'html': panelInstance.html(), - 'active': active - }) + "panelName": panelName, + "icon": panelInstance.icon, + "title": panelInstance.title, + "html": panelInstance.html(), + "active": active + }); } catch (err) { console.log(err); } @@ -740,14 +745,14 @@ define(function(require) { } }); - var TemplatePanels = require('hbs!./sunstone/panels'); + var TemplatePanels = require("hbs!./sunstone/panels"); var html = TemplatePanels({ - 'containerId': containerId, - 'panels': templatePanelsParams - }) + "containerId": containerId, + "panels": templatePanelsParams + }); context.html(html); - $.each(SunstoneCfg['tabs'][tabName]["panelInstances"], function(panelName, panel) { + $.each(SunstoneCfg["tabs"][tabName]["panelInstances"], function(panelName, panel) { panel.setup(context); if(isRefresh && prevPanelStates[panelName] && panel.setState){ @@ -755,19 +760,19 @@ define(function(require) { } }); - $('#' + containerId + 'Tabs', context).on('change.zf.tabs', function(target) { - var tabIdWithHash = $('.is-active > a', this)[0].hash; - var panel = SunstoneCfg['tabs'][tabName]["panelInstances"][tabIdWithHash.substring(1)]; + $("#" + containerId + "Tabs", context).on("change.zf.tabs", function(target) { + var tabIdWithHash = $(".is-active > a", this)[0].hash; + var panel = SunstoneCfg["tabs"][tabName]["panelInstances"][tabIdWithHash.substring(1)]; if (panel && panel.onShow) { panel.onShow(context); } }); - Foundation.reflow(context, 'tabs'); + Foundation.reflow(context, "tabs"); if(activaTabHref != undefined){ - $('[href="' + activaTabHref + '"]', context).trigger("click"); - $('#' + containerId + 'Tabs', context).trigger('change.zf.tabs'); + $("[href=\"" + activaTabHref + "\"]", context).trigger("click"); + $("#" + containerId + "Tabs", context).trigger("change.zf.tabs"); } if (hooks) { @@ -775,7 +780,7 @@ define(function(require) { hook.post(info, (contextTabId||tabName)); }); } - } + }; //Runs a predefined action. Wraps the calls to opennebula.js and //can be use to run action depending on conditions and notify them @@ -875,7 +880,7 @@ define(function(require) { } return 0; - } + }; function _showFormPanel(tabId, formPanelId, action, onShow2) { var context = $("#" + tabId); @@ -890,12 +895,12 @@ define(function(require) { if (!formPanelInstance) { formContext = - $('
    \ -
    \ -
    \ -
    ').appendTo( $(".contentForm", context) ); + $("
    \ +
    \ +
    \ +
    ").appendTo( $(".contentForm", context) ); // Create panelInstance, insert in the DOM and setup var formPanel = tab["formPanels"][formPanelId]; @@ -904,7 +909,7 @@ define(function(require) { return false; } // Panel not defined - Foundation.reflow(context, 'tabs'); + Foundation.reflow(context, "tabs"); formPanelInstance = new formPanel(); tab["formPanelInstances"][formPanelId] = formPanelInstance; @@ -927,7 +932,7 @@ define(function(require) { $(".wizard_tabs", context).show(); } else { $(".wizard_tabs", context).hide(); - $('a[href="#'+tab.tabName+'-wizardForms"]', context).click(); + $("a[href=\"#"+tab.tabName+"-wizardForms\"]", context).click(); } // Hide reset button if not defined @@ -943,14 +948,14 @@ define(function(require) { if (onShow2) { onShow2(formPanelInstance, formContext); } - }, 13) + }, 13); } var _submitFormPanel = function(tabId) { var context = $("#" + tabId); //_popFormPanelLoading(tabId); // Workaround until Foundation.abide support hidden forms - + var context = $("#" + tabId); $(".sunstone-form-title", context).text(Locale.tr("Submitting...")); $(".submit_button", context).text(Locale.tr("Submitting...")); @@ -958,15 +963,15 @@ define(function(require) { _disableFormPanelSubmit(tabId); setTimeout(function() { - var formPanelInstance = SunstoneCfg["tabs"][tabId].activeFormPanel + var formPanelInstance = SunstoneCfg["tabs"][tabId].activeFormPanel; if ($(".wizardForms", context).is(":visible")) { - $('#' + formPanelInstance.formPanelId + 'Wizard').submit(); + $("#" + formPanelInstance.formPanelId + "Wizard").submit(); } else if ($(".advancedForms", context).is(":visible")) { - $('#' + formPanelInstance.formPanelId + 'Advanced').submit(); + $("#" + formPanelInstance.formPanelId + "Advanced").submit(); } - }, 13) - } + }, 13); + }; /** * Resets the form panel. The loading screen is shown, then the panel is reset @@ -979,7 +984,7 @@ define(function(require) { */ var _resetFormPanel = function(tabId, formPanelId) { if (tabId == undefined){ - tabId = _getTab() + tabId = _getTab(); } _popFormPanelLoading(tabId); @@ -987,7 +992,7 @@ define(function(require) { setTimeout(function() { var formPanelInstance; if (formPanelId != undefined) { - formPanelInstance = SunstoneCfg["tabs"][tabId]['formPanelInstances'][formPanelId]; + formPanelInstance = SunstoneCfg["tabs"][tabId]["formPanelInstances"][formPanelId]; } else { formPanelInstance = SunstoneCfg["tabs"][tabId].activeFormPanel; } @@ -1003,8 +1008,8 @@ define(function(require) { if (_formPanelVisible($("#"+tabId))){ _showFormPanel(tabId, formPanelId); } - }, 13) - } + }, 13); + }; /** * Hides the form panel loading (spinning icon on submit), and resets @@ -1015,7 +1020,7 @@ define(function(require) { */ function _hideFormPanelLoading(tabId) { if (tabId == undefined){ - tabId = _getTab() + tabId = _getTab(); } var context = $("#" + tabId); @@ -1038,19 +1043,19 @@ define(function(require) { function _hideFormPanel(tabId) { if (tabId == undefined){ - tabId = _getTab() + tabId = _getTab(); } var context = $("#" + tabId); if (_formPanelVisible(context)){ - $('[href="back"]', context).trigger("click"); + $("[href=\"back\"]", context).trigger("click"); } } function _popFormPanelLoading(tabId) { if (tabId == undefined){ - tabId = _getTab() + tabId = _getTab(); } if(_getTab() != tabId){ @@ -1068,7 +1073,7 @@ define(function(require) { $(".only-sunstone-list", context).hide(); $(".only-sunstone-info", context).hide(); $(".only-sunstone-form", context).show(); - $('.action_blocks', context).removeClass('large-9').addClass('large-12'); + $(".action_blocks", context).removeClass("large-9").addClass("large-12"); $(".sunstone-form-title", context).text(Locale.tr("Loading...")); $(".submit_button", context).text(Locale.tr("Loading...")); @@ -1091,7 +1096,7 @@ define(function(require) { function _enableFormPanelSubmit(tabId) { if (tabId == undefined){ - tabId = _getTab() + tabId = _getTab(); } var context = $("#" + tabId); @@ -1119,51 +1124,51 @@ define(function(require) { button = buttons["action_list"]["actions"][buttonName]; } return button; - } + }; var _rightInfoVisible = function(context) { - return $(".sunstone-info", context).is(':visible'); - } + return $(".sunstone-info", context).is(":visible"); + }; var _rightListVisible = function(context) { - return $(".sunstone-list", context).is(':visible'); - } + return $(".sunstone-list", context).is(":visible"); + }; var _formPanelVisible = function(context) { - return $(".sunstone-form", context).is(':visible'); - } + return $(".sunstone-form", context).is(":visible"); + }; var _rightInfoResourceId = function(context) { return $(".resource-id", context).text(); - } + }; var _getAction = function(actionId) { return SunstoneCfg["actions"][actionId]; - } + }; var _getDataTable = function(tabName) { - if (SunstoneCfg['tabs'][tabName]) { - return SunstoneCfg['tabs'][tabName].dataTable; + if (SunstoneCfg["tabs"][tabName]) { + return SunstoneCfg["tabs"][tabName].dataTable; } - } + }; var _getResource = function(tabName) { - if (SunstoneCfg['tabs'][tabName]) { - return SunstoneCfg['tabs'][tabName].resource; + if (SunstoneCfg["tabs"][tabName]) { + return SunstoneCfg["tabs"][tabName].resource; } - } + }; var _getDialogInstance = function(dialogId) { - var dialogInstance = SunstoneCfg['dialogInstances'][dialogId]; + var dialogInstance = SunstoneCfg["dialogInstances"][dialogId]; if (dialogInstance == undefined) { - var Dialog = SunstoneCfg['dialogs'][dialogId] + var Dialog = SunstoneCfg["dialogs"][dialogId]; var dialogInstance = new Dialog(); dialogInstance.insert(); - SunstoneCfg['dialogInstances'][dialogId] = dialogInstance; + SunstoneCfg["dialogInstances"][dialogId] = dialogInstance; } return dialogInstance; - } + }; var _setupNavigoRoutes = function() { router = new Navigo(null, true); @@ -1177,7 +1182,7 @@ define(function(require) { }.bind(tabName)); router.on(new RegExp("(?:#|/)"+tabName+"/(\\d+)"), function(id){ - _routerShowElement(this, id) + _routerShowElement(this, id); }.bind(tabName)); router.on(new RegExp("(?:#|/)"+tabName), function(){ @@ -1197,7 +1202,7 @@ define(function(require) { }); router.resolve(); - } + }; var Sunstone = { "addMainTabs": _addMainTabs, @@ -1207,7 +1212,7 @@ define(function(require) { "insertPanels": _insertPanels, "getElementRightInfo": _getElementRightInfo, - 'showTab': _showTab, + "showTab": _showTab, "showElement" : _showElement, "getTab": _getTab, @@ -1237,7 +1242,7 @@ define(function(require) { "TOP_INTERVAL": TOP_INTERVAL, "setupNavigoRoutes": _setupNavigoRoutes - } + }; return Sunstone; }); diff --git a/src/sunstone/public/app/tabs/dashboard-tab.js b/src/sunstone/public/app/tabs/dashboard-tab.js index 1e3c86628a..fead984125 100644 --- a/src/sunstone/public/app/tabs/dashboard-tab.js +++ b/src/sunstone/public/app/tabs/dashboard-tab.js @@ -86,8 +86,6 @@ define(function(require) { 'vms': { 'html': require('hbs!./dashboard-tab/vms'), 'onShow': function() { - Sunstone.runAction("VM.list"); - var end_time = -1; // today var start_time = Math.floor(new Date().getTime() / 1000); start_time = start_time - 604800; // 604800 = 7 days = 7*24*60*60 @@ -106,6 +104,7 @@ define(function(require) { success: function(req, response) { Accounting.fillAccounting($("#dashboard_vm_accounting"), req, response, no_table); Accounting.fillAccounting($("#dashboard_user_accounting"), req, response, no_table); + Sunstone.runAction("VM.list"); }, error: Notifier.onError, data: options diff --git a/src/sunstone/public/app/tabs/hosts-tab/form-panels/create.js b/src/sunstone/public/app/tabs/hosts-tab/form-panels/create.js index afe05c9879..2903e2c76c 100644 --- a/src/sunstone/public/app/tabs/hosts-tab/form-panels/create.js +++ b/src/sunstone/public/app/tabs/hosts-tab/form-panels/create.js @@ -262,7 +262,9 @@ define(function(require) { host_json["host"]["region_name"] = region_name; host_json["host"]["ec2_secret"] = ec2_secret; host_json["host"]["ec2_access"] = ec2_access; - host_json["host"]["capacity"] = capacity; + if (capacity.length > 0){ + host_json["host"]["capacity"] = capacity; + } } //Create the OpenNebula.Host. //If it is successfull we refresh the list. diff --git a/src/sunstone/public/app/tabs/provision-tab.js b/src/sunstone/public/app/tabs/provision-tab.js index 2e106a5b07..87433865df 100644 --- a/src/sunstone/public/app/tabs/provision-tab.js +++ b/src/sunstone/public/app/tabs/provision-tab.js @@ -926,6 +926,9 @@ define(function(require) { tab.on("click", "#provision_create_vm .provision_select_template .provision-pricing-table.only-one" , function(){ var create_vm_context = $("#provision_create_vm"); + var that = this; + + that.template_base_json = {}; if ($(this).hasClass("selected")){ //$(".provision_disk_selector", create_vm_context).html(""); @@ -954,6 +957,17 @@ define(function(require) { $("#provision_create_vm .provision_vmgroup").show(); $("#provision_create_vm .provision_ds").show(); + OpenNebula.Template.show({ + data : { + id: template_id, + extended: false + }, + timeout: true, + success: function (request, template_json) { + that.template_base_json= template_json; + } + }); + OpenNebula.Template.show({ data : { id: template_id, @@ -975,6 +989,7 @@ define(function(require) { pers = false; } DisksResize.insert({ + template_base_json: that.template_base_json, template_json: template_json, disksContext: disksContext, force_persistent: pers, diff --git a/src/sunstone/public/app/tabs/provision-tab/templates/list.js b/src/sunstone/public/app/tabs/provision-tab/templates/list.js index 844364553a..5be999c3a5 100644 --- a/src/sunstone/public/app/tabs/provision-tab/templates/list.js +++ b/src/sunstone/public/app/tabs/provision-tab/templates/list.js @@ -169,7 +169,7 @@ define(function(require) { } } - if (Config.isTabActionEnabled("provision-tab", "Template.delete")) { + if (Config.isTabActionEnabled("provision-tab", "Template.delete") && data["PERMISSIONS"]["OWNER_M"] === "1") { actions_html += ''; } diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general.js index a6a40d4c26..c36a6d1457 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general.js @@ -153,9 +153,9 @@ define(function(require) { success: function(request, obj_files){ var totalGB = 0; $.each(that.templateDISKS, function(ikey, ivalue){ - if (ivalue.IMAGE_ID){ + if (ivalue.IMAGE || ivalue.IMAGE_ID){ $.each(obj_files, function(jkey, jvalue){ - if (ivalue.IMAGE_ID == jvalue.IMAGE.ID){ + if ((ivalue.IMAGE && ivalue.IMAGE === jvalue.IMAGE.NAME && ivalue.IMAGE_UNAME === jvalue.IMAGE.UNAME) || (ivalue.IMAGE_ID && ivalue.IMAGE_ID === jvalue.IMAGE.ID)){ totalGB += jvalue.IMAGE.SIZE / 1024; } }); diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js index 284973f02d..8dc0afa011 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js @@ -264,14 +264,29 @@ define(function(require) { this.selected_nodes = selected_nodes; this.template_objects = []; + this.template_base_objects = {}; var templatesContext = $(".list_of_templates", context); var idsLength = this.selected_nodes.length; var idsDone = 0; + $.each(this.selected_nodes, function(index, template_id) { + OpenNebulaTemplate.show({ + data : { + id: template_id, + extended: false + }, + timeout: true, + success: function (request, template_json) { + that.template_base_objects[template_json.VMTEMPLATE.ID] = template_json; + } + }); + }); + templatesContext.html(""); $.each(this.selected_nodes, function(index, template_id) { + OpenNebulaTemplate.show({ data : { id: template_id, @@ -353,6 +368,7 @@ define(function(require) { } DisksResize.insert({ + template_base_json: that.template_base_objects[template_json.VMTEMPLATE.ID], template_json: template_json, disksContext: $(".disksContext" + template_json.VMTEMPLATE.ID, context), force_persistent: $("input.instantiate_pers", context).prop("checked"), diff --git a/src/sunstone/public/app/tabs/users-tab/panels/auth-common.js b/src/sunstone/public/app/tabs/users-tab/panels/auth-common.js index f3dbb2686e..d0de116782 100644 --- a/src/sunstone/public/app/tabs/users-tab/panels/auth-common.js +++ b/src/sunstone/public/app/tabs/users-tab/panels/auth-common.js @@ -30,7 +30,7 @@ define(function(require) { /* TEMPLATES */ - + var TemplateTable = require('utils/panel/template-table'); /* diff --git a/src/sunstone/public/app/tabs/users-tab/panels/auth/html.hbs b/src/sunstone/public/app/tabs/users-tab/panels/auth/html.hbs index 364f3866e4..790391a6a4 100644 --- a/src/sunstone/public/app/tabs/users-tab/panels/auth/html.hbs +++ b/src/sunstone/public/app/tabs/users-tab/panels/auth/html.hbs @@ -29,7 +29,9 @@ {{tr "Authentication driver"}} {{{userCreationHTML}}} {{element.AUTH_DRIVER}} - + {{#isTabActionEnabled tabId "User.change_authentication"}} + + {{/isTabActionEnabled}} {{tr "Password"}} diff --git a/src/sunstone/public/app/tabs/users-tab/panels/info-common.js b/src/sunstone/public/app/tabs/users-tab/panels/info-common.js index 95c17ad290..16061e0c8d 100644 --- a/src/sunstone/public/app/tabs/users-tab/panels/info-common.js +++ b/src/sunstone/public/app/tabs/users-tab/panels/info-common.js @@ -19,19 +19,19 @@ define(function(require) { DEPENDENCIES */ - var TemplateInfo = require('hbs!./info/html'); - var ResourceSelect = require('utils/resource-select'); - var TemplateUtils = require('utils/template-utils'); - var Locale = require('utils/locale'); - var OpenNebulaUser = require('opennebula/user'); - var Sunstone = require('sunstone'); - var UserCreation = require('tabs/users-tab/utils/user-creation'); + var TemplateInfo = require("hbs!./info/html"); + var ResourceSelect = require("utils/resource-select"); + var TemplateUtils = require("utils/template-utils"); + var Locale = require("utils/locale"); + var OpenNebulaUser = require("opennebula/user"); + var Sunstone = require("sunstone"); + var UserCreation = require("tabs/users-tab/utils/user-creation"); /* TEMPLATES */ - var TemplateTable = require('utils/panel/template-table'); + var TemplateTable = require("utils/panel/template-table"); /* CONSTANTS @@ -39,9 +39,9 @@ define(function(require) { var RESOURCE = "User"; var XML_ROOT = "USER"; - var PASSWORD_DIALOG_ID = require('tabs/users-tab/dialogs/password/dialogId'); - var LOGIN_TOKEN_DIALOG_ID = require('tabs/users-tab/dialogs/login-token/dialogId'); - var CONFIRM_DIALOG_ID = require('utils/dialogs/generic-confirm/dialogId'); + var PASSWORD_DIALOG_ID = require("tabs/users-tab/dialogs/password/dialogId"); + var LOGIN_TOKEN_DIALOG_ID = require("tabs/users-tab/dialogs/login-token/dialogId"); + var CONFIRM_DIALOG_ID = require("utils/dialogs/generic-confirm/dialogId"); /* CONSTRUCTOR @@ -77,11 +77,11 @@ define(function(require) { //==== return TemplateInfo({ - 'element': this.element, - 'sunstone_template': this.element.TEMPLATE.SUNSTONE||{}, - 'templateTableHTML': templateTableHTML, - 'tabId': this.tabId, - 'userCreationHTML': this.userCreation.html() + "element": this.element, + "sunstone_template": this.element.TEMPLATE.SUNSTONE||{}, + "templateTableHTML": templateTableHTML, + "tabId": this.tabId, + "userCreationHTML": this.userCreation.html() }); } @@ -104,66 +104,73 @@ define(function(require) { } TemplateTable.setup(strippedTemplate, RESOURCE, this.element.ID, context, hiddenValues); - //=== - + // Change table Order - context.off("click", "#div_edit_table_order") + context.off("click", "#div_edit_table_order"); context.on("click", "#div_edit_table_order", function() { - $(".value_td_table_order", context).html(''); + $(".value_td_table_order", context).html(""); if (that.element.TEMPLATE.SUNSTONE && that.element.TEMPLATE.SUNSTONE.TABLE_ORDER) { - $('#table_order_select', context).val(that.element.TEMPLATE.SUNSTONE.TABLE_ORDER); + $("#table_order_select", context).val(that.element.TEMPLATE.SUNSTONE.TABLE_ORDER); } }); - context.off("click", "#table_order_select") - context.on("click", "#table_order_select", function() { + context.off("change", "#table_order_select"); + context.on("change", "#table_order_select", function() { var sunstone_setting = {TABLE_ORDER : $(this).val()}; - Sunstone.runAction("User.append_sunstone_setting_refresh", that.element.ID, sunstone_setting); + if (sunstone_setting.TABLE_ORDER !== ""){ + Sunstone.runAction("User.append_sunstone_setting_refresh", that.element.ID, sunstone_setting); + } }); // Change language - context.off("click", "#div_edit_language") + context.off("click", "#div_edit_language"); context.on("click", "#div_edit_language", function() { - $(".value_td_language", context).html(''); + $(".value_td_language", context).html(""); if (that.element.TEMPLATE.SUNSTONE && that.element.TEMPLATE.SUNSTONE.LANG) { - $('#language_select', context).val(that.element.TEMPLATE.SUNSTONE.LANG); + $("#language_select", context).val(that.element.TEMPLATE.SUNSTONE.LANG); } }); - context.off("click", "#language_select") - context.on("click", "#language_select", function() { + context.off("change", "#language_select"); + context.on("change", "#language_select", function() { var sunstone_setting = {LANG : $(this).val()}; - Sunstone.runAction("User.append_sunstone_setting_refresh", that.element.ID, sunstone_setting); + if (sunstone_setting.LANG !== ""){ + Sunstone.runAction("User.append_sunstone_setting_refresh", that.element.ID, sunstone_setting); + } }); // Change view - context.off("click", "#div_edit_view") + context.off("click", "#div_edit_view"); context.on("click", "#div_edit_view", function() { - var options = ''; - $.each( config['available_views'], function(id, view) { - options += ''; + var options = ""; + $.each( config["available_views"], function(id, view) { + options += ""; }); - $(".value_td_view", context).html('" + options + - ''); + ""); if (that.element.TEMPLATE.SUNSTONE && that.element.TEMPLATE.SUNSTONE.DEFAULT_VIEW) { - $('#view_select', context).val(that.element.TEMPLATE.SUNSTONE.DEFAULT_VIEW); + $("#view_select", context).val(that.element.TEMPLATE.SUNSTONE.DEFAULT_VIEW); } }); - context.off("click", "#view_select") - context.on("click", "#view_select", function() { + context.off("change", "#view_select"); + context.on("change", "#view_select", function() { var sunstone_setting = {DEFAULT_VIEW : $(this).val()}; - Sunstone.runAction("User.append_sunstone_setting_refresh", that.element.ID, sunstone_setting); + if (sunstone_setting.DEFAULT_VIEW !== ""){ + Sunstone.runAction("User.append_sunstone_setting_refresh", that.element.ID, sunstone_setting); + } }); return false; diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-resize.js b/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-resize.js index 88c09cd6cd..90bd53c320 100644 --- a/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-resize.js +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-resize.js @@ -82,9 +82,10 @@ define(function(require) { Tips.setup(context); $( ".diskSlider", context).html(RangeSlider.html({ min: that.diskSize, - max: Humanize.sizeToMB("500GB")*1024, + max: Humanize.sizeToMB("1024GB")*1024, initial: that.diskSize, - name: "resize" + name: "resize", + max_value: "" })); $( ".uinput-slider-val",context).prop('type', 'text'); $( ".uinput-slider-val",context).val(Humanize.size($( ".uinput-slider",context).val())); @@ -115,7 +116,7 @@ define(function(require) { $('#' + DIALOG_ID + 'Form', context).submit(function() { - var new_size = $( ".uinput-slider",context).val(); + var new_size = $( ".uinput-slider-val",context).val(); new_size = Math.round(parseInt(new_size) / 1024); new_size = new_size.toString(); var obj = { diff --git a/src/sunstone/public/app/utils/common-actions.js b/src/sunstone/public/app/utils/common-actions.js index 8f3598f0c6..b34bf10d61 100644 --- a/src/sunstone/public/app/utils/common-actions.js +++ b/src/sunstone/public/app/utils/common-actions.js @@ -55,7 +55,10 @@ define(function(require) { type: "list", call: that.openNebulaResource.list, callback: function(request, response) { - Sunstone.getDataTable(that.tabId).updateView(request, response); + var datatable = Sunstone.getDataTable(that.tabId); + if (datatable){ + datatable.updateView(request, response); + } }, error: Notifier.onError } diff --git a/src/sunstone/public/app/utils/disks-resize.js b/src/sunstone/public/app/utils/disks-resize.js index 814dcc916d..a977f1b4a7 100644 --- a/src/sunstone/public/app/utils/disks-resize.js +++ b/src/sunstone/public/app/utils/disks-resize.js @@ -22,6 +22,7 @@ define(function(require){ var UserInputs = require('utils/user-inputs'); var WizardFields = require('utils/wizard-fields'); var DisksResizeTemplate = require('hbs!./disks-resize/html'); + var Humanize = require('utils/humanize'); return { 'insert': _insert, @@ -76,6 +77,16 @@ define(function(require){ disks = [template_disk] } + if (opts.template_base_json) { + var template_base_disk = opts.template_base_json.VMTEMPLATE.TEMPLATE.DISK + var disks_base = [] + if ($.isArray(template_base_disk)) { + disks_base = template_base_disk + } else if (!$.isEmptyObject(template_base_disk)) { + disks_base = [template_base_disk] + } + } + if (disks.length > 0) { disksContext.html(DisksResizeTemplate()); @@ -101,6 +112,9 @@ define(function(require){ var diskContext; $(".disksContainer", disksContext).html(""); + + + $.each(disks, function(disk_id, disk) { diskContext = $( '
    '+ @@ -110,8 +124,9 @@ define(function(require){ '
    ' + '
    ' + '
    ').appendTo($(".disksContainer", disksContext)); - - diskContext.data('template_disk', disk); + if (disks_base) { + diskContext.data('template_disk', disks_base[disk_id]); + } var disk_snapshot_total_size = 0; if (disk.DISK_SNAPSHOT_TOTAL_SIZE != undefined) { @@ -175,7 +190,7 @@ define(function(require){ if (disk.SIZE != undefined){ // Range from original size to size + 500GB var min = parseInt(disk.SIZE); - var max = min + 512000; + var max = min + Humanize.sizeToMB("1024GB"); attr = UserInputs.parse( "SIZE", @@ -186,6 +201,7 @@ define(function(require){ "M|number|"+label+"||"); } } + attr.max_value = ""; if(!opts.uinput_mb){ $(".diskSlider", diskContext).html(UserInputs.attributeInput(attr)); } else { diff --git a/src/sunstone/public/app/utils/panel/cluster-tr.js b/src/sunstone/public/app/utils/panel/cluster-tr.js index e1b08c9002..3a2208402b 100644 --- a/src/sunstone/public/app/utils/panel/cluster-tr.js +++ b/src/sunstone/public/app/utils/panel/cluster-tr.js @@ -55,8 +55,7 @@ define(function(require) { }); }); - context.off("click", ".value_td_cluster .resource_list_select"); - context.on("click", ".value_td_cluster .resource_list_select", function() { + context.on("change", ".value_td_cluster .resource_list_select", function() { var newClusterId = $(this).val(); if (newClusterId != "") { Sunstone.runAction(resourceType + ".addtocluster", [resourceId], newClusterId); diff --git a/src/sunstone/public/app/utils/range-slider.js b/src/sunstone/public/app/utils/range-slider.js index 3e9fd26804..4f1ae24346 100644 --- a/src/sunstone/public/app/utils/range-slider.js +++ b/src/sunstone/public/app/utils/range-slider.js @@ -54,7 +54,6 @@ define(function(require) { tick_val += opts.tick_size; } } - sliderId += 1; return TemplateHTML(opts); } diff --git a/src/sunstone/public/app/utils/range-slider/html.hbs b/src/sunstone/public/app/utils/range-slider/html.hbs index 1eda58f234..ecaf74da7f 100644 --- a/src/sunstone/public/app/utils/range-slider/html.hbs +++ b/src/sunstone/public/app/utils/range-slider/html.hbs @@ -23,8 +23,8 @@ {{/if}}
    @@ -34,9 +34,9 @@
    -
    diff --git a/src/sunstone/public/app/utils/user-inputs.js b/src/sunstone/public/app/utils/user-inputs.js index 65ea06ed32..01964ad823 100644 --- a/src/sunstone/public/app/utils/user-inputs.js +++ b/src/sunstone/public/app/utils/user-inputs.js @@ -706,6 +706,9 @@ define(function(require) { break; case "range": case "range-float": + if(attr.max_value != ""){ + attr.max_value = attr.max; + } input = RangeSlider.html(attr); break; diff --git a/src/sunstone/sunstone-server.rb b/src/sunstone/sunstone-server.rb index 7f951a6b3f..1a774044df 100755 --- a/src/sunstone/sunstone-server.rb +++ b/src/sunstone/sunstone-server.rb @@ -715,13 +715,12 @@ end ############################################################################## # GET Resource information ############################################################################## - get '/:resource/:id/template' do @SunstoneServer.get_template(params[:resource], params[:id]) end get '/:resource/:id' do - if params[:extended] + if params[:extended] && params[:extended] != "false" @SunstoneServer.get_resource(params[:resource], params[:id], true) else @SunstoneServer.get_resource(params[:resource], params[:id]) diff --git a/src/tm_mad/fs_lvm/clone b/src/tm_mad/fs_lvm/clone index a891b11a4b..a15d667db7 100755 --- a/src/tm_mad/fs_lvm/clone +++ b/src/tm_mad/fs_lvm/clone @@ -76,7 +76,7 @@ SIZE="${XPATH_ELEMENTS[j++]}" ORIGINAL_SIZE="${XPATH_ELEMENTS[j++]}" TM_MAD="${XPATH_ELEMENTS[j++]}" -FILE_SIZE=`fs_size $SRC_PATH` +FILE_SIZE=`fs_size "${SRC_PATH}" YES` if [ $FILE_SIZE -gt $SIZE ]; then SIZE="$FILE_SIZE" diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 870fb9b97a..97b81898cb 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -2019,7 +2019,12 @@ int VirtualMachine::from_xml(const string &xml_str) int rc = 0; // Initialize the internal XML object - update_from_str(xml_str); + rc = update_from_str(xml_str); + + if ( rc != 0 ) + { + return -1; + } // Get class base attributes rc += xpath(oid, "/VM/ID", -1); diff --git a/src/vmm_mad/remotes/ec2/ec2_driver.rb b/src/vmm_mad/remotes/ec2/ec2_driver.rb index 50030ea6f1..0d2b859e12 100755 --- a/src/vmm_mad/remotes/ec2/ec2_driver.rb +++ b/src/vmm_mad/remotes/ec2/ec2_driver.rb @@ -336,22 +336,22 @@ class EC2Driver if !ec2_value(ec2_info, 'USERDATA') xml = OpenNebula::XMLElement.new xml.initialize_xml(xml_text, 'VM') - end - if xml.has_elements?('TEMPLATE/CONTEXT') - # Since there is only 1 level ',' will not be added - context_str = xml.template_like_str('TEMPLATE/CONTEXT') + if xml.has_elements?('TEMPLATE/CONTEXT') + # Since there is only 1 level ',' will not be added + context_str = xml.template_like_str('TEMPLATE/CONTEXT') - if xml['TEMPLATE/CONTEXT/TOKEN'] == 'YES' - # TODO use OneGate library - token_str = generate_onegate_token(xml) - if token_str - context_str << "\nONEGATE_TOKEN=\"#{token_str}\"" + if xml['TEMPLATE/CONTEXT/TOKEN'] == 'YES' + # TODO use OneGate library + token_str = generate_onegate_token(xml) + if token_str + context_str << "\nONEGATE_TOKEN=\"#{token_str}\"" + end end - end - userdata_key = EC2[:run][:args]["USERDATA"][:opt] - opts[userdata_key] = Base64.encode64(context_str) + userdata_key = EC2[:run][:args]["USERDATA"][:opt] + opts[userdata_key] = Base64.encode64(context_str) + end end instances = @ec2.create_instances(opts) diff --git a/src/vrouter/VirtualRouter.cc b/src/vrouter/VirtualRouter.cc index 9e0d889689..530bc112da 100644 --- a/src/vrouter/VirtualRouter.cc +++ b/src/vrouter/VirtualRouter.cc @@ -409,7 +409,7 @@ int VirtualRouter::release_network_leases(const VectorAttribute * nic) return -1; } - mac = nic->vector_value("MAC"); + mac = nic->vector_value("VROUTER_MAC"); vn = vnpool->get(vnid, true); @@ -457,8 +457,7 @@ static void prepare_nic_vm(VectorAttribute * nic) if (floating) { - nic->remove("MAC"); - + vrouter_prefix(nic, "MAC"); vrouter_prefix(nic, "IP"); vrouter_prefix(nic, "IP6_LINK"); vrouter_prefix(nic, "IP6_ULA"); @@ -659,10 +658,10 @@ int VirtualRouter::detach_nic(int nic_id) return -1; } - obj_template->remove(nic); - release_network_leases(nic); + obj_template->remove(nic); + // Update quotas tmpl.set(nic);