occi 1.2.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/.project +32 -0
- data/.rspec +1 -0
- data/.travis.yml +8 -0
- data/.yardopts +1 -0
- data/AUTHORS +8 -0
- data/Gemfile +35 -14
- data/Gemfile.lock +89 -32
- data/LICENSE +13 -4
- data/README.md +70 -21
- data/Rakefile +25 -21
- data/lib/OpenNebula/Acl.rb +256 -0
- data/lib/OpenNebula/AclPool.rb +53 -0
- data/lib/OpenNebula/Group.rb +147 -0
- data/lib/OpenNebula/GroupPool.rb +54 -0
- data/lib/OpenNebula/Host.rb +143 -0
- data/lib/OpenNebula/HostPool.rb +55 -0
- data/lib/OpenNebula/Image.rb +256 -0
- data/lib/OpenNebula/ImagePool.rb +74 -0
- data/lib/OpenNebula/OpenNebula.rb +137 -0
- data/lib/OpenNebula/Pool.rb +285 -0
- data/lib/OpenNebula/Template.rb +173 -0
- data/lib/OpenNebula/TemplatePool.rb +74 -0
- data/lib/OpenNebula/User.rb +157 -0
- data/lib/OpenNebula/UserPool.rb +53 -0
- data/lib/OpenNebula/VirtualMachine.rb +319 -0
- data/lib/OpenNebula/VirtualMachinePool.rb +120 -0
- data/lib/OpenNebula/VirtualNetwork.rb +229 -0
- data/lib/OpenNebula/VirtualNetworkPool.rb +74 -0
- data/lib/OpenNebula/XMLUtils.rb +337 -0
- data/lib/occi/antlr/.gitignore +18 -0
- data/lib/occi/antlr/OCCI.g +164 -0
- data/lib/occi/antlr/OCCI.tokens +75 -0
- data/lib/occi/antlr/OCCILexer.rb +1532 -0
- data/lib/occi/antlr/OCCIParser.rb +2472 -0
- data/lib/occi/antlr/README.md +2 -0
- data/lib/occi/backend/dummy.rb +232 -0
- data/lib/occi/backend/ec2/Compute.rb +310 -0
- data/lib/occi/backend/ec2/compute.rb +310 -0
- data/lib/occi/backend/ec2/ec2.rb +215 -0
- data/lib/occi/backend/manager.rb +131 -0
- data/lib/occi/backend/opennebula/compute.rb +360 -0
- data/lib/occi/backend/opennebula/network.rb +143 -0
- data/lib/occi/backend/opennebula/opennebula.rb +188 -0
- data/lib/occi/backend/opennebula/storage.rb +175 -0
- data/lib/occi/configuration.rb +118 -0
- data/lib/occi/core/action.rb +29 -0
- data/lib/occi/core/attribute_properties.rb +54 -0
- data/lib/occi/core/attributes.rb +40 -0
- data/lib/occi/core/category.rb +62 -0
- data/lib/occi/core/collection.rb +27 -0
- data/lib/occi/core/entity.rb +135 -0
- data/lib/occi/core/kind.rb +55 -0
- data/lib/occi/core/link.rb +88 -0
- data/lib/occi/core/mixin.rb +43 -0
- data/lib/occi/core/resource.rb +73 -0
- data/lib/occi/exceptions.rb +59 -0
- data/lib/occi/extensions/monitoring/cpu.rb +51 -0
- data/lib/occi/extensions/monitoring/memory.rb +49 -0
- data/lib/occi/extensions/monitoring/metric.rb +54 -0
- data/lib/occi/extensions/monitoring/netrx.rb +49 -0
- data/lib/occi/extensions/monitoring/nettx.rb +55 -0
- data/lib/occi/extensions/one/VNC.rb +58 -0
- data/lib/occi/extensions/one/vnc.rb +58 -0
- data/lib/occi/log.rb +47 -0
- data/lib/occi/parse.rb +164 -0
- data/lib/occi/registry.rb +87 -0
- data/lib/occi/server.rb +594 -0
- data/lib/occi/version.rb +3 -0
- data/occi.gemspec +18 -96
- data/spec/occi/antlr/parser_spec.rb +82 -0
- data/spec/spec_helper.rb +6 -0
- metadata +100 -208
- data/.autotest +0 -21
- data/.rvmrc +0 -1
- data/VERSION +0 -1
- data/lib/occi.rb +0 -1
- data/lib/occi/client.rb +0 -36
- data/lib/occi/compute.rb +0 -4
- data/lib/occi/network.rb +0 -4
- data/lib/occi/resource.rb +0 -59
- data/lib/occi/storage.rb +0 -7
- data/test/fixtures/cassettes/compute_all.yml +0 -28
- data/test/fixtures/cassettes/compute_create.yml +0 -45
- data/test/fixtures/cassettes/compute_destroy.yml +0 -22
- data/test/fixtures/cassettes/compute_find.yml +0 -28
- data/test/fixtures/cassettes/compute_update.yml +0 -35
- data/test/fixtures/cassettes/network_all.yml +0 -28
- data/test/fixtures/cassettes/network_create.yml +0 -37
- data/test/fixtures/cassettes/network_destroy.yml +0 -22
- data/test/fixtures/cassettes/network_find.yml +0 -28
- data/test/fixtures/cassettes/storage_all.yml +0 -28
- data/test/fixtures/cassettes/storage_create.yml +0 -50
- data/test/fixtures/cassettes/storage_destroy.yml +0 -22
- data/test/fixtures/cassettes/storage_find.yml +0 -28
- data/test/lib/occi/compute_test.rb +0 -91
- data/test/lib/occi/network_test.rb +0 -57
- data/test/lib/occi/storage_test.rb +0 -67
- data/test/test_helper.rb +0 -48
@@ -0,0 +1,285 @@
|
|
1
|
+
# -------------------------------------------------------------------------- #
|
2
|
+
# Copyright 2002-2012, 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
|
+
|
18
|
+
module OpenNebula
|
19
|
+
|
20
|
+
# The Pool class represents a generic OpenNebula Pool in XML format
|
21
|
+
# and provides the basic functionality to handle the Pool elements
|
22
|
+
class Pool < XMLPool
|
23
|
+
include Enumerable
|
24
|
+
|
25
|
+
protected
|
26
|
+
#pool:: _String_ XML name of the root element
|
27
|
+
#element:: _String_ XML name of the Pool elements
|
28
|
+
#client:: _Client_ represents a XML-RPC connection
|
29
|
+
def initialize(pool,element,client)
|
30
|
+
super(nil)
|
31
|
+
|
32
|
+
@pool_name = pool.upcase
|
33
|
+
@element_name = element.upcase
|
34
|
+
|
35
|
+
@client = client
|
36
|
+
end
|
37
|
+
|
38
|
+
# Default Factory Method for the Pools. The factory method returns an
|
39
|
+
# suitable PoolElement object. Each Pool MUST implement the
|
40
|
+
# corresponding factory method
|
41
|
+
# element_xml:: _XML_ XML element describing the pool element
|
42
|
+
# [return] a PoolElement object
|
43
|
+
def factory(element_xml)
|
44
|
+
OpenNebula::PoolElement.new(element_xml,client)
|
45
|
+
end
|
46
|
+
|
47
|
+
#######################################################################
|
48
|
+
# Common XML-RPC Methods for all the Pool Types
|
49
|
+
#######################################################################
|
50
|
+
|
51
|
+
#Gets the pool without any filter. Host, Group and User Pools
|
52
|
+
# xml_method:: _String_ the name of the XML-RPC method
|
53
|
+
def info(xml_method)
|
54
|
+
return xmlrpc_info(xml_method)
|
55
|
+
end
|
56
|
+
|
57
|
+
def info_all(xml_method)
|
58
|
+
return xmlrpc_info(xml_method,INFO_ALL,-1,-1)
|
59
|
+
end
|
60
|
+
|
61
|
+
def info_mine(xml_method)
|
62
|
+
return xmlrpc_info(xml_method,INFO_MINE,-1,-1)
|
63
|
+
end
|
64
|
+
|
65
|
+
def info_group(xml_method)
|
66
|
+
return xmlrpc_info(xml_method,INFO_GROUP,-1,-1)
|
67
|
+
end
|
68
|
+
|
69
|
+
def info_filter(xml_method, who, start_id, end_id)
|
70
|
+
return xmlrpc_info(xml_method,who, start_id, end_id)
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
# Calls to the corresponding info method to retreive the pool
|
75
|
+
# representation in XML format
|
76
|
+
# xml_method:: _String_ the name of the XML-RPC method
|
77
|
+
# args:: _Array_ with additional arguments for the info call
|
78
|
+
# [return] nil in case of success or an Error object
|
79
|
+
def xmlrpc_info(xml_method,*args)
|
80
|
+
rc = @client.call(xml_method,*args)
|
81
|
+
|
82
|
+
if !OpenNebula.is_error?(rc)
|
83
|
+
initialize_xml(rc,@pool_name)
|
84
|
+
rc = nil
|
85
|
+
end
|
86
|
+
|
87
|
+
return rc
|
88
|
+
end
|
89
|
+
|
90
|
+
public
|
91
|
+
# Constants for info queries (include/RequestManagerPoolInfoFilter.h)
|
92
|
+
INFO_GROUP = -1
|
93
|
+
INFO_ALL = -2
|
94
|
+
INFO_MINE = -3
|
95
|
+
|
96
|
+
# Iterates over every PoolElement in the Pool and calls the block with a
|
97
|
+
# a PoolElement obtained calling the factory method
|
98
|
+
# block:: _Block_
|
99
|
+
def each(&block)
|
100
|
+
each_element(block) if @xml
|
101
|
+
end
|
102
|
+
|
103
|
+
# DO NOT USE - ONLY REXML BACKEND
|
104
|
+
def to_str
|
105
|
+
str = ""
|
106
|
+
REXML::Formatters::Pretty.new(1).write(@xml,str)
|
107
|
+
|
108
|
+
return str
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# The PoolElement Class represents a generic element of a Pool in
|
113
|
+
# XML format
|
114
|
+
class PoolElement < XMLElement
|
115
|
+
|
116
|
+
protected
|
117
|
+
# node:: _XML_is a XML element that represents the Pool element
|
118
|
+
# client:: _Client_ represents a XML-RPC connection
|
119
|
+
def initialize(node, client)
|
120
|
+
@xml = node
|
121
|
+
@client = client
|
122
|
+
|
123
|
+
if self['ID']
|
124
|
+
@pe_id = self['ID'].to_i
|
125
|
+
else
|
126
|
+
@pe_id = nil
|
127
|
+
end
|
128
|
+
@name = self['NAME'] if self['NAME']
|
129
|
+
end
|
130
|
+
|
131
|
+
#######################################################################
|
132
|
+
# Common XML-RPC Methods for all the Pool Element Types
|
133
|
+
#######################################################################
|
134
|
+
|
135
|
+
# Calls to the corresponding info method to retreive the element
|
136
|
+
# detailed information in XML format
|
137
|
+
# xml_method:: _String_ the name of the XML-RPC method
|
138
|
+
# root_element:: _String_ Base XML element
|
139
|
+
# [return] nil in case of success or an Error object
|
140
|
+
def info(xml_method, root_element)
|
141
|
+
return Error.new('ID not defined') if !@pe_id
|
142
|
+
|
143
|
+
rc = @client.call(xml_method,@pe_id)
|
144
|
+
|
145
|
+
if !OpenNebula.is_error?(rc)
|
146
|
+
initialize_xml(rc, root_element)
|
147
|
+
rc = nil
|
148
|
+
|
149
|
+
@pe_id = self['ID'].to_i if self['ID']
|
150
|
+
@name = self['NAME'] if self['NAME']
|
151
|
+
end
|
152
|
+
|
153
|
+
return rc
|
154
|
+
end
|
155
|
+
|
156
|
+
# Calls to the corresponding allocate method to create a new element
|
157
|
+
# in the OpenNebula core
|
158
|
+
# xml_method:: _String_ the name of the XML-RPC method
|
159
|
+
# args:: _Array_ additional arguments including the template for the
|
160
|
+
# new element
|
161
|
+
# [return] nil in case of success or an Error object
|
162
|
+
def allocate(xml_method, *args)
|
163
|
+
rc = @client.call(xml_method, *args)
|
164
|
+
|
165
|
+
if !OpenNebula.is_error?(rc)
|
166
|
+
@pe_id = rc
|
167
|
+
rc = nil
|
168
|
+
end
|
169
|
+
|
170
|
+
return rc
|
171
|
+
end
|
172
|
+
|
173
|
+
# Calls to the corresponding update method to modify
|
174
|
+
# the object's template
|
175
|
+
# xml_method:: _String_ the name of the XML-RPC method
|
176
|
+
# new_template:: _String_ the new template contents
|
177
|
+
# [return] nil in case of success or an Error object
|
178
|
+
def update(xml_method, new_template)
|
179
|
+
return Error.new('ID not defined') if !@pe_id
|
180
|
+
|
181
|
+
rc = @client.call(xml_method,@pe_id, new_template)
|
182
|
+
rc = nil if !OpenNebula.is_error?(rc)
|
183
|
+
|
184
|
+
return rc
|
185
|
+
end
|
186
|
+
|
187
|
+
# Calls to the corresponding delete method to remove this element
|
188
|
+
# from the OpenNebula core
|
189
|
+
# xml_method:: _String_ the name of the XML-RPC method
|
190
|
+
# [return] nil in case of success or an Error object
|
191
|
+
def delete(xml_method)
|
192
|
+
return Error.new('ID not defined') if !@pe_id
|
193
|
+
|
194
|
+
rc = @client.call(xml_method,@pe_id)
|
195
|
+
rc = nil if !OpenNebula.is_error?(rc)
|
196
|
+
|
197
|
+
return rc
|
198
|
+
end
|
199
|
+
|
200
|
+
# Calls to the corresponding chown method to modify
|
201
|
+
# the object's owner and group
|
202
|
+
# xml_method:: _String_ the name of the XML-RPC method
|
203
|
+
# uid:: _Integer_ the new owner id. Set to -1 to leave the current one
|
204
|
+
# gid:: _Integer_ the new group id. Set to -1 to leave the current one
|
205
|
+
# [return] nil in case of success or an Error object
|
206
|
+
def chown(xml_method, uid, gid)
|
207
|
+
return Error.new('ID not defined') if !@pe_id
|
208
|
+
|
209
|
+
rc = @client.call(xml_method,@pe_id, uid, gid)
|
210
|
+
rc = nil if !OpenNebula.is_error?(rc)
|
211
|
+
|
212
|
+
return rc
|
213
|
+
end
|
214
|
+
|
215
|
+
# Calls to the corresponding chmod method to modify
|
216
|
+
# the object's permission bits
|
217
|
+
#
|
218
|
+
# @param xml_method [String] the name of the XML-RPC method
|
219
|
+
# @param octet [String] Permissions octed , e.g. 640
|
220
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
221
|
+
# otherwise
|
222
|
+
def chmod_octet(xml_method, octet)
|
223
|
+
owner_u = octet[0..0].to_i & 4 != 0 ? 1 : 0
|
224
|
+
owner_m = octet[0..0].to_i & 2 != 0 ? 1 : 0
|
225
|
+
owner_a = octet[0..0].to_i & 1 != 0 ? 1 : 0
|
226
|
+
group_u = octet[1..1].to_i & 4 != 0 ? 1 : 0
|
227
|
+
group_m = octet[1..1].to_i & 2 != 0 ? 1 : 0
|
228
|
+
group_a = octet[1..1].to_i & 1 != 0 ? 1 : 0
|
229
|
+
other_u = octet[2..2].to_i & 4 != 0 ? 1 : 0
|
230
|
+
other_m = octet[2..2].to_i & 2 != 0 ? 1 : 0
|
231
|
+
other_a = octet[2..2].to_i & 1 != 0 ? 1 : 0
|
232
|
+
|
233
|
+
chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
|
234
|
+
other_m, other_a)
|
235
|
+
end
|
236
|
+
|
237
|
+
# Calls to the corresponding chmod method to modify
|
238
|
+
# the object's permission bits
|
239
|
+
# Each [Integer] parameter must be 1 to allow, 0 deny, -1 do not change
|
240
|
+
#
|
241
|
+
# @param xml_method [String] the name of the XML-RPC method
|
242
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
243
|
+
# otherwise
|
244
|
+
def chmod(xml_method, owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
|
245
|
+
other_m, other_a)
|
246
|
+
return Error.new('ID not defined') if !@pe_id
|
247
|
+
|
248
|
+
rc = @client.call(xml_method, @pe_id, owner_u, owner_m,
|
249
|
+
owner_a, group_u, group_m, group_a, other_u,
|
250
|
+
other_m, other_a)
|
251
|
+
rc = nil if !OpenNebula.is_error?(rc)
|
252
|
+
|
253
|
+
return rc
|
254
|
+
end
|
255
|
+
|
256
|
+
public
|
257
|
+
|
258
|
+
# Creates new element specifying its id
|
259
|
+
# id:: identifyier of the element
|
260
|
+
# client:: initialized OpenNebula::Client object
|
261
|
+
def self.new_with_id(id, client=nil)
|
262
|
+
self.new(self.build_xml(id), client)
|
263
|
+
end
|
264
|
+
|
265
|
+
# Returns element identifier
|
266
|
+
# [return] _Integer_ the PoolElement ID
|
267
|
+
def id
|
268
|
+
@pe_id
|
269
|
+
end
|
270
|
+
|
271
|
+
# Gets element name
|
272
|
+
# [return] _String_ the PoolElement name
|
273
|
+
def name
|
274
|
+
@name
|
275
|
+
end
|
276
|
+
|
277
|
+
# DO NOT USE - ONLY REXML BACKEND
|
278
|
+
def to_str
|
279
|
+
str = ""
|
280
|
+
REXML::Formatters::Pretty.new(1).write(@xml,str)
|
281
|
+
|
282
|
+
return str
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
# -------------------------------------------------------------------------- #
|
2
|
+
# Copyright 2002-2012, 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
|
+
|
18
|
+
require 'OpenNebula/Pool'
|
19
|
+
|
20
|
+
module OpenNebula
|
21
|
+
class Template < PoolElement
|
22
|
+
#######################################################################
|
23
|
+
# Constants and Class Methods
|
24
|
+
#######################################################################
|
25
|
+
|
26
|
+
|
27
|
+
TEMPLATE_METHODS = {
|
28
|
+
:allocate => "template.allocate",
|
29
|
+
:instantiate => "template.instantiate",
|
30
|
+
:info => "template.info",
|
31
|
+
:update => "template.update",
|
32
|
+
:publish => "template.publish",
|
33
|
+
:delete => "template.delete",
|
34
|
+
:chown => "template.chown",
|
35
|
+
:chmod => "template.chmod"
|
36
|
+
}
|
37
|
+
|
38
|
+
# Creates a Template description with just its identifier
|
39
|
+
# this method should be used to create plain Template objects.
|
40
|
+
# +id+ the id of the user
|
41
|
+
#
|
42
|
+
# Example:
|
43
|
+
# template = Template.new(Template.build_xml(3),rpc_client)
|
44
|
+
#
|
45
|
+
def Template.build_xml(pe_id=nil)
|
46
|
+
if pe_id
|
47
|
+
obj_xml = "<VMTEMPLATE><ID>#{pe_id}</ID></VMTEMPLATE>"
|
48
|
+
else
|
49
|
+
obj_xml = "<VMTEMPLATE></VMTEMPLATE>"
|
50
|
+
end
|
51
|
+
|
52
|
+
XMLElement.build_xml(obj_xml,'VMTEMPLATE')
|
53
|
+
end
|
54
|
+
|
55
|
+
# Class constructor
|
56
|
+
def initialize(xml, client)
|
57
|
+
super(xml,client)
|
58
|
+
|
59
|
+
@client = client
|
60
|
+
end
|
61
|
+
|
62
|
+
#######################################################################
|
63
|
+
# XML-RPC Methods for the Template Object
|
64
|
+
#######################################################################
|
65
|
+
|
66
|
+
# Retrieves the information of the given Template.
|
67
|
+
def info()
|
68
|
+
super(TEMPLATE_METHODS[:info], 'VMTEMPLATE')
|
69
|
+
end
|
70
|
+
|
71
|
+
# Allocates a new Template in OpenNebula
|
72
|
+
#
|
73
|
+
# +templatename+ A string containing the name of the Template.
|
74
|
+
def allocate(templatename)
|
75
|
+
super(TEMPLATE_METHODS[:allocate], templatename)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Deletes the Template
|
79
|
+
def delete()
|
80
|
+
super(TEMPLATE_METHODS[:delete])
|
81
|
+
end
|
82
|
+
|
83
|
+
# Creates a VM instance from a Template
|
84
|
+
#
|
85
|
+
# +name+ A string containing the name of the VM instance.
|
86
|
+
# [return] The new VM Instance ID, or an Error object
|
87
|
+
def instantiate(name="")
|
88
|
+
return Error.new('ID not defined') if !@pe_id
|
89
|
+
|
90
|
+
name ||= ""
|
91
|
+
rc = @client.call(TEMPLATE_METHODS[:instantiate], @pe_id, name)
|
92
|
+
|
93
|
+
return rc
|
94
|
+
end
|
95
|
+
|
96
|
+
# Replaces the template contents
|
97
|
+
#
|
98
|
+
# +new_template+ New template contents
|
99
|
+
def update(new_template)
|
100
|
+
return Error.new('ID not defined') if !@pe_id
|
101
|
+
|
102
|
+
super(TEMPLATE_METHODS[:update], new_template)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Publishes the Template, to be used by other users
|
106
|
+
def publish
|
107
|
+
set_publish(true)
|
108
|
+
end
|
109
|
+
|
110
|
+
# Unplubishes the Image
|
111
|
+
def unpublish
|
112
|
+
set_publish(false)
|
113
|
+
end
|
114
|
+
|
115
|
+
# Changes the owner/group
|
116
|
+
# uid:: _Integer_ the new owner id. Set to -1 to leave the current one
|
117
|
+
# gid:: _Integer_ the new group id. Set to -1 to leave the current one
|
118
|
+
# [return] nil in case of success or an Error object
|
119
|
+
def chown(uid, gid)
|
120
|
+
super(TEMPLATE_METHODS[:chown], uid, gid)
|
121
|
+
end
|
122
|
+
|
123
|
+
# Changes the Template permissions.
|
124
|
+
#
|
125
|
+
# @param octet [String] Permissions octed , e.g. 640
|
126
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
127
|
+
# otherwise
|
128
|
+
def chmod_octet(octet)
|
129
|
+
super(TEMPLATE_METHODS[:chmod], octet)
|
130
|
+
end
|
131
|
+
|
132
|
+
# Changes the Template permissions.
|
133
|
+
# Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
|
134
|
+
#
|
135
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
136
|
+
# otherwise
|
137
|
+
def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
|
138
|
+
other_m, other_a)
|
139
|
+
super(TEMPLATE_METHODS[:chmod], owner_u, owner_m, owner_a, group_u,
|
140
|
+
group_m, group_a, other_u, other_m, other_a)
|
141
|
+
end
|
142
|
+
|
143
|
+
#######################################################################
|
144
|
+
# Helpers to get Template information
|
145
|
+
#######################################################################
|
146
|
+
|
147
|
+
# Returns the group identifier
|
148
|
+
# [return] _Integer_ the element's group ID
|
149
|
+
def gid
|
150
|
+
self['GID'].to_i
|
151
|
+
end
|
152
|
+
|
153
|
+
def owner_id
|
154
|
+
self['UID'].to_i
|
155
|
+
end
|
156
|
+
|
157
|
+
def public?
|
158
|
+
if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1"
|
159
|
+
true
|
160
|
+
else
|
161
|
+
false
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
private
|
166
|
+
|
167
|
+
def set_publish(published)
|
168
|
+
group_u = published ? 1 : 0
|
169
|
+
|
170
|
+
chmod(-1, -1, -1, group_u, -1, -1, -1, -1, -1)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|