diff --git a/include/Image.h b/include/Image.h index 6c60ac4ab5..9804de2a57 100644 --- a/include/Image.h +++ b/include/Image.h @@ -205,27 +205,44 @@ public: /** * Set/Unset an image as persistent * @param persistent true to make an image persistent + * @param error_str Returns the error reason, if any + * * @return 0 on success */ - int persistent(bool persis) + int persistent(bool persis, string& error_str) { - int rc = -1; + if ( running_vms != 0 ) + { + goto error_vms; + } if (persis == true) { - if (!isPublic() && running_vms == 0) + if ( isPublic() ) { - persistent_img = 1; - rc = 0; + goto error_public; } + + persistent_img = 1; } else { persistent_img = 0; - rc = 0; } - return rc; + return 0; + + error_vms: + error_str = "Image cannot be in 'used' state."; + goto error_common; + + error_public: + error_str = "Image cannot be public and persistent."; + goto error_common; + + error_common: + return -1; + } /** diff --git a/include/InformationManager.h b/include/InformationManager.h index 2fbac3c78d..55ed449804 100644 --- a/include/InformationManager.h +++ b/include/InformationManager.h @@ -34,12 +34,14 @@ public: HostPool * _hpool, time_t _timer_period, time_t _monitor_period, + int _host_limit, const string& _remotes_location, vector& _mads) :MadManager(_mads), hpool(_hpool), timer_period(_timer_period), monitor_period(_monitor_period), + host_limit(_host_limit), remotes_location(_remotes_location) { am.addListener(this); @@ -98,6 +100,11 @@ private: */ time_t monitor_period; + /** + * Host monitoring limit + */ + int host_limit; + /** * Path for the remote action programs */ diff --git a/include/VirtualMachineManager.h b/include/VirtualMachineManager.h index 92b35c6407..03fea34a94 100644 --- a/include/VirtualMachineManager.h +++ b/include/VirtualMachineManager.h @@ -37,6 +37,7 @@ public: HostPool * _hpool, time_t _timer_period, time_t _poll_period, + int _vm_limit, vector& _mads); ~VirtualMachineManager(){}; @@ -118,6 +119,11 @@ private: */ time_t poll_period; + /** + * Virtual Machine polling limit + */ + int vm_limit; + /** * Action engine for the Manager */ diff --git a/install.sh b/install.sh index 77e6f2858a..48e5d7ef44 100755 --- a/install.sh +++ b/install.sh @@ -1102,7 +1102,9 @@ MAN_FILES="share/man/oneauth.1.gz \ share/man/econe-upload.1.gz \ share/man/occi-compute.1.gz \ share/man/occi-network.1.gz \ - share/man/occi-storage.1.gz" + share/man/occi-storage.1.gz \ + share/man/onezone.1.gz \ + share/man/onevdc.1.gz" #----------------------------------------------------------------------------- #----------------------------------------------------------------------------- diff --git a/share/etc/oned.conf b/share/etc/oned.conf index e7d872cc0a..af3757c9bf 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -10,9 +10,11 @@ # than MANAGER_TIMER. # # HOST_MONITORING_INTERVAL: Time in seconds between host monitorization. +# HOST_PER_INTERVAL: Number of hosts monitored in each interval. # # VM_POLLING_INTERVAL: Time in seconds between virtual machine monitorization. # (use 0 to disable VM monitoring). +# VM_PER_INTERVAL: Number of VMs monitored in each interval. # # VM_DIR: Remote path to store the VM images, it should be shared between all # the cluster nodes to perform live migrations. This variable is the default @@ -39,17 +41,19 @@ # DEBUG_LEVEL: 0 = ERROR, 1 = WARNING, 2 = INFO, 3 = DEBUG #******************************************************************************* -#MANAGER_TIMER=30 +#MANAGER_TIMER = 30 HOST_MONITORING_INTERVAL = 600 +#HOST_PER_INTERVAL = 15 VM_POLLING_INTERVAL = 600 +#VM_PER_INTERVAL = 5 #VM_DIR=/srv/cloud/one/var SCRIPTS_REMOTE_DIR=/var/tmp/one -PORT=2633 +PORT = 2633 DB = [ backend = "sqlite" ] @@ -63,7 +67,7 @@ DB = [ backend = "sqlite" ] VNC_BASE_PORT = 5900 -DEBUG_LEVEL=3 +DEBUG_LEVEL = 3 #******************************************************************************* # Physical Networks configuration diff --git a/share/man/SConstruct b/share/man/SConstruct index fa836c96eb..d09dbe8c6a 100644 --- a/share/man/SConstruct +++ b/share/man/SConstruct @@ -43,3 +43,6 @@ env.Man('oneuser') env.Man('onevm') env.Man('onevnet') env.Man('onegroup') +env.Man('onezone') +env.Man('onevdc') + diff --git a/share/man/onevdc.1 b/share/man/onevdc.1 new file mode 100644 index 0000000000..9d958560da --- /dev/null +++ b/share/man/onevdc.1 @@ -0,0 +1,105 @@ +.\" generated with Ronn/v0.7.3 +.\" http://github.com/rtomayko/ronn/tree/0.7.3 +. +.TH "ONEVDC" "1" "July 2011" "" "onevdc(1) -- manages OpenNebula Virtual DataCenters" +. +.SH "NAME" +\fBonevdc\fR +. +.SH "SYNOPSIS" +\fBonevdc\fR command [\fIargs\fR] [\fIoptions\fR] +. +.SH "OPTIONS" +. +.nf + + \-l, \-\-list x,y,z Selects columns to display with list command + \-d, \-\-delay x Sets the delay in seconds for top command + \-x, \-\-xml Show the resource in xml format + \-n, \-\-numeric Do not translate user and group IDs + \-k, \-\-kilobytes Show units in kilobytes + \-v, \-\-verbose Verbose mode + \-h, \-\-help Show this message + \-V, \-\-version Show version and copyright information +. +.fi +. +.SH "COMMANDS" +. +.IP "\(bu" 4 +show \fItext\fR +. +.IP "" 4 +. +.nf + +Show information of a particular VDC +. +.fi +. +.IP "" 0 + +. +.IP "\(bu" 4 +list +. +.IP "" 4 +. +.nf + +Lists VDCs in the pool +valid options: list, delay, xml, numeric, kilobytes +. +.fi +. +.IP "" 0 + +. +.IP "\(bu" 4 +delete \fIvdcid\fR +. +.IP "" 4 +. +.nf + +Deletes a VDC +. +.fi +. +.IP "" 0 + +. +.IP "\(bu" 4 +create \fIfile\fR +. +.IP "" 4 +. +.nf + +Create a new VDC +. +.fi +. +.IP "" 0 + +. +.IP "" 0 +. +.SH "ARGUMENT FORMATS" +. +.IP "\(bu" 4 +file +. +.IP "\(bu" 4 +text +. +.IP "\(bu" 4 +range +. +.IP "" 0 +. +.SH "LICENSE" +OpenNebula 2\.9\.80 Copyright 2002\-2011, OpenNebula Project Leads (OpenNebula\.org) +. +.P +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 diff --git a/share/man/onezone.1 b/share/man/onezone.1 new file mode 100644 index 0000000000..df1d049446 --- /dev/null +++ b/share/man/onezone.1 @@ -0,0 +1,105 @@ +.\" generated with Ronn/v0.7.3 +.\" http://github.com/rtomayko/ronn/tree/0.7.3 +. +.TH "ONEZONE" "1" "July 2011" "" "onezone(1) -- manages OpenNebula zones" +. +.SH "NAME" +\fBonezone\fR +. +.SH "SYNOPSIS" +\fBonezone\fR \fIcommand\fR [\fIargs\fR] [\fIoptions\fR] +. +.SH "OPTIONS" +. +.nf + + \-l, \-\-list x,y,z Selects columns to display with list command + \-d, \-\-delay x Sets the delay in seconds for top command + \-x, \-\-xml Show the resource in xml format + \-n, \-\-numeric Do not translate user and group IDs + \-k, \-\-kilobytes Show units in kilobytes + \-v, \-\-verbose Verbose mode + \-h, \-\-help Show this message + \-V, \-\-version Show version and copyright information +. +.fi +. +.SH "COMMANDS" +. +.IP "\(bu" 4 +show \fItext\fR [\fItext\fR] +. +.IP "" 4 +. +.nf + +Show information of a particular Zone +. +.fi +. +.IP "" 0 + +. +.IP "\(bu" 4 +list +. +.IP "" 4 +. +.nf + +Lists Zones in the pool +valid options: list, delay, xml, numeric, kilobytes +. +.fi +. +.IP "" 0 + +. +.IP "\(bu" 4 +delete \fIzoneid\fR +. +.IP "" 4 +. +.nf + +Deletes a Zone +. +.fi +. +.IP "" 0 + +. +.IP "\(bu" 4 +create \fIfile\fR +. +.IP "" 4 +. +.nf + +Create a new Zone +. +.fi +. +.IP "" 0 + +. +.IP "" 0 +. +.SH "ARGUMENT FORMATS" +. +.IP "\(bu" 4 +file +. +.IP "\(bu" 4 +text +. +.IP "\(bu" 4 +range +. +.IP "" 0 +. +.SH "LICENSE" +OpenNebula 2\.9\.80 Copyright 2002\-2011, OpenNebula Project Leads (OpenNebula\.org) +. +.P +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 diff --git a/src/acct/accounting.rb b/src/acct/accounting.rb index 487c3e2895..de872c4d60 100644 --- a/src/acct/accounting.rb +++ b/src/acct/accounting.rb @@ -1,3 +1,19 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + module OneWatch require 'watch_helper' diff --git a/src/acct/examples/acct_client.rb b/src/acct/examples/acct_client.rb index 73ebbee8b5..b618cd67bc 100644 --- a/src/acct/examples/acct_client.rb +++ b/src/acct/examples/acct_client.rb @@ -1,3 +1,19 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + require 'watch_helper' class AcctClient diff --git a/src/acct/monitoring.rb b/src/acct/monitoring.rb index 5b04a12614..c01e66f83c 100644 --- a/src/acct/monitoring.rb +++ b/src/acct/monitoring.rb @@ -1,3 +1,19 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + module OneWatch require 'watch_helper' diff --git a/src/acct/oneacctd b/src/acct/oneacctd index 77e67accdc..4984ab4caa 100755 --- a/src/acct/oneacctd +++ b/src/acct/oneacctd @@ -54,7 +54,7 @@ start) # check if acct already running acctd_running if [ "$?" = "0" ]; then - echo "acctd already running." + echo "oneacctd already running." exit 1 fi @@ -65,7 +65,7 @@ start) LASTPID=$! if [ $LASTRC -ne 0 ]; then - echo "Error executing acctd." + echo "Error executing oneacctd." echo "Check $ACCTD_LOG for more information" exit 1 else @@ -76,18 +76,18 @@ start) ps $LASTPID > /dev/null 2>&1 if [ $? -ne 0 ]; then - echo "Error executing acctd." + echo "Error executing oneacctd." echo "Check $ACCTD_LOG for more information" exit 1 fi - echo "acctd started" + echo "oneacctd started" ;; stop) # check if running acctd_running if [ "$?" != "0" ]; then - echo "acctd not running." + echo "oneacctd not running." exit 1 fi @@ -96,10 +96,10 @@ stop) kill $ACCTD_PID &> /dev/null rm -f $ACCTD_PID_FILE &> /dev/null - echo "acctd stop" + echo "oneacctd stop" ;; *) - echo "Usage: acctd {start|stop}" >&2 + echo "Usage: oneacctd {start|stop}" >&2 exit 3 ;; esac diff --git a/src/acct/watch_client.rb b/src/acct/watch_client.rb index 6cc295a6b1..ef6ab2ff57 100644 --- a/src/acct/watch_client.rb +++ b/src/acct/watch_client.rb @@ -1,3 +1,19 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + module OneWatchClient require 'acct/watch_helper' diff --git a/src/acct/watch_helper.rb b/src/acct/watch_helper.rb index ce610feee5..b9e07e6244 100644 --- a/src/acct/watch_helper.rb +++ b/src/acct/watch_helper.rb @@ -1,3 +1,19 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + module WatchHelper require 'sequel' require 'yaml' diff --git a/src/cli/cli_helper.rb b/src/cli/cli_helper.rb index c71f86676a..dc97027f28 100644 --- a/src/cli/cli_helper.rb +++ b/src/cli/cli_helper.rb @@ -132,17 +132,19 @@ module CLIHelper def show(data, options={}) update_columns(options) - print_table(data, options) + print_table(data, options) end - def top(data, options={}) - update_columns(options) + def top(options={}, &block) delay=options[:delay] ? options[:delay] : 1 begin while true CLIHelper.scr_cls CLIHelper.scr_move(0,0) + + data = block.call + show(data, options) sleep delay end diff --git a/src/cli/command_parser.rb b/src/cli/command_parser.rb index 357d1082ab..ef2c8da8d2 100755 --- a/src/cli/command_parser.rb +++ b/src/cli/command_parser.rb @@ -338,7 +338,11 @@ EOT }.join(' ') puts "Wrong number of arguments" - puts "The arguments should be: #{args_str}" + if args_str.empty? + puts "No argument is required" + else + puts "The arguments should be: #{args_str}" + end exit -1 end @@ -346,7 +350,15 @@ EOT argument = nil error_msg = nil format.each { |f| - format_hash = @formats[f] ? @formats[f] : @formats[:text] + if @formats[f] + format_hash = @formats[f] + elsif f.nil? + argument = nil + break + else + format_hash = @formats[:text] + end + rc = format_hash[:proc].call(arg) if rc[0]==0 argument=rc[1] @@ -377,7 +389,7 @@ EOT end def format_file(arg) - File.exists?(arg) ? [0,arg] : [-1] + File.file?(arg) ? [0,arg] : [-1] end REG_RANGE=/^(?:(?:\d+\.\.\d+|\d+),)*(?:\d+\.\.\d+|\d+)$/ diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index bfd52313e9..e4c60e7756 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -92,21 +92,17 @@ EOT if options[:xml] return 0, pool.to_xml(true) else - phash = pool.to_hash - rname = self.class.rname + table = format_pool(options) - if phash["#{rname}_POOL"] && - phash["#{rname}_POOL"]["#{rname}"] - if phash["#{rname}_POOL"]["#{rname}"].instance_of?(Array) - phash = phash["#{rname}_POOL"]["#{rname}"] - else - phash = [phash["#{rname}_POOL"]["#{rname}"]] - end + if top + table.top(options) { + pool.info + pool_to_array(pool) + } else - phash = Array.new + table.show(pool_to_array(pool), options) end - format_pool(phash, options, top) return 0 end end @@ -155,14 +151,6 @@ EOT ######################################################################## # Id translation ######################################################################## - def uid_to_str(uid, options={}) - rid_to_str(:users, uid, options) - end - - def gid_to_str(gid, options={}) - rid_to_str(:groups, gid, options) - end - def user_name(resource, options={}) if options[:numeric] resource['UID'] @@ -178,17 +166,17 @@ EOT resource['GNAME'] end end + ######################################################################## # Formatters for arguments ######################################################################## def to_id(name) return 0, name if name.match(/^[0123456789]+$/) - user_flag = -2 - pool = factory_pool(user_flag) + pool = get_pool poolname = self.class.rname - self.class.id_to_name(name, pool, poolname) + OneHelper.name_to_id(name, pool, poolname) end def self.to_id_desc @@ -196,18 +184,22 @@ EOT end def list_to_id(names) - user_flag = -2 - pool = factory_pool(user_flag) - - rc = pool.info - return -1, rc.message if OpenNebula.is_error?(rc) + pool = get_pool + poolname = self.class.rname result = names.split(',').collect { |name| - rc = to_id(name) - unless rc.first==0 - return rc + if name.match(/^[0123456789]+$/) + name + else + rc = OneHelper.name_to_id(name, pool, poolname) + + if rc.first==-1 + return -1, "OpenNebula #{self.rname} #{name} " << + "not found, use the ID instead" + end + + rc[1] end - rc[1] } return 0, result @@ -217,20 +209,36 @@ EOT "Comma-separated list of OpenNebula #{self.rname} names or ids" end + def self.name_to_id(name, pool, ename) + objects=pool.select {|object| object.name==name } + + if objects.length>0 + if objects.length>1 + return -1, "There are multiple #{ename}s with name #{name}." + else + result = objects.first.id + end + else + return -1, "#{ename} named #{name} not found." + end + + return 0, result + end + def filterflag_to_i(str) filter_flag = case str - when "a", "all" then OpenNebula::Pool::INFO_ALL - when "m", "mine" then OpenNebula::Pool::INFO_MINE + when "a", "all" then OpenNebula::Pool::INFO_ALL + when "m", "mine" then OpenNebula::Pool::INFO_MINE when "g", "group" then OpenNebula::Pool::INFO_GROUP else if str.match(/^[0123456789]+$/) str.to_i else - user = translation_hash[:users].select { |k,v| v==str } - if user.length > 0 - user.first.first.to_i + rc = OpenNebulaHelper.rname_to_id(str, "USER") + if rc.first==-1 + return rc else - OpenNebula::Pool::INFO_GROUP + rc[1] end end end @@ -259,26 +267,6 @@ EOT end end - def self.id_to_name(name, pool, ename) - rc = pool.info - return -1, rc.message if OpenNebula.is_error?(rc) - - objects=pool.select {|object| object.name==name } - - if objects.length>0 - if objects.length>1 - return -1, - "There are multiple #{ename}s with name #{name}." - else - result = objects.first.id - end - else - return -1, "#{ename} named #{name} not found." - end - - return 0, result - end - private def retrieve_resource(id) @@ -288,50 +276,65 @@ EOT OpenNebula.is_error?(rc) ? rc : resource end - def translation_hash - @translation_hash ||= { - :users => generate_resource_translation(UserPool), - :groups => generate_resource_translation(GroupPool) - } - end + def pool_to_array(pool) + phash = pool.to_hash + rname = self.class.rname - def generate_resource_translation(pool) - p = pool.new(@client) - p.info - - hash = Hash.new - p.each { |r| hash[r["ID"]]=r["NAME"] } - hash - end - - def rid_to_str(resource, id, options) - if options[:numeric] - id - else - if name = translation_hash[resource][id] - name + if phash["#{rname}_POOL"] && + phash["#{rname}_POOL"]["#{rname}"] + if phash["#{rname}_POOL"]["#{rname}"].instance_of?(Array) + phash = phash["#{rname}_POOL"]["#{rname}"] else - id + phash = [phash["#{rname}_POOL"]["#{rname}"]] + end + else + phash = Array.new + end + + phash + end + + def get_pool + user_flag = OpenNebula::Pool::INFO_ALL + pool = factory_pool(user_flag) + + rc = pool.info + if OpenNebula.is_error?(rc) + user_flag = OpenNebula::Pool::INFO_GROUP + pool = factory_pool(user_flag) + + rc = pool.info + if OpenNebula.is_error?(rc) + return -1, "OpenNebula #{self.rname} name not found," << + " use the ID instead" end end + + pool end end - def OpenNebulaHelper.name_to_id(name, poolname, user_flag=-2) + def OpenNebulaHelper.rname_to_id(name, poolname) return 0, name.to_i if name.match(/^[0123456789]+$/) client = OpenNebula::Client.new - # TBD user_flag + pool = case poolname - when "HOST" then OpenNebula::HostPool.new(client) + when "HOST" then OpenNebula::HostPool.new(client) when "GROUP" then OpenNebula::GroupPool.new(client) when "USER" then OpenNebula::UserPool.new(client) end - OneHelper.id_to_name(name, pool, poolname) + rc = pool.info + if OpenNebula.is_error?(rc) + return -1, "OpenNebula #{self.rname} name not found," << + " use the ID instead" + end + + OneHelper.name_to_id(name, pool, poolname) end - def OpenNebulaHelper.name_to_id_desc(poolname) + def OpenNebulaHelper.rname_to_id_desc(poolname) "OpenNebula #{poolname} name or id" end diff --git a/src/cli/one_helper/oneacl_helper.rb b/src/cli/one_helper/oneacl_helper.rb index 57f8e26591..db06e5f5a0 100644 --- a/src/cli/one_helper/oneacl_helper.rb +++ b/src/cli/one_helper/oneacl_helper.rb @@ -97,10 +97,10 @@ private mask end - def format_pool(pool, options, top=false) - config_file=self.class.table_conf + def format_pool(options) + config_file = self.class.table_conf - table=CLIHelper::ShowTable.new(config_file, self) do + table = CLIHelper::ShowTable.new(config_file, self) do column :ID, "Rule Identifier", :size=>5 do |d| d['ID'] @@ -127,8 +127,7 @@ private default :ID, :USER, :RES_VHNIUTG, :RID, :OPE_CDUMIPpTW end - table.show(pool, options) - + table end end diff --git a/src/cli/one_helper/onegroup_helper.rb b/src/cli/one_helper/onegroup_helper.rb index 2ad7c8990d..592132a6c5 100644 --- a/src/cli/one_helper/onegroup_helper.rb +++ b/src/cli/one_helper/onegroup_helper.rb @@ -100,15 +100,16 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper puts CLIHelper.print_header(str_h1 % "USERS", false) - CLIHelper.print_header("%-15s %-20s" % ["ID","NAME"]) + CLIHelper.print_header("%-15s" % ["ID"]) group.user_ids.each do |uid| - puts "%-15s %-20s" % [uid, self.uid_to_str(uid.to_s)] + puts "%-15s" % [uid] end end - def format_pool(pool, options, top=false) - config_file=self.class.table_conf - table=CLIHelper::ShowTable.new(config_file, self) do + def format_pool(options) + config_file = self.class.table_conf + + table = CLIHelper::ShowTable.new(config_file, self) do column :ID, "ONE identifier for the Group", :size=>4 do |d| d["ID"] end @@ -120,10 +121,6 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper default :ID, :NAME end - if top - table.top(pool, options) - else - table.show(pool, options) - end + table end end diff --git a/src/cli/one_helper/onehost_helper.rb b/src/cli/one_helper/onehost_helper.rb index 8808b3e345..2a23aab046 100644 --- a/src/cli/one_helper/onehost_helper.rb +++ b/src/cli/one_helper/onehost_helper.rb @@ -78,9 +78,10 @@ class OneHostHelper < OpenNebulaHelper::OneHelper puts host.template_str end - def format_pool(pool, options, top=false) - config_file=self.class.table_conf - table=CLIHelper::ShowTable.new(config_file, self) do + def format_pool(options) + config_file = self.class.table_conf + + table = CLIHelper::ShowTable.new(config_file, self) do column :ID, "ONE identifier for Host", :size=>4 do |d| d["ID"] end @@ -136,10 +137,6 @@ class OneHostHelper < OpenNebulaHelper::OneHelper :AMEM, :STAT end - if top - table.top(pool, options) - else - table.show(pool, options) - end + table end end diff --git a/src/cli/one_helper/oneimage_helper.rb b/src/cli/one_helper/oneimage_helper.rb index 2c06a64a78..c79b67f72b 100644 --- a/src/cli/one_helper/oneimage_helper.rb +++ b/src/cli/one_helper/oneimage_helper.rb @@ -77,9 +77,10 @@ class OneImageHelper < OpenNebulaHelper::OneHelper puts image.template_str end - def format_pool(pool, options, top=false) - config_file=self.class.table_conf - table=CLIHelper::ShowTable.new(config_file, self) do + def format_pool(options) + config_file = self.class.table_conf + + table = CLIHelper::ShowTable.new(config_file, self) do column :ID, "ONE identifier for the Image", :size=>4 do |d| d["ID"] end @@ -130,10 +131,6 @@ class OneImageHelper < OpenNebulaHelper::OneHelper :PERSISTENT , :STAT, :RVMS end - if top - table.top(pool, options) - else - table.show(pool, options) - end + table end end diff --git a/src/cli/one_helper/onetemplate_helper.rb b/src/cli/one_helper/onetemplate_helper.rb index c1f24ac553..83e50b572e 100644 --- a/src/cli/one_helper/onetemplate_helper.rb +++ b/src/cli/one_helper/onetemplate_helper.rb @@ -17,6 +17,22 @@ require 'one_helper' class OneTemplateHelper < OpenNebulaHelper::OneHelper + VM_NAME={ + :name => "vm_name", + :short => "-n vm_name", + :large => "--name vm_name", + :format => String, + :description => "Name of the new Virtual Machine" + } + + MULTIPLE={ + :name => "multiple", + :short => "-m x", + :large => "--multiple x", + :format => Integer, + :description => "Instance multiple VMs" + } + def self.rname "VMTEMPLATE" end @@ -60,9 +76,10 @@ class OneTemplateHelper < OpenNebulaHelper::OneHelper puts template.template_str end - def format_pool(pool, options, top=false) - config_file=self.class.table_conf - table=CLIHelper::ShowTable.new(config_file, self) do + def format_pool(options) + config_file = self.class.table_conf + + table = CLIHelper::ShowTable.new(config_file, self) do column :ID, "ONE identifier for the Template", :size=>4 do |d| d["ID"] end @@ -93,10 +110,6 @@ class OneTemplateHelper < OpenNebulaHelper::OneHelper default :ID, :USER, :GROUP, :NAME, :REGTIME, :PUBLIC end - if top - table.top(pool, options) - else - table.show(pool, options) - end + table end end diff --git a/src/cli/one_helper/oneuser_helper.rb b/src/cli/one_helper/oneuser_helper.rb index 24f2fd87e1..f98ad75e73 100644 --- a/src/cli/one_helper/oneuser_helper.rb +++ b/src/cli/one_helper/oneuser_helper.rb @@ -76,9 +76,10 @@ class OneUserHelper < OpenNebulaHelper::OneHelper OpenNebulaHelper.boolean_to_str(user['ENABLED'])] end - def format_pool(pool, options, top=false) - config_file=self.class.table_conf - table=CLIHelper::ShowTable.new(config_file, self) do + def format_pool(options) + config_file = self.class.table_conf + + table = CLIHelper::ShowTable.new(config_file, self) do column :ID, "ONE identifier for the User", :size=>4 do |d| d["ID"] end @@ -88,7 +89,7 @@ class OneUserHelper < OpenNebulaHelper::OneHelper end column :GROUP, "Group of the User", :left, :size=>8 do |d| - helper.gid_to_str(d["GID"], options) + helper.group_name(d, options) end column :PASSWORD, "Password of the User", :size=>50 do |d| @@ -98,10 +99,6 @@ class OneUserHelper < OpenNebulaHelper::OneHelper default :ID, :GROUP, :NAME, :PASSWORD end - if top - table.top(pool, options) - else - table.show(pool, options) - end + table end end diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index c055ee36bd..9ecc4425eb 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -107,9 +107,10 @@ class OneVMHelper < OpenNebulaHelper::OneHelper end end - def format_pool(pool, options, top=false) - config_file=self.class.table_conf - table=CLIHelper::ShowTable.new(config_file, self) do + def format_pool(options) + config_file = self.class.table_conf + + table = CLIHelper::ShowTable.new(config_file, self) do column :ID, "ONE identifier for Virtual Machine", :size=>6 do |d| d["ID"] end @@ -143,7 +144,10 @@ class OneVMHelper < OpenNebulaHelper::OneHelper column :HOSTNAME, "Host where the VM is running", :size=>15 do |d| if d['HISTORY_RECORDS'] && d['HISTORY_RECORDS']['HISTORY'] - d['HISTORY_RECORDS']['HISTORY']['HOSTNAME'] + state_str = VirtualMachine::VM_STATE[d['STATE'].to_i] + if %w{ACTIVE SUSPENDED}.include? state_str + d['HISTORY_RECORDS']['HISTORY']['HOSTNAME'] + end end end @@ -162,11 +166,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper :TIME end - if top - table.top(pool, options) - else - table.show(pool, options) - end + table end def format_history(vm) diff --git a/src/cli/one_helper/onevnet_helper.rb b/src/cli/one_helper/onevnet_helper.rb index 8b1a94c5be..07a4dab8e9 100644 --- a/src/cli/one_helper/onevnet_helper.rb +++ b/src/cli/one_helper/onevnet_helper.rb @@ -72,9 +72,10 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper end end - def format_pool(pool, options, top=false) - config_file=self.class.table_conf - table=CLIHelper::ShowTable.new(config_file, self) do + def format_pool(options) + config_file = self.class.table_conf + + table = CLIHelper::ShowTable.new(config_file, self) do column :ID, "ONE identifier for Virtual Network", :size=>4 do |d| d["ID"] end @@ -120,10 +121,6 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper default :ID, :USER, :GROUP, :NAME, :TYPE, :BRIDGE, :PUBLIC, :LEASES end - if top - table.top(pool, options) - else - table.show(pool, options) - end + table end end \ No newline at end of file diff --git a/src/cli/oneimage b/src/cli/oneimage index 74c361d020..8bc019d045 100755 --- a/src/cli/oneimage +++ b/src/cli/oneimage @@ -48,12 +48,12 @@ cmd=CommandParser::CmdParser.new(ARGV) do ######################################################################## # Formatters for arguments ######################################################################## - set :format, :groupid, OpenNebulaHelper.name_to_id_desc("GROUP") do |arg| - OpenNebulaHelper.name_to_id(arg, "GROUP") + set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg| + OpenNebulaHelper.rname_to_id(arg, "GROUP") end - set :format, :userid, OpenNebulaHelper.name_to_id_desc("USER") do |arg| - OpenNebulaHelper.name_to_id(arg, "USER") + set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg| + OpenNebulaHelper.rname_to_id(arg, "USER") end set :format, :imageid, OneImageHelper.to_id_desc do |arg| diff --git a/src/cli/onetemplate b/src/cli/onetemplate index 9b5d586e04..7b652fa65a 100755 --- a/src/cli/onetemplate +++ b/src/cli/onetemplate @@ -40,20 +40,25 @@ cmd=CommandParser::CmdParser.new(ARGV) do # Global Options ######################################################################## set :option, CommandParser::OPTIONS - + list_options = CLIHelper::OPTIONS list_options << OpenNebulaHelper::XML list_options << OpenNebulaHelper::NUMERIC + instantiate_options = [ + OneTemplateHelper::VM_NAME, + OneTemplateHelper::MULTIPLE + ] + ######################################################################## # Formatters for arguments ######################################################################## - set :format, :groupid, OpenNebulaHelper.name_to_id_desc("GROUP") do |arg| - OpenNebulaHelper.name_to_id(arg, "GROUP") + set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg| + OpenNebulaHelper.rname_to_id(arg, "GROUP") end - set :format, :userid, OpenNebulaHelper.name_to_id_desc("USER") do |arg| - OpenNebulaHelper.name_to_id(arg, "USER") + set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg| + OpenNebulaHelper.rname_to_id(arg, "USER") end set :format, :templateid, OneTemplateHelper.to_id_desc do |arg| @@ -98,16 +103,26 @@ cmd=CommandParser::CmdParser.new(ARGV) do managed with the 'onevm' command EOT - command :instantiate, instantiate_desc, [:range,:templateid_list] do - helper.perform_actions(args[0],options,"instantiated") do |t| - res = t.instantiate + command :instantiate, instantiate_desc, :templateid, + :options=>instantiate_options do + exit_code=0 - if !OpenNebula.is_error?(res) - puts "VM ID: #{res}" + number = options[:multiple] || 1 + number.times do + exit_code=helper.perform_action(args[0],options,"instantiated") do |t| + res = t.instantiate(options[:vm_name]) + + if !OpenNebula.is_error?(res) + puts "VM ID: #{res}" + end + + res end - res + break if exit_code==-1 end + + exit_code end publish_desc = <<-EOT.unindent @@ -148,7 +163,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do command :chown, chown_desc, [:range, :templateid_list], :userid, [:groupid,nil] do - gid = args[2].nil? ? -1 : args[2].to_id + gid = args[2].nil? ? -1 : args[2].to_i helper.perform_actions(args[0],options,"Owner/Group changed") do |t| t.chown(args[1].to_i, gid) end diff --git a/src/cli/oneuser b/src/cli/oneuser index ffb4346786..d1ee7fcfe1 100755 --- a/src/cli/oneuser +++ b/src/cli/oneuser @@ -64,8 +64,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do ######################################################################## # Formatters for arguments ######################################################################## - set :format, :groupid, OpenNebulaHelper.name_to_id_desc("GROUP") do |arg| - OpenNebulaHelper.name_to_id(arg, "GROUP") + set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg| + OpenNebulaHelper.rname_to_id(arg, "GROUP") end set :format, :userid, OneUserHelper.to_id_desc do |arg| diff --git a/src/cli/onevm b/src/cli/onevm index 9a1102b450..0c5716f38c 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -44,16 +44,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do ######################################################################## # Formatters for arguments ######################################################################## - set :format, :hostid, OpenNebulaHelper.name_to_id_desc("HOST") do |arg| - OpenNebulaHelper.name_to_id(arg, "HOST") + set :format, :hostid, OpenNebulaHelper.rname_to_id_desc("HOST") do |arg| + OpenNebulaHelper.rname_to_id(arg, "HOST") end - set :format, :groupid, OpenNebulaHelper.name_to_id_desc("GROUP") do |arg| - OpenNebulaHelper.name_to_id(arg, "GROUP") + set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg| + OpenNebulaHelper.rname_to_id(arg, "GROUP") end - set :format, :userid, OpenNebulaHelper.name_to_id_desc("USER") do |arg| - OpenNebulaHelper.name_to_id(arg, "USER") + set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg| + OpenNebulaHelper.rname_to_id(arg, "USER") end set :format, :vmid, OneVMHelper.to_id_desc do |arg| @@ -240,7 +240,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do command :resubmit, resubmit_desc, [:range,:vmid_list] do helper.perform_actions(args[0],options,"resubmiting") do |vm| - vm.restart + vm.resubmit end end diff --git a/src/cli/onevnet b/src/cli/onevnet index 5376291da9..f152a103df 100755 --- a/src/cli/onevnet +++ b/src/cli/onevnet @@ -44,12 +44,12 @@ cmd=CommandParser::CmdParser.new(ARGV) do ######################################################################## # Formatters for arguments ######################################################################## - set :format, :groupid, OpenNebulaHelper.name_to_id_desc("GROUP") do |arg| - OpenNebulaHelper.name_to_id(arg, "GROUP") + set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg| + OpenNebulaHelper.rname_to_id(arg, "GROUP") end - set :format, :userid, OpenNebulaHelper.name_to_id_desc("USER") do |arg| - OpenNebulaHelper.name_to_id(arg, "USER") + set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg| + OpenNebulaHelper.rname_to_id(arg, "USER") end set :format, :vnetid, OneVNetHelper.to_id_desc do |arg| diff --git a/src/cloud/occi/etc/templates/common.erb b/src/cloud/occi/etc/templates/common.erb index 2280a6b111..459ea02e69 100644 --- a/src/cloud/occi/etc/templates/common.erb +++ b/src/cloud/occi/etc/templates/common.erb @@ -4,7 +4,9 @@ # You can add common attributes for your cloud templates (e.g. OS) # -NAME = "<%= @vm_info['NAME'] %>" +<% if @vm_info['NAME'] %> + NAME = "<%= @vm_info['NAME'] %>" +<% end %> <% @vm_info.each('DISK') do |disk| %> <% if disk.attr('STORAGE','href') %> diff --git a/src/cloud/occi/lib/VirtualMachineOCCI.rb b/src/cloud/occi/lib/VirtualMachineOCCI.rb index 6773e42ff1..6d62bfe724 100755 --- a/src/cloud/occi/lib/VirtualMachineOCCI.rb +++ b/src/cloud/occi/lib/VirtualMachineOCCI.rb @@ -50,7 +50,7 @@ class VirtualMachineOCCI < VirtualMachine <% end %> <% end %> - <% if self['TEMPLATE/CONTEXT'] %> + <% if self.has_elements?('TEMPLATE/CONTEXT') %> <% self.each('TEMPLATE/CONTEXT/*') do |cont| %> <% if cont.text %> diff --git a/src/im/InformationManager.cc b/src/im/InformationManager.cc index fc662ed910..34d7030137 100644 --- a/src/im/InformationManager.cc +++ b/src/im/InformationManager.cc @@ -147,9 +147,6 @@ void InformationManager::timer_action() Host * host; istringstream iss; - // -------------- Max. number of hosts to monitor. --------------------- - int host_limit = 15; - mark = mark + timer_period; if ( mark >= 600 ) diff --git a/src/image/test/ImagePoolTest.cc b/src/image/test/ImagePoolTest.cc index ceef84f48c..78a353f766 100644 --- a/src/image/test/ImagePoolTest.cc +++ b/src/image/test/ImagePoolTest.cc @@ -744,8 +744,9 @@ public: void persistence() { - int oid; - int success; + int oid; + int success; + string error_msg; ImagePoolFriend * imp = static_cast(pool); Image * img; @@ -800,7 +801,7 @@ public: CPPUNIT_ASSERT( img != 0 ); // make it persistent - success = img->persistent(true); + success = img->persistent(true, error_msg); CPPUNIT_ASSERT( success == 0 ); CPPUNIT_ASSERT( img->isPersistent() == true ); @@ -816,7 +817,7 @@ public: // make it non-persistent - success = img->persistent(false); + success = img->persistent(false, error_msg); CPPUNIT_ASSERT( success == 0 ); CPPUNIT_ASSERT( img->isPersistent() == false ); diff --git a/src/lcm/test/DummyManager.h b/src/lcm/test/DummyManager.h index 26dd3a04af..25cc7c7721 100644 --- a/src/lcm/test/DummyManager.h +++ b/src/lcm/test/DummyManager.h @@ -93,7 +93,7 @@ public: time_t _poll_period, vector& _mads): VirtualMachineManager( _vmpool, _hpool, _timer_period, - _poll_period, _mads){} + _poll_period, 5, _mads){} void trigger(Actions action, int _vid) { diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index e5fd6bc7e3..685e93cf22 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -339,9 +339,12 @@ void Nebula::start() { time_t poll_period; vector vmm_mads; + int vm_limit; nebula_configuration->get("VM_POLLING_INTERVAL", poll_period); + nebula_configuration->get("VM_PER_INTERVAL", vm_limit); + nebula_configuration->get("VM_MAD", vmm_mads); vmm = new VirtualMachineManager( @@ -349,6 +352,7 @@ void Nebula::start() hpool, timer_period, poll_period, + vm_limit, vmm_mads); } catch (bad_alloc&) @@ -385,14 +389,18 @@ void Nebula::start() { vector im_mads; time_t monitor_period; + int host_limit; nebula_configuration->get("HOST_MONITORING_INTERVAL", monitor_period); + nebula_configuration->get("HOST_PER_INTERVAL", host_limit); + nebula_configuration->get("IM_MAD", im_mads); im = new InformationManager(hpool, timer_period, monitor_period, + host_limit, remotes_location, im_mads); } diff --git a/src/nebula/NebulaTemplate.cc b/src/nebula/NebulaTemplate.cc index 91c0f29812..4e7e87b8b6 100644 --- a/src/nebula/NebulaTemplate.cc +++ b/src/nebula/NebulaTemplate.cc @@ -47,7 +47,9 @@ NebulaTemplate::NebulaTemplate(string& etc_location, string& var_location) # Daemon configuration attributes #------------------------------------------------------------------------------- # HOST_MONITORING_INTERVAL +# HOST_PER_INTERVAL # VM_POLLING_INTERVAL +# VM_PER_INTERVAL # VM_DIR # PORT # DB @@ -61,12 +63,24 @@ NebulaTemplate::NebulaTemplate(string& etc_location, string& var_location) attribute = new SingleAttribute("HOST_MONITORING_INTERVAL",value); conf_default.insert(make_pair(attribute->name(),attribute)); + // HOST_PER_INTERVAL + value = "15"; + + attribute = new SingleAttribute("HOST_PER_INTERVAL",value); + conf_default.insert(make_pair(attribute->name(),attribute)); + // POLL_INTERVAL value = "600"; attribute = new SingleAttribute("VM_POLLING_INTERVAL",value); conf_default.insert(make_pair(attribute->name(),attribute)); + // VM_PER_INTERVAL + value = "5"; + + attribute = new SingleAttribute("VM_PER_INTERVAL",value); + conf_default.insert(make_pair(attribute->name(),attribute)); + //VM_DIR attribute = new SingleAttribute("VM_DIR",var_location); conf_default.insert(make_pair(attribute->name(),attribute)); diff --git a/src/oca/ruby/OpenNebula/Template.rb b/src/oca/ruby/OpenNebula/Template.rb index ffb099edd4..fa12eea96e 100644 --- a/src/oca/ruby/OpenNebula/Template.rb +++ b/src/oca/ruby/OpenNebula/Template.rb @@ -60,7 +60,7 @@ module OpenNebula # --------------------------------------------------------------------- # XML-RPC Methods for the Template Object # --------------------------------------------------------------------- - + # Retrieves the information of the given Template. def info() super(TEMPLATE_METHODS[:info], 'VMTEMPLATE') @@ -85,6 +85,7 @@ module OpenNebula def instantiate(name="") return Error.new('ID not defined') if !@pe_id + name ||= "" rc = @client.call(TEMPLATE_METHODS[:instantiate], @pe_id, name) return rc diff --git a/src/oca/ruby/OpenNebula/VirtualMachine.rb b/src/oca/ruby/OpenNebula/VirtualMachine.rb index c2292bc6a4..75e0aeaae5 100644 --- a/src/oca/ruby/OpenNebula/VirtualMachine.rb +++ b/src/oca/ruby/OpenNebula/VirtualMachine.rb @@ -213,14 +213,16 @@ module OpenNebula # Set the specified vm's disk to be saved in a new image # when the VirtualMachine shutdowns # - # +disk_id+ ID of the disk to be saved + # @param disk_id [Integer] ID of the disk to be saved + # @param image_name [String] Name for the new image where the + # disk will be saved # - # +image_name+ Name for the new image where the disk will be saved + # @return [Integer, OpenNebula::Error] the new Image ID in case of + # success, error otherwise def save_as(disk_id, image_name) return Error.new('ID not defined') if !@pe_id rc = @client.call(VM_METHODS[:savedisk], @pe_id, disk_id, image_name) - rc = nil if !OpenNebula.is_error?(rc) return rc end diff --git a/src/onedb/onedb b/src/onedb/onedb index b1c257fdae..1f94760aa5 100755 --- a/src/onedb/onedb +++ b/src/onedb/onedb @@ -160,8 +160,12 @@ cmd=CommandParser::CmdParser.new(ARGV) do EOT command :backup, backup_desc, [:output_file, nil], :options=>FORCE do - helper = OneDB.new(options) - helper.backup(args[0], options) + begin + helper = OneDB.new(options) + helper.backup(args[0], options) + rescue Exception => e + [-1, e.message] + end end ########################################################################### @@ -173,8 +177,12 @@ cmd=CommandParser::CmdParser.new(ARGV) do EOT command :version , version_desc do - helper = OneDB.new(options) - helper.version(options) + begin + helper = OneDB.new(options) + helper.version(options) + rescue Exception => e + [-1, e.message] + end end ########################################################################### @@ -185,8 +193,12 @@ cmd=CommandParser::CmdParser.new(ARGV) do EOT command :history , history_desc do - helper = OneDB.new(options) - helper.history + begin + helper = OneDB.new(options) + helper.history + rescue Exception => e + [-1, e.message] + end end ########################################################################### @@ -198,8 +210,12 @@ cmd=CommandParser::CmdParser.new(ARGV) do EOT command :restore , restore_desc, [:backup_file, nil], :options=>FORCE do - helper = OneDB.new(options) - helper.restore(args[0], options) + begin + helper = OneDB.new(options) + helper.restore(args[0], options) + rescue Exception => e + [-1, e.message] + end end ########################################################################### @@ -212,7 +228,11 @@ cmd=CommandParser::CmdParser.new(ARGV) do EOT command :upgrade , upgrade_desc, [:version, nil], :options=>[FORCE,BACKUP] do - helper = OneDB.new(options) - helper.upgrade(args[0], options) + begin + helper = OneDB.new(options) + helper.upgrade(args[0], options) + rescue Exception => e + [-1, e.message] + end end end \ No newline at end of file diff --git a/src/onedb/onedb.rb b/src/onedb/onedb.rb index 3bccae244a..367bc43867 100644 --- a/src/onedb/onedb.rb +++ b/src/onedb/onedb.rb @@ -50,8 +50,8 @@ class OneDB bck_file = @backend.bck_file if bck_file.nil? if !ops[:force] && File.exists?(bck_file) - puts "File #{bck_file} exists, backup aborted. Use -f to overwrite." - raise + raise "File #{bck_file} exists, backup aborted. Use -f " << + "to overwrite." end @backend.backup(bck_file) @@ -62,8 +62,7 @@ class OneDB bck_file = @backend.bck_file if bck_file.nil? if !File.exists?(bck_file) - puts "File #{bck_file} doesn't exist, backup restoration aborted." - return -1 + raise "File #{bck_file} doesn't exist, backup restoration aborted." end one_not_running @@ -115,7 +114,6 @@ class OneDB # At least one upgrade will be executed, make DB backup backup(ops[:backup], ops) - puts " > Running migrator #{file}" if ops[:verbose] load(file) @@ -123,9 +121,8 @@ class OneDB result = @backend.up if !result - puts "Error while upgrading from #{version} to " << - " #{@backend.db_version}" - return -1 + raise "Error while upgrading from #{version} to " << + " #{@backend.db_version}" end puts " > Done" if ops[:verbose] @@ -148,8 +145,7 @@ class OneDB config = Configuration.new("#{ETC_LOCATION}/oned.conf") if config[:db] == nil - puts "No DB defined." - raise + raise "No DB defined." end if config[:db]["BACKEND"].upcase.include? "SQLITE" @@ -164,9 +160,8 @@ class OneDB :db_name => config[:db]["DB_NAME"] ) else - puts "Could not load DB configuration from " << - "#{ETC_LOCATION}/oned.conf" - raise + raise "Could not load DB configuration from " << + "#{ETC_LOCATION}/oned.conf" end return 0 @@ -174,8 +169,7 @@ class OneDB def one_not_running() if File.exists?(LOCK_FILE) - puts "First stop OpenNebula. Lock file found: #{LOCK_FILE}" - raise + raise "First stop OpenNebula. Lock file found: #{LOCK_FILE}" end end end \ No newline at end of file diff --git a/src/onedb/onedb_backend.rb b/src/onedb/onedb_backend.rb index f9b8ce2f76..cfe079052d 100644 --- a/src/onedb/onedb_backend.rb +++ b/src/onedb/onedb_backend.rb @@ -37,18 +37,16 @@ class OneDBBacKEnd rescue # If the DB doesn't have db_version table, it means it is empty or a 2.x if !db_exists? - puts "Database schema does not look to be created by OpenNebula:" - puts "table user_pool is missing or empty." - raise + raise "Database schema does not look to be created by " << + "OpenNebula: table user_pool is missing or empty." end begin # Table image_pool is present only in 2.X DBs @db.fetch("SELECT * FROM image_pool") { |row| } rescue - puts "Database schema looks to be created by OpenNebula 1.X." - puts "This tool only works with databases created by 2.X versions." - raise + raise "Database schema looks to be created by OpenNebula 1.X." << + "This tool only works with databases created by 2.X versions." end comment = "Could not read any previous db_versioning data, " << @@ -73,8 +71,7 @@ class OneDBBacKEnd puts "" end rescue Exception => e - puts "No version records found. Error message:" - puts e.message + raise "No version records found. Error message: " + e.message end end @@ -115,13 +112,13 @@ class OneDBBacKEnd end end -class OneDBBackEndMySQL < OneDBBacKEnd +class BackEndMySQL < OneDBBacKEnd def initialize(opts={}) - @server = ops[:server] - @port = ops[:port] - @user = ops[:user] - @passwd = ops[:passwd] - @db_name = ops[:db_name] + @server = opts[:server] + @port = opts[:port] + @user = opts[:user] + @passwd = opts[:passwd] + @db_name = opts[:db_name] # Check for errors: error = false @@ -130,8 +127,7 @@ class OneDBBackEndMySQL < OneDBBacKEnd (error = true; missing = "DBNAME") if @db_name == nil if error - puts "MySQL option #{missing} is needed" - exit -1 + raise "MySQL option #{missing} is needed" end # Check for defaults: @@ -156,8 +152,7 @@ class OneDBBackEndMySQL < OneDBBacKEnd rc = system(cmd) if !rc - puts "Unknown error running '#{cmd}'" - raise + raise "Unknown error running '#{cmd}'" end puts "MySQL dump stored in #{bck_file}" @@ -169,9 +164,8 @@ class OneDBBackEndMySQL < OneDBBacKEnd connect_db if !force && db_exists? - puts "MySQL database #{@db_name} at #{@server} exists," << - " use -f to overwrite." - raise + raise "MySQL database #{@db_name} at #{@server} exists," << + " use -f to overwrite." end mysql_cmd = "mysql -u #{@user} -p#{@passwd} -h #{@server} -P #{@port} " @@ -179,22 +173,19 @@ class OneDBBackEndMySQL < OneDBBacKEnd drop_cmd = mysql_cmd + "-e 'DROP DATABASE IF EXISTS #{@db_name};'" rc = system(drop_cmd) if !rc - puts "Error dropping MySQL DB #{@db_name} at #{@server}." - raise + raise "Error dropping MySQL DB #{@db_name} at #{@server}." end create_cmd = mysql_cmd+"-e 'CREATE DATABASE IF NOT EXISTS #{@db_name};'" rc = system(create_cnd) if !rc - puts "Error creating MySQL DB #{@db_name} at #{@server}." - raise + raise "Error creating MySQL DB #{@db_name} at #{@server}." end restore_cmd = mysql_cmd + "#{@db_name} < #{bck_file}" rc = system(restore_cmd) if !rc - puts "Error while restoring MySQL DB #{@db_name} at #{@server}." - raise + raise "Error while restoring MySQL DB #{@db_name} at #{@server}." end puts "MySQL DB #{@db_name} at #{@server} restored." @@ -204,13 +195,24 @@ class OneDBBackEndMySQL < OneDBBacKEnd def connect_db endpoint = "mysql://#{@user}:#{@passwd}@#{@server}:#{@port}/#{@db_name}" - @db = Sequel.connect(endpoint) + + begin + @db = Sequel.connect(endpoint) + rescue Exception => e + raise "Error connecting to DB: " + e.message + end end end class BackEndSQLite < OneDBBacKEnd + require 'fileutils' + def initialize(file) @sqlite_file = file + + if !File.exists?(@sqlite_file) + raise "File #{@sqlite_file} doesn't exist" + end end def bck_file @@ -218,20 +220,14 @@ class BackEndSQLite < OneDBBacKEnd end def backup(bck_file) - if !File.exists?(@sqlite_file) - puts "File #{@sqlite_file} doesn't exist, backup aborted." - raise - end - FileUtils.cp(@sqlite_file, "#{bck_file}") puts "Sqlite database backup stored in #{bck_file}" puts "Use 'onedb restore' or copy the file back to restore the DB." end def restore(bck_file, force=nil) - if !force && File.exists?(@sqlite_file) - puts "File #{@sqlite_file} exists, use -f to overwrite." - raise + if !force + raise "File #{@sqlite_file} exists, use -f to overwrite." end FileUtils.cp(bck_file, @sqlite_file) @@ -241,11 +237,10 @@ class BackEndSQLite < OneDBBacKEnd private def connect_db - if !File.exists?(@sqlite_file) - puts "File #{@sqlite_file} doesn't exist." - raise + begin + @db = Sequel.sqlite(@sqlite_file) + rescue Exception => e + raise "Error connecting to DB: " + e.message end - - @db = Sequel.sqlite(@sqlite_file) end end \ No newline at end of file diff --git a/src/ozones/Client/bin/onevdc b/src/ozones/Client/bin/onevdc index 49514be190..c15193e244 100755 --- a/src/ozones/Client/bin/onevdc +++ b/src/ozones/Client/bin/onevdc @@ -15,7 +15,7 @@ require 'command_parser' require 'ozones_helper/vdc_helper.rb' cmd=CommandParser::CmdParser.new(ARGV) do - usage "`ovdcs` command [] []" + usage "`onevdc` command [] []" version OpenNebulaHelper::ONE_VERSION ######################################################################## diff --git a/src/ozones/Client/bin/onezone b/src/ozones/Client/bin/onezone index e2076f93c4..13a0626460 100755 --- a/src/ozones/Client/bin/onezone +++ b/src/ozones/Client/bin/onezone @@ -15,7 +15,7 @@ require 'command_parser' require 'ozones_helper/zones_helper.rb' cmd=CommandParser::CmdParser.new(ARGV) do - usage "`ozones` [] []" + usage "`onezone` [] []" version OpenNebulaHelper::ONE_VERSION ######################################################################## diff --git a/src/pool/PoolSQL.cc b/src/pool/PoolSQL.cc index 6575e06f9d..175db7be9f 100644 --- a/src/pool/PoolSQL.cc +++ b/src/pool/PoolSQL.cc @@ -185,6 +185,11 @@ PoolObjectSQL * PoolSQL::get( if ( olock == true ) { objectsql->lock(); + + if ( objectsql->isValid() == false ) + { + objectsql = 0; + } } } @@ -246,19 +251,19 @@ PoolObjectSQL * PoolSQL::get(const string& name, int ouid, bool olock) index = name_pool.find(key(name,ouid)); - if ( index != name_pool.end() ) + if ( index != name_pool.end() && index->second->isValid() == true ) { - if ( index->second->isValid() == false ) - { - objectsql = 0; - } - else - { - objectsql = index->second; + objectsql = index->second; - if ( olock == true ) + if ( olock == true ) + { + objectsql->lock(); + + if ( objectsql->isValid() == false ) { - objectsql->lock(); + objectsql->unlock(); + + objectsql = 0; } } @@ -281,6 +286,19 @@ PoolObjectSQL * PoolSQL::get(const string& name, int ouid, bool olock) return 0; } + if ( index != name_pool.end() && index->second->isValid() == false ) + { + index->second->lock(); + + PoolObjectSQL * tmp_ptr = index->second; + string tmp_okey = key(tmp_ptr->name,tmp_ptr->uid); + + pool.erase(tmp_ptr->oid); + name_pool.erase(tmp_okey); + + delete tmp_ptr; + } + string okey = key(objectsql->name,objectsql->uid); pool.insert(make_pair(objectsql->oid, objectsql)); @@ -323,7 +341,7 @@ void PoolSQL::replace() if ( index == pool.end()) { oid_queue.pop(); - break; + continue; } rc = pthread_mutex_trylock(&(index->second->mutex)); diff --git a/src/pool/test/TestPoolSQL.cc b/src/pool/test/TestPoolSQL.cc index 4442d62e96..bb8f64afc5 100644 --- a/src/pool/test/TestPoolSQL.cc +++ b/src/pool/test/TestPoolSQL.cc @@ -27,123 +27,85 @@ #include "TestPoolSQL.h" /* ************************************************************************** */ -/* Database Access Functions */ +/* Database Access Functions */ /* ************************************************************************** */ const char * TestObjectSQL::table = "test_pool"; -const char * TestObjectSQL::db_names = "(oid,number,name)"; +const char * TestObjectSQL::db_names = "oid,name,body,uid,number"; const char * TestObjectSQL::db_bootstrap = "CREATE TABLE test_pool (" - "oid INTEGER, number INTEGER, name TEXT, PRIMARY KEY(oid))"; - -/* -------------------------------------------------------------------------- */ - -int TestObjectSQL::unmarshall(void * nil, int num, char **values, char **names) -{ - if ((!values[OID]) || - (!values[NUMBER]) || - (!values[TEXT]) || - (num != LIMIT )) - { - return -1; - } - - oid = atoi(values[OID]); - number = atoi(values[NUMBER]); - text = values[TEXT]; - - return 0; -} - -/* -------------------------------------------------------------------------- */ - -int TestObjectSQL::select(SqlDB *db) -{ - ostringstream oss; - int rc; - int boid; - - set_callback( - static_cast(&TestObjectSQL::unmarshall),0); - oss << "SELECT * FROM " << table << " WHERE oid = " << oid; - - boid = oid; - oid = -1; - - rc = db->exec(oss, this); - - unset_callback(); - - if ((rc != 0) || (oid != boid )) - { - return -1; - } - - return 0; -} + "oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, uid INTEGER, " + "number INTEGER)"; /* -------------------------------------------------------------------------- */ int TestObjectSQL::insert(SqlDB *db, string& str) { - ostringstream oss; - - int rc; - char * sql_text; - - sql_text = db->escape_str(text.c_str()); - - oss << "INSERT INTO " << table << " "<< db_names <<" VALUES (" - << oid << "," - << number << "," - << "'" << sql_text << "')"; - - rc = db->exec(oss); - - db->free_str(sql_text); - - return rc; + return insert_replace(db, false); } /* -------------------------------------------------------------------------- */ int TestObjectSQL::update(SqlDB *db) { - ostringstream oss; - - int rc; - char * sql_text; - - sql_text = db->escape_str(text.c_str()); - - oss << "REPLACE INTO " << table << " "<< db_names <<" VALUES (" - << oid << "," - << number << "," - << "'" << sql_text << "')"; - - rc = db->exec(oss); - - db->free_str(sql_text); - - return rc; + return insert_replace(db, true); } /* -------------------------------------------------------------------------- */ -int TestObjectSQL::drop(SqlDB * db) +int TestObjectSQL::insert_replace(SqlDB *db, bool replace) { - ostringstream oss; - int rc; + ostringstream oss; - oss << "DELETE FROM " << table << " WHERE oid=" << oid; + int rc; + string xml_body; + + char * sql_name; + char * sql_xml; + + // Update the User + + sql_name = db->escape_str(name.c_str()); + + if ( sql_name == 0 ) + { + goto error_name; + } + + sql_xml = db->escape_str(to_xml(xml_body).c_str()); + + if ( sql_xml == 0 ) + { + goto error_body; + } + + // Construct the SQL statement to Insert or Replace + if(replace) + { + oss << "REPLACE"; + } + else + { + oss << "INSERT"; + } + + oss << " INTO " << table << " ("<< db_names <<") VALUES (" + << oid << "," + << "'" << sql_name << "'," + << "'" << sql_xml << "'," + << uid << "," + << number << ")"; rc = db->exec(oss); - if ( rc == 0 ) - { - set_valid(false); - } + db->free_str(sql_name); + db->free_str(sql_xml); return rc; + +error_body: + db->free_str(sql_name); +error_name: + return -1; } diff --git a/src/pool/test/TestPoolSQL.h b/src/pool/test/TestPoolSQL.h index 9dd86a041d..db6637697b 100644 --- a/src/pool/test/TestPoolSQL.h +++ b/src/pool/test/TestPoolSQL.h @@ -30,7 +30,7 @@ class TestObjectSQL : public PoolObjectSQL { public: //OBJECT ATTRIBUTES - TestObjectSQL(int n=-1, string t="default"):PoolObjectSQL(-1,"",0,0,"","",0),number(n),text(t){}; + TestObjectSQL(int n=-1, string t="default"):PoolObjectSQL(-1,t,0,0,"","",table),number(n),text(t){}; ~TestObjectSQL(){}; @@ -41,22 +41,16 @@ public: // OBJECTSQL INTERFACE int unmarshall(void * nil, int num, char **names, char ** values); - int select(SqlDB *db); - int insert(SqlDB *db, string& err); int update(SqlDB *db); - int drop(SqlDB *db); + int insert_replace(SqlDB *db, bool replace); - // DATABASE IMPLEMENTATION - enum ColNames + int drop(SqlDB *db) { - OID = 0, - NUMBER = 1, - TEXT = 2, - LIMIT = 3 - }; + return PoolObjectSQL::drop(db); + } static const char * db_names; @@ -74,11 +68,47 @@ public: string& to_xml(string& xml) const { + ostringstream oss; + + oss << "" + << "" << oid << "" + << "" << uid << "" + << "" << gid << "" + << "" << uname << "" + << "" << gname << "" + << "" << name << "" + << "" << number << "" + << "" << text << "" + << ""; + + xml = oss.str(); + return xml; }; int from_xml(const string &xml_str) { + int rc = 0; + + // Initialize the internal XML object + update_from_str(xml_str); + + // Get class base attributes + rc += xpath(oid, "/TEST/ID", -1); + rc += xpath(uid, "/TEST/UID", -1); + rc += xpath(gid, "/TEST/GID", -1); + rc += xpath(uname, "/TEST/UNAME", "not_found"); + rc += xpath(gname, "/TEST/GNAME", "not_found"); + rc += xpath(name, "/TEST/NAME", "not_found"); + + rc += xpath(number, "/TEST/NUMBER", -1); + rc += xpath(text, "/TEST/TEXT", "not_found"); + + if ( rc != 0 ) + { + return -1; + } + return 0; }; }; @@ -95,7 +125,15 @@ public: int oid, bool lock) { - return static_cast(PoolSQL::get(oid,lock));; + return static_cast(PoolSQL::get(oid,lock)); + } + + TestObjectSQL * get( + const string& name, + int ouid, + bool olock) + { + return static_cast(PoolSQL::get(name, ouid, olock)); } int dump(std::ostringstream&, const std::string&){return -1;}; diff --git a/src/pool/test/pool.cc b/src/pool/test/pool.cc index e0df566f90..d689660cf4 100644 --- a/src/pool/test/pool.cc +++ b/src/pool/test/pool.cc @@ -34,6 +34,7 @@ class PoolTest : public OneUnitTest CPPUNIT_TEST (wrong_get); CPPUNIT_TEST (search); CPPUNIT_TEST (cache_test); + CPPUNIT_TEST (cache_name_test); CPPUNIT_TEST_SUITE_END (); private: @@ -63,8 +64,8 @@ public: void tearDown() { - delete_db(); delete pool; + delete_db(); }; /* ********************************************************************* */ @@ -196,6 +197,92 @@ public: obj_lock->unlock(); } }; + + + void cache_name_test() + { + TestObjectSQL *obj; + TestObjectSQL *obj_lock; + + ostringstream oss; + string err_str; + + //pin object in the cache, it can't be removed - + //Should be set to MAX_POOL -1 + for (int i=0 ; i < 14999 ; i++) + { + oss.str(""); + oss << "obj_" << i; + + create_allocate(i, oss.str()); + + obj_lock = pool->get(oss.str(), 0, true); + CPPUNIT_ASSERT(obj_lock != 0); + } + + for (int i=14999 ; i < 15200 ; i++) //Works with just 1 cache line + { + oss.str(""); + oss << "obj_" << i; + + create_allocate(i, oss.str()); + } + + for (int i=14999; i < 15200 ; i++) + { + oss.str(""); + oss << "obj_" << i; + + obj = pool->get(oss.str(), 0, true); + CPPUNIT_ASSERT(obj != 0); + + CPPUNIT_ASSERT(obj->number == i); + CPPUNIT_ASSERT(obj->get_name() == obj->text); + CPPUNIT_ASSERT(obj->get_name() == oss.str()); + obj->unlock(); + } + + // Delete some of the locked objects, and create new with the same name + for (int i=10 ; i < 21 ; i++) + { + oss.str(""); + oss << "obj_" << i; + + obj_lock = pool->get(oss.str(), 0, false); + CPPUNIT_ASSERT(obj_lock != 0); + + pool->drop(obj_lock, err_str); + obj_lock->unlock(); + + create_allocate(i, oss.str()); + } + + // Try to get the new objects + for (int i=10 ; i < 21 ; i++) + { + oss.str(""); + oss << "obj_" << i; + + obj = pool->get(oss.str(), 0, true); + + CPPUNIT_ASSERT(obj != 0); + + CPPUNIT_ASSERT(obj->number == i); + CPPUNIT_ASSERT(obj->get_oid() >= 15200); + CPPUNIT_ASSERT(obj->get_name() == oss.str()); + obj->unlock(); + } + + for (int i=0 ; i < 14999 ; i++) + { + obj_lock = pool->get(i, false); + + if ( obj_lock != 0 ) + { + obj_lock->unlock(); + } + } + }; }; /* ************************************************************************* */ diff --git a/src/rm/RequestManagerImage.cc b/src/rm/RequestManagerImage.cc index 665e47ba59..0348ffa3a7 100644 --- a/src/rm/RequestManagerImage.cc +++ b/src/rm/RequestManagerImage.cc @@ -87,17 +87,17 @@ void ImagePersistent::request_execute(xmlrpc_c::paramList const& paramList, return; } - rc = image->persistent(persistent_flag); + rc = image->persistent(persistent_flag, err_msg); if ( rc != 0 ) { if (persistent_flag == true) { - err_msg = "Could not make image persistent"; + err_msg = "Could not make image persistent: " + err_msg; } else { - err_msg = "Could not make image non-persistent"; + err_msg = "Could not make image non-persistent: " + err_msg; } failure_response(INTERNAL,request_error(err_msg,""), att); diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index f2344f6342..efae90e0f7 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -243,7 +243,7 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList, break; case -2: failure_response(ACTION, - request_error("Worng state to perform action",""), + request_error("Wrong state to perform action",""), att); break; case -3: @@ -296,7 +296,7 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, if ( vm->get_state() != VirtualMachine::PENDING ) { failure_response(ACTION, - request_error("Worng state to perform action",""), + request_error("Wrong state to perform action",""), att); vm->unlock(); @@ -355,7 +355,7 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList (vm->hasPreviousHistory() && vm->get_previous_reason() == History::NONE)) { failure_response(ACTION, - request_error("Worng state to perform action",""), + request_error("Wrong state to perform action",""), att); vm->unlock(); diff --git a/src/scheduler/include/HostPoolXML.h b/src/scheduler/include/HostPoolXML.h index 8160262df6..843790602e 100644 --- a/src/scheduler/include/HostPoolXML.h +++ b/src/scheduler/include/HostPoolXML.h @@ -46,7 +46,7 @@ protected: int get_suitable_nodes(vector& content) { - return get_nodes("/HOST_POOL/HOST[STATE<3]", content); + return get_nodes("/HOST_POOL/HOST[STATE=2]", content); }; void add_object(xmlNodePtr node); diff --git a/src/sunstone/etc/sunstone-server.conf b/src/sunstone/etc/sunstone-server.conf index a1d8b64246..37ff230bdc 100644 --- a/src/sunstone/etc/sunstone-server.conf +++ b/src/sunstone/etc/sunstone-server.conf @@ -5,4 +5,3 @@ PORT=9869 # VNC Configuration VNC_PROXY_BASE_PORT=29876 NOVNC_PATH= - diff --git a/src/sunstone/models/SunstoneServer.rb b/src/sunstone/models/SunstoneServer.rb index 4c045e4872..18e98cc371 100644 --- a/src/sunstone/models/SunstoneServer.rb +++ b/src/sunstone/models/SunstoneServer.rb @@ -20,6 +20,9 @@ include OpenNebulaJSON require 'acct/watch_client' class SunstoneServer + # FLAG that will filter the elements retrieved from the Pools + POOL_FILTER = Pool::INFO_GROUP + def initialize(username, password) # TBD one_client_user(name) from CloudServer @client = Client.new("dummy:dummy") @@ -57,13 +60,19 @@ class SunstoneServer # ############################################################################ def get_pool(kind,gid) + if gid == "0" + user_flag = Pool::INFO_ALL + else + user_flag = POOL_FILTER + end + pool = case kind when "group" then GroupPoolJSON.new(@client) when "host" then HostPoolJSON.new(@client) - when "image" then ImagePoolJSON.new(@client) - when "template" then TemplatePoolJSON.new(@client) - when "vm" then VirtualMachinePoolJSON.new(@client) - when "vnet" then VirtualNetworkPoolJSON.new(@client) + when "image" then ImagePoolJSON.new(@client, user_flag) + when "template" then TemplatePoolJSON.new(@client, user_flag) + when "vm" then VirtualMachinePoolJSON.new(@client, user_flag) + when "vnet" then VirtualNetworkPoolJSON.new(@client, user_flag) when "user" then UserPoolJSON.new(@client) when "acl" then AclPoolJSON.new(@client) else @@ -71,11 +80,7 @@ class SunstoneServer return [404, error.to_json] end - rc = case kind - when "group","host","user","acl" then pool.info - else - gid != "0" ? pool.info_group : pool.info_all - end + rc = pool.info if OpenNebula.is_error?(rc) return [500, rc.to_json] diff --git a/src/sunstone/sunstone-server.rb b/src/sunstone/sunstone-server.rb index cadc3eaad2..44faec1422 100755 --- a/src/sunstone/sunstone-server.rb +++ b/src/sunstone/sunstone-server.rb @@ -183,16 +183,14 @@ get '/:resource/monitor' do @SunstoneServer.get_monitoring( nil, params[:resource], - params[:monitor_resources] - ) + params[:monitor_resources]) end get '/:resource/:id/monitor' do @SunstoneServer.get_monitoring( params[:id], params[:resource], - params[:monitor_resources] - ) + params[:monitor_resources]) end @@ -200,7 +198,8 @@ end # GET Pool information ############################################################################## get '/:pool' do - @SunstoneServer.get_pool(params[:pool],session[:user_gid]) + @SunstoneServer.get_pool(params[:pool], + session[:user_gid]) end ############################################################################## @@ -283,5 +282,7 @@ end # Perform an action on a Resource ############################################################################## post '/:resource/:id/action' do - @SunstoneServer.perform_action(params[:resource], params[:id], request.body.read) + @SunstoneServer.perform_action(params[:resource], + params[:id], + request.body.read) end diff --git a/src/test/NebulaTest.cc b/src/test/NebulaTest.cc index d25c93adbb..1949fba438 100644 --- a/src/test/NebulaTest.cc +++ b/src/test/NebulaTest.cc @@ -71,6 +71,7 @@ VirtualMachineManager* NebulaTest::create_vmm(VirtualMachinePool* vmpool, hpool, timer_period, poll_period, + 5, vmm_mads); } @@ -90,6 +91,7 @@ InformationManager* NebulaTest::create_im(HostPool* hpool, return new InformationManager(hpool, timer_period, monitor_period, + 15, remotes_location, im_mads); } diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 9cd0b5951c..bc07b80299 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -982,6 +982,10 @@ int VirtualMachine::save_disk(int disk_id, int img_id, string& error_str) ostringstream oss; istringstream iss; + if ( state == DONE || state == FAILED ) + { + goto error_state; + } num_disks = obj_template->get("DISK",disks); @@ -1022,6 +1026,10 @@ int VirtualMachine::save_disk(int disk_id, int img_id, string& error_str) goto error_not_found; +error_state: + oss << "VM cannot be in DONE or FAILED state."; + goto error_common; + error_persistent: oss << "Source image for DISK " << disk_id << " is persistent."; goto error_common; @@ -1034,7 +1042,6 @@ error_not_found: oss << "The DISK " << disk_id << " does not exist for VM " << oid << "."; error_common: - NebulaLog::log("VM",Log::ERROR, oss); error_str = oss.str(); return -1; diff --git a/src/vmm/LibVirtDriverVMware.cc b/src/vmm/LibVirtDriverVMware.cc index afa0175070..b4662e8d41 100644 --- a/src/vmm/LibVirtDriverVMware.cc +++ b/src/vmm/LibVirtDriverVMware.cc @@ -240,18 +240,17 @@ int LibVirtDriver::deployment_description_vmware( { file << "/>" << endl; } - - file << "\t\t\t" << endl; + file << "\t\t\t" << endl; } else { if (!default_driver.empty()) { - file << default_driver << "'/>" << endl; + file << "\t\t\t" << endl; } } diff --git a/src/vmm/VirtualMachineManager.cc b/src/vmm/VirtualMachineManager.cc index 5aec753989..fc43d3380f 100644 --- a/src/vmm/VirtualMachineManager.cc +++ b/src/vmm/VirtualMachineManager.cc @@ -33,12 +33,14 @@ VirtualMachineManager::VirtualMachineManager( HostPool * _hpool, time_t _timer_period, time_t _poll_period, + int _vm_limit, vector& _mads): MadManager(_mads), vmpool(_vmpool), hpool(_hpool), timer_period(_timer_period), - poll_period(_poll_period) + poll_period(_poll_period), + vm_limit(_vm_limit) { am.addListener(this); }; @@ -822,10 +824,6 @@ void VirtualMachineManager::timer_action() const VirtualMachineManagerDriver * vmd; - // -------------- Max. number of VMs to monitor. --------------------- - int vm_limit = 5; - - mark = mark + timer_period; if ( mark >= 600 )