Statistics
| Branch: | Tag: | Revision:

one / src / oca / ruby / OpenNebula / Group.rb @ ae53d437

History | View | Annotate | Download (3.36 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 Group < PoolElement
21
        # ---------------------------------------------------------------------
22
        # Constants and Class Methods
23
        # ---------------------------------------------------------------------
24
        GROUP_METHODS = {
25
            :info       => "group.info",
26
            :allocate   => "group.allocate",
27
            :delete     => "group.delete",
28
        }
29

    
30
        # Creates a Group description with just its identifier
31
        # this method should be used to create plain Group objects.
32
        # +id+ the id of the user
33
        #
34
        # Example:
35
        #   group = Group.new(Group.build_xml(3),rpc_client)
36
        #
37
        def Group.build_xml(pe_id=nil)
38
            if pe_id
39
                group_xml = "<GROUP><ID>#{pe_id}</ID></GROUP>"
40
            else
41
                group_xml = "<GROUP></GROUP>"
42
            end
43

    
44
            XMLElement.build_xml(group_xml,'GROUP')
45
        end
46

    
47
        # ---------------------------------------------------------------------
48
        # Class constructor
49
        # ---------------------------------------------------------------------
50
        def initialize(xml, client)
51
            super(xml,client)
52

    
53
            @client = client
54
        end
55

    
56
        # ---------------------------------------------------------------------
57
        # XML-RPC Methods for the Group Object
58
        # ---------------------------------------------------------------------
59

    
60
        # Retrieves the information of the given Group.
61
        def info()
62
            super(GROUP_METHODS[:info], 'GROUP')
63
        end
64

    
65
        # Allocates a new Group in OpenNebula
66
        #
67
        # +groupname+ A string containing the name of the Group.
68
        def allocate(groupname)
69
            super(GROUP_METHODS[:allocate], groupname)
70
        end
71

    
72
        # Deletes the Group
73
        def delete()
74
            super(GROUP_METHODS[:delete])
75
        end
76

    
77
        # ---------------------------------------------------------------------
78
        # Helpers to get information
79
        # ---------------------------------------------------------------------
80

    
81
        # Returns the owner (numeric value)
82
        def uid
83
            self['UID'].to_i
84
        end
85

    
86
    end
87
end