diff --git a/src/image/Image.cc b/src/image/Image.cc index 800ef4427a..267a8768bb 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -877,52 +877,39 @@ void Image::set_state_unlock() bool Image::test_set_persistent(Template * image_template, int uid, int gid, bool is_allocate) { - string per_tmpl; - bool per, rcb; + Nebula& nd = Nebula::instance(); - rcb = image_template->get("PERSISTENT", per_tmpl); + string per_oned; + string conf_name; - // Not set in image template or empty - if ( rcb == false || per_tmpl.empty() ) + bool persistent; + + if ( is_allocate ) { - Nebula& nd = Nebula::instance(); - - string per_oned; - string conf_name; - - int rc; - - if ( is_allocate ) - { - conf_name = "DEFAULT_IMAGE_PERSISTENT_NEW"; - } - else - { - conf_name = "DEFAULT_IMAGE_PERSISTENT"; - } - - rc = nd.get_configuration_attribute(uid, gid, conf_name, per_oned); - - if ( rc == 0 && one_util::toupper(per_oned) == "YES" ) - { - per = true; - } - else - { - per = false; - } - } - else if ( one_util::toupper(per_tmpl) == "YES" ) - { - per = true; + conf_name = "DEFAULT_IMAGE_PERSISTENT_NEW"; } else { - per = false; + conf_name = "DEFAULT_IMAGE_PERSISTENT"; } - image_template->replace("PERSISTENT", per); + int rc = nd.get_configuration_attribute(uid, gid, conf_name, per_oned); - return per; + if ( rc != 0 || per_oned.empty() ) //No DEFAULT_* defined or empty value + { + image_template->get("PERSISTENT", persistent); + } + else if ( rc == 0 && one_util::toupper(per_oned) == "YES" ) + { + persistent = true; + } + else + { + persistent = false; + } + + image_template->replace("PERSISTENT", persistent); + + return persistent; } diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index c16f8d8fb5..ec93d893b9 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -535,7 +535,7 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params, // ------------------------- Check persistent only ------------------------- - tmpl->get("PERSISTENT", persistent_attr); + persistent_attr = Image::test_set_persistent(tmpl, att.uid, att.gid, true); if ( ds_persistent_only && persistent_attr == false ) { diff --git a/src/rm/RequestManagerImage.cc b/src/rm/RequestManagerImage.cc index baef45b6b8..adfd93b33f 100644 --- a/src/rm/RequestManagerImage.cc +++ b/src/rm/RequestManagerImage.cc @@ -382,6 +382,9 @@ Request::ErrorCode ImageClone::request_execute( img->unlock(); + //Update persistent attribute from base image if needed + Image::test_set_persistent(tmpl, att.uid, att.gid, false); + // ----------------------- Get target Datastore info ----------------------- ds = dspool->get(ds_id, true); @@ -503,7 +506,8 @@ Request::ErrorCode ImageClone::request_execute( // -------------------------- Check Quotas ---------------------------- - if ( quota_authorization(&img_usage, Quotas::DATASTORE, att, att.resp_msg) == false ) + if ( quota_authorization(&img_usage, Quotas::DATASTORE, att, + att.resp_msg) == false ) { delete tmpl; return AUTHORIZATION; diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index 435a41e807..888c824338 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -1449,6 +1449,8 @@ void VirtualMachineDiskSaveas::request_execute( itemplate->add("DEV_PREFIX", dev_prefix); } + Image::test_set_persistent(itemplate, att.uid, att.gid, false); + img_usage.add("SIZE", size); img_usage.add("DATASTORE", ds_id);