mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-26 06:50:09 +03:00
feature #203: Removed Auth from allocate (VM, IMAGE & NET). Added NETWORK and NETWORK_ID for NICs and IMAGE and IMAGE_ID for DISKS
This commit is contained in:
parent
9ed94ae7f4
commit
1035fe7722
@ -29,8 +29,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class AuthRequest;
|
||||
|
||||
/**
|
||||
* The Image Pool class.
|
||||
*/
|
||||
@ -170,7 +168,7 @@ public:
|
||||
* @param disk the disk to be generated
|
||||
* @return 0 on success, -1 error, -2 not using the pool
|
||||
*/
|
||||
int disk_attribute(VectorAttribute * disk, int * index, AuthRequest * ar);
|
||||
int disk_attribute(VectorAttribute * disk, int * index);
|
||||
|
||||
static const string& source_prefix()
|
||||
{
|
||||
|
@ -31,8 +31,6 @@ using namespace std;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
class AuthRequest;
|
||||
|
||||
/**
|
||||
* The Virtual Machine class. It represents a VM...
|
||||
*/
|
||||
@ -704,7 +702,7 @@ public:
|
||||
* Get all network leases for this Virtual Machine
|
||||
* @return 0 if success
|
||||
*/
|
||||
int get_network_leases(AuthRequest *ar);
|
||||
int get_network_leases();
|
||||
|
||||
/**
|
||||
* Releases all network leases taken by this Virtual Machine
|
||||
@ -715,7 +713,7 @@ public:
|
||||
* Get all disk images for this Virtual Machine
|
||||
* @return 0 if success
|
||||
*/
|
||||
int get_disk_images(AuthRequest *ar);
|
||||
int get_disk_images();
|
||||
|
||||
/**
|
||||
* Releases all disk images taken by this Virtual Machine
|
||||
|
@ -24,8 +24,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class AuthRequest;
|
||||
|
||||
/**
|
||||
* The Virtual Network Pool class. ...
|
||||
*/
|
||||
@ -88,7 +86,7 @@ public:
|
||||
* @param vid of the VM requesting the lease
|
||||
* @return 0 on success, -1 error, -2 not using the pool
|
||||
*/
|
||||
int nic_attribute(VectorAttribute * nic, int vid, AuthRequest *ar);
|
||||
int nic_attribute(VectorAttribute * nic, int vid);
|
||||
|
||||
/**
|
||||
* Updates the template of a VN, adding a new attribute (replacing it if
|
||||
|
@ -210,27 +210,6 @@ int Image::insert(SqlDB *db)
|
||||
|
||||
source = tmp_sourcestream.str();
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Authorize this request
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( uid != 0 ) // uid == 0 means oneadmin
|
||||
{
|
||||
string t64;
|
||||
AuthRequest ar(uid);
|
||||
|
||||
ar.add_auth(AuthRequest::IMAGE,
|
||||
image_template.to_xml(t64),
|
||||
AuthRequest::CREATE,
|
||||
uid,
|
||||
public_img);
|
||||
|
||||
if (UserPool::authorize(ar) == -1)
|
||||
{
|
||||
goto error_authorize;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------ INSERT THE TEMPLATE --------------------
|
||||
|
||||
if ( image_template.id == -1 )
|
||||
@ -270,10 +249,6 @@ error_type:
|
||||
NebulaLog::log("IMG", Log::ERROR, "Incorrect TYPE in image template");
|
||||
goto error_common;
|
||||
|
||||
error_authorize:
|
||||
NebulaLog::log("IMG", Log::ERROR, "Error authorizing Image creation");
|
||||
goto error_common;
|
||||
|
||||
error_common:
|
||||
return -1;
|
||||
}
|
||||
@ -560,12 +535,10 @@ int Image::disk_attribute(VectorAttribute * disk, int * index)
|
||||
{
|
||||
string overwrite;
|
||||
string saveas;
|
||||
string name;
|
||||
string bus;
|
||||
|
||||
ostringstream iid;
|
||||
|
||||
name = disk->vector_value("NAME");
|
||||
overwrite = disk->vector_value("OVERWRITE");
|
||||
saveas = disk->vector_value("SAVE_AS");
|
||||
bus = disk->vector_value("BUS");
|
||||
@ -595,10 +568,9 @@ int Image::disk_attribute(VectorAttribute * disk, int * index)
|
||||
|
||||
map<string,string> new_disk;
|
||||
|
||||
new_disk.insert(make_pair("NAME",name));
|
||||
new_disk.insert(make_pair("IID", iid.str()));
|
||||
|
||||
new_disk.insert(make_pair("SOURCE", source));
|
||||
new_disk.insert(make_pair("IMAGE", name));
|
||||
new_disk.insert(make_pair("IMAGE_ID", iid.str()));
|
||||
new_disk.insert(make_pair("SOURCE", source));
|
||||
|
||||
if (!overwrite.empty())
|
||||
{
|
||||
|
@ -19,7 +19,6 @@
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ImagePool.h"
|
||||
#include "AuthManager.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -190,20 +189,37 @@ int ImagePool::dump(ostringstream& oss, const string& where)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ImagePool::disk_attribute(VectorAttribute * disk,
|
||||
int * index,
|
||||
AuthRequest * ar)
|
||||
int * index)
|
||||
{
|
||||
string source;
|
||||
Image * img;
|
||||
Image * img = 0;
|
||||
|
||||
source = disk->vector_value("NAME");
|
||||
source = disk->vector_value("IMAGE");
|
||||
|
||||
if (source.empty())
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
istringstream is;
|
||||
int image_id;
|
||||
|
||||
img = get(source,true);
|
||||
source = disk->vector_value("IMAGE_ID");
|
||||
|
||||
if (source.empty())
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
|
||||
is.str(source);
|
||||
is >> image_id;
|
||||
|
||||
if( !is.fail() )
|
||||
{
|
||||
img = get(image_id,true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
img = get(source,true);
|
||||
}
|
||||
|
||||
if (img == 0)
|
||||
{
|
||||
@ -212,12 +228,6 @@ int ImagePool::disk_attribute(VectorAttribute * disk,
|
||||
|
||||
int rc = img->disk_attribute(disk,index);
|
||||
|
||||
ar->add_auth(AuthRequest::IMAGE,
|
||||
img->get_iid(),
|
||||
AuthRequest::USE,
|
||||
img->get_uid(),
|
||||
img->isPublic());
|
||||
|
||||
img->unlock();
|
||||
|
||||
return rc;
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "VirtualMachine.h"
|
||||
#include "VirtualNetworkPool.h"
|
||||
#include "NebulaLog.h"
|
||||
#include "AuthManager.h"
|
||||
|
||||
#include "Nebula.h"
|
||||
|
||||
@ -268,8 +267,6 @@ int VirtualMachine::insert(SqlDB * db)
|
||||
string value;
|
||||
ostringstream oss;
|
||||
|
||||
AuthRequest ar(uid);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Set a template ID if it wasn't already assigned
|
||||
// ------------------------------------------------------------------------
|
||||
@ -306,7 +303,7 @@ int VirtualMachine::insert(SqlDB * db)
|
||||
// Get network leases
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
rc = get_network_leases(&ar);
|
||||
rc = get_network_leases();
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
@ -317,7 +314,7 @@ int VirtualMachine::insert(SqlDB * db)
|
||||
// Get disk images
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
rc = get_disk_images(&ar);
|
||||
rc = get_disk_images();
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
@ -344,26 +341,6 @@ int VirtualMachine::insert(SqlDB * db)
|
||||
|
||||
parse_graphics();
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Authorize this request
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( uid != 0 ) // uid == 0 means oneadmin
|
||||
{
|
||||
string t64;
|
||||
|
||||
ar.add_auth(AuthRequest::VM,
|
||||
vm_template.to_xml(t64),
|
||||
AuthRequest::CREATE,
|
||||
uid,
|
||||
false);
|
||||
|
||||
if (UserPool::authorize(ar) == -1)
|
||||
{
|
||||
goto error_authorize;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Insert the template first, so we get a valid template ID. Then the VM
|
||||
// ------------------------------------------------------------------------
|
||||
@ -410,9 +387,6 @@ error_requirements:
|
||||
NebulaLog::log("ONE",Log::ERROR, "Could not parse REQUIREMENTS for VM");
|
||||
goto error_common;
|
||||
|
||||
error_authorize:
|
||||
NebulaLog::log("ONE",Log::ERROR, "Error authorizing VM creation");
|
||||
|
||||
error_common:
|
||||
release_network_leases();
|
||||
release_disk_images();
|
||||
@ -819,7 +793,7 @@ void VirtualMachine::get_requirements (int& cpu, int& memory, int& disk)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachine::get_disk_images(AuthRequest *ar)
|
||||
int VirtualMachine::get_disk_images()
|
||||
{
|
||||
int num_disks, rc;
|
||||
vector<Attribute * > disks;
|
||||
@ -841,7 +815,7 @@ int VirtualMachine::get_disk_images(AuthRequest *ar)
|
||||
continue;
|
||||
}
|
||||
|
||||
rc = ipool->disk_attribute(disk, &index, ar);
|
||||
rc = ipool->disk_attribute(disk, &index);
|
||||
|
||||
if (rc == -1) // 0 OK, -2 not using the Image pool
|
||||
{
|
||||
@ -879,7 +853,7 @@ void VirtualMachine::release_disk_images()
|
||||
continue;
|
||||
}
|
||||
|
||||
iid = disk->vector_value("IID");
|
||||
iid = disk->vector_value("IMAGE_ID");
|
||||
|
||||
if ( iid.empty() )
|
||||
{
|
||||
@ -902,7 +876,7 @@ void VirtualMachine::release_disk_images()
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachine::get_network_leases(AuthRequest *ar)
|
||||
int VirtualMachine::get_network_leases()
|
||||
{
|
||||
int num_nics, rc;
|
||||
vector<Attribute * > nics;
|
||||
@ -923,7 +897,7 @@ int VirtualMachine::get_network_leases(AuthRequest *ar)
|
||||
continue;
|
||||
}
|
||||
|
||||
rc = vnpool->nic_attribute(nic, oid, ar);
|
||||
rc = vnpool->nic_attribute(nic, oid);
|
||||
|
||||
if (rc == -1)
|
||||
{
|
||||
@ -962,7 +936,7 @@ void VirtualMachine::release_network_leases()
|
||||
continue;
|
||||
}
|
||||
|
||||
vnid = nic->vector_value("VNID");
|
||||
vnid = nic->vector_value("NETWORK_ID");
|
||||
|
||||
if ( vnid.empty() )
|
||||
{
|
||||
|
@ -317,27 +317,6 @@ int VirtualNetwork::insert(SqlDB * db)
|
||||
|
||||
vn_template.erase("PUBLIC");
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Authorize this request
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( uid != 0 ) // uid == 0 means oneadmin
|
||||
{
|
||||
string t64;
|
||||
AuthRequest ar(uid);
|
||||
|
||||
ar.add_auth(AuthRequest::NET,
|
||||
vn_template.to_xml(t64),
|
||||
AuthRequest::CREATE,
|
||||
uid,
|
||||
public_vnet);
|
||||
|
||||
if (UserPool::authorize(ar) == -1)
|
||||
{
|
||||
goto error_authorize;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------ INSERT THE TEMPLATE --------------------
|
||||
|
||||
if ( vn_template.id == -1 )
|
||||
@ -440,10 +419,6 @@ error_bridge:
|
||||
ose << "No BRIDGE in template for Virtual Network id " << oid;
|
||||
goto error_common;
|
||||
|
||||
error_authorize:
|
||||
ose << "Error authorizing Virtual Network creation";
|
||||
goto error_common;
|
||||
|
||||
error_template:
|
||||
ose << "Can not insert in DB template for Virtual Network id " << oid;
|
||||
goto error_common;
|
||||
@ -640,7 +615,6 @@ int VirtualNetwork::nic_attribute(VectorAttribute *nic, int vid)
|
||||
{
|
||||
int rc;
|
||||
|
||||
string network;
|
||||
string model;
|
||||
string ip;
|
||||
string mac;
|
||||
@ -649,7 +623,6 @@ int VirtualNetwork::nic_attribute(VectorAttribute *nic, int vid)
|
||||
|
||||
map<string,string> new_nic;
|
||||
|
||||
network = nic->vector_value("NETWORK");
|
||||
model = nic->vector_value("MODEL");
|
||||
ip = nic->vector_value("IP");
|
||||
vnid << oid;
|
||||
@ -676,11 +649,11 @@ int VirtualNetwork::nic_attribute(VectorAttribute *nic, int vid)
|
||||
// NEW NIC ATTRIBUTES
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
new_nic.insert(make_pair("NETWORK",network));
|
||||
new_nic.insert(make_pair("MAC" ,mac));
|
||||
new_nic.insert(make_pair("BRIDGE" ,bridge));
|
||||
new_nic.insert(make_pair("VNID" ,vnid.str()));
|
||||
new_nic.insert(make_pair("IP" ,ip));
|
||||
new_nic.insert(make_pair("NETWORK" ,name));
|
||||
new_nic.insert(make_pair("MAC" ,mac));
|
||||
new_nic.insert(make_pair("BRIDGE" ,bridge));
|
||||
new_nic.insert(make_pair("NETWORK_ID",vnid.str()));
|
||||
new_nic.insert(make_pair("IP" ,ip));
|
||||
|
||||
if (!model.empty())
|
||||
{
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
#include "VirtualNetworkPool.h"
|
||||
#include "NebulaLog.h"
|
||||
#include "AuthManager.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <ctype.h>
|
||||
@ -220,20 +219,39 @@ int VirtualNetworkPool::dump(ostringstream& oss, const string& where)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualNetworkPool::nic_attribute(VectorAttribute * nic,
|
||||
int vid,
|
||||
AuthRequest * ar)
|
||||
int vid)
|
||||
{
|
||||
string network;
|
||||
VirtualNetwork * vnet;
|
||||
VirtualNetwork * vnet = 0;
|
||||
|
||||
network = nic->vector_value("NETWORK");
|
||||
|
||||
if (network.empty())
|
||||
{
|
||||
istringstream is;
|
||||
int network_id;
|
||||
|
||||
network = nic->vector_value("NETWORK_ID");
|
||||
|
||||
if(network.empty())
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
|
||||
is.str(network);
|
||||
is >> network_id;
|
||||
|
||||
if( !is.fail() )
|
||||
{
|
||||
vnet = get(network_id,true);
|
||||
}
|
||||
|
||||
return -2;
|
||||
}
|
||||
|
||||
vnet = get(network,true);
|
||||
else
|
||||
{
|
||||
vnet = get(network,true);
|
||||
}
|
||||
|
||||
if (vnet == 0)
|
||||
{
|
||||
@ -242,13 +260,8 @@ int VirtualNetworkPool::nic_attribute(VectorAttribute * nic,
|
||||
|
||||
int rc = vnet->nic_attribute(nic,vid);
|
||||
|
||||
ar->add_auth(AuthRequest::NET,
|
||||
vnet->get_vnid(),
|
||||
AuthRequest::USE,
|
||||
vnet->get_uid(),
|
||||
vnet->isPublic());
|
||||
|
||||
vnet->unlock();
|
||||
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user