From 8a4135faafc1d8b5e8ab34af8c8e533e3d1981ab Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Tue, 26 Jan 2016 20:46:45 +0100 Subject: [PATCH] Feature #4217: Add extra_data to the register and clone operations --- include/ImageManager.h | 8 +++++++- src/image/ImageManagerActions.cc | 10 +++++++--- src/image/ImagePool.cc | 14 ++++++++++++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/include/ImageManager.h b/include/ImageManager.h index e0acf44ddd..755d50b655 100644 --- a/include/ImageManager.h +++ b/include/ImageManager.h @@ -133,11 +133,15 @@ public: * Adds a new image to the repository copying or creating it as needed * @param img pointer to the image * @param ds_data data of the associated datastore in XML format + * @param extra_data data to be sent to the driver * @param error Error reason * * @return 0 on success */ - int register_image(int iid, const string& ds_data, string& error); + int register_image(int iid, + const string& ds_data, + const string& extra_data, + string& error); /** * Checks if an image is ready to be cloned @@ -163,12 +167,14 @@ public: * @param new_id of the new image * @param cloning_id of the image to be cloned * @param ds_data data of the associated datastore in XML format + * @param extra_data data to be sent to the driver * @param error describing the error * @return 0 on success */ int clone_image(int new_id, int cloning_id, const string& ds_data, + const string& extra_data, string& error); /** * Deletes an image from the repository and the DB. The Datastore image list diff --git a/src/image/ImageManagerActions.cc b/src/image/ImageManagerActions.cc index c451de5fcd..25bf7d2c30 100644 --- a/src/image/ImageManagerActions.cc +++ b/src/image/ImageManagerActions.cc @@ -658,6 +658,7 @@ int ImageManager::set_clone_state(int new_id, int cloning_id, std::string& error int ImageManager::clone_image(int new_id, int cloning_id, const string& ds_data, + const string& extra_data, string& error) { const ImageManagerDriver* imd = get(); @@ -692,7 +693,7 @@ int ImageManager::clone_image(int new_id, return -1; } - drv_msg = format_message(img->to_xml(img_tmpl), ds_data, ""); + drv_msg = format_message(img->to_xml(img_tmpl), ds_data, extra_data); imd->clone(img->get_oid(), *drv_msg); @@ -711,7 +712,10 @@ int ImageManager::clone_image(int new_id, /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int ImageManager::register_image(int iid, const string& ds_data, string& error) +int ImageManager::register_image(int iid, + const string& ds_data, + const string& extra_data, + string& error) { const ImageManagerDriver* imd = get(); @@ -738,7 +742,7 @@ int ImageManager::register_image(int iid, const string& ds_data, string& error) return -1; } - drv_msg = format_message(img->to_xml(img_tmpl), ds_data, ""); + drv_msg = format_message(img->to_xml(img_tmpl), ds_data, extra_data); path = img->get_path(); if ( path.empty() == true ) //NO PATH diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index 5900707160..57671186cb 100644 --- a/src/image/ImagePool.cc +++ b/src/image/ImagePool.cc @@ -103,6 +103,8 @@ int ImagePool::allocate ( string type; ostringstream oss; + int rc; + img = new Image(uid, gid, uname, gname, umask, img_template); // ------------------------------------------------------------------------- @@ -169,7 +171,9 @@ int ImagePool::allocate ( { if (cloning_id == -1) { - if ( imagem->register_image(*oid, ds_data, error_str) == -1 ) + rc = imagem->register_image(*oid, ds_data, extra_data, error_str); + + if ( rc == -1 ) { img = get(*oid, true); @@ -188,7 +192,13 @@ int ImagePool::allocate ( } else { - if (imagem->clone_image(*oid, cloning_id, ds_data, error_str) == -1) + rc = imagem->clone_image(*oid, + cloning_id, + ds_data, + extra_data, + error_str); + + if (rc == -1) { img = get(*oid, true);