diff --git a/src/cli/oneimage b/src/cli/oneimage index 349c7916cc..56d2e073c4 100755 --- a/src/cli/oneimage +++ b/src/cli/oneimage @@ -202,6 +202,17 @@ cmd=CommandParser::CmdParser.new(ARGV) do end end + chmod_desc = <<-EOT.unindent + Changes the Image permissions + EOT + + command :chmod, chmod_desc, [:range, :imageid_list], :octet do + helper.perform_actions(args[0],options, + "Permissions changed") do |image| + image.chmod_octet(args[1]) + end + end + list_desc = <<-EOT.unindent Lists Images in the pool EOT diff --git a/src/cli/onetemplate b/src/cli/onetemplate index 7b652fa65a..98e3285b6c 100755 --- a/src/cli/onetemplate +++ b/src/cli/onetemplate @@ -169,6 +169,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do end end + chmod_desc = <<-EOT.unindent + Changes the Template permissions + EOT + + command :chmod, chmod_desc, [:range, :templateid_list], :octet do + helper.perform_actions(args[0],options, "Permissions changed") do |t| + t.chmod_octet(args[1]) + end + end + update_desc = <<-EOT.unindent Launches the system editor to modify and update the template contents EOT diff --git a/src/cli/onevm b/src/cli/onevm index d94455657e..7e6be901c7 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -333,7 +333,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do end chown_desc = <<-EOT.unindent - Changes the Image owner and group + Changes the VM owner and group EOT command :chown, chown_desc, [:range, :vmid_list], :userid, @@ -344,6 +344,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do end end + chmod_desc = <<-EOT.unindent + Changes the VM permissions + EOT + + command :chmod, chmod_desc, [:range, :vmid_list], :octet do + helper.perform_actions(args[0],options, "Permissions changed") do |vm| + vm.chmod_octet(args[1]) + end + end + list_desc = <<-EOT.unindent Lists VMs in the pool EOT diff --git a/src/cli/onevnet b/src/cli/onevnet index 91a648c97c..63a7d6297c 100755 --- a/src/cli/onevnet +++ b/src/cli/onevnet @@ -173,6 +173,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do end end + chmod_desc = <<-EOT.unindent + Changes the Virtual Network permissions + EOT + + command :chmod, chmod_desc, [:range, :vnetid_list], :octet do + helper.perform_actions(args[0],options, "Permissions changed") do |vn| + vn.chmod_octet(args[1]) + end + end + list_desc = <<-EOT.unindent Lists Virtual Networks in the pool EOT diff --git a/src/oca/ruby/OpenNebula/Image.rb b/src/oca/ruby/OpenNebula/Image.rb index 9aa496fc17..fbd5082edb 100644 --- a/src/oca/ruby/OpenNebula/Image.rb +++ b/src/oca/ruby/OpenNebula/Image.rb @@ -30,10 +30,10 @@ module OpenNebula :allocate => "image.allocate", :update => "image.update", :enable => "image.enable", - :publish => "image.publish", :persistent => "image.persistent", :delete => "image.delete", :chown => "image.chown", + :chmod => "image.chmod", :chtype => "image.chtype" } @@ -146,6 +146,26 @@ module OpenNebula super(IMAGE_METHODS[:chown], uid, gid) end + # Changes the Image 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(IMAGE_METHODS[:chmod], octet) + end + + # Changes the Image 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(IMAGE_METHODS[:chmod], owner_u, owner_m, owner_a, group_u, + group_m, group_a, other_u, other_m, other_a) + end + # Changes the Image type # @param type [String] new Image type # @return [nil, OpenNebula::Error] nil in case of success, Error @@ -211,12 +231,9 @@ module OpenNebula end def set_publish(published) - return Error.new('ID not defined') if !@pe_id + group_u = published ? 1 : 0 - rc = @client.call(IMAGE_METHODS[:publish], @pe_id, published) - rc = nil if !OpenNebula.is_error?(rc) - - return rc + chmod(-1, -1, -1, group_u, -1, -1, -1, -1, -1) end def set_persistent(persistence) diff --git a/src/oca/ruby/OpenNebula/Pool.rb b/src/oca/ruby/OpenNebula/Pool.rb index 7410125311..3a3c86d746 100644 --- a/src/oca/ruby/OpenNebula/Pool.rb +++ b/src/oca/ruby/OpenNebula/Pool.rb @@ -212,6 +212,47 @@ module OpenNebula return rc end + # Calls to the corresponding chmod method to modify + # the object's permission bits + # + # @param xml_method [String] the name of the XML-RPC method + # @param octet [String] Permissions octed , e.g. 640 + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def chmod_octet(xml_method, octet) + owner_u = octet[0..0].to_i & 4 != 0 ? 1 : 0 + owner_m = octet[0..0].to_i & 2 != 0 ? 1 : 0 + owner_a = octet[0..0].to_i & 1 != 0 ? 1 : 0 + group_u = octet[1..1].to_i & 4 != 0 ? 1 : 0 + group_m = octet[1..1].to_i & 2 != 0 ? 1 : 0 + group_a = octet[1..1].to_i & 1 != 0 ? 1 : 0 + other_u = octet[2..2].to_i & 4 != 0 ? 1 : 0 + other_m = octet[2..2].to_i & 2 != 0 ? 1 : 0 + other_a = octet[2..2].to_i & 1 != 0 ? 1 : 0 + + chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, + other_m, other_a) + end + + # Calls to the corresponding chmod method to modify + # the object's permission bits + # Each [Integer] parameter must be 1 to allow, 0 deny, -1 do not change + # + # @param xml_method [String] the name of the XML-RPC method + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def chmod(xml_method, owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, + other_m, other_a) + return Error.new('ID not defined') if !@pe_id + + rc = @client.call(xml_method, @pe_id, owner_u, owner_m, + owner_a, group_u, group_m, group_a, other_u, + other_m, other_a) + rc = nil if !OpenNebula.is_error?(rc) + + return rc + end + public # Creates new element specifying its id diff --git a/src/oca/ruby/OpenNebula/Template.rb b/src/oca/ruby/OpenNebula/Template.rb index 07beb53f89..825e1b3c21 100644 --- a/src/oca/ruby/OpenNebula/Template.rb +++ b/src/oca/ruby/OpenNebula/Template.rb @@ -31,7 +31,8 @@ module OpenNebula :update => "template.update", :publish => "template.publish", :delete => "template.delete", - :chown => "template.chown" + :chown => "template.chown", + :chmod => "template.chmod" } # Creates a Template description with just its identifier @@ -119,6 +120,26 @@ module OpenNebula super(TEMPLATE_METHODS[:chown], uid, gid) end + # Changes the Template 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(TEMPLATE_METHODS[:chmod], octet) + end + + # Changes the Template 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(TEMPLATE_METHODS[:chmod], owner_u, owner_m, owner_a, group_u, + group_m, group_a, other_u, other_m, other_a) + end + ####################################################################### # Helpers to get Template information ####################################################################### @@ -136,12 +157,9 @@ module OpenNebula private def set_publish(published) - return Error.new('ID not defined') if !@pe_id + group_u = published ? 1 : 0 - rc = @client.call(TEMPLATE_METHODS[:publish], @pe_id, published) - rc = nil if !OpenNebula.is_error?(rc) - - return rc + chmod(-1, -1, -1, group_u, -1, -1, -1, -1, -1) end end end diff --git a/src/oca/ruby/OpenNebula/VirtualMachine.rb b/src/oca/ruby/OpenNebula/VirtualMachine.rb index 1690e210c1..72bf4c4598 100644 --- a/src/oca/ruby/OpenNebula/VirtualMachine.rb +++ b/src/oca/ruby/OpenNebula/VirtualMachine.rb @@ -31,7 +31,8 @@ module OpenNebula :migrate => "vm.migrate", :deploy => "vm.deploy", :savedisk => "vm.savedisk", - :chown => "vm.chown" + :chown => "vm.chown", + :chmod => "vm.chmod", } VM_STATE=%w{INIT PENDING HOLD ACTIVE STOPPED SUSPENDED DONE FAILED} @@ -244,6 +245,26 @@ module OpenNebula super(VM_METHODS[:chown], uid, gid) end + # Changes the 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(VM_METHODS[:chmod], octet) + end + + # Changes the 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(VM_METHODS[:chmod], owner_u, owner_m, owner_a, group_u, + group_m, group_a, other_u, other_m, other_a) + end + ####################################################################### # Helpers to get VirtualMachine information ####################################################################### diff --git a/src/oca/ruby/OpenNebula/VirtualNetwork.rb b/src/oca/ruby/OpenNebula/VirtualNetwork.rb index b932d7cbe8..1dc568e0ce 100644 --- a/src/oca/ruby/OpenNebula/VirtualNetwork.rb +++ b/src/oca/ruby/OpenNebula/VirtualNetwork.rb @@ -32,6 +32,7 @@ module OpenNebula :addleases => "vn.addleases", :rmleases => "vn.rmleases", :chown => "vn.chown", + :chmod => "vn.chmod", :update => "vn.update", :hold => "vn.hold", :release => "vn.release" @@ -164,6 +165,26 @@ module OpenNebula super(VN_METHODS[:chown], uid, gid) end + # Changes the virtual network 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(VN_METHODS[:chmod], octet) + end + + # Changes the virtual network 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(VN_METHODS[:chmod], owner_u, owner_m, owner_a, group_u, + group_m, group_a, other_u, other_m, other_a) + end + ####################################################################### # Helpers to get VirtualNetwork information ####################################################################### @@ -191,12 +212,9 @@ module OpenNebula private def set_publish(published) - return Error.new('ID not defined') if !@pe_id + group_u = published ? 1 : 0 - rc = @client.call(VN_METHODS[:publish], @pe_id, published) - rc = nil if !OpenNebula.is_error?(rc) - - return rc + chmod(-1, -1, -1, group_u, -1, -1, -1, -1, -1) end end