From e02a9f9424cd12351611b75967607ec57f7903e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Czern=C3=BD?= Date: Mon, 4 Jan 2021 17:14:46 +0100 Subject: [PATCH] F #4090: Inherit vector values (#560) Vector attributes are merged with DISK/NIC attribute --- src/datastore/Datastore.cc | 30 ++++++++++++++++++++++++------ src/image/Image.cc | 29 ++++++++++++++++++++++++----- src/vnm/VirtualNetwork.cc | 31 +++++++++++++++++++++++++------ 3 files changed, 73 insertions(+), 17 deletions(-) diff --git a/src/datastore/Datastore.cc b/src/datastore/Datastore.cc index 9ac150c2cd..8f54dabc74 100644 --- a/src/datastore/Datastore.cc +++ b/src/datastore/Datastore.cc @@ -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); + } } } diff --git a/src/image/Image.cc b/src/image/Image.cc index 531b51b147..ff936bd710 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -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); + } } } } diff --git a/src/vnm/VirtualNetwork.cc b/src/vnm/VirtualNetwork.cc index caad97e6f3..3a7c0fcf97 100644 --- a/src/vnm/VirtualNetwork.cc +++ b/src/vnm/VirtualNetwork.cc @@ -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); + } } }