From 1fde5eca2e5ea02543e4b45628e3573a21cdf0fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 23 Nov 2012 16:03:10 +0100 Subject: [PATCH] Feature #1611: Add xml-rpc methods to retrieve and update the default user & group quotas --- include/Nebula.h | 10 ++++ include/RequestManagerSystem.h | 101 +++++++++++++++++++++++++++++++++ src/rm/RequestManager.cc | 14 ++++- src/rm/RequestManagerSystem.cc | 98 ++++++++++++++++++++++++++++++++ 4 files changed, 221 insertions(+), 2 deletions(-) diff --git a/include/Nebula.h b/include/Nebula.h index d1f5560a87..4038c6df7a 100644 --- a/include/Nebula.h +++ b/include/Nebula.h @@ -318,11 +318,21 @@ public: return default_user_quota; }; + int set_default_user_quota(Template *tmpl, string& error) + { + return default_user_quota.set(tmpl, error); + }; + const Quotas& get_default_group_quota() { return default_group_quota; }; + int set_default_group_quota(Template *tmpl, string& error) + { + return default_group_quota.set(tmpl, error); + }; + private: // ----------------------------------------------------------------------- diff --git a/include/RequestManagerSystem.h b/include/RequestManagerSystem.h index be66eaed25..cbd0696d57 100644 --- a/include/RequestManagerSystem.h +++ b/include/RequestManagerSystem.h @@ -78,6 +78,107 @@ public: RequestAttributes& att); }; +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +class UserQuotaInfo : public RequestManagerSystem +{ +public: + UserQuotaInfo(): + RequestManagerSystem("UserQuotaInfo", + "Returns the default user quota limits", + "A:s") + { + auth_op = AuthRequest::ADMIN; + }; + + ~UserQuotaInfo(){}; + + void request_execute(xmlrpc_c::paramList const& _paramList, + RequestAttributes& att); +}; + +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +class GroupQuotaInfo : public RequestManagerSystem +{ +public: + GroupQuotaInfo(): + RequestManagerSystem("GroupQuotaInfo", + "Returns the default group quota limits", + "A:s") + { + auth_op = AuthRequest::ADMIN; + }; + + ~GroupQuotaInfo(){}; + + void request_execute(xmlrpc_c::paramList const& _paramList, + RequestAttributes& att); +}; + +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +class QuotaUpdate : public RequestManagerSystem +{ +public: + QuotaUpdate(const string& method_name, + const string& help): + RequestManagerSystem(method_name, + help, + "A:ss") + { + auth_op = AuthRequest::ADMIN; + }; + + ~QuotaUpdate(){}; + + void request_execute(xmlrpc_c::paramList const& _paramList, + RequestAttributes& att); + + virtual int set_default_quota(Template *tmpl, string& error) = 0; + + virtual string& get_default_quota(string& xml) = 0; +}; + +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +class UserQuotaUpdate : public QuotaUpdate +{ +public: + UserQuotaUpdate(): + QuotaUpdate("UserQuotaUpdate", + "Updates the default user quota limits") + { + auth_op = AuthRequest::ADMIN; + }; + + int set_default_quota(Template *tmpl, string& error); + + string& get_default_quota(string& xml); +}; + +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +class GroupQuotaUpdate : public QuotaUpdate +{ +public: + GroupQuotaUpdate(): + QuotaUpdate("GroupQuotaUpdate", + "Updates the default group quota limits") + { + auth_op = AuthRequest::ADMIN; + }; + + int set_default_quota(Template *tmpl, string& error); + + string& get_default_quota(string& xml); +}; + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/src/rm/RequestManager.cc b/src/rm/RequestManager.cc index 5e9e0311b1..1ba7f4b8bf 100644 --- a/src/rm/RequestManager.cc +++ b/src/rm/RequestManager.cc @@ -368,6 +368,12 @@ void RequestManager::register_xml_methods() xmlrpc_c::methodPtr system_version(new SystemVersion()); xmlrpc_c::methodPtr system_config(new SystemConfig()); + xmlrpc_c::methodPtr user_get_default_quota(new UserQuotaInfo()); + xmlrpc_c::methodPtr user_set_default_quota(new UserQuotaUpdate()); + + xmlrpc_c::methodPtr group_get_default_quota(new GroupQuotaInfo()); + xmlrpc_c::methodPtr group_set_default_quota(new GroupQuotaUpdate()); + /* VM related methods */ RequestManagerRegistry.addMethod("one.vm.deploy", vm_deploy); RequestManagerRegistry.addMethod("one.vm.action", vm_action); @@ -416,6 +422,9 @@ void RequestManager::register_xml_methods() RequestManagerRegistry.addMethod("one.grouppool.info", grouppool_info); + RequestManagerRegistry.addMethod("one.groupquota.info", group_get_default_quota); + RequestManagerRegistry.addMethod("one.groupquota.update", group_set_default_quota); + /* Network related methods*/ RequestManagerRegistry.addMethod("one.vn.addleases", vn_addleases); RequestManagerRegistry.addMethod("one.vn.rmleases", vn_rmleases); @@ -441,6 +450,9 @@ void RequestManager::register_xml_methods() RequestManagerRegistry.addMethod("one.user.quota", user_set_quota); RequestManagerRegistry.addMethod("one.userpool.info", userpool_info); + + RequestManagerRegistry.addMethod("one.userquota.info", user_get_default_quota); + RequestManagerRegistry.addMethod("one.userquota.update", user_set_default_quota); /* Image related methods*/ RequestManagerRegistry.addMethod("one.image.persistent", image_persistent); @@ -500,8 +512,6 @@ void RequestManager::register_xml_methods() /* System related methods */ RequestManagerRegistry.addMethod("one.system.version", system_version); RequestManagerRegistry.addMethod("one.system.config", system_config); - - }; /* -------------------------------------------------------------------------- */ diff --git a/src/rm/RequestManagerSystem.cc b/src/rm/RequestManagerSystem.cc index df3f39204c..fd35a7f131 100644 --- a/src/rm/RequestManagerSystem.cc +++ b/src/rm/RequestManagerSystem.cc @@ -56,3 +56,101 @@ void SystemConfig::request_execute(xmlrpc_c::paramList const& paramList, /* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */ + +void UserQuotaInfo::request_execute(xmlrpc_c::paramList const& paramList, + RequestAttributes& att) +{ + string xml; + success_response(Nebula::instance().get_default_user_quota().to_xml(xml), att); + + return; +} + +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +void GroupQuotaInfo::request_execute(xmlrpc_c::paramList const& paramList, + RequestAttributes& att) +{ + string xml; + success_response(Nebula::instance().get_default_group_quota().to_xml(xml), att); + + return; +} + +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +void QuotaUpdate::request_execute(xmlrpc_c::paramList const& paramList, + RequestAttributes& att) +{ + string quota_str = xmlrpc_c::value_string(paramList.getString(1)); + string error_str; + Template quota_tmpl; + string xml; + + int rc; + + if ( att.gid != GroupPool::ONEADMIN_ID ) + { + failure_response(AUTHORIZATION, + "The default quotas can only be updated by users in the oneadmin group", + att); + return; + } + + rc = quota_tmpl.parse_str_or_xml(quota_str, error_str); + + if ( rc != 0 ) + { + failure_response(ACTION, request_error(error_str,""), att); + return; + } + + rc = set_default_quota("a_tmpl, error_str); + + if ( rc != 0 ) + { + failure_response(ACTION, request_error(error_str,""), att); + return; + } + + success_response(get_default_quota(xml), att); + + return; +} + +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +int UserQuotaUpdate::set_default_quota(Template *tmpl, string& error) +{ + return Nebula::instance().set_default_user_quota(tmpl, error); +} + +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +string& UserQuotaUpdate::get_default_quota(string& xml) +{ + return Nebula::instance().get_default_user_quota().to_xml(xml); +} + +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +int GroupQuotaUpdate::set_default_quota(Template *tmpl, string& error) +{ + return Nebula::instance().set_default_group_quota(tmpl, error); +} + +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +string& GroupQuotaUpdate::get_default_quota(string& xml) +{ + return Nebula::instance().get_default_group_quota().to_xml(xml); +} + +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */