Class: VirtualMachineDriver
Overview
This class provides basic messaging and logging functionality to implement OpenNebula Drivers. A driver is a program that specialize the OpenNebula behavior by interfacing with specific infrastructure functionalities.
A Driver inherits this class and only has to provide methods for each action it wants to receive. The method must be associated with the action name through the register_action function
Constant Summary
collapse
- ACTION =
Virtual Machine Driver Protocol constants
{
:deploy => "DEPLOY",
:shutdown => "SHUTDOWN",
:reboot => "REBOOT",
:reset => "RESET",
:cancel => "CANCEL",
:save => "SAVE",
:restore => "RESTORE",
:migrate => "MIGRATE",
:poll => "POLL",
:log => "LOG",
:attach_disk => "ATTACHDISK",
:detach_disk => "DETACHDISK",
:snapshot_create => "SNAPSHOTCREATE",
:snapshot_revert => "SNAPSHOTREVERT",
:snapshot_delete => "SNAPSHOTDELETE",
:cleanup => "CLEANUP",
:attach_nic => "ATTACHNIC",
:detach_nic => "DETACHNIC",
:disk_snapshot_create => "DISKSNAPSHOTCREATE",
:update_sg => "UPDATESG"
}
- POLL_ATTRIBUTE =
{
:memory => "MEMORY",
:cpu => "CPU",
:nettx => "NETTX",
:netrx => "NETRX",
:state => "STATE",
:disk_size => "DISK_SIZE",
:snapshot_size => "SNAPSHOT_SIZE"
}
- VM_STATE =
{
:active => 'a',
:paused => 'p',
:error => 'e',
:deleted => 'd',
:unknown => '-'
}
- HOST_ARG =
1
DriverExecHelper::RESULT
Instance Attribute Summary
#local_scripts_base_path, #local_scripts_path, #remote_scripts_base_path, #remote_scripts_path
Instance Method Summary
collapse
-
#attach_disk(id, drv_message) ⇒ Object
-
#attach_nic(id, drv_message) ⇒ Object
-
#cancel(id, drv_message) ⇒ Object
-
#cleanup(id, drv_message) ⇒ Object
-
#decode(drv_message) ⇒ REXML::Element
Decodes the encoded XML driver message received from the core.
-
#deploy(id, drv_message) ⇒ Object
Virtual Machine Manager Protocol Actions (generic implementation).
-
#detach_disk(id, drv_message) ⇒ Object
-
#detach_nic(id, drv_message) ⇒ Object
-
#disk_snapshot_create(id, drv_message) ⇒ Object
-
#initialize(directory, options = {}) ⇒ VirtualMachineDriver
constructor
Register default actions for the protocol.
-
#local_action(command, id, action) ⇒ Object
Execute a command associated to an action and id on localhost.
-
#migrate(id, drv_message) ⇒ Object
-
#poll(id, drv_message) ⇒ Object
-
#reboot(id, drv_message) ⇒ Object
-
#remotes_action(command, id, host, action, remote_dir, std_in = nil) ⇒ Object
Execute a command associated to an action and id in a remote host.
-
#reset(id, drv_message) ⇒ Object
-
#restore(id, drv_message) ⇒ Object
-
#save(id, drv_message) ⇒ Object
-
#shutdown(id, drv_message) ⇒ Object
-
#snapshot_create(id, drv_message) ⇒ Object
-
#snapshot_delete(id, drv_message) ⇒ Object
-
#snapshot_revert(id, drv_message) ⇒ Object
-
#update_sg(id, drv_message) ⇒ Object
#do_action, parse_actions_list, #start_driver
#action_command_line, #action_is_local?, #action_script_name, failed?, #get_info_from_execution, #initialize_helper, #log, #log_method, #read_configuration, #send_message
#cancel_action, #register_action, #start_listener, #trigger_action
Constructor Details
Register default actions for the protocol.
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/VirtualMachineDriver.rb', line 82
def initialize(directory, options={})
@options={
:threaded => true,
:single_host => true
}.merge!(options)
super(directory, @options)
@hosts = Array.new
register_action(ACTION[:deploy].to_sym, method("deploy"))
register_action(ACTION[:shutdown].to_sym, method("shutdown"))
register_action(ACTION[:reboot].to_sym, method("reboot"))
register_action(ACTION[:reset].to_sym, method("reset"))
register_action(ACTION[:cancel].to_sym, method("cancel"))
register_action(ACTION[:save].to_sym, method("save"))
register_action(ACTION[:restore].to_sym, method("restore"))
register_action(ACTION[:migrate].to_sym, method("migrate"))
register_action(ACTION[:poll].to_sym, method("poll"))
register_action(ACTION[:attach_disk].to_sym, method("attach_disk"))
register_action(ACTION[:detach_disk].to_sym, method("detach_disk"))
register_action(ACTION[:snapshot_create].to_sym, method("snapshot_create"))
register_action(ACTION[:snapshot_revert].to_sym, method("snapshot_revert"))
register_action(ACTION[:snapshot_delete].to_sym, method("snapshot_delete"))
register_action(ACTION[:cleanup].to_sym, method("cleanup"))
register_action(ACTION[:attach_nic].to_sym, method("attach_nic"))
register_action(ACTION[:detach_nic].to_sym, method("detach_nic"))
register_action(ACTION[:disk_snapshot_create].to_sym, method("disk_snapshot_create"))
register_action(ACTION[:update_sg].to_sym, method("update_sg"))
end
|
Instance Method Details
#attach_disk(id, drv_message) ⇒ Object
180
181
182
183
|
# File 'lib/VirtualMachineDriver.rb', line 180
def attach_disk(id, drv_message)
error = "Action not implemented by driver #{self.class}"
send_message(ACTION[:attach_disk],RESULT[:failure],id,error)
end
|
#attach_nic(id, drv_message) ⇒ Object
190
191
192
193
|
# File 'lib/VirtualMachineDriver.rb', line 190
def attach_nic(id, drv_message)
error = "Action not implemented by driver #{self.class}"
send_message(ACTION[:attach_nic],RESULT[:failure],id,error)
end
|
#cancel(id, drv_message) ⇒ Object
155
156
157
158
|
# File 'lib/VirtualMachineDriver.rb', line 155
def cancel(id, drv_message)
error = "Action not implemented by driver #{self.class}"
send_message(ACTION[:cancel],RESULT[:failure],id,error)
end
|
#cleanup(id, drv_message) ⇒ Object
225
226
227
228
|
# File 'lib/VirtualMachineDriver.rb', line 225
def cleanup(id, drv_message)
error = "Action not implemented by driver #{self.class}"
send_message(ACTION[:cleanup],RESULT[:failure],id,error)
end
|
#decode(drv_message) ⇒ REXML::Element
Decodes the encoded XML driver message received from the core
117
118
119
120
121
122
|
# File 'lib/VirtualMachineDriver.rb', line 117
def decode(drv_message)
message = Base64.decode64(drv_message)
xml_doc = REXML::Document.new(message)
xml_doc.root
end
|
#deploy(id, drv_message) ⇒ Object
Virtual Machine Manager Protocol Actions (generic implementation)
135
136
137
138
|
# File 'lib/VirtualMachineDriver.rb', line 135
def deploy(id, drv_message)
error = "Action not implemented by driver #{self.class}"
send_message(ACTION[:deploy],RESULT[:failure],id,error)
end
|
#detach_disk(id, drv_message) ⇒ Object
185
186
187
188
|
# File 'lib/VirtualMachineDriver.rb', line 185
def detach_disk(id, drv_message)
error = "Action not implemented by driver #{self.class}"
send_message(ACTION[:detach_disk],RESULT[:failure],id,error)
end
|
#detach_nic(id, drv_message) ⇒ Object
195
196
197
198
|
# File 'lib/VirtualMachineDriver.rb', line 195
def detach_nic(id, drv_message)
error = "Action not implemented by driver #{self.class}"
send_message(ACTION[:detach_nic],RESULT[:failure],id,error)
end
|
#disk_snapshot_create(id, drv_message) ⇒ Object
215
216
217
218
|
# File 'lib/VirtualMachineDriver.rb', line 215
def disk_snapshot_create(id, drv_message)
error = "Action not implemented by driver #{self.class}"
send_message(ACTION[:disk_snapshot_create],RESULT[:failure],id,error)
end
|
#local_action(command, id, action) ⇒ Object
Execute a command associated to an action and id on localhost
130
131
132
|
# File 'lib/VirtualMachineDriver.rb', line 130
def local_action(command, id, action)
super(command,id,ACTION[action])
end
|
#migrate(id, drv_message) ⇒ Object
170
171
172
173
|
# File 'lib/VirtualMachineDriver.rb', line 170
def migrate(id, drv_message)
error = "Action not implemented by driver #{self.class}"
send_message(ACTION[:migrate],RESULT[:failure],id,error)
end
|
#poll(id, drv_message) ⇒ Object
175
176
177
178
|
# File 'lib/VirtualMachineDriver.rb', line 175
def poll(id, drv_message)
error = "Action not implemented by driver #{self.class}"
send_message(ACTION[:poll],RESULT[:failure],id,error)
end
|
#reboot(id, drv_message) ⇒ Object
145
146
147
148
|
# File 'lib/VirtualMachineDriver.rb', line 145
def reboot(id, drv_message)
error = "Action not implemented by driver #{self.class}"
send_message(ACTION[:reboot],RESULT[:failure],id,error)
end
|
#remotes_action(command, id, host, action, remote_dir, std_in = nil) ⇒ Object
Execute a command associated to an action and id in a remote host.
125
126
127
|
# File 'lib/VirtualMachineDriver.rb', line 125
def remotes_action(command, id, host, action, remote_dir, std_in=nil)
super(command,id,host,ACTION[action],remote_dir,std_in)
end
|
#reset(id, drv_message) ⇒ Object
150
151
152
153
|
# File 'lib/VirtualMachineDriver.rb', line 150
def reset(id, drv_message)
error = "Action not implemented by driver #{self.class}"
send_message(ACTION[:reset],RESULT[:failure],id,error)
end
|
#restore(id, drv_message) ⇒ Object
165
166
167
168
|
# File 'lib/VirtualMachineDriver.rb', line 165
def restore(id, drv_message)
error = "Action not implemented by driver #{self.class}"
send_message(ACTION[:restore],RESULT[:failure],id,error)
end
|
#save(id, drv_message) ⇒ Object
160
161
162
163
|
# File 'lib/VirtualMachineDriver.rb', line 160
def save(id, drv_message)
error = "Action not implemented by driver #{self.class}"
send_message(ACTION[:save],RESULT[:failure],id,error)
end
|
#shutdown(id, drv_message) ⇒ Object
140
141
142
143
|
# File 'lib/VirtualMachineDriver.rb', line 140
def shutdown(id, drv_message)
error = "Action not implemented by driver #{self.class}"
send_message(ACTION[:shutdown],RESULT[:failure],id,error)
end
|
#snapshot_create(id, drv_message) ⇒ Object
200
201
202
203
|
# File 'lib/VirtualMachineDriver.rb', line 200
def snapshot_create(id, drv_message)
error = "Action not implemented by driver #{self.class}"
send_message(ACTION[:snapshot_create],RESULT[:failure],id,error)
end
|
#snapshot_delete(id, drv_message) ⇒ Object
210
211
212
213
|
# File 'lib/VirtualMachineDriver.rb', line 210
def snapshot_delete(id, drv_message)
error = "Action not implemented by driver #{self.class}"
send_message(ACTION[:snapshot_delete],RESULT[:failure],id,error)
end
|
#snapshot_revert(id, drv_message) ⇒ Object
205
206
207
208
|
# File 'lib/VirtualMachineDriver.rb', line 205
def snapshot_revert(id, drv_message)
error = "Action not implemented by driver #{self.class}"
send_message(ACTION[:snapshot_revert],RESULT[:failure],id,error)
end
|
#update_sg(id, drv_message) ⇒ Object
220
221
222
223
|
# File 'lib/VirtualMachineDriver.rb', line 220
def update_sg(id, drv_message)
error = "Action not implemented by driver #{self.class}"
send_message(ACTION[:update_sg],RESULT[:failure],id,error)
end
|