mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-13 13:17:39 +03:00
Feature #862: Add chmod methods to Ruby OCA and CLI
This commit is contained in:
parent
38f494855b
commit
ed68b74c5d
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
#######################################################################
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user