F #5058: Test and set persistent attribute in one.image.create

one.image.clone and one.vm.disksaveas
This commit is contained in:
Ruben S. Montero committed 2017-03-15 17:17:07 +01:00
1 parent 92312dc50f
commit 4197718d13
4 files changed
+33 -40

No files matched your search

+25 -38
View File
@@ -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;
}
+1 -1
View File
@@ -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 )
{
+5 -1
View File
@@ -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;
+2
View File
@@ -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);