opennebula-oca 3.9.0.beta → 3.9.90.rc
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -0
- metadata +35 -108
- data/LICENSE +0 -202
- data/NOTICE +0 -48
- data/lib/opennebula/acl.rb +0 -259
- data/lib/opennebula/acl_pool.rb +0 -53
- data/lib/opennebula/client.rb +0 -102
- data/lib/opennebula/cluster.rb +0 -247
- data/lib/opennebula/cluster_pool.rb +0 -56
- data/lib/opennebula/datastore.rb +0 -169
- data/lib/opennebula/datastore_pool.rb +0 -53
- data/lib/opennebula/document.rb +0 -259
- data/lib/opennebula/document_json.rb +0 -129
- data/lib/opennebula/document_pool.rb +0 -97
- data/lib/opennebula/document_pool_json.rb +0 -58
- data/lib/opennebula/error.rb +0 -52
- data/lib/opennebula/group.rb +0 -161
- data/lib/opennebula/group_pool.rb +0 -54
- data/lib/opennebula/host.rb +0 -199
- data/lib/opennebula/host_pool.rb +0 -91
- data/lib/opennebula/image.rb +0 -293
- data/lib/opennebula/image_pool.rb +0 -74
- data/lib/opennebula/ldap_auth.rb +0 -99
- data/lib/opennebula/ldap_auth_spec.rb +0 -70
- data/lib/opennebula/pool.rb +0 -157
- data/lib/opennebula/pool_element.rb +0 -269
- data/lib/opennebula/server_cipher_auth.rb +0 -148
- data/lib/opennebula/server_x509_auth.rb +0 -104
- data/lib/opennebula/ssh_auth.rb +0 -139
- data/lib/opennebula/system.rb +0 -141
- data/lib/opennebula/template.rb +0 -201
- data/lib/opennebula/template_pool.rb +0 -74
- data/lib/opennebula/user.rb +0 -172
- data/lib/opennebula/user_pool.rb +0 -53
- data/lib/opennebula/virtual_machine.rb +0 -426
- data/lib/opennebula/virtual_machine_pool.rb +0 -318
- data/lib/opennebula/virtual_network.rb +0 -247
- data/lib/opennebula/virtual_network_pool.rb +0 -74
- data/lib/opennebula/x509_auth.rb +0 -241
- data/lib/opennebula/xml_element.rb +0 -427
- data/lib/opennebula/xml_pool.rb +0 -45
- data/lib/opennebula/xml_utils.rb +0 -34
- data/lib/opennebula.rb +0 -58
@@ -1,426 +0,0 @@
|
|
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_element'
|
19
|
-
|
20
|
-
module OpenNebula
|
21
|
-
class VirtualMachine < PoolElement
|
22
|
-
#######################################################################
|
23
|
-
# Constants and Class Methods
|
24
|
-
#######################################################################
|
25
|
-
|
26
|
-
|
27
|
-
VM_METHODS = {
|
28
|
-
:info => "vm.info",
|
29
|
-
:allocate => "vm.allocate",
|
30
|
-
:action => "vm.action",
|
31
|
-
:migrate => "vm.migrate",
|
32
|
-
:deploy => "vm.deploy",
|
33
|
-
:savedisk => "vm.savedisk",
|
34
|
-
:chown => "vm.chown",
|
35
|
-
:chmod => "vm.chmod",
|
36
|
-
:monitoring => "vm.monitoring",
|
37
|
-
:attach => "vm.attach",
|
38
|
-
:detach => "vm.detach",
|
39
|
-
:rename => "vm.rename"
|
40
|
-
}
|
41
|
-
|
42
|
-
VM_STATE=%w{INIT PENDING HOLD ACTIVE STOPPED SUSPENDED DONE FAILED
|
43
|
-
POWEROFF}
|
44
|
-
|
45
|
-
LCM_STATE=%w{LCM_INIT PROLOG BOOT RUNNING MIGRATE SAVE_STOP SAVE_SUSPEND
|
46
|
-
SAVE_MIGRATE PROLOG_MIGRATE PROLOG_RESUME EPILOG_STOP EPILOG
|
47
|
-
SHUTDOWN CANCEL FAILURE CLEANUP UNKNOWN HOTPLUG SHUTDOWN_POWEROFF
|
48
|
-
BOOT_UNKNOWN BOOT_POWEROFF BOOT_SUSPENDED BOOT_STOPPED}
|
49
|
-
|
50
|
-
SHORT_VM_STATES={
|
51
|
-
"INIT" => "init",
|
52
|
-
"PENDING" => "pend",
|
53
|
-
"HOLD" => "hold",
|
54
|
-
"ACTIVE" => "actv",
|
55
|
-
"STOPPED" => "stop",
|
56
|
-
"SUSPENDED" => "susp",
|
57
|
-
"DONE" => "done",
|
58
|
-
"FAILED" => "fail",
|
59
|
-
"POWEROFF" => "poff"
|
60
|
-
}
|
61
|
-
|
62
|
-
SHORT_LCM_STATES={
|
63
|
-
"PROLOG" => "prol",
|
64
|
-
"BOOT" => "boot",
|
65
|
-
"RUNNING" => "runn",
|
66
|
-
"MIGRATE" => "migr",
|
67
|
-
"SAVE_STOP" => "save",
|
68
|
-
"SAVE_SUSPEND" => "save",
|
69
|
-
"SAVE_MIGRATE" => "save",
|
70
|
-
"PROLOG_MIGRATE"=> "migr",
|
71
|
-
"PROLOG_RESUME" => "prol",
|
72
|
-
"EPILOG_STOP" => "epil",
|
73
|
-
"EPILOG" => "epil",
|
74
|
-
"SHUTDOWN" => "shut",
|
75
|
-
"CANCEL" => "shut",
|
76
|
-
"FAILURE" => "fail",
|
77
|
-
"CLEANUP" => "clea",
|
78
|
-
"UNKNOWN" => "unkn",
|
79
|
-
"HOTPLUG" => "hotp",
|
80
|
-
"SHUTDOWN_POWEROFF" => "shut",
|
81
|
-
"BOOT_UNKNOWN" => "boot",
|
82
|
-
"BOOT_POWEROFF" => "boot",
|
83
|
-
"BOOT_SUSPENDED" => "boot",
|
84
|
-
"BOOT_STOPPED" => "boot"
|
85
|
-
}
|
86
|
-
|
87
|
-
MIGRATE_REASON=%w{NONE ERROR STOP_RESUME USER CANCEL}
|
88
|
-
|
89
|
-
SHORT_MIGRATE_REASON={
|
90
|
-
"NONE" => "none",
|
91
|
-
"ERROR" => "erro",
|
92
|
-
"STOP_RESUME" => "stop",
|
93
|
-
"USER" => "user",
|
94
|
-
"CANCEL" => "canc"
|
95
|
-
}
|
96
|
-
|
97
|
-
# Creates a VirtualMachine description with just its identifier
|
98
|
-
# this method should be used to create plain VirtualMachine objects.
|
99
|
-
# +id+ the id of the vm
|
100
|
-
#
|
101
|
-
# Example:
|
102
|
-
# vnet = VirtualMachine.new(VirtualMachine.build_xml(3),rpc_client)
|
103
|
-
#
|
104
|
-
def VirtualMachine.build_xml(pe_id=nil)
|
105
|
-
if pe_id
|
106
|
-
vm_xml = "<VM><ID>#{pe_id}</ID></VM>"
|
107
|
-
else
|
108
|
-
vm_xml = "<VM></VM>"
|
109
|
-
end
|
110
|
-
|
111
|
-
XMLElement.build_xml(vm_xml, 'VM')
|
112
|
-
end
|
113
|
-
|
114
|
-
def VirtualMachine.get_reason(reason)
|
115
|
-
reason=MIGRATE_REASON[reason.to_i]
|
116
|
-
reason_str=SHORT_MIGRATE_REASON[reason]
|
117
|
-
|
118
|
-
reason_str
|
119
|
-
end
|
120
|
-
|
121
|
-
# Class constructor
|
122
|
-
def initialize(xml, client)
|
123
|
-
super(xml,client)
|
124
|
-
end
|
125
|
-
|
126
|
-
#######################################################################
|
127
|
-
# XML-RPC Methods for the Virtual Machine Object
|
128
|
-
#######################################################################
|
129
|
-
|
130
|
-
# Retrieves the information of the given VirtualMachine.
|
131
|
-
def info()
|
132
|
-
super(VM_METHODS[:info], 'VM')
|
133
|
-
end
|
134
|
-
|
135
|
-
# Allocates a new VirtualMachine in OpenNebula
|
136
|
-
#
|
137
|
-
# +description+ A string containing the template of the VirtualMachine.
|
138
|
-
def allocate(description)
|
139
|
-
super(VM_METHODS[:allocate],description)
|
140
|
-
end
|
141
|
-
|
142
|
-
# Initiates the instance of the VM on the target host.
|
143
|
-
#
|
144
|
-
# @param host_id [Interger] The host id (hid) of the target host where
|
145
|
-
# the VM will be instantiated.
|
146
|
-
# @param enforce [true|false] If it is set to true, the host capacity
|
147
|
-
# will be checked, and the deployment will fail if the host is
|
148
|
-
# overcommited. Defaults to false
|
149
|
-
#
|
150
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
151
|
-
# otherwise
|
152
|
-
def deploy(host_id, enforce=false)
|
153
|
-
return call(VM_METHODS[:deploy], @pe_id, host_id.to_i, enforce)
|
154
|
-
end
|
155
|
-
|
156
|
-
# Shutdowns an already deployed VM
|
157
|
-
def shutdown
|
158
|
-
action('shutdown')
|
159
|
-
end
|
160
|
-
|
161
|
-
# Powers off a running VM
|
162
|
-
def poweroff
|
163
|
-
action('poweroff')
|
164
|
-
end
|
165
|
-
|
166
|
-
# Reboots an already deployed VM
|
167
|
-
def reboot
|
168
|
-
action('reboot')
|
169
|
-
end
|
170
|
-
|
171
|
-
# Resets an already deployed VM
|
172
|
-
def reset
|
173
|
-
action('reset')
|
174
|
-
end
|
175
|
-
|
176
|
-
# Cancels a running VM
|
177
|
-
def cancel
|
178
|
-
action('cancel')
|
179
|
-
end
|
180
|
-
|
181
|
-
# Sets a VM to hold state, scheduler will not deploy it
|
182
|
-
def hold
|
183
|
-
action('hold')
|
184
|
-
end
|
185
|
-
|
186
|
-
# Releases a VM from hold state
|
187
|
-
def release
|
188
|
-
action('release')
|
189
|
-
end
|
190
|
-
|
191
|
-
# Stops a running VM
|
192
|
-
def stop
|
193
|
-
action('stop')
|
194
|
-
end
|
195
|
-
|
196
|
-
# Saves a running VM
|
197
|
-
def suspend
|
198
|
-
action('suspend')
|
199
|
-
end
|
200
|
-
|
201
|
-
# Resumes the execution of a saved VM
|
202
|
-
def resume
|
203
|
-
action('resume')
|
204
|
-
end
|
205
|
-
|
206
|
-
# Attaches a disk to a running VM
|
207
|
-
def attachdisk(disk)
|
208
|
-
return Error.new('ID not defined') if !@pe_id
|
209
|
-
|
210
|
-
rc = @client.call(VM_METHODS[:attach], @pe_id, disk)
|
211
|
-
rc = nil if !OpenNebula.is_error?(rc)
|
212
|
-
|
213
|
-
return rc
|
214
|
-
end
|
215
|
-
|
216
|
-
# Detaches a disk from a running VM
|
217
|
-
def detachdisk(disk)
|
218
|
-
return Error.new('ID not defined') if !@pe_id
|
219
|
-
|
220
|
-
rc = @client.call(VM_METHODS[:detach], @pe_id, disk)
|
221
|
-
rc = nil if !OpenNebula.is_error?(rc)
|
222
|
-
|
223
|
-
return rc
|
224
|
-
end
|
225
|
-
|
226
|
-
# Deletes a VM from the pool
|
227
|
-
def finalize
|
228
|
-
action('finalize')
|
229
|
-
end
|
230
|
-
|
231
|
-
# Forces a re-deployment of a VM in UNKNOWN or BOOT state
|
232
|
-
def restart
|
233
|
-
action('restart')
|
234
|
-
end
|
235
|
-
|
236
|
-
# Resubmits a VM to PENDING state
|
237
|
-
def resubmit
|
238
|
-
action('resubmit')
|
239
|
-
end
|
240
|
-
|
241
|
-
# Sets the re-scheduling flag for the VM
|
242
|
-
def resched
|
243
|
-
action('resched')
|
244
|
-
end
|
245
|
-
|
246
|
-
# Unsets the re-scheduling flag for the VM
|
247
|
-
def unresched
|
248
|
-
action('unresched')
|
249
|
-
end
|
250
|
-
|
251
|
-
# Saves a running VM and starts it again in the specified host
|
252
|
-
#
|
253
|
-
# @param host_id [Interger] The host id (hid) of the target host where
|
254
|
-
# the VM will be migrated.
|
255
|
-
# @param enforce [true|false] If it is set to true, the host capacity
|
256
|
-
# will be checked, and the deployment will fail if the host is
|
257
|
-
# overcommited. Defaults to false
|
258
|
-
#
|
259
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
260
|
-
# otherwise
|
261
|
-
def migrate(host_id, enforce=false)
|
262
|
-
return call(VM_METHODS[:migrate], @pe_id, host_id.to_i, false, enforce)
|
263
|
-
end
|
264
|
-
|
265
|
-
# Migrates a running VM to another host without downtime
|
266
|
-
#
|
267
|
-
# @param host_id [Interger] The host id (hid) of the target host where
|
268
|
-
# the VM will be migrated.
|
269
|
-
# @param enforce [true|false] If it is set to true, the host capacity
|
270
|
-
# will be checked, and the deployment will fail if the host is
|
271
|
-
# overcommited. Defaults to false
|
272
|
-
#
|
273
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
274
|
-
# otherwise
|
275
|
-
def live_migrate(host_id, enforce=false)
|
276
|
-
return call(VM_METHODS[:migrate], @pe_id, host_id.to_i, true, enforce)
|
277
|
-
end
|
278
|
-
|
279
|
-
# Set the specified vm's disk to be saved in a new image
|
280
|
-
# when the VirtualMachine shutdowns
|
281
|
-
#
|
282
|
-
# @param disk_id [Integer] ID of the disk to be saved
|
283
|
-
# @param image_name [String] Name for the new image where the
|
284
|
-
# disk will be saved
|
285
|
-
# @param image_type [String] Type of the new image. Set to empty string
|
286
|
-
# to use the default type
|
287
|
-
#
|
288
|
-
# @return [Integer, OpenNebula::Error] the new Image ID in case of
|
289
|
-
# success, error otherwise
|
290
|
-
def save_as(disk_id, image_name, image_type="")
|
291
|
-
return Error.new('ID not defined') if !@pe_id
|
292
|
-
|
293
|
-
rc = @client.call(VM_METHODS[:savedisk],
|
294
|
-
@pe_id,
|
295
|
-
disk_id,
|
296
|
-
image_name,
|
297
|
-
image_type)
|
298
|
-
|
299
|
-
return rc
|
300
|
-
end
|
301
|
-
|
302
|
-
# Changes the owner/group
|
303
|
-
# uid:: _Integer_ the new owner id. Set to -1 to leave the current one
|
304
|
-
# gid:: _Integer_ the new group id. Set to -1 to leave the current one
|
305
|
-
# [return] nil in case of success or an Error object
|
306
|
-
def chown(uid, gid)
|
307
|
-
super(VM_METHODS[:chown], uid, gid)
|
308
|
-
end
|
309
|
-
|
310
|
-
# Changes the permissions.
|
311
|
-
#
|
312
|
-
# @param octet [String] Permissions octed , e.g. 640
|
313
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
314
|
-
# otherwise
|
315
|
-
def chmod_octet(octet)
|
316
|
-
super(VM_METHODS[:chmod], octet)
|
317
|
-
end
|
318
|
-
|
319
|
-
# Changes the permissions.
|
320
|
-
# Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
|
321
|
-
#
|
322
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
323
|
-
# otherwise
|
324
|
-
def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
|
325
|
-
other_m, other_a)
|
326
|
-
super(VM_METHODS[:chmod], owner_u, owner_m, owner_a, group_u,
|
327
|
-
group_m, group_a, other_u, other_m, other_a)
|
328
|
-
end
|
329
|
-
|
330
|
-
# Retrieves this VM's monitoring data from OpenNebula
|
331
|
-
#
|
332
|
-
# @param [Array<String>] xpath_expressions Elements to retrieve.
|
333
|
-
#
|
334
|
-
# @return [Hash<String, Array<Array<int>>>, OpenNebula::Error] Hash with
|
335
|
-
# the requested xpath expressions, and an Array of 'timestamp, value'.
|
336
|
-
#
|
337
|
-
# @example
|
338
|
-
# vm.monitoring( ['CPU', 'NET_TX', 'TEMPLATE/CUSTOM_PROBE'] )
|
339
|
-
#
|
340
|
-
# { "NET_TX" =>
|
341
|
-
# [["1337264510", "210"],
|
342
|
-
# ["1337264553", "220"],
|
343
|
-
# ["1337264584", "230"]],
|
344
|
-
# "TEMPLATE/CUSTOM_PROBE" =>
|
345
|
-
# [],
|
346
|
-
# "CPU" =>
|
347
|
-
# [["1337264510", "0"],
|
348
|
-
# ["1337264553", "0"],
|
349
|
-
# ["1337264584", "0"]]
|
350
|
-
# }
|
351
|
-
def monitoring(xpath_expressions)
|
352
|
-
return super(VM_METHODS[:monitoring], 'VM',
|
353
|
-
'LAST_POLL', xpath_expressions)
|
354
|
-
end
|
355
|
-
|
356
|
-
# Retrieves this VM's monitoring data from OpenNebula, in XML
|
357
|
-
#
|
358
|
-
# @return [String] VM monitoring data, in XML
|
359
|
-
def monitoring_xml()
|
360
|
-
return Error.new('ID not defined') if !@pe_id
|
361
|
-
|
362
|
-
return @client.call(VM_METHODS[:monitoring], @pe_id)
|
363
|
-
end
|
364
|
-
|
365
|
-
# Renames this VM
|
366
|
-
#
|
367
|
-
# @param name [String] New name for the VM.
|
368
|
-
#
|
369
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
370
|
-
# otherwise
|
371
|
-
def rename(name)
|
372
|
-
return call(VM_METHODS[:rename], @pe_id, name)
|
373
|
-
end
|
374
|
-
|
375
|
-
#######################################################################
|
376
|
-
# Helpers to get VirtualMachine information
|
377
|
-
#######################################################################
|
378
|
-
|
379
|
-
# Returns the VM state of the VirtualMachine (numeric value)
|
380
|
-
def state
|
381
|
-
self['STATE'].to_i
|
382
|
-
end
|
383
|
-
|
384
|
-
# Returns the VM state of the VirtualMachine (string value)
|
385
|
-
def state_str
|
386
|
-
VM_STATE[state]
|
387
|
-
end
|
388
|
-
|
389
|
-
# Returns the LCM state of the VirtualMachine (numeric value)
|
390
|
-
def lcm_state
|
391
|
-
self['LCM_STATE'].to_i
|
392
|
-
end
|
393
|
-
|
394
|
-
# Returns the LCM state of the VirtualMachine (string value)
|
395
|
-
def lcm_state_str
|
396
|
-
LCM_STATE[lcm_state]
|
397
|
-
end
|
398
|
-
|
399
|
-
# Returns the short status string for the VirtualMachine
|
400
|
-
def status
|
401
|
-
short_state_str=SHORT_VM_STATES[state_str]
|
402
|
-
|
403
|
-
if short_state_str=="actv"
|
404
|
-
short_state_str=SHORT_LCM_STATES[lcm_state_str]
|
405
|
-
end
|
406
|
-
|
407
|
-
short_state_str
|
408
|
-
end
|
409
|
-
|
410
|
-
# Returns the group identifier
|
411
|
-
# [return] _Integer_ the element's group ID
|
412
|
-
def gid
|
413
|
-
self['GID'].to_i
|
414
|
-
end
|
415
|
-
|
416
|
-
private
|
417
|
-
def action(name)
|
418
|
-
return Error.new('ID not defined') if !@pe_id
|
419
|
-
|
420
|
-
rc = @client.call(VM_METHODS[:action], name, @pe_id)
|
421
|
-
rc = nil if !OpenNebula.is_error?(rc)
|
422
|
-
|
423
|
-
return rc
|
424
|
-
end
|
425
|
-
end
|
426
|
-
end
|