1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-27 03:21:29 +03:00

Bug #758: Create default ACL rules when creating a new group in Sunstone

This commit is contained in:
Hector Sanjuan 2011-09-01 01:00:12 +02:00 committed by Ruben S. Montero
parent 6683dd64e8
commit 9ce9362829

View File

@ -16,6 +16,12 @@
require 'OpenNebulaJSON/JSONUtils'
if ONE_LOCATION
GROUP_DEFAULT=ONE_LOCATION+"/etc/group.default"
else
GROUP_DEFAULT="/etc/one/group.default"
end
module OpenNebulaJSON
class GroupJSON < OpenNebula::Group
include JSONUtils
@ -26,7 +32,35 @@ module OpenNebulaJSON
return group_hash
end
self.allocate(group_hash['name'])
rc_alloc = self.allocate(group_hash['name'])
#if group allocation was successful
if !OpenNebula.is_error?(rc_alloc)
#create default ACL rules - inspired by cli's onegroup_helper.rb
File.open(GROUP_DEFAULT).each_line{ |l|
next if l.match(/^#/)
rule = "@#{self.id} #{l}"
parse = OpenNebula::Acl.parse_rule(rule)
if OpenNebula.is_error?(parse)
puts "Error parsing rule #{rule}"
puts "Error message" << parse.message
next
end
xml = OpenNebula::Acl.build_xml
acl = OpenNebula::Acl.new(xml, @client)
rc = acl.allocate(*parse)
if OpenNebula.is_error?(rc)
puts "Error creating rule #{rule}"
puts "Error message" << rc.message
next
end
}
end
return rc_alloc
end
def perform_action(template_json)