mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-22 22:03:39 +03:00
F #4393: Move authorize disk to VirtualMachineDisk class
This commit is contained in:
parent
9297321d91
commit
71e7b3dc20
@ -178,13 +178,6 @@ public:
|
||||
void disk_attribute(VirtualMachineDisk* disk,
|
||||
int disk_id,
|
||||
int uid);
|
||||
/**
|
||||
* Generates an Authorization token for the DISK attribute
|
||||
* @param disk the disk to be authorized
|
||||
* @param uid of owner (to look for the image id within her images)
|
||||
* @param ar the AuthRequest
|
||||
*/
|
||||
void authorize_disk(VirtualMachineDisk * disk, int uid, AuthRequest * ar);
|
||||
|
||||
static const string& default_type()
|
||||
{
|
||||
|
@ -23,6 +23,8 @@
|
||||
#include "VirtualMachineAttribute.h"
|
||||
#include "Snapshots.h"
|
||||
|
||||
class AuthRequest;
|
||||
|
||||
/**
|
||||
* The VirtualMachine DISK attribute
|
||||
*/
|
||||
@ -132,6 +134,14 @@ public:
|
||||
*/
|
||||
void extended_info(int uid);
|
||||
|
||||
/**
|
||||
* Fills the authorization request for this disk based on its Image use
|
||||
* requirements
|
||||
* @param uid of user making the request
|
||||
* @param ar auth request
|
||||
*/
|
||||
void authorize(int uid, AuthRequest* ar);
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Snapshots Interface */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
@ -510,48 +510,3 @@ void ImagePool::disk_attribute(
|
||||
disk->replace("DISK_ID", disk_id);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void ImagePool::authorize_disk(VirtualMachineDisk* disk,int uid,AuthRequest* ar)
|
||||
{
|
||||
string source;
|
||||
Image * img = 0;
|
||||
|
||||
int iid;
|
||||
|
||||
PoolObjectAuth perm;
|
||||
|
||||
if ( disk->vector_value("IMAGE", source) == 0 )
|
||||
{
|
||||
int uiid = disk->get_uid(uid);
|
||||
|
||||
if ( uiid == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
img = get(source , uiid, true);
|
||||
|
||||
if ( img != 0 )
|
||||
{
|
||||
disk->replace("IMAGE_ID", img->get_oid());
|
||||
}
|
||||
}
|
||||
else if ( disk->vector_value("IMAGE_ID", iid) == 0 )
|
||||
{
|
||||
img = get(iid, true);
|
||||
}
|
||||
|
||||
if (img == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
img->get_permissions(perm);
|
||||
|
||||
img->unlock();
|
||||
|
||||
ar->add_auth(AuthRequest::USE, perm);
|
||||
}
|
||||
|
||||
|
@ -3072,7 +3072,6 @@ void VirtualMachine::set_auth_request(int uid,
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
ImagePool * ipool = nd.get_ipool();
|
||||
VirtualNetworkPool * vnpool = nd.get_vnpool();
|
||||
SecurityGroupPool * sgpool = nd.get_secgrouppool();
|
||||
|
||||
@ -3081,7 +3080,7 @@ void VirtualMachine::set_auth_request(int uid,
|
||||
|
||||
for( disk = disks.begin(); disk != disks.end(); ++disk)
|
||||
{
|
||||
ipool->authorize_disk(*disk, uid, &ar);
|
||||
(*disk)->authorize(uid, &ar);
|
||||
}
|
||||
|
||||
vectors.clear();
|
||||
|
@ -31,6 +31,7 @@ bool VirtualMachineDisk::is_volatile() const
|
||||
return ( type == "SWAP" || type == "FS");
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string VirtualMachineDisk::get_tm_target() const
|
||||
{
|
||||
@ -54,6 +55,8 @@ string VirtualMachineDisk::get_tm_target() const
|
||||
return one_util::toupper(target);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachineDisk::get_uid(int _uid)
|
||||
{
|
||||
istringstream is;
|
||||
@ -97,7 +100,6 @@ int VirtualMachineDisk::get_uid(int _uid)
|
||||
return uid;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachineDisk::get_image_id(int &id, int uid)
|
||||
@ -148,6 +150,53 @@ void VirtualMachineDisk::extended_info(int uid)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachineDisk::authorize(int uid, AuthRequest* ar)
|
||||
{
|
||||
string source;
|
||||
Image * img = 0;
|
||||
|
||||
int iid;
|
||||
|
||||
PoolObjectAuth perm;
|
||||
|
||||
ImagePool * ipool = Nebula::instance().get_ipool();
|
||||
|
||||
if ( vector_value("IMAGE", source) == 0 )
|
||||
{
|
||||
int uiid = get_uid(uid);
|
||||
|
||||
if ( uiid == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
img = ipool->get(source , uiid, true);
|
||||
|
||||
if ( img != 0 )
|
||||
{
|
||||
replace("IMAGE_ID", img->get_oid());
|
||||
}
|
||||
}
|
||||
else if ( vector_value("IMAGE_ID", iid) == 0 )
|
||||
{
|
||||
img = ipool->get(iid, true);
|
||||
}
|
||||
|
||||
if (img == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
img->get_permissions(perm);
|
||||
|
||||
img->unlock();
|
||||
|
||||
ar->add_auth(AuthRequest::USE, perm);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachineDisk::create_snapshot(const string& name, string& error)
|
||||
{
|
||||
long long size_mb, snap_size;
|
||||
@ -267,6 +316,15 @@ void VirtualMachineDisk::delete_snapshot(int snap_id, Template **ds_quotas,
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* VIRTUALMACHINEDISKS */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user