Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Feature #2696: Add generic Template for Groups

  • Loading branch information...
commit c58cc19d01c9225ab0f9b166b7b0122267717e72 1 parent 7b972c0
Tino Vázquez tinova authored
16 include/Group.h
View
@@ -21,6 +21,7 @@
#include "ObjectCollection.h"
#include "User.h"
#include "QuotasSQL.h"
+#include "Template.h"
using namespace std;
@@ -109,6 +110,14 @@ class Group : public PoolObjectSQL, ObjectCollection
return quota.update(oid, db);
};
+ /**
+ * Factory method for Group templates
+ */
+ Template * get_new_template() const
+ {
+ return new Template;
+ }
+
private:
// -------------------------------------------------------------------------
@@ -128,9 +137,14 @@ class Group : public PoolObjectSQL, ObjectCollection
{
// Allow users in this group to see it
group_u = 1;
+
+ obj_template = new Template;
};
- virtual ~Group(){};
+ virtual ~Group()
+ {
+ delete obj_template;
+ };
// *************************************************************************
// Attributes (Private)
18 include/RequestManagerUpdateTemplate.h
View
@@ -239,6 +239,24 @@ class ZoneUpdateTemplate : public RequestManagerUpdateTemplate
~ZoneUpdateTemplate(){};
};
+/* ------------------------------------------------------------------------- */
+/* ------------------------------------------------------------------------- */
+
+class GroupUpdateTemplate : public RequestManagerUpdateTemplate
+{
+public:
+ GroupUpdateTemplate():
+ RequestManagerUpdateTemplate("GroupUpdateTemplate",
+ "Updates a Group template")
+ {
+ Nebula& nd = Nebula::instance();
+ pool = nd.get_gpool();
+ auth_object = PoolObjectSQL::GROUP;
+ };
+
+ ~GroupUpdateTemplate(){};
+};
+
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
2  include/UserTemplate.h
View
@@ -35,4 +35,4 @@ class UserTemplate : public Template
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
-#endif /*IMAGE_TEMPLATE_H_*/
+#endif /*USER_TEMPLATE_H_*/
4 src/cli/one_helper/onegroup_helper.rb
View
@@ -213,6 +213,10 @@ def format_resource(group, options = {})
puts str % ["NAME", group.name]
puts
+ CLIHelper.print_header(str_h1 % "GROUP TEMPLATE",false)
+ puts group.template_str
+ puts
+
CLIHelper.print_header(str_h1 % "USERS", false)
CLIHelper.print_header("%-15s" % ["ID"])
group.user_ids.each do |uid|
18 src/cli/onegroup
View
@@ -135,6 +135,24 @@ cmd=CommandParser::CmdParser.new(ARGV) do
end
end
+ update_desc = <<-EOT.unindent
+ Update the template contents. If a path is not provided the editor will
+ be launched to modify the current content.
+ EOT
+
+ command :update, update_desc, :groupid, [:file, nil],
+ :options=>OpenNebulaHelper::APPEND do
+ helper.perform_action(args[0],options,"modified") do |obj|
+ if options[:append]
+ str = OpenNebulaHelper.append_template(args[0], obj, args[1])
+ else
+ str = OpenNebulaHelper.update_template(args[0], obj, args[1])
+ end
+
+ obj.update(str, options[:append])
+ end
+ end
+
delete_desc = <<-EOT.unindent
Deletes the given Group
EOT
19 src/group/Group.cc
View
@@ -214,6 +214,7 @@ string& Group::to_xml_extended(string& xml, bool extended) const
{
ostringstream oss;
string collection_xml;
+ string template_xml;
set<pair<int,int> >::const_iterator it;
@@ -221,8 +222,9 @@ string& Group::to_xml_extended(string& xml, bool extended) const
oss <<
"<GROUP>" <<
- "<ID>" << oid << "</ID>" <<
- "<NAME>" << name << "</NAME>" <<
+ "<ID>" << oid << "</ID>" <<
+ "<NAME>" << name << "</NAME>" <<
+ obj_template->to_xml(template_xml) <<
collection_xml;
for (it = providers.begin(); it != providers.end(); it++)
@@ -285,6 +287,19 @@ int Group::from_xml(const string& xml)
ObjectXML::free_nodes(content);
content.clear();
+ // Get associated metadata for the group
+ ObjectXML::get_nodes("/GROUP/TEMPLATE", content);
+
+ if (content.empty())
+ {
+ return -1;
+ }
+
+ rc += obj_template->from_xml_node(content[0]);
+
+ ObjectXML::free_nodes(content);
+ content.clear();
+
// Set of resource providers
ObjectXML::get_nodes("/GROUP/RESOURCE_PROVIDER", content);
13 src/oca/ruby/opennebula/group.rb
View
@@ -26,6 +26,7 @@ class Group < PoolElement
GROUP_METHODS = {
:info => "group.info",
:allocate => "group.allocate",
+ :update => "group.update",
:delete => "group.delete",
:quota => "group.quota",
:add_provider => "group.addprovider",
@@ -222,6 +223,18 @@ def allocate(groupname)
super(GROUP_METHODS[:allocate], groupname)
end
+ # Replaces the template contents
+ #
+ # @param new_template [String] New template contents
+ # @param append [true, false] True to append new attributes instead of
+ # replace the whole template
+ #
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
+ # otherwise
+ def update(new_template=nil, append=false)
+ super(GROUP_METHODS[:update], new_template, append ? 1 : 0)
+ end
+
# Deletes the Group
def delete()
super(GROUP_METHODS[:delete])
13 src/rm/RequestManager.cc
View
@@ -437,6 +437,7 @@ void RequestManager::register_xml_methods()
/* Group related methods */
xmlrpc_c::method * group_allocate_pt;
+ xmlrpc_c::method * group_update_pt;
xmlrpc_c::method * group_delete_pt;
xmlrpc_c::method * group_add_provider_pt;
xmlrpc_c::method * group_del_provider_pt;
@@ -447,6 +448,7 @@ void RequestManager::register_xml_methods()
group_delete_pt = new RequestManagerProxy("one.group.delete");
group_add_provider_pt = new RequestManagerProxy("one.group.addprovider");
group_del_provider_pt = new RequestManagerProxy("one.group.delprovider");
+ group_update_pt = new RequestManagerProxy("one.group.update");
}
else
{
@@ -454,12 +456,14 @@ void RequestManager::register_xml_methods()
group_delete_pt = new GroupDelete();
group_add_provider_pt = new GroupAddProvider();
group_del_provider_pt = new GroupDelProvider();
+ group_update_pt = new GroupUpdateTemplate();
}
xmlrpc_c::methodPtr group_allocate(group_allocate_pt);
xmlrpc_c::methodPtr group_delete(group_delete_pt);
xmlrpc_c::methodPtr group_add_provider(group_add_provider_pt);
xmlrpc_c::methodPtr group_del_provider(group_del_provider_pt);
+ xmlrpc_c::methodPtr group_update(group_update_pt);
xmlrpc_c::methodPtr group_info(new GroupInfo());
xmlrpc_c::methodPtr group_set_quota(new GroupSetQuota());
@@ -467,12 +471,13 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr group_get_default_quota(new GroupQuotaInfo());
xmlrpc_c::methodPtr group_set_default_quota(new GroupQuotaUpdate());
- RequestManagerRegistry.addMethod("one.group.allocate", group_allocate);
- RequestManagerRegistry.addMethod("one.group.delete", group_delete);
- RequestManagerRegistry.addMethod("one.group.info", group_info);
- RequestManagerRegistry.addMethod("one.group.quota", group_set_quota);
+ RequestManagerRegistry.addMethod("one.group.allocate", group_allocate);
+ RequestManagerRegistry.addMethod("one.group.delete", group_delete);
+ RequestManagerRegistry.addMethod("one.group.info", group_info);
+ RequestManagerRegistry.addMethod("one.group.quota", group_set_quota);
RequestManagerRegistry.addMethod("one.group.addprovider",group_add_provider);
RequestManagerRegistry.addMethod("one.group.delprovider",group_del_provider);
+ RequestManagerRegistry.addMethod("one.group.update", group_update);
RequestManagerRegistry.addMethod("one.grouppool.info", grouppool_info);
Please sign in to comment.
Something went wrong with that request. Please try again.