From 437a01a2c625b53b4daeed94c6925345c31cc2a7 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Wed, 1 Jun 2011 12:41:46 +0200 Subject: [PATCH] feature #622: Added PERSISTENT tag to DISKs based in persistent IMAGES. New method to setup auth requests for virtual machine templates. --- include/Template.h | 1 - include/VMTemplate.h | 9 ------ include/VirtualMachine.h | 15 ++++++++++ src/image/Image.cc | 1 + src/rm/RequestManager.cc | 7 ++--- src/vm/VirtualMachine.cc | 60 +++++++++++++++++++++++++++++++++++++++- 6 files changed, 78 insertions(+), 15 deletions(-) diff --git a/include/Template.h b/include/Template.h index 2c623ffb42..3d74d6f3e7 100644 --- a/include/Template.h +++ b/include/Template.h @@ -134,7 +134,6 @@ public: const string& name, vector& values); - /** * Removes an attribute from the template, and frees the attributes. * @param name of the attribute diff --git a/include/VMTemplate.h b/include/VMTemplate.h index 50a8283147..4955affc84 100644 --- a/include/VMTemplate.h +++ b/include/VMTemplate.h @@ -73,15 +73,6 @@ public: { return new VirtualMachineTemplate( *(static_cast(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: diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index b6482cc683..f8a27e5c67 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -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: // ------------------------------------------------------------------------- diff --git a/src/image/Image.cc b/src/image/Image.cc index 3f1fa179a6..6a7a1dcbde 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -457,6 +457,7 @@ int Image::disk_attribute( VectorAttribute * disk, { disk->replace("CLONE","NO"); disk->replace("SAVE","YES"); + disk->replace("PERSISTENT","YES"); } else { diff --git a/src/rm/RequestManager.cc b/src/rm/RequestManager.cc index 033f61d79a..20ff730e63 100644 --- a/src/rm/RequestManager.cc +++ b/src/rm/RequestManager.cc @@ -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); diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index f800e8522f..b636a6d456 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -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 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(vectors[i]); + + if ( vector == 0 ) + { + continue; + } + + ipool->authorize_disk(vector,uid,&ar); + } + + vectors.clear(); + + num = tmpl->get("NIC",vectors); + + for(int i=0; i(vectors[i]); + + if ( vector == 0 ) + { + continue; + } + + vnpool->authorize_nic(vector,uid,&ar); + } +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + pthread_mutex_t VirtualMachine::lex_mutex = PTHREAD_MUTEX_INITIALIZER; extern "C"