mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-28 14:50:08 +03:00
Feature #1112: Add permissions to DS. New chown & chmod methods
This commit is contained in:
parent
864daba3ed
commit
6ff6e1f200
@ -81,7 +81,6 @@ public:
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
class VirtualNetworkChmod: public RequestManagerChmod
|
||||
{
|
||||
public:
|
||||
@ -117,6 +116,25 @@ public:
|
||||
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class DatastoreChmod: public RequestManagerChmod
|
||||
{
|
||||
public:
|
||||
DatastoreChmod():
|
||||
RequestManagerChmod("DatastoreChmod",
|
||||
"Changes permission bits of a datastore")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_dspool();
|
||||
auth_object = PoolObjectSQL::DATASTORE;
|
||||
};
|
||||
|
||||
~DatastoreChmod(){};
|
||||
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -153,6 +153,25 @@ public:
|
||||
RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class DatastoreChown: public RequestManagerChown
|
||||
{
|
||||
public:
|
||||
DatastoreChown():
|
||||
RequestManagerChown("Datastore",
|
||||
"Changes ownership of a datastore")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_dspool();
|
||||
auth_object = PoolObjectSQL::DATASTORE;
|
||||
};
|
||||
|
||||
~DatastoreChown(){};
|
||||
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -73,6 +73,18 @@ class OneDatastoreHelper < OpenNebulaHelper::OneHelper
|
||||
puts str % ["BASE PATH",datastore['BASE_PATH']]
|
||||
puts
|
||||
|
||||
CLIHelper.print_header(str_h1 % "PERMISSIONS",false)
|
||||
|
||||
["OWNER", "GROUP", "OTHER"].each { |e|
|
||||
mask = "---"
|
||||
mask[0] = "u" if datastore["PERMISSIONS/#{e}_U"] == "1"
|
||||
mask[1] = "m" if datastore["PERMISSIONS/#{e}_M"] == "1"
|
||||
mask[2] = "a" if datastore["PERMISSIONS/#{e}_A"] == "1"
|
||||
|
||||
puts str % [e, mask]
|
||||
}
|
||||
puts
|
||||
|
||||
CLIHelper.print_header(str_h1 % "IMAGES", false)
|
||||
CLIHelper.print_header("%-15s" % ["ID"])
|
||||
datastore.img_ids.each do |id|
|
||||
|
@ -86,6 +86,38 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
end
|
||||
end
|
||||
|
||||
chgrp_desc = <<-EOT.unindent
|
||||
Changes the Datastore group
|
||||
EOT
|
||||
|
||||
command :chgrp, chgrp_desc,[:range, :datastoreid_list], :groupid do
|
||||
helper.perform_actions(args[0],options,"Group changed") do |obj|
|
||||
obj.chown(-1, args[1].to_i)
|
||||
end
|
||||
end
|
||||
|
||||
chown_desc = <<-EOT.unindent
|
||||
Changes the Datastore owner and group
|
||||
EOT
|
||||
|
||||
command :chown, chown_desc, [:range, :datastoreid_list], :userid,
|
||||
[:groupid,nil] do
|
||||
gid = args[2].nil? ? -1 : args[2].to_i
|
||||
helper.perform_actions(args[0],options,"Owner/Group changed") do |obj|
|
||||
obj.chown(args[1].to_i, gid)
|
||||
end
|
||||
end
|
||||
|
||||
chmod_desc = <<-EOT.unindent
|
||||
Changes the Datastore permissions
|
||||
EOT
|
||||
|
||||
command :chmod, chmod_desc, [:range, :datastoreid_list], :octet do
|
||||
helper.perform_actions(args[0],options, "Permissions changed") do |obj|
|
||||
obj.chmod_octet(args[1])
|
||||
end
|
||||
end
|
||||
|
||||
list_desc = <<-EOT.unindent
|
||||
Lists Datastores in the pool
|
||||
EOT
|
||||
|
@ -227,6 +227,7 @@ string& Datastore::to_xml(string& xml) const
|
||||
ostringstream oss;
|
||||
string collection_xml;
|
||||
string template_xml;
|
||||
string perms_xml;
|
||||
|
||||
ObjectCollection::to_xml(collection_xml);
|
||||
|
||||
@ -238,6 +239,7 @@ string& Datastore::to_xml(string& xml) const
|
||||
"<UNAME>" << uname << "</UNAME>" <<
|
||||
"<GNAME>" << gname << "</GNAME>" <<
|
||||
"<NAME>" << name << "</NAME>" <<
|
||||
perms_to_xml(perms_xml) <<
|
||||
"<TYPE>" << type << "</TYPE>" <<
|
||||
"<TM_MAD>" << tm_mad << "</TM_MAD>" <<
|
||||
"<BASE_PATH>" << base_path << "</BASE_PATH>" <<
|
||||
@ -277,6 +279,9 @@ int Datastore::from_xml(const string& xml)
|
||||
rc += xpath(cluster_id, "/DATASTORE/CLUSTER_ID", -1);
|
||||
rc += xpath(cluster, "/DATASTORE/CLUSTER", "not_found");
|
||||
|
||||
// Permissions
|
||||
rc += perms_from_xml();
|
||||
|
||||
// Get associated classes
|
||||
ObjectXML::get_nodes("/DATASTORE/IMAGES", content);
|
||||
|
||||
|
@ -26,7 +26,9 @@ module OpenNebula
|
||||
DATASTORE_METHODS = {
|
||||
:info => "datastore.info",
|
||||
:allocate => "datastore.allocate",
|
||||
:delete => "datastore.delete"
|
||||
:delete => "datastore.delete",
|
||||
:chown => "datastore.chown",
|
||||
:chmod => "datastore.chmod"
|
||||
}
|
||||
|
||||
# Creates a Datastore description with just its identifier
|
||||
@ -76,6 +78,37 @@ module OpenNebula
|
||||
super(DATASTORE_METHODS[:delete])
|
||||
end
|
||||
|
||||
# Changes the owner/group
|
||||
#
|
||||
# @param uid [Integer] the new owner id. Set to -1 to leave the current one
|
||||
# @param gid [Integer] the new group id. Set to -1 to leave the current one
|
||||
#
|
||||
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
||||
# otherwise
|
||||
def chown(uid, gid)
|
||||
super(DATASTORE_METHODS[:chown], uid, gid)
|
||||
end
|
||||
|
||||
# Changes the datastore permissions.
|
||||
#
|
||||
# @param octet [String] Permissions octed , e.g. 640
|
||||
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
||||
# otherwise
|
||||
def chmod_octet(octet)
|
||||
super(DATASTORE_METHODS[:chmod], octet)
|
||||
end
|
||||
|
||||
# Changes the datastore permissions.
|
||||
# Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
|
||||
#
|
||||
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
||||
# otherwise
|
||||
def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
|
||||
other_m, other_a)
|
||||
super(DATASTORE_METHODS[:chmod], owner_u, owner_m, owner_a, group_u,
|
||||
group_m, group_a, other_u, other_m, other_a)
|
||||
end
|
||||
|
||||
# ---------------------------------------------------------------------
|
||||
# Helpers to get information
|
||||
# ---------------------------------------------------------------------
|
||||
|
@ -158,9 +158,12 @@ module OpenNebula
|
||||
end
|
||||
|
||||
# Changes the owner/group
|
||||
# uid:: _Integer_ the new owner id. Set to -1 to leave the current one
|
||||
# gid:: _Integer_ the new group id. Set to -1 to leave the current one
|
||||
# [return] nil in case of success or an Error object
|
||||
#
|
||||
# @param uid [Integer] the new owner id. Set to -1 to leave the current one
|
||||
# @param gid [Integer] the new group id. Set to -1 to leave the current one
|
||||
#
|
||||
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
||||
# otherwise
|
||||
def chown(uid, gid)
|
||||
super(VN_METHODS[:chown], uid, gid)
|
||||
end
|
||||
|
@ -313,12 +313,14 @@ void RequestManager::register_xml_methods()
|
||||
xmlrpc_c::methodPtr vn_chown(new VirtualNetworkChown());
|
||||
xmlrpc_c::methodPtr image_chown(new ImageChown());
|
||||
xmlrpc_c::methodPtr user_chown(new UserChown());
|
||||
xmlrpc_c::methodPtr datastore_chown(new DatastoreChown());
|
||||
|
||||
// Chmod Methods
|
||||
xmlrpc_c::methodPtr vm_chmod(new VirtualMachineChmod());
|
||||
xmlrpc_c::methodPtr template_chmod(new TemplateChmod());
|
||||
xmlrpc_c::methodPtr vn_chmod(new VirtualNetworkChmod());
|
||||
xmlrpc_c::methodPtr image_chmod(new ImageChmod());
|
||||
xmlrpc_c::methodPtr datastore_chmod(new DatastoreChmod());
|
||||
|
||||
// ACL Methods
|
||||
xmlrpc_c::methodPtr acl_addrule(new AclAddRule());
|
||||
@ -419,6 +421,8 @@ void RequestManager::register_xml_methods()
|
||||
RequestManagerRegistry.addMethod("one.datastore.allocate",datastore_allocate);
|
||||
RequestManagerRegistry.addMethod("one.datastore.delete", datastore_delete);
|
||||
RequestManagerRegistry.addMethod("one.datastore.info", datastore_info);
|
||||
RequestManagerRegistry.addMethod("one.datastore.chown", datastore_chown);
|
||||
RequestManagerRegistry.addMethod("one.datastore.chmod", datastore_chmod);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.datastorepool.info",datastorepool_info);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user