1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

F #4090: Inherit vector values (#560)

Vector attributes are merged with DISK/NIC attribute
This commit is contained in:
Pavel Czerný 2021-01-04 17:14:46 +01:00 committed by GitHub
parent ea89a41c6f
commit 1c3bda1d49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 17 deletions

View File

@ -154,13 +154,31 @@ void Datastore::disk_attribute(
for (const auto& inherit : inherit_attrs)
{
current_val = disk->vector_value(inherit);
get_template_attribute(inherit, inherit_val);
if ( current_val.empty() && !inherit_val.empty() )
if (auto va = PoolObjectSQL::get_template_attribute(inherit))
{
disk->replace(inherit, inherit_val);
// Vector attribute, inherit all its values
const auto& values = va->value();
for (const auto& val : values)
{
string current_val = disk->vector_value(val.first);
if (current_val.empty() && !val.second.empty())
{
disk->replace(val.first, val.second);
}
}
}
else
{
// Simple attribute, inherit value
string current_val = disk->vector_value(inherit);
PoolObjectSQL::get_template_attribute(inherit, inherit_val);
if (current_val.empty() && !inherit_val.empty())
{
disk->replace(inherit, inherit_val);
}
}
}

View File

@ -678,12 +678,31 @@ void Image::disk_attribute(VirtualMachineDisk * disk,
for (const auto& inherit : inherit_attrs)
{
string current_val = disk->vector_value(inherit);
get_template_attribute(inherit, inherit_val);
if (current_val.empty() && !inherit_val.empty())
if (auto va = PoolObjectSQL::get_template_attribute(inherit))
{
disk->replace(inherit, inherit_val);
// Vector attribute, inherit all its values
const auto& values = va->value();
for (const auto& val : values)
{
string current_val = disk->vector_value(val.first);
if (current_val.empty() && !val.second.empty())
{
disk->replace(val.first, val.second);
}
}
}
else
{
// Simple attribute, inherit value
string current_val = disk->vector_value(inherit);
PoolObjectSQL::get_template_attribute(inherit, inherit_val);
if (current_val.empty() && !inherit_val.empty())
{
disk->replace(inherit, inherit_val);
}
}
}
}

View File

@ -882,14 +882,33 @@ int VirtualNetwork::nic_attribute(
inherit_attrs);
}
for (const auto& inherited : inherit_attrs)
for (const auto& inherit : inherit_attrs)
{
string current_val = nic->vector_value(inherited);
PoolObjectSQL::get_template_attribute(inherited, inherit_val);
if (current_val.empty() && !inherit_val.empty())
if (auto va = PoolObjectSQL::get_template_attribute(inherit))
{
nic->replace(inherited, inherit_val);
// Vector attribute, inherit all its values
const auto& values = va->value();
for (const auto& val : values)
{
string current_val = nic->vector_value(val.first);
if (current_val.empty() && !val.second.empty())
{
nic->replace(val.first, val.second);
}
}
}
else
{
// Simple attribute, inherit value
string current_val = nic->vector_value(inherit);
PoolObjectSQL::get_template_attribute(inherit, inherit_val);
if (current_val.empty() && !inherit_val.empty())
{
nic->replace(inherit, inherit_val);
}
}
}