mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-20 10:50:08 +03:00
Merge branch 'master' into feature-746
Conflicts: src/sunstone/models/SunstoneServer.rb
This commit is contained in:
commit
02344c18f6
@ -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;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,12 +34,14 @@ public:
|
||||
HostPool * _hpool,
|
||||
time_t _timer_period,
|
||||
time_t _monitor_period,
|
||||
int _host_limit,
|
||||
const string& _remotes_location,
|
||||
vector<const Attribute*>& _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
|
||||
*/
|
||||
|
@ -37,6 +37,7 @@ public:
|
||||
HostPool * _hpool,
|
||||
time_t _timer_period,
|
||||
time_t _poll_period,
|
||||
int _vm_limit,
|
||||
vector<const Attribute*>& _mads);
|
||||
|
||||
~VirtualMachineManager(){};
|
||||
@ -118,6 +119,11 @@ private:
|
||||
*/
|
||||
time_t poll_period;
|
||||
|
||||
/**
|
||||
* Virtual Machine polling limit
|
||||
*/
|
||||
int vm_limit;
|
||||
|
||||
/**
|
||||
* Action engine for the Manager
|
||||
*/
|
||||
|
@ -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"
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#-----------------------------------------------------------------------------
|
||||
|
@ -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
|
||||
|
@ -43,3 +43,6 @@ env.Man('oneuser')
|
||||
env.Man('onevm')
|
||||
env.Man('onevnet')
|
||||
env.Man('onegroup')
|
||||
env.Man('onezone')
|
||||
env.Man('onevdc')
|
||||
|
||||
|
105
share/man/onevdc.1
Normal file
105
share/man/onevdc.1
Normal file
@ -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
|
105
share/man/onezone.1
Normal file
105
share/man/onezone.1
Normal file
@ -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
|
@ -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'
|
||||
|
||||
|
@ -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
|
||||
|
@ -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'
|
||||
|
||||
|
@ -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
|
||||
|
@ -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'
|
||||
|
||||
|
@ -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'
|
||||
|
@ -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
|
||||
|
@ -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+)$/
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
@ -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|
|
||||
|
@ -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
|
||||
|
@ -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|
|
||||
|
@ -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
|
||||
|
||||
|
@ -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|
|
||||
|
@ -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') %>
|
||||
|
@ -50,7 +50,7 @@ class VirtualMachineOCCI < VirtualMachine
|
||||
<% end %>
|
||||
</NIC>
|
||||
<% end %>
|
||||
<% if self['TEMPLATE/CONTEXT'] %>
|
||||
<% if self.has_elements?('TEMPLATE/CONTEXT') %>
|
||||
<CONTEXT>
|
||||
<% self.each('TEMPLATE/CONTEXT/*') do |cont| %>
|
||||
<% if cont.text %>
|
||||
|
@ -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 )
|
||||
|
@ -744,8 +744,9 @@ public:
|
||||
|
||||
void persistence()
|
||||
{
|
||||
int oid;
|
||||
int success;
|
||||
int oid;
|
||||
int success;
|
||||
string error_msg;
|
||||
ImagePoolFriend * imp = static_cast<ImagePoolFriend *>(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 );
|
||||
|
||||
|
@ -93,7 +93,7 @@ public:
|
||||
time_t _poll_period,
|
||||
vector<const Attribute*>& _mads):
|
||||
VirtualMachineManager( _vmpool, _hpool, _timer_period,
|
||||
_poll_period, _mads){}
|
||||
_poll_period, 5, _mads){}
|
||||
|
||||
void trigger(Actions action, int _vid)
|
||||
{
|
||||
|
@ -339,9 +339,12 @@ void Nebula::start()
|
||||
{
|
||||
time_t poll_period;
|
||||
vector<const Attribute *> 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<const Attribute *> 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);
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
@ -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
|
@ -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
|
@ -15,7 +15,7 @@ require 'command_parser'
|
||||
require 'ozones_helper/vdc_helper.rb'
|
||||
|
||||
cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
usage "`ovdcs` command [<args>] [<options>]"
|
||||
usage "`onevdc` command [<args>] [<options>]"
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
########################################################################
|
||||
|
@ -15,7 +15,7 @@ require 'command_parser'
|
||||
require 'ozones_helper/zones_helper.rb'
|
||||
|
||||
cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
usage "`ozones` <command> [<args>] [<options>]"
|
||||
usage "`onezone` <command> [<args>] [<options>]"
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
########################################################################
|
||||
|
@ -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));
|
||||
|
@ -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<Callbackable::Callback>(&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;
|
||||
}
|
||||
|
@ -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 << "<TEST>"
|
||||
<< "<ID>" << oid << "</ID>"
|
||||
<< "<UID>" << uid << "</UID>"
|
||||
<< "<GID>" << gid << "</GID>"
|
||||
<< "<UNAME>" << uname << "</UNAME>"
|
||||
<< "<GNAME>" << gname << "</GNAME>"
|
||||
<< "<NAME>" << name << "</NAME>"
|
||||
<< "<NUMBER>" << number << "</NUMBER>"
|
||||
<< "<TEXT>" << text << "</TEXT>"
|
||||
<< "</TEST>";
|
||||
|
||||
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<TestObjectSQL *>(PoolSQL::get(oid,lock));;
|
||||
return static_cast<TestObjectSQL *>(PoolSQL::get(oid,lock));
|
||||
}
|
||||
|
||||
TestObjectSQL * get(
|
||||
const string& name,
|
||||
int ouid,
|
||||
bool olock)
|
||||
{
|
||||
return static_cast<TestObjectSQL *>(PoolSQL::get(name, ouid, olock));
|
||||
}
|
||||
|
||||
int dump(std::ostringstream&, const std::string&){return -1;};
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/* ************************************************************************* */
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -46,7 +46,7 @@ protected:
|
||||
|
||||
int get_suitable_nodes(vector<xmlNodePtr>& content)
|
||||
{
|
||||
return get_nodes("/HOST_POOL/HOST[STATE<3]", content);
|
||||
return get_nodes("/HOST_POOL/HOST[STATE=2]", content);
|
||||
};
|
||||
|
||||
void add_object(xmlNodePtr node);
|
||||
|
@ -5,4 +5,3 @@ PORT=9869
|
||||
# VNC Configuration
|
||||
VNC_PROXY_BASE_PORT=29876
|
||||
NOVNC_PATH=
|
||||
|
||||
|
@ -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]
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -240,18 +240,17 @@ int LibVirtDriver::deployment_description_vmware(
|
||||
{
|
||||
file << "/>" << endl;
|
||||
}
|
||||
|
||||
file << "\t\t\t<driver name='";
|
||||
|
||||
if ( !driver.empty() )
|
||||
{
|
||||
file << driver << "'/>" << endl;
|
||||
file << "\t\t\t<driver name='" << driver << "'/>" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!default_driver.empty())
|
||||
{
|
||||
file << default_driver << "'/>" << endl;
|
||||
file << "\t\t\t<driver name='" <<
|
||||
default_driver << "'/>" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,12 +33,14 @@ VirtualMachineManager::VirtualMachineManager(
|
||||
HostPool * _hpool,
|
||||
time_t _timer_period,
|
||||
time_t _poll_period,
|
||||
int _vm_limit,
|
||||
vector<const Attribute*>& _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 )
|
||||
|
Loading…
x
Reference in New Issue
Block a user