mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-27 03:21:29 +03:00
Merge branch 'feature-788' of git.opennebula.org:one into feature-788
This commit is contained in:
commit
d16a20c757
@ -90,14 +90,21 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the source path of the image
|
||||
* @return source of image
|
||||
* Sets the source path of the image
|
||||
*/
|
||||
void set_source(const string& _source)
|
||||
{
|
||||
source = _source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size for the image
|
||||
*/
|
||||
void set_size(unsigned int _size_mb)
|
||||
{
|
||||
size_mb = _size_mb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of the image
|
||||
* @return type
|
||||
@ -285,27 +292,32 @@ private:
|
||||
/**
|
||||
* Type of the Image
|
||||
*/
|
||||
ImageType type;
|
||||
ImageType type;
|
||||
|
||||
/**
|
||||
* Persistency of the Image
|
||||
*/
|
||||
int persistent_img;
|
||||
int persistent_img;
|
||||
|
||||
/**
|
||||
* Registration time
|
||||
*/
|
||||
time_t regtime;
|
||||
time_t regtime;
|
||||
|
||||
/**
|
||||
* Path to the image
|
||||
*/
|
||||
string source;
|
||||
string source;
|
||||
|
||||
/**
|
||||
* Size of the image in MB
|
||||
*/
|
||||
unsigned int size_mb;
|
||||
|
||||
/**
|
||||
* Image state
|
||||
*/
|
||||
ImageState state;
|
||||
ImageState state;
|
||||
|
||||
/**
|
||||
* Number of VMs using the image
|
||||
|
@ -98,14 +98,14 @@ module OneWatchClient
|
||||
max_per_vm =
|
||||
rsql.
|
||||
group(:id, :last_poll).
|
||||
select(:last_poll, :MAX[mr.to_sym].as(:max_mr))
|
||||
select{[:last_poll, max(mr.to_sym).as(:max_mr)]}
|
||||
|
||||
# SUM the monitoring resource for each last_poll value
|
||||
last_poll_and_sum =
|
||||
max_per_vm.
|
||||
from_self.
|
||||
group(:last_poll).
|
||||
select(:last_poll, :SUM[:max_mr].as(:sum_mr))
|
||||
select{[:last_poll, sum(:max_mr).as(:sum_mr)]}
|
||||
|
||||
# Retrieve the information in an Array
|
||||
a = Array.new
|
||||
@ -113,7 +113,7 @@ module OneWatchClient
|
||||
if row[:last_poll] && row[:last_poll] != 0
|
||||
a << [row[:last_poll], row[:sum_mr].to_i]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
a
|
||||
end
|
||||
@ -229,4 +229,4 @@ module OneWatchClient
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
:NAME:
|
||||
:desc: Name of the Image
|
||||
:size: 16
|
||||
:size: 12
|
||||
:left: true
|
||||
|
||||
:USER:
|
||||
@ -18,6 +18,10 @@
|
||||
:size: 8
|
||||
:left: true
|
||||
|
||||
:SIZE:
|
||||
:desc: Size of the Image
|
||||
:size: 7
|
||||
|
||||
:TYPE:
|
||||
:desc: Type of the Image
|
||||
:size: 4
|
||||
@ -47,6 +51,7 @@
|
||||
- :USER
|
||||
- :GROUP
|
||||
- :NAME
|
||||
- :SIZE
|
||||
- :TYPE
|
||||
- :REGTIME
|
||||
- :PUBLIC
|
||||
|
@ -363,11 +363,11 @@ EOT
|
||||
|
||||
BinarySufix = ["K", "M", "G", "T" ]
|
||||
|
||||
def OpenNebulaHelper.unit_to_str(value, options)
|
||||
def OpenNebulaHelper.unit_to_str(value, options, unit="K")
|
||||
if options[:kilobytes]
|
||||
value
|
||||
else
|
||||
i=0
|
||||
i=BinarySufix.index(unit).to_i
|
||||
|
||||
while value > 1024 && i < 3 do
|
||||
value /= 1024.0
|
||||
|
@ -57,10 +57,10 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
|
||||
str_h1="%-80s"
|
||||
|
||||
CLIHelper.print_header(str_h1 % "IMAGE #{image['ID']} INFORMATION")
|
||||
puts str % ["ID", image.id.to_s]
|
||||
puts str % ["ID", image.id.to_s]
|
||||
puts str % ["NAME", image.name]
|
||||
puts str % ["USER", image['UNAME']]
|
||||
puts str % ["GROUP", image['GNAME']]
|
||||
puts str % ["GROUP",image['GNAME']]
|
||||
puts str % ["TYPE", image.type_str]
|
||||
puts str % ["REGISTER TIME",
|
||||
OpenNebulaHelper.time_to_str(image['REGTIME'])]
|
||||
@ -68,7 +68,8 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
|
||||
OpenNebulaHelper.boolean_to_str(image['PUBLIC'])]
|
||||
puts str % ["PERSISTENT",
|
||||
OpenNebulaHelper.boolean_to_str(image["PERSISTENT"])]
|
||||
puts str % ["SOURCE", image['SOURCE']]
|
||||
puts str % ["SOURCE",image['SOURCE']]
|
||||
puts str % ["SIZE", image['SIZE']]
|
||||
puts str % ["STATE", image.short_state_str]
|
||||
puts str % ["RUNNING_VMS", image['RUNNING_VMS']]
|
||||
puts
|
||||
@ -85,7 +86,7 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
|
||||
d["ID"]
|
||||
end
|
||||
|
||||
column :NAME, "Name of the Image", :left, :size=>15 do |d|
|
||||
column :NAME, "Name of the Image", :left, :size=>12 do |d|
|
||||
d["NAME"]
|
||||
end
|
||||
|
||||
@ -127,7 +128,12 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
|
||||
d['RUNNING_VMS']
|
||||
end
|
||||
|
||||
default :ID, :USER, :GROUP, :NAME, :TYPE, :REGTIME, :PUBLIC,
|
||||
column :SIZE, "Size of the image",
|
||||
:size=>7 do |d|
|
||||
OpenNebulaHelper.unit_to_str(d['SIZE'].to_i,options,"M")
|
||||
end
|
||||
|
||||
default :ID, :USER, :GROUP, :NAME, :SIZE, :TYPE, :REGTIME, :PUBLIC,
|
||||
:PERSISTENT , :STAT, :RVMS
|
||||
end
|
||||
|
||||
|
@ -43,6 +43,7 @@ Image::Image(int _uid,
|
||||
type(OS),
|
||||
regtime(time(0)),
|
||||
source("-"),
|
||||
size_mb(0),
|
||||
state(INIT),
|
||||
running_vms(0)
|
||||
{
|
||||
@ -334,6 +335,7 @@ string& Image::to_xml(string& xml) const
|
||||
"<PERSISTENT>" << persistent_img << "</PERSISTENT>" <<
|
||||
"<REGTIME>" << regtime << "</REGTIME>" <<
|
||||
"<SOURCE>" << source << "</SOURCE>" <<
|
||||
"<SIZE>" << size_mb << "</SIZE>" <<
|
||||
"<STATE>" << state << "</STATE>" <<
|
||||
"<RUNNING_VMS>" << running_vms << "</RUNNING_VMS>" <<
|
||||
obj_template->to_xml(template_xml) <<
|
||||
@ -374,6 +376,7 @@ int Image::from_xml(const string& xml)
|
||||
rc += xpath(regtime, "/IMAGE/REGTIME", 0);
|
||||
|
||||
rc += xpath(source, "/IMAGE/SOURCE", "not_found");
|
||||
rc += xpath(size_mb, "/IMAGE/SIZE", 0);
|
||||
rc += xpath(int_state, "/IMAGE/STATE", 0);
|
||||
rc += xpath(running_vms, "/IMAGE/RUNNING_VMS", -1);
|
||||
|
||||
|
@ -91,6 +91,7 @@ void ImageManagerDriver::protocol(
|
||||
int id;
|
||||
Image * image;
|
||||
string source;
|
||||
unsigned int size_mb;
|
||||
|
||||
string info;
|
||||
|
||||
@ -130,6 +131,27 @@ void ImageManagerDriver::protocol(
|
||||
else
|
||||
return;
|
||||
|
||||
// Parse driver message for CP, MV and MKFS
|
||||
// <CP|MV|MKFS> SUCESS IMAGE_ID SOURCE SIZE
|
||||
if ( (result == "SUCCESS") && (action != "RM") )
|
||||
{
|
||||
if ( is.good() )
|
||||
{
|
||||
is >> source >> ws;
|
||||
}
|
||||
|
||||
if ( is.good() )
|
||||
{
|
||||
is >> size_mb >> ws;
|
||||
}
|
||||
|
||||
if ( is.fail() )
|
||||
{
|
||||
result = "FAILURE";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Get the image from the pool
|
||||
image = ipool->get(id,true);
|
||||
|
||||
@ -143,19 +165,9 @@ void ImageManagerDriver::protocol(
|
||||
{
|
||||
if ( result == "SUCCESS" )
|
||||
{
|
||||
string source;
|
||||
|
||||
if ( is.good() )
|
||||
{
|
||||
is >> source >> ws;
|
||||
}
|
||||
|
||||
if ( is.fail() )
|
||||
{
|
||||
goto error_cp;
|
||||
}
|
||||
|
||||
image->set_source(source);
|
||||
image->set_size(size_mb);
|
||||
|
||||
image->set_state(Image::READY);
|
||||
|
||||
ipool->update(image);
|
||||
@ -173,22 +185,13 @@ void ImageManagerDriver::protocol(
|
||||
{
|
||||
if (image->get_source() == "-")
|
||||
{
|
||||
string source;
|
||||
|
||||
if ( is.good() )
|
||||
{
|
||||
is >> source >> ws;
|
||||
}
|
||||
|
||||
if ( is.fail() )
|
||||
{
|
||||
goto error_mv;
|
||||
}
|
||||
|
||||
image->set_source(source);
|
||||
}
|
||||
|
||||
image->set_size(size_mb);
|
||||
|
||||
image->set_state(Image::READY);
|
||||
|
||||
ipool->update(image);
|
||||
|
||||
NebulaLog::log("ImM", Log::INFO, "Image saved and ready to use.");
|
||||
@ -202,19 +205,9 @@ void ImageManagerDriver::protocol(
|
||||
{
|
||||
if ( result == "SUCCESS" )
|
||||
{
|
||||
string source;
|
||||
|
||||
if ( is.good() )
|
||||
{
|
||||
is >> source >> ws;
|
||||
}
|
||||
|
||||
if ( is.fail() )
|
||||
{
|
||||
goto error_mkfs;
|
||||
}
|
||||
|
||||
image->set_source(source);
|
||||
image->set_size(size_mb);
|
||||
|
||||
image->set_state(Image::READY);
|
||||
|
||||
ipool->update(image);
|
||||
|
@ -52,6 +52,9 @@ http://*)
|
||||
;;
|
||||
esac
|
||||
|
||||
# ---------------- Get the size of the image & fix perms ------------
|
||||
exec_and_log "chmod 0660 $DST"
|
||||
|
||||
echo "$DST"
|
||||
SIZE=`fs_du $DST`
|
||||
|
||||
echo "$DST $SIZE"
|
||||
|
@ -39,3 +39,16 @@ EOF
|
||||
|
||||
echo "$IMAGE_REPOSITORY_PATH/`echo $CANONICAL_MD5 | cut -d ' ' -f1`"
|
||||
}
|
||||
|
||||
function fs_du {
|
||||
|
||||
SIZE=`$DU -m $1 2>/dev/null`
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
SIZE=0
|
||||
else
|
||||
SIZE=`echo $SIZE | cut -f1 -d' '`
|
||||
fi
|
||||
|
||||
echo "$SIZE"
|
||||
}
|
||||
|
@ -65,4 +65,7 @@ exec_and_log "$MKFS -t $FSTYPE $OPTS $DST" \
|
||||
|
||||
exec_and_log "chmod 0660 $DST"
|
||||
|
||||
echo "$DST"
|
||||
# ---------------- Get the size of the image ------------
|
||||
SIZE=`fs_du $DST`
|
||||
|
||||
echo "$DST $SIZE"
|
||||
|
@ -64,4 +64,7 @@ esac
|
||||
|
||||
exec_and_log "chmod 0660 $DST"
|
||||
|
||||
echo "$DST"
|
||||
# ---------------- Get the size of the image ------------
|
||||
SIZE=`fs_du $DST`
|
||||
|
||||
echo "$DST $SIZE"
|
||||
|
@ -20,6 +20,7 @@ BASH=/bin/bash
|
||||
CUT=cut
|
||||
DATE=/bin/date
|
||||
DD=/bin/dd
|
||||
DU=/bin/du
|
||||
LVCREATE=/sbin/lvcreate
|
||||
LVREMOVE=/sbin/lvremove
|
||||
LVS=/sbin/lvs
|
||||
|
Loading…
Reference in New Issue
Block a user