1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

F #5356: add CLI chmod support /u/g/o (#2054)

This commit is contained in:
Alejandro Huertas Herrero 2022-05-18 14:51:51 +02:00 committed by GitHub
parent 59e19003a8
commit 5b35eb7946
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 56 additions and 14 deletions

View File

@ -2305,4 +2305,46 @@ EOT
end
end
# Convert u=rwx,g=rx,o=r to octet
#
# @param perm [String] Permissions in human readbale format
#
# @return [String] Permissions in octet format
def OpenNebulaHelper.to_octet(perm)
begin
Integer(perm).to_s
rescue StandardError
perm = perm.split(',')
ret = 0
perm.each do |p|
p = p.split('=')
next unless p.size == 2
r = p[1].count('r')
w = p[1].count('w')
x = p[1].count('x')
rwx = (2 ** 0) * x + (2 ** 1) * w + (2 ** 2) * r
case p[0]
when 'u'
ret += rwx * 100
when 'g'
ret += rwx * 10
else
ret += rwx * 1
end
end
if ret == 0
STDERR.puts 'Error in permissions format'
exit(-1)
else
ret.to_s
end
end
end
end

View File

@ -158,7 +158,7 @@ CommandParser::CmdParser.new(ARGV) do
command :chmod, chmod_desc, [:range, :datastoreid_list], :octet do
helper.perform_actions(args[0], options, 'Permissions changed') do |obj|
obj.chmod_octet(args[1])
obj.chmod_octet(OpenNebulaHelper.to_octet(args[1]))
end
end

View File

@ -285,7 +285,7 @@ CommandParser::CmdParser.new(ARGV) do
Service.perform_actions(args[0]) do |service_id|
params = {}
params['octet'] = args[1]
params['octet'] = OpenNebulaHelper.to_octet(args[1])
json = Service.build_json_action('chmod', params)

View File

@ -346,7 +346,7 @@ CommandParser::CmdParser.new(ARGV) do
Service.perform_actions(args[0]) do |service_id|
params = {}
params['octet'] = args[1]
params['octet'] = OpenNebulaHelper.to_octet(args[1])
json = Service.build_json_action('chmod', params)

View File

@ -363,7 +363,7 @@ CommandParser::CmdParser.new(ARGV) do
command :chmod, chmod_desc, [:range, :imageid_list], :octet do
helper.perform_actions(args[0], options,
'Permissions changed') do |image|
image.chmod_octet(args[1])
image.chmod_octet(OpenNebulaHelper.to_octet(args[1]))
end
end

View File

@ -151,7 +151,7 @@ CommandParser::CmdParser.new(ARGV) do
command :chmod, chmod_desc, [:range, :marketplaceid_list], :octet do
helper.perform_actions(args[0], options, 'Permissions changed') do |obj|
obj.chmod_octet(args[1])
obj.chmod_octet(OpenNebulaHelper.to_octet(args[1]))
end
end

View File

@ -388,7 +388,7 @@ CommandParser::CmdParser.new(ARGV) do
command :chmod, chmod_desc, [:range, :appid_list], :octet do
helper.perform_actions(args[0], options, 'Permissions changed') do |app|
app.chmod_octet(args[1])
app.chmod_octet(OpenNebulaHelper.to_octet(args[1]))
end
end

View File

@ -220,7 +220,7 @@ CommandParser::CmdParser.new(ARGV) do
command :chmod, chmod_desc, [:range, :providerid_list], :octet do
helper.perform_actions(args[0], options, 'Permissions changed') do |p|
p.chmod_octet(args[1])
p.chmod_octet(OpenNebulaHelper.to_octet(args[1]))
end
end
end

View File

@ -174,7 +174,7 @@ CommandParser::CmdParser.new(ARGV) do
command :chmod, chmod_desc, [:range, :secgroupid_list], :octet do
helper.perform_actions(args[0], options, 'Permissions changed') do |t|
t.chmod_octet(args[1])
t.chmod_octet(OpenNebulaHelper.to_octet(args[1]))
end
end

View File

@ -378,7 +378,7 @@ CommandParser::CmdParser.new(ARGV) do
recursive = (options[:recursive] == true)
helper.perform_actions(args[0], options, 'Permissions changed') do |t|
t.chmod_octet(args[1], recursive)
t.chmod_octet(OpenNebulaHelper.to_octet(args[1]), recursive)
end
end

View File

@ -981,7 +981,7 @@ CommandParser::CmdParser.new(ARGV) do
command :chmod, chmod_desc, [:range, :vmid_list], :octet do
helper.perform_actions(args[0], options, 'Permissions changed') do |vm|
vm.chmod_octet(args[1])
vm.chmod_octet(OpenNebulaHelper.to_octet(args[1]))
end
end

View File

@ -197,7 +197,7 @@ CommandParser::CmdParser.new(ARGV) do
command :chmod, chmod_desc, [:range, :vmgroupid_list], :octet do
helper.perform_actions(args[0], options, 'Permissions changed') do |t|
t.chmod_octet(args[1])
t.chmod_octet(OpenNebulaHelper.to_octet(args[1]))
end
end

View File

@ -335,7 +335,7 @@ CommandParser::CmdParser.new(ARGV) do
command :chmod, chmod_desc, [:range, :vnetid_list], :octet do
helper.perform_actions(args[0], options, 'Permissions changed') do |vn|
vn.chmod_octet(args[1])
vn.chmod_octet(OpenNebulaHelper.to_octet(args[1]))
end
end

View File

@ -314,7 +314,7 @@ CommandParser::CmdParser.new(ARGV) do
recursive = (options[:recursive] == true)
helper.perform_actions(args[0], options, 'Permissions changed') do |t|
t.chmod_octet(args[1], recursive)
t.chmod_octet(OpenNebulaHelper.to_octet(args[1]), recursive)
end
end

View File

@ -251,7 +251,7 @@ CommandParser::CmdParser.new(ARGV) do
command :chmod, chmod_desc, [:range, :vrouterid_list], :octet do
helper.perform_actions(args[0], options, 'Permissions changed') do |obj|
obj.chmod_octet(args[1])
obj.chmod_octet(OpenNebulaHelper.to_octet(args[1]))
end
end