diff --git a/include/Image.h b/include/Image.h index ecbeadf6e4..6d3721cc22 100644 --- a/include/Image.h +++ b/include/Image.h @@ -191,6 +191,18 @@ public: return (persistent_img == 1); }; + bool is_managed() const + { + bool one_managed; + + if (get_template_attribute("OPENNEBULA_MANAGED", one_managed) == false) + { + one_managed = true; + } + + return one_managed; + } + /** * Check the PERSISTENT attribute in an image Template, if not set the * DEFAULT_IMAGE_PERSISTENT and DEFAULT_IMAGE_PERSISTENT_NEW are check in diff --git a/include/VirtualMachineDisk.h b/include/VirtualMachineDisk.h index 87194cfa3f..9494dbb5f0 100644 --- a/include/VirtualMachineDisk.h +++ b/include/VirtualMachineDisk.h @@ -52,6 +52,18 @@ public: return is_flag("PERSISTENT"); } + bool is_managed() const + { + bool one_managed; + + if (vector_value("OPENNEBULA_MANAGED", one_managed) == -1) + { + one_managed = true; + } + + return one_managed; + } + void set_attach() { set_flag("ATTACH"); diff --git a/src/rm/RequestManagerClone.cc b/src/rm/RequestManagerClone.cc index 90b3db1728..105f2aedaa 100644 --- a/src/rm/RequestManagerClone.cc +++ b/src/rm/RequestManagerClone.cc @@ -198,17 +198,20 @@ Request::ErrorCode VMTemplateClone::clone(int source_id, const string &name, goto error_images; } - ec = img_persistent.request_execute(new_img_id, true, img_att); - - if (ec != SUCCESS) + if ( (*disk)->is_managed() ) { - NebulaLog::log("ReM", Log::ERROR, failure_message(ec, img_att)); + ec = img_persistent.request_execute(new_img_id, true, img_att); - img_delete.request_execute(img_id, img_att); + if (ec != SUCCESS) + { + NebulaLog::log("ReM",Log::ERROR,failure_message(ec,img_att)); - att.resp_msg = "Failed to clone images: " + img_att.resp_msg; + img_delete.request_execute(img_id, img_att); - goto error_images; + att.resp_msg = "Failed to clone images: " + img_att.resp_msg; + + goto error_images; + } } (*disk)->remove("IMAGE"); diff --git a/src/rm/RequestManagerImage.cc b/src/rm/RequestManagerImage.cc index 99ff2776ae..c0d613d57c 100644 --- a/src/rm/RequestManagerImage.cc +++ b/src/rm/RequestManagerImage.cc @@ -118,6 +118,15 @@ Request::ErrorCode ImagePersistent::request_execute( ds_id = image->get_ds_id(); + if ( !image->is_managed() ) + { + att.resp_msg = "Cannot change persistent state for non-managed images"; + + image->unlock(); + + return ACTION; + } + image->unlock(); ds = dspool->get(ds_id, true);