diff --git a/include/RequestManagerChmod.h b/include/RequestManagerChmod.h index 60282af845..4341c1fc4f 100644 --- a/include/RequestManagerChmod.h +++ b/include/RequestManagerChmod.h @@ -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(){}; + +}; + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/include/RequestManagerChown.h b/include/RequestManagerChown.h index c0591bb36c..9ccedc49a0 100644 --- a/include/RequestManagerChown.h +++ b/include/RequestManagerChown.h @@ -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(){}; + +}; + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/src/cli/one_helper/onedatastore_helper.rb b/src/cli/one_helper/onedatastore_helper.rb index 1202763765..b88a5f6b4d 100644 --- a/src/cli/one_helper/onedatastore_helper.rb +++ b/src/cli/one_helper/onedatastore_helper.rb @@ -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| diff --git a/src/cli/onedatastore b/src/cli/onedatastore index 5f30f913ce..e86de396e8 100755 --- a/src/cli/onedatastore +++ b/src/cli/onedatastore @@ -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 diff --git a/src/datastore/Datastore.cc b/src/datastore/Datastore.cc index d363dff1ca..49da72cfaf 100644 --- a/src/datastore/Datastore.cc +++ b/src/datastore/Datastore.cc @@ -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 << "" << "" << gname << "" << "" << name << "" << + perms_to_xml(perms_xml) << "" << type << "" << "" << tm_mad << "" << "" << 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); diff --git a/src/oca/ruby/OpenNebula/Datastore.rb b/src/oca/ruby/OpenNebula/Datastore.rb index 23d87c026b..7c0df9fc7c 100644 --- a/src/oca/ruby/OpenNebula/Datastore.rb +++ b/src/oca/ruby/OpenNebula/Datastore.rb @@ -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 # --------------------------------------------------------------------- diff --git a/src/oca/ruby/OpenNebula/VirtualNetwork.rb b/src/oca/ruby/OpenNebula/VirtualNetwork.rb index 134e0a038c..1c24e0ad95 100644 --- a/src/oca/ruby/OpenNebula/VirtualNetwork.rb +++ b/src/oca/ruby/OpenNebula/VirtualNetwork.rb @@ -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 diff --git a/src/rm/RequestManager.cc b/src/rm/RequestManager.cc index ad21a5fa11..639980dc8c 100644 --- a/src/rm/RequestManager.cc +++ b/src/rm/RequestManager.cc @@ -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);