opennebula 6.6.1 → 6.6.3
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.
- checksums.yaml +4 -4
- data/lib/DriverExecHelper.rb +1 -1
- data/lib/HostSyncManager.rb +111 -0
- data/lib/VirtualMachineDriver.rb +8 -1
- data/lib/cloud/CloudClient.rb +1 -1
- data/lib/host.rb +1 -1
- data/lib/models/service.rb +31 -10
- data/lib/opennebula/flow/service_template.rb +11 -1
- data/lib/opennebula/pool_element.rb +48 -47
- data/lib/opennebula/virtual_machine.rb +301 -295
- data/lib/opennebula.rb +1 -1
- data/lib/virtual_wire.rb +1 -1
- metadata +3 -2
@@ -18,224 +18,218 @@ require 'opennebula/lockable_ext'
|
|
18
18
|
require 'opennebula/pool_element'
|
19
19
|
|
20
20
|
module OpenNebula
|
21
|
+
|
21
22
|
class VirtualMachine < PoolElement
|
23
|
+
|
22
24
|
#######################################################################
|
23
25
|
# Constants and Class Methods
|
24
26
|
#######################################################################
|
25
27
|
|
26
28
|
VM_METHODS = {
|
27
|
-
:info =>
|
28
|
-
:allocate =>
|
29
|
-
:action =>
|
30
|
-
:migrate =>
|
31
|
-
:deploy =>
|
32
|
-
:chown =>
|
33
|
-
:chmod =>
|
34
|
-
:monitoring =>
|
35
|
-
:attach =>
|
36
|
-
:detach =>
|
37
|
-
:rename =>
|
38
|
-
:update =>
|
39
|
-
:resize =>
|
40
|
-
:snapshotcreate =>
|
41
|
-
:snapshotrevert =>
|
42
|
-
:snapshotdelete =>
|
43
|
-
:attachnic =>
|
44
|
-
:detachnic =>
|
45
|
-
:recover =>
|
46
|
-
:disksaveas =>
|
47
|
-
:disksnapshotcreate =>
|
48
|
-
:disksnapshotrevert =>
|
49
|
-
:disksnapshotdelete =>
|
50
|
-
:disksnapshotrename =>
|
51
|
-
:diskresize =>
|
52
|
-
:updateconf =>
|
53
|
-
:lock =>
|
54
|
-
:unlock =>
|
55
|
-
:schedadd =>
|
56
|
-
:scheddelete =>
|
57
|
-
:schedupdate =>
|
58
|
-
:attachsg =>
|
59
|
-
:detachsg =>
|
60
|
-
:backup =>
|
61
|
-
:updatenic =>
|
29
|
+
:info => 'vm.info',
|
30
|
+
:allocate => 'vm.allocate',
|
31
|
+
:action => 'vm.action',
|
32
|
+
:migrate => 'vm.migrate',
|
33
|
+
:deploy => 'vm.deploy',
|
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
|
+
:update => 'vm.update',
|
41
|
+
:resize => 'vm.resize',
|
42
|
+
:snapshotcreate => 'vm.snapshotcreate',
|
43
|
+
:snapshotrevert => 'vm.snapshotrevert',
|
44
|
+
:snapshotdelete => 'vm.snapshotdelete',
|
45
|
+
:attachnic => 'vm.attachnic',
|
46
|
+
:detachnic => 'vm.detachnic',
|
47
|
+
:recover => 'vm.recover',
|
48
|
+
:disksaveas => 'vm.disksaveas',
|
49
|
+
:disksnapshotcreate => 'vm.disksnapshotcreate',
|
50
|
+
:disksnapshotrevert => 'vm.disksnapshotrevert',
|
51
|
+
:disksnapshotdelete => 'vm.disksnapshotdelete',
|
52
|
+
:disksnapshotrename => 'vm.disksnapshotrename',
|
53
|
+
:diskresize => 'vm.diskresize',
|
54
|
+
:updateconf => 'vm.updateconf',
|
55
|
+
:lock => 'vm.lock',
|
56
|
+
:unlock => 'vm.unlock',
|
57
|
+
:schedadd => 'vm.schedadd',
|
58
|
+
:scheddelete => 'vm.scheddelete',
|
59
|
+
:schedupdate => 'vm.schedupdate',
|
60
|
+
:attachsg => 'vm.attachsg',
|
61
|
+
:detachsg => 'vm.detachsg',
|
62
|
+
:backup => 'vm.backup',
|
63
|
+
:updatenic => 'vm.updatenic',
|
64
|
+
:backupcancel => 'vm.backupcancel'
|
62
65
|
}
|
63
66
|
|
64
|
-
VM_STATE
|
65
|
-
|
66
|
-
|
67
|
-
LCM_STATE
|
68
|
-
LCM_INIT
|
69
|
-
PROLOG
|
70
|
-
BOOT
|
71
|
-
RUNNING
|
72
|
-
MIGRATE
|
73
|
-
SAVE_STOP
|
74
|
-
SAVE_SUSPEND
|
75
|
-
SAVE_MIGRATE
|
76
|
-
PROLOG_MIGRATE
|
77
|
-
PROLOG_RESUME
|
78
|
-
EPILOG_STOP
|
79
|
-
EPILOG
|
80
|
-
SHUTDOWN
|
81
|
-
CANCEL
|
82
|
-
FAILURE
|
83
|
-
CLEANUP_RESUBMIT
|
84
|
-
UNKNOWN
|
85
|
-
HOTPLUG
|
86
|
-
SHUTDOWN_POWEROFF
|
87
|
-
BOOT_UNKNOWN
|
88
|
-
BOOT_POWEROFF
|
89
|
-
BOOT_SUSPENDED
|
90
|
-
BOOT_STOPPED
|
91
|
-
CLEANUP_DELETE
|
92
|
-
HOTPLUG_SNAPSHOT
|
93
|
-
HOTPLUG_NIC
|
94
|
-
HOTPLUG_SAVEAS
|
95
|
-
HOTPLUG_SAVEAS_POWEROFF
|
96
|
-
HOTPLUG_SAVEAS_SUSPENDED
|
97
|
-
SHUTDOWN_UNDEPLOY
|
98
|
-
EPILOG_UNDEPLOY
|
99
|
-
PROLOG_UNDEPLOY
|
100
|
-
BOOT_UNDEPLOY
|
101
|
-
HOTPLUG_PROLOG_POWEROFF
|
102
|
-
HOTPLUG_EPILOG_POWEROFF
|
103
|
-
BOOT_MIGRATE
|
104
|
-
BOOT_FAILURE
|
105
|
-
BOOT_MIGRATE_FAILURE
|
106
|
-
PROLOG_MIGRATE_FAILURE
|
107
|
-
PROLOG_FAILURE
|
108
|
-
EPILOG_FAILURE
|
109
|
-
EPILOG_STOP_FAILURE
|
110
|
-
EPILOG_UNDEPLOY_FAILURE
|
111
|
-
PROLOG_MIGRATE_POWEROFF
|
112
|
-
PROLOG_MIGRATE_POWEROFF_FAILURE
|
113
|
-
PROLOG_MIGRATE_SUSPEND
|
114
|
-
PROLOG_MIGRATE_SUSPEND_FAILURE
|
115
|
-
BOOT_UNDEPLOY_FAILURE
|
116
|
-
BOOT_STOPPED_FAILURE
|
117
|
-
PROLOG_RESUME_FAILURE
|
118
|
-
PROLOG_UNDEPLOY_FAILURE
|
119
|
-
DISK_SNAPSHOT_POWEROFF
|
120
|
-
DISK_SNAPSHOT_REVERT_POWEROFF
|
121
|
-
DISK_SNAPSHOT_DELETE_POWEROFF
|
122
|
-
DISK_SNAPSHOT_SUSPENDED
|
123
|
-
DISK_SNAPSHOT_REVERT_SUSPENDED
|
124
|
-
DISK_SNAPSHOT_DELETE_SUSPENDED
|
125
|
-
DISK_SNAPSHOT
|
126
|
-
DISK_SNAPSHOT_REVERT
|
127
|
-
DISK_SNAPSHOT_DELETE
|
128
|
-
PROLOG_MIGRATE_UNKNOWN
|
129
|
-
PROLOG_MIGRATE_UNKNOWN_FAILURE
|
130
|
-
DISK_RESIZE
|
131
|
-
DISK_RESIZE_POWEROFF
|
132
|
-
DISK_RESIZE_UNDEPLOYED
|
133
|
-
HOTPLUG_NIC_POWEROFF
|
134
|
-
HOTPLUG_RESIZE
|
135
|
-
HOTPLUG_SAVEAS_UNDEPLOYED
|
136
|
-
HOTPLUG_SAVEAS_STOPPED
|
137
|
-
BACKUP
|
138
|
-
BACKUP_POWEROFF
|
139
|
-
|
67
|
+
VM_STATE=['INIT', 'PENDING', 'HOLD', 'ACTIVE', 'STOPPED', 'SUSPENDED', 'DONE', 'FAILED',
|
68
|
+
'POWEROFF', 'UNDEPLOYED', 'CLONING', 'CLONING_FAILURE']
|
69
|
+
|
70
|
+
LCM_STATE=[
|
71
|
+
'LCM_INIT',
|
72
|
+
'PROLOG',
|
73
|
+
'BOOT',
|
74
|
+
'RUNNING',
|
75
|
+
'MIGRATE',
|
76
|
+
'SAVE_STOP',
|
77
|
+
'SAVE_SUSPEND',
|
78
|
+
'SAVE_MIGRATE',
|
79
|
+
'PROLOG_MIGRATE',
|
80
|
+
'PROLOG_RESUME',
|
81
|
+
'EPILOG_STOP',
|
82
|
+
'EPILOG',
|
83
|
+
'SHUTDOWN',
|
84
|
+
'CANCEL',
|
85
|
+
'FAILURE',
|
86
|
+
'CLEANUP_RESUBMIT',
|
87
|
+
'UNKNOWN',
|
88
|
+
'HOTPLUG',
|
89
|
+
'SHUTDOWN_POWEROFF',
|
90
|
+
'BOOT_UNKNOWN',
|
91
|
+
'BOOT_POWEROFF',
|
92
|
+
'BOOT_SUSPENDED',
|
93
|
+
'BOOT_STOPPED',
|
94
|
+
'CLEANUP_DELETE',
|
95
|
+
'HOTPLUG_SNAPSHOT',
|
96
|
+
'HOTPLUG_NIC',
|
97
|
+
'HOTPLUG_SAVEAS',
|
98
|
+
'HOTPLUG_SAVEAS_POWEROFF',
|
99
|
+
'HOTPLUG_SAVEAS_SUSPENDED',
|
100
|
+
'SHUTDOWN_UNDEPLOY',
|
101
|
+
'EPILOG_UNDEPLOY',
|
102
|
+
'PROLOG_UNDEPLOY',
|
103
|
+
'BOOT_UNDEPLOY',
|
104
|
+
'HOTPLUG_PROLOG_POWEROFF',
|
105
|
+
'HOTPLUG_EPILOG_POWEROFF',
|
106
|
+
'BOOT_MIGRATE',
|
107
|
+
'BOOT_FAILURE',
|
108
|
+
'BOOT_MIGRATE_FAILURE',
|
109
|
+
'PROLOG_MIGRATE_FAILURE',
|
110
|
+
'PROLOG_FAILURE',
|
111
|
+
'EPILOG_FAILURE',
|
112
|
+
'EPILOG_STOP_FAILURE',
|
113
|
+
'EPILOG_UNDEPLOY_FAILURE',
|
114
|
+
'PROLOG_MIGRATE_POWEROFF',
|
115
|
+
'PROLOG_MIGRATE_POWEROFF_FAILURE',
|
116
|
+
'PROLOG_MIGRATE_SUSPEND',
|
117
|
+
'PROLOG_MIGRATE_SUSPEND_FAILURE',
|
118
|
+
'BOOT_UNDEPLOY_FAILURE',
|
119
|
+
'BOOT_STOPPED_FAILURE',
|
120
|
+
'PROLOG_RESUME_FAILURE',
|
121
|
+
'PROLOG_UNDEPLOY_FAILURE',
|
122
|
+
'DISK_SNAPSHOT_POWEROFF',
|
123
|
+
'DISK_SNAPSHOT_REVERT_POWEROFF',
|
124
|
+
'DISK_SNAPSHOT_DELETE_POWEROFF',
|
125
|
+
'DISK_SNAPSHOT_SUSPENDED',
|
126
|
+
'DISK_SNAPSHOT_REVERT_SUSPENDED',
|
127
|
+
'DISK_SNAPSHOT_DELETE_SUSPENDED',
|
128
|
+
'DISK_SNAPSHOT',
|
129
|
+
'DISK_SNAPSHOT_REVERT',
|
130
|
+
'DISK_SNAPSHOT_DELETE',
|
131
|
+
'PROLOG_MIGRATE_UNKNOWN',
|
132
|
+
'PROLOG_MIGRATE_UNKNOWN_FAILURE',
|
133
|
+
'DISK_RESIZE',
|
134
|
+
'DISK_RESIZE_POWEROFF',
|
135
|
+
'DISK_RESIZE_UNDEPLOYED',
|
136
|
+
'HOTPLUG_NIC_POWEROFF',
|
137
|
+
'HOTPLUG_RESIZE',
|
138
|
+
'HOTPLUG_SAVEAS_UNDEPLOYED',
|
139
|
+
'HOTPLUG_SAVEAS_STOPPED',
|
140
|
+
'BACKUP',
|
141
|
+
'BACKUP_POWEROFF'
|
142
|
+
]
|
140
143
|
|
141
144
|
SHORT_VM_STATES={
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
145
|
+
'INIT' => 'init',
|
146
|
+
'PENDING' => 'pend',
|
147
|
+
'HOLD' => 'hold',
|
148
|
+
'ACTIVE' => 'actv',
|
149
|
+
'STOPPED' => 'stop',
|
150
|
+
'SUSPENDED' => 'susp',
|
151
|
+
'DONE' => 'done',
|
152
|
+
'FAILED' => 'fail',
|
153
|
+
'POWEROFF' => 'poff',
|
154
|
+
'UNDEPLOYED' => 'unde',
|
155
|
+
'CLONING' => 'clon',
|
156
|
+
'CLONING_FAILURE' => 'fail'
|
154
157
|
}
|
155
158
|
|
156
159
|
SHORT_LCM_STATES={
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
160
|
+
'PROLOG' => 'prol',
|
161
|
+
'BOOT' => 'boot',
|
162
|
+
'RUNNING' => 'runn',
|
163
|
+
'MIGRATE' => 'migr',
|
164
|
+
'SAVE_STOP' => 'save',
|
165
|
+
'SAVE_SUSPEND' => 'save',
|
166
|
+
'SAVE_MIGRATE' => 'save',
|
167
|
+
'PROLOG_MIGRATE' => 'migr',
|
168
|
+
'PROLOG_RESUME' => 'prol',
|
169
|
+
'EPILOG_STOP' => 'epil',
|
170
|
+
'EPILOG' => 'epil',
|
171
|
+
'SHUTDOWN' => 'shut',
|
172
|
+
'CANCEL' => 'shut',
|
173
|
+
'FAILURE' => 'fail',
|
174
|
+
'CLEANUP_RESUBMIT' => 'clea',
|
175
|
+
'UNKNOWN' => 'unkn',
|
176
|
+
'HOTPLUG' => 'hotp',
|
177
|
+
'SHUTDOWN_POWEROFF' => 'shut',
|
178
|
+
'BOOT_UNKNOWN' => 'boot',
|
179
|
+
'BOOT_POWEROFF' => 'boot',
|
180
|
+
'BOOT_SUSPENDED' => 'boot',
|
181
|
+
'BOOT_STOPPED' => 'boot',
|
182
|
+
'CLEANUP_DELETE' => 'clea',
|
183
|
+
'HOTPLUG_SNAPSHOT' => 'snap',
|
184
|
+
'HOTPLUG_NIC' => 'hotp',
|
185
|
+
'HOTPLUG_SAVEAS' => 'hotp',
|
186
|
+
'HOTPLUG_SAVEAS_POWEROFF' => 'hotp',
|
187
|
+
'HOTPLUG_SAVEAS_SUSPENDED' => 'hotp',
|
188
|
+
'SHUTDOWN_UNDEPLOY' => 'shut',
|
189
|
+
'EPILOG_UNDEPLOY' => 'epil',
|
190
|
+
'PROLOG_UNDEPLOY' => 'prol',
|
191
|
+
'BOOT_UNDEPLOY' => 'boot',
|
192
|
+
'HOTPLUG_PROLOG_POWEROFF' => 'hotp',
|
193
|
+
'HOTPLUG_EPILOG_POWEROFF' => 'hotp',
|
194
|
+
'BOOT_MIGRATE' => 'boot',
|
195
|
+
'BOOT_FAILURE' => 'fail',
|
196
|
+
'BOOT_MIGRATE_FAILURE' => 'fail',
|
197
|
+
'PROLOG_MIGRATE_FAILURE' => 'fail',
|
198
|
+
'PROLOG_FAILURE' => 'fail',
|
199
|
+
'EPILOG_FAILURE' => 'fail',
|
200
|
+
'EPILOG_STOP_FAILURE' => 'fail',
|
201
|
+
'EPILOG_UNDEPLOY_FAILURE' => 'fail',
|
202
|
+
'PROLOG_MIGRATE_POWEROFF' => 'migr',
|
203
|
+
'PROLOG_MIGRATE_POWEROFF_FAILURE' => 'fail',
|
204
|
+
'PROLOG_MIGRATE_SUSPEND' => 'migr',
|
205
|
+
'PROLOG_MIGRATE_SUSPEND_FAILURE' => 'fail',
|
206
|
+
'BOOT_UNDEPLOY_FAILURE' => 'fail',
|
207
|
+
'BOOT_STOPPED_FAILURE' => 'fail',
|
208
|
+
'PROLOG_RESUME_FAILURE' => 'fail',
|
209
|
+
'PROLOG_UNDEPLOY_FAILURE' => 'fail',
|
210
|
+
'DISK_SNAPSHOT_POWEROFF' => 'snap',
|
211
|
+
'DISK_SNAPSHOT_REVERT_POWEROFF' => 'snap',
|
212
|
+
'DISK_SNAPSHOT_DELETE_POWEROFF' => 'snap',
|
213
|
+
'DISK_SNAPSHOT_SUSPENDED' => 'snap',
|
214
|
+
'DISK_SNAPSHOT_REVERT_SUSPENDED'=> 'snap',
|
215
|
+
'DISK_SNAPSHOT_DELETE_SUSPENDED'=> 'snap',
|
216
|
+
'DISK_SNAPSHOT' => 'snap',
|
217
|
+
'DISK_SNAPSHOT_DELETE' => 'snap',
|
218
|
+
'PROLOG_MIGRATE_UNKNOWN' => 'migr',
|
219
|
+
'PROLOG_MIGRATE_UNKNOWN_FAILURE' => 'fail',
|
220
|
+
'DISK_RESIZE' => 'drsz',
|
221
|
+
'DISK_RESIZE_POWEROFF' => 'drsz',
|
222
|
+
'DISK_RESIZE_UNDEPLOYED' => 'drsz',
|
223
|
+
'HOTPLUG_NIC_POWEROFF' => 'hotp',
|
224
|
+
'HOTPLUG_RESIZE' => 'hotp',
|
225
|
+
'HOTPLUG_SAVEAS_UNDEPLOYED' => 'hotp',
|
226
|
+
'HOTPLUG_SAVEAS_STOPPED' => 'hotp',
|
227
|
+
'BACKUP' => 'back',
|
228
|
+
'BACKUP_POWEROFF' => 'back'
|
226
229
|
}
|
227
230
|
|
228
|
-
HISTORY_ACTION
|
229
|
-
|
230
|
-
delete-recreate reboot reboot-hard resched unresched poweroff
|
231
|
-
poweroff-hard disk-attach disk-detach nic-attach nic-detach
|
232
|
-
disk-snapshot-create disk-snapshot-delete terminate terminate-hard
|
233
|
-
disk-resize deploy chown chmod updateconf rename resize update
|
234
|
-
snapshot-resize snapshot-delete snapshot-revert disk-saveas
|
235
|
-
disk-snapshot-revert recover retry monitor disk-snapshot-rename
|
236
|
-
alias-attach alias-detach poweroff-migrate poweroff-hard-migrate
|
237
|
-
backup nic-update
|
238
|
-
}
|
231
|
+
HISTORY_ACTION=['none', 'migrate', 'live-migrate', 'shutdown', 'shutdown-hard', 'undeploy',
|
232
|
+
'undeploy-hard', 'hold', 'release', 'stop', 'suspend', 'resume', 'boot', 'delete', 'delete-recreate', 'reboot', 'reboot-hard', 'resched', 'unresched', 'poweroff', 'poweroff-hard', 'disk-attach', 'disk-detach', 'nic-attach', 'nic-detach', 'disk-snapshot-create', 'disk-snapshot-delete', 'terminate', 'terminate-hard', 'disk-resize', 'deploy', 'chown', 'chmod', 'updateconf', 'rename', 'resize', 'update', 'snapshot-resize', 'snapshot-delete', 'snapshot-revert', 'disk-saveas', 'disk-snapshot-revert', 'recover', 'retry', 'monitor', 'disk-snapshot-rename', 'alias-attach', 'alias-detach', 'poweroff-migrate', 'poweroff-hard-migrate', 'backup', 'nic-update']
|
239
233
|
|
240
234
|
EXTERNAL_IP_ATTRS = [
|
241
235
|
'GUEST_IP',
|
@@ -248,14 +242,15 @@ module OpenNebula
|
|
248
242
|
|
249
243
|
# VirtualMachineDriver constants
|
250
244
|
module Driver
|
245
|
+
|
251
246
|
POLL_ATTRIBUTE = {
|
252
|
-
:memory =>
|
253
|
-
:cpu =>
|
254
|
-
:nettx =>
|
255
|
-
:netrx =>
|
256
|
-
:state =>
|
257
|
-
:disk_size =>
|
258
|
-
:snapshot_size =>
|
247
|
+
:memory => 'MEMORY',
|
248
|
+
:cpu => 'CPU',
|
249
|
+
:nettx => 'NETTX',
|
250
|
+
:netrx => 'NETRX',
|
251
|
+
:state => 'STATE',
|
252
|
+
:disk_size => 'DISK_SIZE',
|
253
|
+
:snapshot_size => 'SNAPSHOT_SIZE'
|
259
254
|
}
|
260
255
|
|
261
256
|
VM_STATE = {
|
@@ -265,6 +260,7 @@ module OpenNebula
|
|
265
260
|
:deleted => 'd',
|
266
261
|
:unknown => '-'
|
267
262
|
}
|
263
|
+
|
268
264
|
end
|
269
265
|
|
270
266
|
# Creates a VirtualMachine description with just its identifier
|
@@ -274,25 +270,25 @@ module OpenNebula
|
|
274
270
|
# Example:
|
275
271
|
# vm = VirtualMachine.new(VirtualMachine.build_xml(3),rpc_client)
|
276
272
|
#
|
277
|
-
def
|
273
|
+
def self.build_xml(pe_id = nil)
|
278
274
|
if pe_id
|
279
275
|
vm_xml = "<VM><ID>#{pe_id}</ID></VM>"
|
280
276
|
else
|
281
|
-
vm_xml =
|
277
|
+
vm_xml = '<VM></VM>'
|
282
278
|
end
|
283
279
|
|
284
280
|
XMLElement.build_xml(vm_xml, 'VM')
|
285
281
|
end
|
286
282
|
|
287
|
-
def
|
288
|
-
|
283
|
+
def self.get_history_action(action)
|
284
|
+
HISTORY_ACTION[action.to_i]
|
289
285
|
end
|
290
286
|
|
291
287
|
# Class constructor
|
292
288
|
def initialize(xml, client)
|
293
289
|
LockableExt.make_lockable(self, VM_METHODS)
|
294
290
|
|
295
|
-
super(xml,client)
|
291
|
+
super(xml, client)
|
296
292
|
end
|
297
293
|
|
298
294
|
#######################################################################
|
@@ -304,7 +300,7 @@ module OpenNebula
|
|
304
300
|
super(VM_METHODS[:info], 'VM', decrypt)
|
305
301
|
end
|
306
302
|
|
307
|
-
|
303
|
+
alias info! info
|
308
304
|
|
309
305
|
# Allocates a new VirtualMachine in OpenNebula
|
310
306
|
#
|
@@ -315,7 +311,7 @@ module OpenNebula
|
|
315
311
|
#
|
316
312
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
317
313
|
# otherwise
|
318
|
-
def allocate(description, hold=false)
|
314
|
+
def allocate(description, hold = false)
|
319
315
|
super(VM_METHODS[:allocate], description, hold)
|
320
316
|
end
|
321
317
|
|
@@ -327,7 +323,7 @@ module OpenNebula
|
|
327
323
|
#
|
328
324
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
329
325
|
# otherwise
|
330
|
-
def update(new_template=nil, append=false)
|
326
|
+
def update(new_template = nil, append = false)
|
331
327
|
super(VM_METHODS[:update], new_template, append ? 1 : 0)
|
332
328
|
end
|
333
329
|
|
@@ -336,7 +332,7 @@ module OpenNebula
|
|
336
332
|
# @param indent [true,false] indents the resulting string, defaults to true
|
337
333
|
#
|
338
334
|
# @return [String] The USER_TEMPLATE
|
339
|
-
def user_template_str(indent=true)
|
335
|
+
def user_template_str(indent = true)
|
340
336
|
template_like_str('USER_TEMPLATE', indent)
|
341
337
|
end
|
342
338
|
|
@@ -352,7 +348,7 @@ module OpenNebula
|
|
352
348
|
end
|
353
349
|
|
354
350
|
def replace(opts = {})
|
355
|
-
super(opts,
|
351
|
+
super(opts, 'USER_TEMPLATE')
|
356
352
|
end
|
357
353
|
|
358
354
|
# Initiates the instance of the VM on the target host.
|
@@ -367,40 +363,40 @@ module OpenNebula
|
|
367
363
|
#
|
368
364
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
369
365
|
# otherwise
|
370
|
-
def deploy(host_id, enforce=false, ds_id
|
366
|
+
def deploy(host_id, enforce = false, ds_id = -1, extra_template = '')
|
371
367
|
enforce ||= false
|
372
368
|
ds_id ||= -1
|
373
|
-
extra_template ||=
|
369
|
+
extra_template ||= ''
|
374
370
|
|
375
|
-
|
371
|
+
info
|
376
372
|
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
373
|
+
call(VM_METHODS[:deploy],
|
374
|
+
@pe_id,
|
375
|
+
host_id.to_i,
|
376
|
+
enforce,
|
377
|
+
ds_id.to_i,
|
378
|
+
extra_template)
|
383
379
|
end
|
384
380
|
|
385
381
|
# Shutdowns an already deployed VM
|
386
|
-
def terminate(hard=false)
|
382
|
+
def terminate(hard = false)
|
387
383
|
action(hard ? 'terminate-hard' : 'terminate')
|
388
384
|
end
|
389
385
|
|
390
|
-
|
386
|
+
alias shutdown terminate
|
391
387
|
|
392
388
|
# Shuts down an already deployed VM, saving its state in the system DS
|
393
|
-
def undeploy(hard=false)
|
389
|
+
def undeploy(hard = false)
|
394
390
|
action(hard ? 'undeploy-hard' : 'undeploy')
|
395
391
|
end
|
396
392
|
|
397
393
|
# Powers off a running VM
|
398
|
-
def poweroff(hard=false)
|
394
|
+
def poweroff(hard = false)
|
399
395
|
action(hard ? 'poweroff-hard' : 'poweroff')
|
400
396
|
end
|
401
397
|
|
402
398
|
# Reboots an already deployed VM
|
403
|
-
def reboot(hard=false)
|
399
|
+
def reboot(hard = false)
|
404
400
|
action(hard ? 'reboot-hard' : 'reboot')
|
405
401
|
end
|
406
402
|
|
@@ -435,10 +431,10 @@ module OpenNebula
|
|
435
431
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
436
432
|
# otherwise
|
437
433
|
def disk_attach(disk_template)
|
438
|
-
|
434
|
+
call(VM_METHODS[:attach], @pe_id, disk_template)
|
439
435
|
end
|
440
436
|
|
441
|
-
|
437
|
+
alias attachdisk disk_attach
|
442
438
|
|
443
439
|
# Detaches a disk from a running VM
|
444
440
|
#
|
@@ -446,10 +442,10 @@ module OpenNebula
|
|
446
442
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
447
443
|
# otherwise
|
448
444
|
def disk_detach(disk_id)
|
449
|
-
|
445
|
+
call(VM_METHODS[:detach], @pe_id, disk_id)
|
450
446
|
end
|
451
447
|
|
452
|
-
|
448
|
+
alias detachdisk disk_detach
|
453
449
|
|
454
450
|
# Attaches a NIC to a running VM
|
455
451
|
#
|
@@ -457,7 +453,7 @@ module OpenNebula
|
|
457
453
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
458
454
|
# otherwise
|
459
455
|
def nic_attach(nic_template)
|
460
|
-
|
456
|
+
call(VM_METHODS[:attachnic], @pe_id, nic_template)
|
461
457
|
end
|
462
458
|
|
463
459
|
# Detaches a NIC from a running VM
|
@@ -466,7 +462,7 @@ module OpenNebula
|
|
466
462
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
467
463
|
# otherwise
|
468
464
|
def nic_detach(nic_id)
|
469
|
-
|
465
|
+
call(VM_METHODS[:detachnic], @pe_id, nic_id)
|
470
466
|
end
|
471
467
|
|
472
468
|
# Updates a NIC for a running VM
|
@@ -478,7 +474,7 @@ module OpenNebula
|
|
478
474
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
479
475
|
# otherwise
|
480
476
|
def nic_update(nic_id, nic_template, append = false)
|
481
|
-
|
477
|
+
call(VM_METHODS[:updatenic], @pe_id, nic_id, nic_template, append ? 1 : 0)
|
482
478
|
end
|
483
479
|
|
484
480
|
# Attaches a Security Groupt to a running VM
|
@@ -488,7 +484,7 @@ module OpenNebula
|
|
488
484
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
489
485
|
# otherwise
|
490
486
|
def sg_attach(nic_id, sg_id)
|
491
|
-
|
487
|
+
call(VM_METHODS[:attachsg], @pe_id, nic_id, sg_id)
|
492
488
|
end
|
493
489
|
|
494
490
|
# Detaches a Security Group from a running VM
|
@@ -497,7 +493,7 @@ module OpenNebula
|
|
497
493
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
498
494
|
# otherwise
|
499
495
|
def sg_detach(nic_id, sg_id)
|
500
|
-
|
496
|
+
call(VM_METHODS[:detachsg], @pe_id, nic_id, sg_id)
|
501
497
|
end
|
502
498
|
|
503
499
|
# Sets the re-scheduling flag for the VM
|
@@ -529,13 +525,13 @@ module OpenNebula
|
|
529
525
|
#
|
530
526
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
531
527
|
# otherwise
|
532
|
-
def migrate(host_id, live=false, enforce=false, ds_id
|
528
|
+
def migrate(host_id, live = false, enforce = false, ds_id = -1, mtype = 0)
|
533
529
|
call(VM_METHODS[:migrate], @pe_id, host_id.to_i, live==true,
|
534
|
-
|
530
|
+
enforce, ds_id.to_i, mtype)
|
535
531
|
end
|
536
532
|
|
537
533
|
# @deprecated use {#migrate} instead
|
538
|
-
def live_migrate(host_id, enforce=false)
|
534
|
+
def live_migrate(host_id, enforce = false)
|
539
535
|
migrate(host_id, true, enforce)
|
540
536
|
end
|
541
537
|
|
@@ -551,16 +547,15 @@ module OpenNebula
|
|
551
547
|
#
|
552
548
|
# @return [Integer, OpenNebula::Error] the new Image ID in case of
|
553
549
|
# success, error otherwise
|
554
|
-
def disk_saveas(disk_id, image_name, image_type=
|
555
|
-
return Error.new('ID not defined')
|
550
|
+
def disk_saveas(disk_id, image_name, image_type = '', snap_id = -1)
|
551
|
+
return Error.new('ID not defined') unless @pe_id
|
556
552
|
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
return rc
|
553
|
+
@client.call(VM_METHODS[:disksaveas],
|
554
|
+
@pe_id,
|
555
|
+
disk_id,
|
556
|
+
image_name,
|
557
|
+
image_type,
|
558
|
+
snap_id)
|
564
559
|
end
|
565
560
|
|
566
561
|
# Resize the VM
|
@@ -575,7 +570,7 @@ module OpenNebula
|
|
575
570
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
576
571
|
# otherwise
|
577
572
|
def resize(capacity_template, enforce)
|
578
|
-
|
573
|
+
call(VM_METHODS[:resize], @pe_id, capacity_template, enforce)
|
579
574
|
end
|
580
575
|
|
581
576
|
# Changes the owner/group
|
@@ -601,7 +596,7 @@ module OpenNebula
|
|
601
596
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
602
597
|
# otherwise
|
603
598
|
def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
|
604
|
-
|
599
|
+
other_m, other_a)
|
605
600
|
super(VM_METHODS[:chmod], owner_u, owner_m, owner_a, group_u,
|
606
601
|
group_m, group_a, other_u, other_m, other_a)
|
607
602
|
end
|
@@ -624,16 +619,16 @@ module OpenNebula
|
|
624
619
|
# }
|
625
620
|
#
|
626
621
|
def monitoring(xpath_expressions)
|
627
|
-
|
622
|
+
super(VM_METHODS[:monitoring], xpath_expressions)
|
628
623
|
end
|
629
624
|
|
630
625
|
# Retrieves this VM's monitoring data from OpenNebula, in XML
|
631
626
|
#
|
632
627
|
# @return [String] VM monitoring data, in XML
|
633
|
-
def monitoring_xml
|
634
|
-
return Error.new('ID not defined')
|
628
|
+
def monitoring_xml
|
629
|
+
return Error.new('ID not defined') unless @pe_id
|
635
630
|
|
636
|
-
|
631
|
+
@client.call(VM_METHODS[:monitoring], @pe_id)
|
637
632
|
end
|
638
633
|
|
639
634
|
# Renames this VM
|
@@ -643,7 +638,7 @@ module OpenNebula
|
|
643
638
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
644
639
|
# otherwise
|
645
640
|
def rename(name)
|
646
|
-
|
641
|
+
call(VM_METHODS[:rename], @pe_id, name)
|
647
642
|
end
|
648
643
|
|
649
644
|
# Creates a new VM snapshot
|
@@ -652,11 +647,11 @@ module OpenNebula
|
|
652
647
|
#
|
653
648
|
# @return [Integer, OpenNebula::Error] The new snaphost ID in case
|
654
649
|
# of success, Error otherwise
|
655
|
-
def snapshot_create(name=
|
656
|
-
return Error.new('ID not defined')
|
650
|
+
def snapshot_create(name = '')
|
651
|
+
return Error.new('ID not defined') unless @pe_id
|
657
652
|
|
658
|
-
name ||=
|
659
|
-
|
653
|
+
name ||= ''
|
654
|
+
@client.call(VM_METHODS[:snapshotcreate], @pe_id, name)
|
660
655
|
end
|
661
656
|
|
662
657
|
# Reverts to a snapshot
|
@@ -666,7 +661,7 @@ module OpenNebula
|
|
666
661
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
667
662
|
# otherwise
|
668
663
|
def snapshot_revert(snap_id)
|
669
|
-
|
664
|
+
call(VM_METHODS[:snapshotrevert], @pe_id, snap_id)
|
670
665
|
end
|
671
666
|
|
672
667
|
# Deletes a VM snapshot
|
@@ -676,7 +671,7 @@ module OpenNebula
|
|
676
671
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
677
672
|
# otherwise
|
678
673
|
def snapshot_delete(snap_id)
|
679
|
-
|
674
|
+
call(VM_METHODS[:snapshotdelete], @pe_id, snap_id)
|
680
675
|
end
|
681
676
|
|
682
677
|
# Takes a new snapshot of a disk
|
@@ -686,7 +681,7 @@ module OpenNebula
|
|
686
681
|
#
|
687
682
|
# @return [Integer, OpenNebula::Error] The new snapshot ID or error
|
688
683
|
def disk_snapshot_create(disk_id, name)
|
689
|
-
|
684
|
+
call(VM_METHODS[:disksnapshotcreate], @pe_id, disk_id, name)
|
690
685
|
end
|
691
686
|
|
692
687
|
# Reverts disk state to a previously taken snapshot
|
@@ -697,7 +692,7 @@ module OpenNebula
|
|
697
692
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
698
693
|
# otherwise
|
699
694
|
def disk_snapshot_revert(disk_id, snap_id)
|
700
|
-
|
695
|
+
call(VM_METHODS[:disksnapshotrevert], @pe_id, disk_id, snap_id)
|
701
696
|
end
|
702
697
|
|
703
698
|
# Deletes a disk snapshot
|
@@ -708,7 +703,7 @@ module OpenNebula
|
|
708
703
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
709
704
|
# otherwise
|
710
705
|
def disk_snapshot_delete(disk_id, snap_id)
|
711
|
-
|
706
|
+
call(VM_METHODS[:disksnapshotdelete], @pe_id, disk_id, snap_id)
|
712
707
|
end
|
713
708
|
|
714
709
|
# Renames a disk snapshot
|
@@ -720,7 +715,7 @@ module OpenNebula
|
|
720
715
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
721
716
|
# otherwise
|
722
717
|
def disk_snapshot_rename(disk_id, snap_id, new_name)
|
723
|
-
|
718
|
+
call(VM_METHODS[:disksnapshotrename], @pe_id, disk_id, snap_id, new_name)
|
724
719
|
end
|
725
720
|
|
726
721
|
# Changes the size of a disk
|
@@ -730,7 +725,7 @@ module OpenNebula
|
|
730
725
|
#
|
731
726
|
# @return [nil, OpenNebula::Error] nil in case of success or error
|
732
727
|
def disk_resize(disk_id, size)
|
733
|
-
|
728
|
+
call(VM_METHODS[:diskresize], @pe_id, disk_id, size.to_s)
|
734
729
|
end
|
735
730
|
|
736
731
|
# Recovers an ACTIVE VM
|
@@ -741,11 +736,11 @@ module OpenNebula
|
|
741
736
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
742
737
|
# otherwise
|
743
738
|
def recover(result)
|
744
|
-
|
739
|
+
call(VM_METHODS[:recover], @pe_id, result)
|
745
740
|
end
|
746
741
|
|
747
742
|
# Deletes a VM from the pool
|
748
|
-
def delete(recreate=false)
|
743
|
+
def delete(recreate = false)
|
749
744
|
if recreate
|
750
745
|
recover(4)
|
751
746
|
else
|
@@ -766,7 +761,7 @@ module OpenNebula
|
|
766
761
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
767
762
|
# otherwise
|
768
763
|
def updateconf(new_conf, append = false)
|
769
|
-
|
764
|
+
call(VM_METHODS[:updateconf], @pe_id, new_conf, append ? 1 : 0)
|
770
765
|
end
|
771
766
|
|
772
767
|
# Add sched actions
|
@@ -775,7 +770,7 @@ module OpenNebula
|
|
775
770
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
776
771
|
# otherwise
|
777
772
|
def sched_action_add(sched_template)
|
778
|
-
|
773
|
+
call(VM_METHODS[:schedadd], @pe_id, sched_template)
|
779
774
|
end
|
780
775
|
|
781
776
|
# Delete sched action
|
@@ -784,7 +779,7 @@ module OpenNebula
|
|
784
779
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
785
780
|
# otherwise
|
786
781
|
def sched_action_delete(sched_id)
|
787
|
-
|
782
|
+
call(VM_METHODS[:scheddelete], @pe_id, sched_id.to_i)
|
788
783
|
end
|
789
784
|
|
790
785
|
# Update sched_action
|
@@ -794,8 +789,8 @@ module OpenNebula
|
|
794
789
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
795
790
|
# otherwise
|
796
791
|
def sched_action_update(sched_id, sched_template)
|
797
|
-
|
798
|
-
|
792
|
+
call(VM_METHODS[:schedupdate], @pe_id, sched_id.to_i,
|
793
|
+
sched_template)
|
799
794
|
end
|
800
795
|
|
801
796
|
# Generate a backup for the VM (backup config must be set)
|
@@ -804,7 +799,15 @@ module OpenNebula
|
|
804
799
|
# @return [Integer, OpenNebula::Error] ID of the resulting BACKUP image
|
805
800
|
# in case of success, Error otherwise.
|
806
801
|
def backup(ds_id = -1, reset = false)
|
807
|
-
|
802
|
+
@client.call(VM_METHODS[:backup], @pe_id, ds_id, reset)
|
803
|
+
end
|
804
|
+
|
805
|
+
# Cancel ongoing backup operation for the VM
|
806
|
+
#
|
807
|
+
# @return [nil, OpenNebula::Error] nil in case of sucess, Error
|
808
|
+
# otherwise.
|
809
|
+
def backup_cancel
|
810
|
+
@client.call(VM_METHODS[:backupcancel], @pe_id)
|
808
811
|
end
|
809
812
|
|
810
813
|
########################################################################
|
@@ -835,7 +838,7 @@ module OpenNebula
|
|
835
838
|
def status
|
836
839
|
short_state_str=SHORT_VM_STATES[state_str]
|
837
840
|
|
838
|
-
if short_state_str==
|
841
|
+
if short_state_str=='actv'
|
839
842
|
short_state_str=SHORT_LCM_STATES[lcm_state_str]
|
840
843
|
end
|
841
844
|
|
@@ -857,7 +860,7 @@ module OpenNebula
|
|
857
860
|
retrieve_xmlelements('//HISTORY')[seq].to_xml
|
858
861
|
end
|
859
862
|
|
860
|
-
def wait_state(state, timeout=120)
|
863
|
+
def wait_state(state, timeout = 120)
|
861
864
|
require 'opennebula/wait_ext'
|
862
865
|
|
863
866
|
extend OpenNebula::WaitExt
|
@@ -869,7 +872,7 @@ module OpenNebula
|
|
869
872
|
true
|
870
873
|
end
|
871
874
|
|
872
|
-
def wait_state2(state, lcm_state, timeout=120)
|
875
|
+
def wait_state2(state, lcm_state, timeout = 120)
|
873
876
|
extend OpenNebula::WaitExt
|
874
877
|
|
875
878
|
rc = wait2(state, lcm_state, timeout)
|
@@ -879,26 +882,27 @@ module OpenNebula
|
|
879
882
|
true
|
880
883
|
end
|
881
884
|
|
882
|
-
|
885
|
+
private
|
886
|
+
|
883
887
|
def action(name)
|
884
|
-
return Error.new('ID not defined')
|
888
|
+
return Error.new('ID not defined') unless @pe_id
|
885
889
|
|
886
890
|
rc = @client.call(VM_METHODS[:action], name, @pe_id)
|
887
|
-
rc = nil
|
891
|
+
rc = nil unless OpenNebula.is_error?(rc)
|
888
892
|
|
889
|
-
|
893
|
+
rc
|
890
894
|
end
|
891
895
|
|
892
|
-
def wait_lcm_state(state, timeout=10)
|
893
|
-
vm_state =
|
894
|
-
lcm_state =
|
896
|
+
def wait_lcm_state(state, timeout = 10)
|
897
|
+
vm_state = ''
|
898
|
+
lcm_state = ''
|
895
899
|
|
896
900
|
timeout.times do
|
897
|
-
rc = info
|
901
|
+
rc = info
|
898
902
|
return rc if OpenNebula.is_error?(rc)
|
899
903
|
|
900
|
-
vm_state = state_str
|
901
|
-
lcm_state = lcm_state_str
|
904
|
+
vm_state = state_str
|
905
|
+
lcm_state = lcm_state_str
|
902
906
|
|
903
907
|
if lcm_state == state
|
904
908
|
return true
|
@@ -907,8 +911,10 @@ module OpenNebula
|
|
907
911
|
sleep 1
|
908
912
|
end
|
909
913
|
|
910
|
-
|
914
|
+
Error.new("Timeout expired for state #{state}. "<<
|
911
915
|
"VM is in state #{vm_state}, #{lcm_state}")
|
912
916
|
end
|
917
|
+
|
913
918
|
end
|
919
|
+
|
914
920
|
end
|