From 492d5fce2c0b6aee257e369652a0649bbdc9b635 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sun, 12 Mar 2017 23:39:45 +0100 Subject: [PATCH] F #5058: Method to get user-based configuration attributes for oned --- include/Nebula.h | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/include/Nebula.h b/include/Nebula.h index 8e031351c6..26dfdb21b4 100644 --- a/include/Nebula.h +++ b/include/Nebula.h @@ -420,6 +420,70 @@ public: nebula_configuration->get(name, value); }; + /** + * Gets a user-configurable attribute for oned. Users (and groups) may + * store oned attributes in the "OPENNEBULA" vector. This function gets + * the value querying first the user, then the group and finally oned.conf + * @param uid of the user + * @param gid of the group + * @param name of the attribute + * @param value of the attribute + * + * @return 0 on success -1 otherwise + */ + template + int get_configuration_attribute(int uid, int gid, const std::string& name, + T& value) const + { + User * user = upool->get(uid, true); + + if ( user == 0 ) + { + return -1; + } + + const VectorAttribute * uconf; + + uconf = user->get_template_attribute("OPENNEBULA"); + + if ( uconf != 0 ) + { + if ( uconf->vector_value(name, value) == 0 ) + { + user->unlock(); + return 0; + } + } + + user->unlock(); + + Group * group = gpool->get(gid, true); + + if ( group == 0 ) + { + return -1; + } + + const VectorAttribute * gconf; + + gconf = group->get_template_attribute("OPENNEBULA"); + + if ( gconf != 0 ) + { + if ( gconf->vector_value(name, value) == 0 ) + { + group->unlock(); + return 0; + } + } + + group->unlock(); + + nebula_configuration->get(name, value); + + return 0; + } + /** * Gets a DS configuration attribute */