Statistics
| Branch: | Tag: | Revision:

one / src / oca / ruby / OpenNebula / Acl.rb @ bfaabf35

History | View | Annotate | Download (3.26 KB)

1
# -------------------------------------------------------------------------- #
2
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org)             #
3
#                                                                            #
4
# Licensed under the Apache License, Version 2.0 (the "License"); you may    #
5
# not use this file except in compliance with the License. You may obtain    #
6
# a copy of the License at                                                   #
7
#                                                                            #
8
# http://www.apache.org/licenses/LICENSE-2.0                                 #
9
#                                                                            #
10
# Unless required by applicable law or agreed to in writing, software        #
11
# distributed under the License is distributed on an "AS IS" BASIS,          #
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
13
# See the License for the specific language governing permissions and        #
14
# limitations under the License.                                             #
15
#--------------------------------------------------------------------------- #
16

    
17
require 'OpenNebula/Pool'
18

    
19
module OpenNebula
20
    class Acl < XMLElement
21

    
22
        #######################################################################
23
        # Constants and Class Methods
24
        #######################################################################
25
        ACL_METHODS = {
26
            :info       => "acl.info",
27
            :addrule    => "acl.addrule",
28
            :delrule    => "acl.delrule"
29
        }
30

    
31
        #######################################################################
32
        # Class constructor
33
        #######################################################################
34
        def initialize(client)
35
            @client = client
36
        end
37

    
38
        #######################################################################
39
        # XML-RPC Methods
40
        #######################################################################
41

    
42
        # Retrieves the ACL rule set
43
        def info()
44
            rc = @client.call( ACL_METHODS[:info] )
45

    
46
            if !OpenNebula.is_error?(rc)
47
                initialize_xml(rc, 'ACL')
48
                rc = nil
49
            end
50

    
51
            return rc
52
        end
53

    
54
        # Adds a new ACL rule.
55
        #
56
        # +user+ A hex number, e.g. 0x100000001
57
        # +resource+ A hex number, e.g. 0x2100000001
58
        # +rights+ A hex number, e.g. 0x10
59
        def addrule(user, resource, rights)
60
            rc = @client.call( ACL_METHODS[:addrule], user, resource, rights )
61

    
62
            rc = nil if !OpenNebula.is_error?(rc)
63

    
64
            return rc
65
        end
66

    
67
        # Deletes an existing ACL rule.
68
        #
69
        # +user+ A hex number, e.g. 0x100000001
70
        # +resource+ A hex number, e.g. 0x2100000001
71
        # +rights+ A hex number, e.g. 0x10
72
        def delrule(user, resource, rights)
73
            rc = @client.call( ACL_METHODS[:delrule], user, resource, rights )
74

    
75
            rc = nil if !OpenNebula.is_error?(rc)
76

    
77
            return rc
78
        end
79

    
80
        #######################################################################
81
        # Helpers
82
        #######################################################################
83

    
84
    private
85

    
86
    end
87
end