opennebula-oca 3.8.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/OpenNebula/Acl.rb +259 -0
- data/lib/OpenNebula/AclPool.rb +53 -0
- data/lib/OpenNebula/Cluster.rb +247 -0
- data/lib/OpenNebula/ClusterPool.rb +56 -0
- data/lib/OpenNebula/Datastore.rb +147 -0
- data/lib/OpenNebula/DatastorePool.rb +53 -0
- data/lib/OpenNebula/Document.rb +248 -0
- data/lib/OpenNebula/DocumentJSON.rb +129 -0
- data/lib/OpenNebula/DocumentPool.rb +97 -0
- data/lib/OpenNebula/DocumentPoolJSON.rb +58 -0
- data/lib/OpenNebula/Group.rb +161 -0
- data/lib/OpenNebula/GroupPool.rb +54 -0
- data/lib/OpenNebula/Host.rb +199 -0
- data/lib/OpenNebula/HostPool.rb +91 -0
- data/lib/OpenNebula/Image.rb +279 -0
- data/lib/OpenNebula/ImagePool.rb +74 -0
- data/lib/OpenNebula/Pool.rb +406 -0
- data/lib/OpenNebula/Template.rb +190 -0
- data/lib/OpenNebula/TemplatePool.rb +74 -0
- data/lib/OpenNebula/User.rb +172 -0
- data/lib/OpenNebula/UserPool.rb +53 -0
- data/lib/OpenNebula/VirtualMachine.rb +406 -0
- data/lib/OpenNebula/VirtualMachinePool.rb +318 -0
- data/lib/OpenNebula/VirtualNetwork.rb +236 -0
- data/lib/OpenNebula/VirtualNetworkPool.rb +74 -0
- data/lib/OpenNebula/XMLUtils.rb +436 -0
- data/lib/OpenNebula.rb +175 -0
- metadata +94 -0
@@ -0,0 +1,406 @@
|
|
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, *args)
|
58
|
+
return xmlrpc_info(xml_method,INFO_ALL,-1,-1, *args)
|
59
|
+
end
|
60
|
+
|
61
|
+
def info_mine(xml_method, *args)
|
62
|
+
return xmlrpc_info(xml_method,INFO_MINE,-1,-1, *args)
|
63
|
+
end
|
64
|
+
|
65
|
+
def info_group(xml_method, *args)
|
66
|
+
return xmlrpc_info(xml_method,INFO_GROUP,-1,-1, *args)
|
67
|
+
end
|
68
|
+
|
69
|
+
def info_filter(xml_method, who, start_id, end_id, *args)
|
70
|
+
return xmlrpc_info(xml_method,who, start_id, end_id, *args)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Retrieves the monitoring data for all the Objects in the pool
|
74
|
+
#
|
75
|
+
# @param [String] xml_method xml-rcp method
|
76
|
+
# @param [String] root_elem Root for each individual PoolElement
|
77
|
+
# @param [String] timestamp_elem Name of the XML element with the last
|
78
|
+
# monitorization timestamp
|
79
|
+
# @param [Array<String>] xpath_expressions Elements to retrieve.
|
80
|
+
# @param args arguemnts for the xml_method call
|
81
|
+
#
|
82
|
+
# @return [Hash<String, <Hash<String, Array<Array<int>>>>>,
|
83
|
+
# OpenNebula::Error] The first level hash uses the Object ID as keys,
|
84
|
+
# and as value a Hash with the requested xpath expressions,
|
85
|
+
# and an Array of 'timestamp, value'.
|
86
|
+
def monitoring(xml_method, root_elem, timestamp_elem, xpath_expressions,
|
87
|
+
*args)
|
88
|
+
|
89
|
+
rc = @client.call(xml_method, *args)
|
90
|
+
|
91
|
+
if ( OpenNebula.is_error?(rc) )
|
92
|
+
return rc
|
93
|
+
end
|
94
|
+
|
95
|
+
xmldoc = XMLElement.new
|
96
|
+
xmldoc.initialize_xml(rc, 'MONITORING_DATA')
|
97
|
+
|
98
|
+
hash = {}
|
99
|
+
|
100
|
+
# Get all existing Object IDs
|
101
|
+
ids = xmldoc.retrieve_elements("#{root_elem}/ID")
|
102
|
+
|
103
|
+
if ids.nil?
|
104
|
+
return hash
|
105
|
+
else
|
106
|
+
ids.uniq!
|
107
|
+
end
|
108
|
+
|
109
|
+
ids.each { |id|
|
110
|
+
hash[id] = OpenNebula.process_monitoring(
|
111
|
+
xmldoc, root_elem, timestamp_elem, id, xpath_expressions)
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
return hash
|
116
|
+
end
|
117
|
+
|
118
|
+
private
|
119
|
+
# Calls to the corresponding info method to retreive the pool
|
120
|
+
# representation in XML format
|
121
|
+
# xml_method:: _String_ the name of the XML-RPC method
|
122
|
+
# args:: _Array_ with additional arguments for the info call
|
123
|
+
# [return] nil in case of success or an Error object
|
124
|
+
def xmlrpc_info(xml_method,*args)
|
125
|
+
rc = @client.call(xml_method,*args)
|
126
|
+
|
127
|
+
if !OpenNebula.is_error?(rc)
|
128
|
+
initialize_xml(rc,@pool_name)
|
129
|
+
rc = nil
|
130
|
+
end
|
131
|
+
|
132
|
+
return rc
|
133
|
+
end
|
134
|
+
|
135
|
+
public
|
136
|
+
# Constants for info queries (include/RequestManagerPoolInfoFilter.h)
|
137
|
+
INFO_GROUP = -1
|
138
|
+
INFO_ALL = -2
|
139
|
+
INFO_MINE = -3
|
140
|
+
|
141
|
+
# Iterates over every PoolElement in the Pool and calls the block with a
|
142
|
+
# a PoolElement obtained calling the factory method
|
143
|
+
# block:: _Block_
|
144
|
+
def each(&block)
|
145
|
+
each_element(block) if @xml
|
146
|
+
end
|
147
|
+
|
148
|
+
# DO NOT USE - ONLY REXML BACKEND
|
149
|
+
def to_str
|
150
|
+
str = ""
|
151
|
+
REXML::Formatters::Pretty.new(1).write(@xml,str)
|
152
|
+
|
153
|
+
return str
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
# The PoolElement Class represents a generic element of a Pool in
|
158
|
+
# XML format
|
159
|
+
class PoolElement < XMLElement
|
160
|
+
|
161
|
+
protected
|
162
|
+
# node:: _XML_is a XML element that represents the Pool element
|
163
|
+
# client:: _Client_ represents a XML-RPC connection
|
164
|
+
def initialize(node, client)
|
165
|
+
@xml = node
|
166
|
+
@client = client
|
167
|
+
|
168
|
+
if self['ID']
|
169
|
+
@pe_id = self['ID'].to_i
|
170
|
+
else
|
171
|
+
@pe_id = nil
|
172
|
+
end
|
173
|
+
@name = self['NAME'] if self['NAME']
|
174
|
+
end
|
175
|
+
|
176
|
+
#######################################################################
|
177
|
+
# Common XML-RPC Methods for all the Pool Element Types
|
178
|
+
#######################################################################
|
179
|
+
|
180
|
+
# Common client call wrapper. Checks that @pe_id is defined, and
|
181
|
+
# returns nil instead of the response if it is successful
|
182
|
+
#
|
183
|
+
# @param [String] xml_method xml-rpc method
|
184
|
+
# @param [Array] args any arguments for the xml-rpc method
|
185
|
+
#
|
186
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
187
|
+
# otherwise
|
188
|
+
def call(xml_method, *args)
|
189
|
+
return Error.new('ID not defined') if !@pe_id
|
190
|
+
|
191
|
+
rc = @client.call(xml_method, *args)
|
192
|
+
rc = nil if !OpenNebula.is_error?(rc)
|
193
|
+
|
194
|
+
return rc
|
195
|
+
end
|
196
|
+
|
197
|
+
# Calls to the corresponding info method to retreive the element
|
198
|
+
# detailed information in XML format
|
199
|
+
#
|
200
|
+
# @param [String] xml_method the name of the XML-RPC method
|
201
|
+
# @param [String] root_element Base XML element name
|
202
|
+
# @param [Array] args additional arguments
|
203
|
+
#
|
204
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
205
|
+
# otherwise
|
206
|
+
def info(xml_method, root_element)
|
207
|
+
return Error.new('ID not defined') if !@pe_id
|
208
|
+
|
209
|
+
rc = @client.call(xml_method, @pe_id)
|
210
|
+
|
211
|
+
if !OpenNebula.is_error?(rc)
|
212
|
+
initialize_xml(rc, root_element)
|
213
|
+
rc = nil
|
214
|
+
|
215
|
+
@pe_id = self['ID'].to_i if self['ID']
|
216
|
+
@name = self['NAME'] if self['NAME']
|
217
|
+
end
|
218
|
+
|
219
|
+
return rc
|
220
|
+
end
|
221
|
+
|
222
|
+
# Calls to the corresponding allocate method to create a new element
|
223
|
+
# in the OpenNebula core
|
224
|
+
#
|
225
|
+
# @param [String] xml_method the name of the XML-RPC method
|
226
|
+
# @param [Array] args any extra arguments for the xml-rpc method
|
227
|
+
#
|
228
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
229
|
+
# otherwise
|
230
|
+
def allocate(xml_method, *args)
|
231
|
+
rc = @client.call(xml_method, *args)
|
232
|
+
|
233
|
+
if !OpenNebula.is_error?(rc)
|
234
|
+
@pe_id = rc
|
235
|
+
rc = nil
|
236
|
+
end
|
237
|
+
|
238
|
+
return rc
|
239
|
+
end
|
240
|
+
|
241
|
+
# Calls to the corresponding update method to modify
|
242
|
+
# the object's template
|
243
|
+
#
|
244
|
+
# @param [String] xml_method the name of the XML-RPC method
|
245
|
+
# @param [String] new_template the new template contents
|
246
|
+
# @param [Array] args any extra arguments for the xml-rpc method
|
247
|
+
#
|
248
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
249
|
+
# otherwise
|
250
|
+
def update(xml_method, new_template, *args)
|
251
|
+
new_template ||= template_xml
|
252
|
+
|
253
|
+
return call(xml_method, @pe_id, new_template, *args)
|
254
|
+
end
|
255
|
+
|
256
|
+
# Calls to the corresponding delete method to remove this element
|
257
|
+
# from the OpenNebula core
|
258
|
+
#
|
259
|
+
# @param [String] xml_method the name of the XML-RPC method
|
260
|
+
#
|
261
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
262
|
+
# otherwise
|
263
|
+
def delete(xml_method)
|
264
|
+
return call(xml_method,@pe_id)
|
265
|
+
end
|
266
|
+
|
267
|
+
# Calls to the corresponding chown method to modify
|
268
|
+
# the object's owner and group
|
269
|
+
#
|
270
|
+
# @param [String] xml_method the name of the XML-RPC method
|
271
|
+
# @param [Integer] uid the new owner id. Set to -1 to leave the current one
|
272
|
+
# @param [Integer] gid the new goup id. Set to -1 to leave the current one
|
273
|
+
#
|
274
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
275
|
+
# otherwise
|
276
|
+
def chown(xml_method, uid, gid)
|
277
|
+
return call(xml_method, @pe_id, uid, gid)
|
278
|
+
end
|
279
|
+
|
280
|
+
# Calls to the corresponding chmod method to modify
|
281
|
+
# the object's permission bits
|
282
|
+
#
|
283
|
+
# @param xml_method [String] the name of the XML-RPC method
|
284
|
+
# @param octet [String] Permissions octed , e.g. 640
|
285
|
+
#
|
286
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
287
|
+
# otherwise
|
288
|
+
def chmod_octet(xml_method, octet)
|
289
|
+
owner_u = octet[0..0].to_i & 4 != 0 ? 1 : 0
|
290
|
+
owner_m = octet[0..0].to_i & 2 != 0 ? 1 : 0
|
291
|
+
owner_a = octet[0..0].to_i & 1 != 0 ? 1 : 0
|
292
|
+
group_u = octet[1..1].to_i & 4 != 0 ? 1 : 0
|
293
|
+
group_m = octet[1..1].to_i & 2 != 0 ? 1 : 0
|
294
|
+
group_a = octet[1..1].to_i & 1 != 0 ? 1 : 0
|
295
|
+
other_u = octet[2..2].to_i & 4 != 0 ? 1 : 0
|
296
|
+
other_m = octet[2..2].to_i & 2 != 0 ? 1 : 0
|
297
|
+
other_a = octet[2..2].to_i & 1 != 0 ? 1 : 0
|
298
|
+
|
299
|
+
chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
|
300
|
+
other_m, other_a)
|
301
|
+
end
|
302
|
+
|
303
|
+
# Calls to the corresponding chmod method to modify
|
304
|
+
# the object's permission bits
|
305
|
+
# Each [Integer] parameter must be 1 to allow, 0 deny, -1 do not change
|
306
|
+
#
|
307
|
+
# @param xml_method [String] the name of the XML-RPC method
|
308
|
+
#
|
309
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
310
|
+
# otherwise
|
311
|
+
def chmod(xml_method, owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
|
312
|
+
other_m, other_a)
|
313
|
+
return call(xml_method, @pe_id, owner_u, owner_m,
|
314
|
+
owner_a, group_u, group_m, group_a, other_u,
|
315
|
+
other_m, other_a)
|
316
|
+
end
|
317
|
+
|
318
|
+
|
319
|
+
# Retrieves this Element's monitoring data from OpenNebula
|
320
|
+
#
|
321
|
+
# @param [String] xml_method the name of the XML-RPC method
|
322
|
+
# @param [String] root_elem Root for each individual PoolElement
|
323
|
+
# @param [String] timestamp_elem Name of the XML element with the last
|
324
|
+
# monitorization timestamp
|
325
|
+
# @param xpath_expressions [Array<String>] Xpath expressions for the
|
326
|
+
# elements to retrieve.
|
327
|
+
#
|
328
|
+
# @return [Hash<String, Array<Array<int>>, OpenNebula::Error] Hash with
|
329
|
+
# the requested xpath expressions, and an Array of [timestamp, value].
|
330
|
+
def monitoring(xml_method, root_elem, timestamp_elem, xpath_expressions)
|
331
|
+
return Error.new('ID not defined') if !@pe_id
|
332
|
+
|
333
|
+
rc = @client.call(xml_method, @pe_id)
|
334
|
+
|
335
|
+
if ( OpenNebula.is_error?(rc) )
|
336
|
+
return rc
|
337
|
+
end
|
338
|
+
|
339
|
+
xmldoc = XMLElement.new
|
340
|
+
xmldoc.initialize_xml(rc, 'MONITORING_DATA')
|
341
|
+
|
342
|
+
|
343
|
+
return OpenNebula.process_monitoring(
|
344
|
+
xmldoc, root_elem, timestamp_elem, @pe_id, xpath_expressions)
|
345
|
+
end
|
346
|
+
|
347
|
+
public
|
348
|
+
|
349
|
+
# Creates new element specifying its id
|
350
|
+
# id:: identifyier of the element
|
351
|
+
# client:: initialized OpenNebula::Client object
|
352
|
+
def self.new_with_id(id, client=nil)
|
353
|
+
self.new(self.build_xml(id), client)
|
354
|
+
end
|
355
|
+
|
356
|
+
# Returns element identifier
|
357
|
+
# [return] _Integer_ the PoolElement ID
|
358
|
+
def id
|
359
|
+
@pe_id
|
360
|
+
end
|
361
|
+
|
362
|
+
# Gets element name
|
363
|
+
# [return] _String_ the PoolElement name
|
364
|
+
def name
|
365
|
+
@name
|
366
|
+
end
|
367
|
+
|
368
|
+
# DO NOT USE - ONLY REXML BACKEND
|
369
|
+
def to_str
|
370
|
+
str = ""
|
371
|
+
REXML::Formatters::Pretty.new(1).write(@xml,str)
|
372
|
+
|
373
|
+
return str
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
# Processes the monitoring data in XML returned by OpenNebula
|
378
|
+
#
|
379
|
+
# @param [XMLElement] xmldoc monitoring data returned by OpenNebula
|
380
|
+
# @param [String] root_elem Root for each individual PoolElement
|
381
|
+
# @param [String] timestamp_elem Name of the XML element with the last
|
382
|
+
# monitorization timestamp
|
383
|
+
# @param [Integer] Id of the object to process
|
384
|
+
# @param [Array<String>] xpath_expressions Elements to retrieve.
|
385
|
+
# @param args arguemnts for the xml_method call
|
386
|
+
#
|
387
|
+
# @return [Hash<String, Array<Array<int>>, OpenNebula::Error] Hash with
|
388
|
+
# the requested xpath expressions, and an Array of [timestamp, value].
|
389
|
+
def self.process_monitoring(xmldoc, root_elem, timestamp_elem, oid, xpath_expressions)
|
390
|
+
hash = {}
|
391
|
+
timestamps = xmldoc.retrieve_elements(
|
392
|
+
"#{root_elem}[ID=#{oid}]/#{timestamp_elem}")
|
393
|
+
|
394
|
+
xpath_expressions.each { |xpath|
|
395
|
+
xpath_values = xmldoc.retrieve_elements("#{root_elem}[ID=#{oid}]/#{xpath}")
|
396
|
+
|
397
|
+
if ( xpath_values.nil? )
|
398
|
+
hash[xpath] = []
|
399
|
+
else
|
400
|
+
hash[xpath] = timestamps.zip(xpath_values)
|
401
|
+
end
|
402
|
+
}
|
403
|
+
|
404
|
+
return hash
|
405
|
+
end
|
406
|
+
end
|
@@ -0,0 +1,190 @@
|
|
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
|
+
:delete => "template.delete",
|
33
|
+
:chown => "template.chown",
|
34
|
+
:chmod => "template.chmod",
|
35
|
+
:clone => "template.clone"
|
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
|
+
# @param description [String] The contents of the Template.
|
74
|
+
#
|
75
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
76
|
+
# otherwise
|
77
|
+
def allocate(description)
|
78
|
+
super(TEMPLATE_METHODS[:allocate], description)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Deletes the Template
|
82
|
+
def delete()
|
83
|
+
super(TEMPLATE_METHODS[:delete])
|
84
|
+
end
|
85
|
+
|
86
|
+
# Creates a VM instance from a Template
|
87
|
+
#
|
88
|
+
# +name+ A string containing the name of the VM instance.
|
89
|
+
# [return] The new VM Instance ID, or an Error object
|
90
|
+
def instantiate(name="")
|
91
|
+
return Error.new('ID not defined') if !@pe_id
|
92
|
+
|
93
|
+
name ||= ""
|
94
|
+
rc = @client.call(TEMPLATE_METHODS[:instantiate], @pe_id, name)
|
95
|
+
|
96
|
+
return rc
|
97
|
+
end
|
98
|
+
|
99
|
+
# Replaces the template contents
|
100
|
+
#
|
101
|
+
# +new_template+ New template contents
|
102
|
+
def update(new_template)
|
103
|
+
return Error.new('ID not defined') if !@pe_id
|
104
|
+
|
105
|
+
super(TEMPLATE_METHODS[:update], new_template)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Publishes the Template, to be used by other users
|
109
|
+
def publish
|
110
|
+
set_publish(true)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Unplubishes the Image
|
114
|
+
def unpublish
|
115
|
+
set_publish(false)
|
116
|
+
end
|
117
|
+
|
118
|
+
# Changes the owner/group
|
119
|
+
# uid:: _Integer_ the new owner id. Set to -1 to leave the current one
|
120
|
+
# gid:: _Integer_ the new group id. Set to -1 to leave the current one
|
121
|
+
# [return] nil in case of success or an Error object
|
122
|
+
def chown(uid, gid)
|
123
|
+
super(TEMPLATE_METHODS[:chown], uid, gid)
|
124
|
+
end
|
125
|
+
|
126
|
+
# Changes the Template permissions.
|
127
|
+
#
|
128
|
+
# @param octet [String] Permissions octed , e.g. 640
|
129
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
130
|
+
# otherwise
|
131
|
+
def chmod_octet(octet)
|
132
|
+
super(TEMPLATE_METHODS[:chmod], octet)
|
133
|
+
end
|
134
|
+
|
135
|
+
# Changes the Template permissions.
|
136
|
+
# Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
|
137
|
+
#
|
138
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
139
|
+
# otherwise
|
140
|
+
def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
|
141
|
+
other_m, other_a)
|
142
|
+
super(TEMPLATE_METHODS[:chmod], owner_u, owner_m, owner_a, group_u,
|
143
|
+
group_m, group_a, other_u, other_m, other_a)
|
144
|
+
end
|
145
|
+
|
146
|
+
# Clones this Template into a new one
|
147
|
+
#
|
148
|
+
# @param [String] name for the new Template.
|
149
|
+
#
|
150
|
+
# @return [Integer, OpenNebula::Error] The new Template ID in case
|
151
|
+
# of success, Error otherwise
|
152
|
+
def clone(name)
|
153
|
+
return Error.new('ID not defined') if !@pe_id
|
154
|
+
|
155
|
+
rc = @client.call(TEMPLATE_METHODS[:clone], @pe_id, name)
|
156
|
+
|
157
|
+
return rc
|
158
|
+
end
|
159
|
+
|
160
|
+
#######################################################################
|
161
|
+
# Helpers to get Template information
|
162
|
+
#######################################################################
|
163
|
+
|
164
|
+
# Returns the group identifier
|
165
|
+
# [return] _Integer_ the element's group ID
|
166
|
+
def gid
|
167
|
+
self['GID'].to_i
|
168
|
+
end
|
169
|
+
|
170
|
+
def owner_id
|
171
|
+
self['UID'].to_i
|
172
|
+
end
|
173
|
+
|
174
|
+
def public?
|
175
|
+
if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1"
|
176
|
+
true
|
177
|
+
else
|
178
|
+
false
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
private
|
183
|
+
|
184
|
+
def set_publish(published)
|
185
|
+
group_u = published ? 1 : 0
|
186
|
+
|
187
|
+
chmod(-1, -1, -1, group_u, -1, -1, -1, -1, -1)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
@@ -0,0 +1,74 @@
|
|
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 TemplatePool < Pool
|
22
|
+
#######################################################################
|
23
|
+
# Constants and Class attribute accessors
|
24
|
+
#######################################################################
|
25
|
+
|
26
|
+
|
27
|
+
TEMPLATE_POOL_METHODS = {
|
28
|
+
:info => "templatepool.info"
|
29
|
+
}
|
30
|
+
|
31
|
+
#######################################################################
|
32
|
+
# Class constructor & Pool Methods
|
33
|
+
#######################################################################
|
34
|
+
|
35
|
+
# +client+ a Client object that represents an XML-RPC connection
|
36
|
+
# +user_id+ used to refer to a Pool with Templates from that user
|
37
|
+
def initialize(client, user_id=-1)
|
38
|
+
super('VMTEMPLATE_POOL','VMTEMPLATE',client)
|
39
|
+
|
40
|
+
@user_id = user_id
|
41
|
+
end
|
42
|
+
|
43
|
+
# Factory method to create Template objects
|
44
|
+
def factory(element_xml)
|
45
|
+
OpenNebula::Template.new(element_xml,@client)
|
46
|
+
end
|
47
|
+
|
48
|
+
#######################################################################
|
49
|
+
# XML-RPC Methods for the Template Object
|
50
|
+
#######################################################################
|
51
|
+
|
52
|
+
# Retrieves all or part of the VirtualMachines in the pool.
|
53
|
+
def info(*args)
|
54
|
+
case args.size
|
55
|
+
when 0
|
56
|
+
info_filter(TEMPLATE_POOL_METHODS[:info],@user_id,-1,-1)
|
57
|
+
when 3
|
58
|
+
info_filter(TEMPLATE_POOL_METHODS[:info],args[0],args[1],args[2])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def info_all()
|
63
|
+
return super(TEMPLATE_POOL_METHODS[:info])
|
64
|
+
end
|
65
|
+
|
66
|
+
def info_mine()
|
67
|
+
return super(TEMPLATE_POOL_METHODS[:info])
|
68
|
+
end
|
69
|
+
|
70
|
+
def info_group()
|
71
|
+
return super(TEMPLATE_POOL_METHODS[:info])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|