0007-Bug-758-Create-default-ACL-rules-when-creating-a-new.patch

patch - Hector Sanjuan, 08/31/2011 11:36 PM

Download (2.21 KB)

View differences:

src/sunstone/models/OpenNebulaJSON/GroupJSON.rb
16 16

  
17 17
require 'OpenNebulaJSON/JSONUtils'
18 18

  
19
if ONE_LOCATION
20
    GROUP_DEFAULT=ONE_LOCATION+"/etc/group.default"
21
else
22
    GROUP_DEFAULT="/etc/one/group.default"
23
end
24

  
19 25
module OpenNebulaJSON
20 26
    class GroupJSON < OpenNebula::Group
21 27
        include JSONUtils
......
26 32
                return group_hash
27 33
            end
28 34

  
29
            self.allocate(group_hash['name'])
35
            rc_alloc = self.allocate(group_hash['name'])
36

  
37
            #if group allocation was successful
38
            if !OpenNebula.is_error?(rc_alloc)
39
                #create default ACL rules - inspired by cli's onegroup_helper.rb
40

  
41
                File.open(GROUP_DEFAULT).each_line{ |l|
42
                    next if l.match(/^#/)
43

  
44
                    rule = "@#{self.id} #{l}"
45
                    parse = OpenNebula::Acl.parse_rule(rule)
46
                    if OpenNebula.is_error?(parse)
47
                        puts "Error parsing rule #{rule}"
48
                        puts "Error message" << parse.message
49
                        next
50
                    end
51

  
52
                    xml = OpenNebula::Acl.build_xml
53
                    acl = OpenNebula::Acl.new(xml, @client)
54
                    rc = acl.allocate(*parse)
55
                    if OpenNebula.is_error?(rc)
56
                        puts "Error creating rule #{rule}"
57
                        puts "Error message" << rc.message
58
                        next
59
                    end
60
                }
61
            end
62

  
63
            return rc_alloc
30 64
        end
31 65

  
32 66
        def perform_action(template_json)
33
-