mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-08 20:58:17 +03:00
feature #4317: Recursive disk operations can work on DISK based on image
names.
This commit is contained in:
parent
a48444848a
commit
60ea093786
@ -228,6 +228,11 @@ public:
|
||||
attribute_value = va.attribute_value;
|
||||
};
|
||||
|
||||
VectorAttribute(const VectorAttribute* va):Attribute(va->attribute_name)
|
||||
{
|
||||
attribute_value = va->attribute_value;
|
||||
};
|
||||
|
||||
~VectorAttribute(){};
|
||||
|
||||
/**
|
||||
|
@ -209,12 +209,13 @@ public:
|
||||
*/
|
||||
static int get_disk_uid(VectorAttribute * disk, int _uid);
|
||||
|
||||
/**
|
||||
* Get the disk id based on its string representation. Used in VM parsers
|
||||
* @param id_s the string id
|
||||
* @return the id in int form
|
||||
*/
|
||||
static int get_disk_id(const string& id_s);
|
||||
/**
|
||||
* Gets the IDs of the images associated to a set of disks
|
||||
* @param dsk a vector with the DISK attributes
|
||||
* @param ids set of image ids
|
||||
* @param uid effective user id makeing the call
|
||||
*/
|
||||
void get_image_ids(vector<VectorAttribute *>& dsk, set<int>& ids, int uid);
|
||||
|
||||
private:
|
||||
//--------------------------------------------------------------------------
|
||||
|
@ -71,12 +71,21 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns all the DISK/IMAGE_IDs in the Template
|
||||
* @return image IDs
|
||||
* Returns a copy of the DISK attributes of this template, the attributes
|
||||
* are copied and must be freed by the calling function.
|
||||
* @param a vector to store the disks.
|
||||
*/
|
||||
void get_img_ids(vector<int>& img_ids)
|
||||
void get_disks(vector<VectorAttribute *>& disks)
|
||||
{
|
||||
xpaths<int>(img_ids,"/VMTEMPLATE/TEMPLATE/DISK/IMAGE_ID");
|
||||
vector<const VectorAttribute *> _disks;
|
||||
|
||||
obj_template->get("DISK", _disks);
|
||||
|
||||
for (vector<const VectorAttribute *>::const_iterator i = _disks.begin();
|
||||
i != _disks.end() ; ++i)
|
||||
{
|
||||
disks.push_back(new VectorAttribute(*i));
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -290,24 +290,6 @@ int ImagePool::get_disk_uid(VectorAttribute * disk, int _uid)
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ImagePool::get_disk_id(const string& id_s)
|
||||
{
|
||||
istringstream is;
|
||||
int id;
|
||||
|
||||
is.str(id_s);
|
||||
is >> id;
|
||||
|
||||
if( is.fail() )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ImagePool::acquire_disk(int vm_id,
|
||||
VectorAttribute * disk,
|
||||
int disk_id,
|
||||
@ -331,16 +313,8 @@ int ImagePool::acquire_disk(int vm_id,
|
||||
|
||||
*snap = 0;
|
||||
|
||||
if (!(source = disk->vector_value("IMAGE_ID")).empty())
|
||||
if ( disk->vector_value("IMAGE_ID", iid) == 0 )
|
||||
{
|
||||
iid = get_disk_id(source);
|
||||
|
||||
if ( iid == -1)
|
||||
{
|
||||
error_str = "Wrong ID set in IMAGE_ID";
|
||||
return -1;
|
||||
}
|
||||
|
||||
img = imagem->acquire_image(vm_id, iid, error_str);
|
||||
|
||||
if ( img == 0 )
|
||||
@ -348,7 +322,7 @@ int ImagePool::acquire_disk(int vm_id,
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (!(source = disk->vector_value("IMAGE")).empty())
|
||||
else if ( disk->vector_value("IMAGE", source) == 0 )
|
||||
{
|
||||
int uiid = get_disk_uid(disk,uid);
|
||||
|
||||
@ -376,7 +350,7 @@ int ImagePool::acquire_disk(int vm_id,
|
||||
{
|
||||
string type = disk->vector_value("TYPE");
|
||||
|
||||
transform(type.begin(),type.end(),type.begin(),(int(*)(int))toupper);
|
||||
one_util::toupper(type);
|
||||
|
||||
if ( type != "SWAP" && type != "FS" )
|
||||
{
|
||||
@ -384,10 +358,9 @@ int ImagePool::acquire_disk(int vm_id,
|
||||
return -1;
|
||||
}
|
||||
|
||||
int rc;
|
||||
long long size;
|
||||
|
||||
rc = disk->vector_value("SIZE", size);
|
||||
int rc = disk->vector_value("SIZE", size);
|
||||
|
||||
if ( rc != 0 || size <= 0 )
|
||||
{
|
||||
@ -411,7 +384,7 @@ int ImagePool::acquire_disk(int vm_id,
|
||||
DatastorePool * ds_pool = nd.get_dspool();
|
||||
|
||||
long long size = 0;
|
||||
bool has_size = (disk->vector_value("SIZE", size) == 0);
|
||||
bool has_size = (disk->vector_value("SIZE", size) == 0);
|
||||
|
||||
if (has_size && img->is_persistent() && size != img->get_size())
|
||||
{
|
||||
@ -494,6 +467,7 @@ void ImagePool::disk_attribute(
|
||||
string source;
|
||||
Image * img = 0;
|
||||
int datastore_id;
|
||||
int iid;
|
||||
|
||||
string dev_prefix;
|
||||
Image::ImageType img_type;
|
||||
@ -503,18 +477,13 @@ void ImagePool::disk_attribute(
|
||||
Nebula& nd = Nebula::instance();
|
||||
DatastorePool * ds_pool = nd.get_dspool();
|
||||
|
||||
if (!(source = disk->vector_value("IMAGE_ID")).empty())
|
||||
if ( disk->vector_value("IMAGE_ID", iid) == 0 )
|
||||
{
|
||||
int iid = get_disk_id(source);
|
||||
|
||||
if ( iid != -1)
|
||||
{
|
||||
img = get(iid, true);
|
||||
}
|
||||
img = get(iid, true);
|
||||
}
|
||||
else if (!(source = disk->vector_value("IMAGE")).empty())
|
||||
else if ( disk->vector_value("IMAGE", source) == 0 )
|
||||
{
|
||||
int uiid = get_disk_uid(disk,uid);
|
||||
int uiid = get_disk_uid(disk, uid);
|
||||
|
||||
if ( uiid != -1)
|
||||
{
|
||||
@ -541,11 +510,14 @@ void ImagePool::disk_attribute(
|
||||
|
||||
void ImagePool::authorize_disk(VectorAttribute * disk,int uid, AuthRequest * ar)
|
||||
{
|
||||
string source;
|
||||
Image * img = 0;
|
||||
string source;
|
||||
Image * img = 0;
|
||||
|
||||
int iid;
|
||||
|
||||
PoolObjectAuth perm;
|
||||
|
||||
if (!(source = disk->vector_value("IMAGE")).empty())
|
||||
if ( disk->vector_value("IMAGE", source) == 0 )
|
||||
{
|
||||
int uiid = get_disk_uid(disk,uid);
|
||||
|
||||
@ -561,15 +533,8 @@ void ImagePool::authorize_disk(VectorAttribute * disk,int uid, AuthRequest * ar)
|
||||
disk->replace("IMAGE_ID", img->get_oid());
|
||||
}
|
||||
}
|
||||
else if (!(source = disk->vector_value("IMAGE_ID")).empty())
|
||||
else if ( disk->vector_value("IMAGE_ID", iid) == 0 )
|
||||
{
|
||||
int iid = get_disk_id(source);
|
||||
|
||||
if ( iid == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
img = get(iid, true);
|
||||
}
|
||||
|
||||
@ -584,3 +549,46 @@ void ImagePool::authorize_disk(VectorAttribute * disk,int uid, AuthRequest * ar)
|
||||
|
||||
ar->add_auth(AuthRequest::USE, perm);
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void ImagePool::get_image_ids(vector<VectorAttribute *>& disks, set<int>& ids,
|
||||
int uid)
|
||||
{
|
||||
vector<VectorAttribute *>::iterator i;
|
||||
|
||||
int iid;
|
||||
string iname;
|
||||
|
||||
Image * img = 0;
|
||||
|
||||
for ( i = disks.begin() ; i != disks.end(); ++i )
|
||||
{
|
||||
if ( (*i)->vector_value("IMAGE_ID", iid) == 0 )
|
||||
{
|
||||
ids.insert(iid);
|
||||
}
|
||||
else if ( (*i)->vector_value("IMAGE", iname) == 0 )
|
||||
{
|
||||
int uiid = get_disk_uid(*i, uid);
|
||||
|
||||
if ( uiid == -1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
img = get(iname, uiid, true);
|
||||
|
||||
if ( img != 0 )
|
||||
{
|
||||
ids.insert(img->get_oid());
|
||||
|
||||
img->unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -214,8 +214,15 @@ void TemplateChmod::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
{
|
||||
VMTemplate* tmpl = static_cast<VMTemplatePool*>(pool)->get(oid, true);
|
||||
|
||||
vector<VectorAttribute *> disks;
|
||||
|
||||
int rc = 0;
|
||||
|
||||
set<int> error_ids;
|
||||
set<int> img_ids;
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
ImagePool* ipool = nd.get_ipool();
|
||||
|
||||
if ( tmpl == 0 )
|
||||
{
|
||||
@ -224,23 +231,16 @@ void TemplateChmod::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
vector<int> img_ids;
|
||||
|
||||
tmpl->get_img_ids(img_ids);
|
||||
tmpl->get_disks(disks);
|
||||
|
||||
tmpl->unlock();
|
||||
|
||||
ErrorCode ec;
|
||||
ipool->get_image_ids(disks, img_ids, att.uid);
|
||||
|
||||
for (vector<int>::iterator it = img_ids.begin(); it != img_ids.end(); it++)
|
||||
for (set<int>::iterator it = img_ids.begin(); it != img_ids.end(); it++)
|
||||
{
|
||||
ec = ImageChmod::chmod(*it,
|
||||
owner_u, owner_m, owner_a,
|
||||
group_u, group_m, group_a,
|
||||
other_u, other_m, other_a,
|
||||
att);
|
||||
|
||||
if (ec != SUCCESS)
|
||||
if ( ImageChmod::chmod(*it, owner_u, owner_m, owner_a, group_u,
|
||||
group_m, group_a, other_u, other_m, other_a, att) != SUCCESS)
|
||||
{
|
||||
NebulaLog::log("ReM", Log::ERROR, failure_message(ec, att));
|
||||
|
||||
@ -249,6 +249,12 @@ void TemplateChmod::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
}
|
||||
}
|
||||
|
||||
for (vector<VectorAttribute *>::iterator i = disks.begin();
|
||||
i != disks.end() ; i++)
|
||||
{
|
||||
delete *i;
|
||||
}
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
att.resp_msg = "Cannot chmod " + object_name(PoolObjectSQL::IMAGE) +
|
||||
|
@ -148,13 +148,17 @@ int RequestManagerDelete::drop(
|
||||
void TemplateDelete::request_execute(
|
||||
xmlrpc_c::paramList const& paramList, RequestAttributes& att)
|
||||
{
|
||||
int oid = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
bool recursive = false;
|
||||
int oid = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
bool recursive = false;
|
||||
|
||||
VMTemplate * object;
|
||||
string error_msg;
|
||||
vector<int> img_ids;
|
||||
set<int> error_ids;
|
||||
ErrorCode ec;
|
||||
|
||||
string error_msg;
|
||||
set<int> error_ids;
|
||||
set<int> img_ids;
|
||||
ErrorCode ec;
|
||||
|
||||
vector<VectorAttribute *> disks;
|
||||
|
||||
if (paramList.size() > 2)
|
||||
{
|
||||
@ -182,7 +186,7 @@ void TemplateDelete::request_execute(
|
||||
|
||||
if (recursive)
|
||||
{
|
||||
object->get_img_ids(img_ids);
|
||||
object->get_disks(disks);
|
||||
}
|
||||
|
||||
object->unlock();
|
||||
@ -198,13 +202,14 @@ void TemplateDelete::request_execute(
|
||||
|
||||
if (recursive)
|
||||
{
|
||||
ErrorCode ec;
|
||||
Nebula& nd = Nebula::instance();
|
||||
ImagePool* ipool = nd.get_ipool();
|
||||
|
||||
for (vector<int>::iterator it = img_ids.begin(); it != img_ids.end(); it++)
|
||||
ipool->get_image_ids(disks, img_ids, att.uid);
|
||||
|
||||
for (set<int>::iterator it = img_ids.begin(); it != img_ids.end(); it++)
|
||||
{
|
||||
ec = ImageDelete::delete_img(*it, att);
|
||||
|
||||
if (ec != SUCCESS)
|
||||
if ( ImageDelete::delete_img(*it, att) != SUCCESS )
|
||||
{
|
||||
NebulaLog::log("ReM", Log::ERROR, failure_message(ec, att));
|
||||
|
||||
@ -212,6 +217,12 @@ void TemplateDelete::request_execute(
|
||||
rc = -1;
|
||||
}
|
||||
}
|
||||
|
||||
for (vector<VectorAttribute *>::iterator i = disks.begin() ;
|
||||
i != disks.end() ; i++)
|
||||
{
|
||||
delete *i;
|
||||
}
|
||||
}
|
||||
|
||||
if ( rc != 0 )
|
||||
|
@ -188,9 +188,11 @@ int get_image_path(VirtualMachine * vm,
|
||||
}
|
||||
else if ( var1 == "IMAGE_ID" )
|
||||
{
|
||||
iid = ImagePool::get_disk_id(val1);
|
||||
istringstream is(val1);
|
||||
|
||||
if ( iid != -1 )
|
||||
is >> iid;
|
||||
|
||||
if ( !is.fail() )
|
||||
{
|
||||
img = ipool->get(iid, true);
|
||||
}
|
||||
@ -250,7 +252,7 @@ int get_image_path(VirtualMachine * vm,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#line 254 "vm_file_var_syntax.cc" /* yacc.c:339 */
|
||||
#line 256 "vm_file_var_syntax.cc" /* yacc.c:339 */
|
||||
|
||||
# ifndef YY_NULLPTR
|
||||
# if defined __cplusplus && 201103L <= __cplusplus
|
||||
@ -302,13 +304,13 @@ extern int vm_file_var__debug;
|
||||
|
||||
union YYSTYPE
|
||||
{
|
||||
#line 206 "vm_file_var_syntax.y" /* yacc.c:355 */
|
||||
#line 208 "vm_file_var_syntax.y" /* yacc.c:355 */
|
||||
|
||||
char * val_str;
|
||||
int val_int;
|
||||
char val_char;
|
||||
|
||||
#line 312 "vm_file_var_syntax.cc" /* yacc.c:355 */
|
||||
#line 314 "vm_file_var_syntax.cc" /* yacc.c:355 */
|
||||
};
|
||||
|
||||
typedef union YYSTYPE YYSTYPE;
|
||||
@ -338,7 +340,7 @@ int vm_file_var__parse (mem_collector * mc, VirtualMachine * vm, vector<int> *
|
||||
|
||||
/* Copy the second part of user declarations. */
|
||||
|
||||
#line 342 "vm_file_var_syntax.cc" /* yacc.c:358 */
|
||||
#line 344 "vm_file_var_syntax.cc" /* yacc.c:358 */
|
||||
|
||||
#ifdef short
|
||||
# undef short
|
||||
@ -638,7 +640,7 @@ static const yytype_uint8 yytranslate[] =
|
||||
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
|
||||
static const yytype_uint8 yyrline[] =
|
||||
{
|
||||
0, 230, 230, 231, 235, 253
|
||||
0, 232, 232, 233, 237, 255
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -1518,7 +1520,7 @@ yyreduce:
|
||||
switch (yyn)
|
||||
{
|
||||
case 4:
|
||||
#line 236 "vm_file_var_syntax.y" /* yacc.c:1646 */
|
||||
#line 238 "vm_file_var_syntax.y" /* yacc.c:1646 */
|
||||
{
|
||||
string file((yyvsp[-6].val_str));
|
||||
string var1((yyvsp[-4].val_str));
|
||||
@ -1536,11 +1538,11 @@ yyreduce:
|
||||
YYABORT;
|
||||
}
|
||||
}
|
||||
#line 1540 "vm_file_var_syntax.cc" /* yacc.c:1646 */
|
||||
#line 1542 "vm_file_var_syntax.cc" /* yacc.c:1646 */
|
||||
break;
|
||||
|
||||
case 5:
|
||||
#line 254 "vm_file_var_syntax.y" /* yacc.c:1646 */
|
||||
#line 256 "vm_file_var_syntax.y" /* yacc.c:1646 */
|
||||
{
|
||||
string file((yyvsp[-10].val_str));
|
||||
string var1((yyvsp[-8].val_str));
|
||||
@ -1561,11 +1563,11 @@ yyreduce:
|
||||
YYABORT;
|
||||
}
|
||||
}
|
||||
#line 1565 "vm_file_var_syntax.cc" /* yacc.c:1646 */
|
||||
#line 1567 "vm_file_var_syntax.cc" /* yacc.c:1646 */
|
||||
break;
|
||||
|
||||
|
||||
#line 1569 "vm_file_var_syntax.cc" /* yacc.c:1646 */
|
||||
#line 1571 "vm_file_var_syntax.cc" /* yacc.c:1646 */
|
||||
default: break;
|
||||
}
|
||||
/* User semantic actions sometimes alter yychar, and that requires
|
||||
@ -1800,7 +1802,7 @@ yyreturn:
|
||||
#endif
|
||||
return yyresult;
|
||||
}
|
||||
#line 275 "vm_file_var_syntax.y" /* yacc.c:1906 */
|
||||
#line 277 "vm_file_var_syntax.y" /* yacc.c:1906 */
|
||||
|
||||
|
||||
extern "C" void vm_file_var__error(
|
||||
|
@ -62,7 +62,7 @@ extern int vm_file_var__debug;
|
||||
|
||||
union YYSTYPE
|
||||
{
|
||||
#line 206 "vm_file_var_syntax.y" /* yacc.c:1909 */
|
||||
#line 208 "vm_file_var_syntax.y" /* yacc.c:1909 */
|
||||
|
||||
char * val_str;
|
||||
int val_int;
|
||||
|
@ -133,9 +133,11 @@ int get_image_path(VirtualMachine * vm,
|
||||
}
|
||||
else if ( var1 == "IMAGE_ID" )
|
||||
{
|
||||
iid = ImagePool::get_disk_id(val1);
|
||||
istringstream is(val1);
|
||||
|
||||
if ( iid != -1 )
|
||||
is >> iid;
|
||||
|
||||
if ( !is.fail() )
|
||||
{
|
||||
img = ipool->get(iid, true);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user