Statistics
| Branch: | Tag: | Revision:

one / src / oca / ruby / opennebula / vm_group.rb @ 202b47e9

History | View | Annotate | Download (6.69 KB)

1
# -------------------------------------------------------------------------- #
2
# Copyright 2002-2016, OpenNebula Project, OpenNebula Systems                #
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_element'
18

    
19
module OpenNebula
20
    class VMGroup < PoolElement
21
        #######################################################################
22
        # Constants and Class Methods
23
        #######################################################################
24
        VMGROUP_METHODS = {
25
            :allocate    => "vmgroup.allocate",
26
            :info        => "vmgroup.info",
27
            #:update      => "vmgroup.update",
28
            :delete      => "vmgroup.delete",
29
            #:chown       => "vmgroup.chown",
30
            #:chmod       => "vmgroup.chmod",
31
            #:clone       => "vmgroup.clone",
32
            #:rename      => "vmgroup.rename"
33
        }
34

    
35
        # Creates a VMGroup description with just its identifier
36
        # this method should be used to create plain VMGroup objects.
37
        # @param pe_id [Integer] the id of the object
38
        def VMGroup.build_xml(pe_id=nil)
39
            if pe_id
40
                obj_xml = "<VM_GROUP><ID>#{pe_id}</ID></VM_GROUP>"
41
            else
42
                obj_xml = "<VM_GROUP></VM_GROUP>"
43
            end
44

    
45
            XMLElement.build_xml(obj_xml,'VM_GROUP')
46
        end
47

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

    
52
            @client = client
53
        end
54

    
55
        #######################################################################
56
        # XML-RPC Methods for the VMGroup Object
57
        #######################################################################
58

    
59
        # Retrieves the information of the VMGroup.
60
        def info()
61
            super(VMGROUP_METHODS[:info], 'VM_GROUP')
62
        end
63

    
64
        alias_method :info!, :info
65

    
66
        # Allocates a new VMGroup in OpenNebula
67
        #
68
        # @param description [String] The contents of the VMGroup.
69
        #
70
        # @return [nil, OpenNebula::Error] nil in case of success, Error
71
        #   otherwise
72
        def allocate(description)
73
            super(VMGROUP_METHODS[:allocate], description)
74
        end
75

    
76
        # Deletes the SecurityGroup
77
        def delete()
78
            super(VMGROUP_METHODS[:delete])
79
        end
80
=begin
81
        # Replaces the securitygroup contents
82
        #
83
        # @param new_securitygroup [String] New securitygroup contents
84
        # @param append [true, false] True to append new attributes instead of
85
        #   replace the whole securitygroup
86
        #
87
        # @return [nil, OpenNebula::Error] nil in case of success, Error
88
        #   otherwise
89
        def update(new_securitygroup, append=false)
90
            super(SECGROUP_METHODS[:update], new_securitygroup, append ? 1 : 0)
91
        end
92

93
        # Changes the owner/group
94
        #
95
        # @param uid [Integer] the new owner id. Set to -1 to leave the current one
96
        # @param gid [Integer] the new group id. Set to -1 to leave the current one
97
        # @return [nil, OpenNebula::Error] nil in case of success, Error
98
        #   otherwise
99
        def chown(uid, gid)
100
            super(SECGROUP_METHODS[:chown], uid, gid)
101
        end
102

103
        # Changes the SecurityGroup permissions.
104
        #
105
        # @param octet [String] Permissions octed , e.g. 640
106
        # @return [nil, OpenNebula::Error] nil in case of success, Error
107
        #   otherwise
108
        def chmod_octet(octet)
109
            super(SECGROUP_METHODS[:chmod], octet)
110
        end
111

112
        # Changes the SecurityGroup permissions.
113
        # Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
114
        #
115
        # @return [nil, OpenNebula::Error] nil in case of success, Error
116
        #   otherwise
117
        def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
118
                other_m, other_a)
119
            super(SECGROUP_METHODS[:chmod], owner_u, owner_m, owner_a, group_u,
120
                group_m, group_a, other_u, other_m, other_a)
121
        end
122

123
        # Clones this SecurityGroup into a new one
124
        #
125
        # @param [String] name for the new SecurityGroup.
126
        #
127
        # @return [Integer, OpenNebula::Error] The new SecurityGroup ID in case
128
        #   of success, Error otherwise
129
        def clone(name)
130
            return Error.new('ID not defined') if !@pe_id
131

132
            rc = @client.call(SECGROUP_METHODS[:clone], @pe_id, name)
133

134
            return rc
135
        end
136

137
        # Renames this SecurityGroup
138
        #
139
        # @param name [String] New name for the SecurityGroup.
140
        #
141
        # @return [nil, OpenNebula::Error] nil in case of success, Error
142
        #   otherwise
143
        def rename(name)
144
            return call(SECGROUP_METHODS[:rename], @pe_id, name)
145
        end
146

147
        # Commit SG changes to associated VMs
148
        #
149
        # @param recover [Bool] If true will only operate on outdated and error
150
        # VMs. This is intended for retrying updates of VMs or reinitialize the
151
        # updating process if oned stopped or fail.
152
        #
153
        # @return [nil, OpenNebula::Error] nil in case of success, Error
154
        #   otherwise
155
        def commit(recover)
156
            return call(SECGROUP_METHODS[:commit], @pe_id, recover)
157
        end
158
=end
159
        #######################################################################
160
        # Helpers to get VMGroup information
161
        #######################################################################
162

    
163
        # Returns the group identifier
164
        # [return] _Integer_ the element's group ID
165
        def gid
166
            self['GID'].to_i
167
        end
168

    
169
        def owner_id
170
            self['UID'].to_i
171
        end
172

    
173
        # [return] _Array_ with the name of roles
174
        def role_names
175
            self.retrieve_elements('ROLES/ROLE/NAME')
176
        end
177
    end
178
end