mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-23 17:33:56 +03:00
feature #622: Added PERSISTENT tag to DISKs based in persistent IMAGES. New method to setup auth requests for virtual machine templates.
This commit is contained in:
parent
0a13288330
commit
437a01a2c6
@ -134,7 +134,6 @@ public:
|
||||
const string& name,
|
||||
vector<Attribute *>& values);
|
||||
|
||||
|
||||
/**
|
||||
* Removes an attribute from the template, and frees the attributes.
|
||||
* @param name of the attribute
|
||||
|
@ -73,15 +73,6 @@ public:
|
||||
{
|
||||
return new VirtualMachineTemplate(
|
||||
*(static_cast<VirtualMachineTemplate *>(obj_template)));
|
||||
|
||||
// TODO: Check if there is a more efficient way to do this copy.
|
||||
/*string xml_str;
|
||||
VirtualMachineTemplate * new_template = new VirtualMachineTemplate();
|
||||
|
||||
obj_template->to_xml(xml_str);
|
||||
new_template->from_xml(xml_str);
|
||||
|
||||
return new_template;*/
|
||||
};
|
||||
|
||||
private:
|
||||
|
@ -28,6 +28,8 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class AuthRequest;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@ -657,6 +659,19 @@ public:
|
||||
*/
|
||||
int save_disk(int disk_id, int img_id, string& error_str);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Authorization related functions
|
||||
// ------------------------------------------------------------------------
|
||||
/**
|
||||
* Sets an authorization request for a VirtualMachine template based on
|
||||
* the images and networks used
|
||||
* @param uid for template owner
|
||||
* @param ar the AuthRequest object
|
||||
* @param tmpl the virtual machine template
|
||||
*/
|
||||
static void set_auth_request(int uid,
|
||||
AuthRequest& ar,
|
||||
VirtualMachineTemplate *tmpl);
|
||||
private:
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
@ -457,6 +457,7 @@ int Image::disk_attribute( VectorAttribute * disk,
|
||||
{
|
||||
disk->replace("CLONE","NO");
|
||||
disk->replace("SAVE","YES");
|
||||
disk->replace("PERSISTENT","YES");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -227,6 +227,7 @@ void RequestManager::register_xml_methods()
|
||||
xmlrpc_c::methodPtr vn_rmleases(new VirtualNetworkRemoveLeases());
|
||||
|
||||
// Allocate Methods
|
||||
xmlrpc_c::methodPtr vm_allocate(new VirtualMachineAllocate());
|
||||
xmlrpc_c::methodPtr image_allocate(new ImageAllocate());
|
||||
xmlrpc_c::methodPtr vn_allocate(new VirtualNetworkAllocate());
|
||||
xmlrpc_c::methodPtr group_allocate(new GroupAllocate());
|
||||
@ -273,9 +274,7 @@ void RequestManager::register_xml_methods()
|
||||
xmlrpc_c::methodPtr vnpool_info(new VirtualNetworkPoolInfo());
|
||||
xmlrpc_c::methodPtr imagepool_info(new ImagePoolInfo());
|
||||
|
||||
/* xmlrpc_c::methodPtr vm_allocate(new
|
||||
RequestManager::VirtualMachineAllocate(vmpool,vnpool,ipool,tpool,upool));
|
||||
|
||||
/*
|
||||
xmlrpc_c::methodPtr vm_deploy(new
|
||||
RequestManager::VirtualMachineDeploy(vmpool,hpool,upool));
|
||||
|
||||
@ -361,13 +360,13 @@ void RequestManager::register_xml_methods()
|
||||
*/
|
||||
/* VM related methods */
|
||||
/*
|
||||
RequestManagerRegistry.addMethod("one.vm.allocate", vm_allocate);
|
||||
RequestManagerRegistry.addMethod("one.vm.deploy", vm_deploy);
|
||||
RequestManagerRegistry.addMethod("one.vm.action", vm_action);
|
||||
RequestManagerRegistry.addMethod("one.vm.migrate", vm_migrate);
|
||||
RequestManagerRegistry.addMethod("one.vm.savedisk", vm_savedisk);
|
||||
RequestManagerRegistry.addMethod("one.vm.chown", vm_chown);
|
||||
*/
|
||||
RequestManagerRegistry.addMethod("one.vm.allocate", vm_allocate);
|
||||
RequestManagerRegistry.addMethod("one.vm.info", vm_info);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.vmpool.info", vm_pool_info);
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include "VirtualMachine.h"
|
||||
#include "VirtualNetworkPool.h"
|
||||
#include "ImagePool.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
#include "Nebula.h"
|
||||
@ -987,6 +988,11 @@ int VirtualMachine::save_disk(int disk_id, int img_id, string& error_str)
|
||||
goto error_saved;
|
||||
}
|
||||
|
||||
if(!((disk->vector_value("PERSISTENT")).empty()))
|
||||
{
|
||||
goto error_persistent;
|
||||
}
|
||||
|
||||
disk->replace("SAVE", "YES");
|
||||
|
||||
oss << (img_id);
|
||||
@ -998,8 +1004,12 @@ int VirtualMachine::save_disk(int disk_id, int img_id, string& error_str)
|
||||
|
||||
goto error_not_found;
|
||||
|
||||
error_persistent:
|
||||
oss << "Source image for DISK " << disk_id << " is persistent.";
|
||||
goto error_common;
|
||||
|
||||
error_saved:
|
||||
oss << "The DISK " << disk_id << " is already suppossed to be saved.";
|
||||
oss << "The DISK " << disk_id << " is already going to be saved.";
|
||||
goto error_common;
|
||||
|
||||
error_not_found:
|
||||
@ -1015,6 +1025,54 @@ error_common:
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachine::set_auth_request(int uid,
|
||||
AuthRequest& ar,
|
||||
VirtualMachineTemplate *tmpl)
|
||||
{
|
||||
int num;
|
||||
vector<Attribute * > vectors;
|
||||
VectorAttribute * vector;
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
ImagePool * ipool = nd.get_ipool();
|
||||
VirtualNetworkPool * vnpool = nd.get_vnpool();
|
||||
|
||||
num = tmpl->get("DISK",vectors);
|
||||
|
||||
for(int i=0; i<num; i++)
|
||||
{
|
||||
|
||||
vector = dynamic_cast<VectorAttribute * >(vectors[i]);
|
||||
|
||||
if ( vector == 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ipool->authorize_disk(vector,uid,&ar);
|
||||
}
|
||||
|
||||
vectors.clear();
|
||||
|
||||
num = tmpl->get("NIC",vectors);
|
||||
|
||||
for(int i=0; i<num; i++)
|
||||
{
|
||||
vector = dynamic_cast<VectorAttribute * >(vectors[i]);
|
||||
|
||||
if ( vector == 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
vnpool->authorize_nic(vector,uid,&ar);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
pthread_mutex_t VirtualMachine::lex_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
extern "C"
|
||||
|
Loading…
Reference in New Issue
Block a user