mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
parent
59e19003a8
commit
5b35eb7946
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user