1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-08 20:58:17 +03:00

feature #788: Compute image size when moving an image to the repository. Drivers now return <CP|MV|MKFS> SUCESS IMAGE_ID SOURCE SIZE. The fs based image repository drivers has been updates, oneimage utility has been also updated to show the size (list and show operations).

This commit is contained in:
Ruben S. Montero 2011-08-31 16:21:18 +02:00
parent f75fd60284
commit c8f44ede9a
10 changed files with 94 additions and 52 deletions

View File

@ -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

View File

@ -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

View File

@ -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)
end
default :ID, :USER, :GROUP, :NAME, :SIZE, :TYPE, :REGTIME, :PUBLIC,
:PERSISTENT , :STAT, :RVMS
end

View File

@ -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);

View File

@ -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);

View File

@ -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"

View File

@ -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"
}

View File

@ -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"

View File

@ -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"

View File

@ -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