Class: VirtualMachineDriver

Inherits:
OpenNebulaDriver show all
Defined in:
lib/VirtualMachineDriver.rb

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

Direct Known Subclasses

TemplateDriver

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",
    :resize_disk => "RESIZEDISK",
    :update_sg   => "UPDATESG",
    :update_conf => "UPDATECONF",
    :resize      => "RESIZE",
    :backup      => "BACKUP",
    :update_nic   => "UPDATENIC",
    :backup_cancel=> "BACKUPCANCEL"
}
POLL_ATTRIBUTE =
OpenNebula::VirtualMachine::Driver::POLL_ATTRIBUTE
VM_STATE =
OpenNebula::VirtualMachine::Driver::VM_STATE
HOST_ARG =
1

Constants included from DriverExecHelper

DriverExecHelper::RESULT

Instance Attribute Summary

Attributes inherited from OpenNebulaDriver

#local_scripts_base_path, #local_scripts_path, #remote_scripts_base_path, #remote_scripts_path

Instance Method Summary collapse

Methods inherited from OpenNebulaDriver

#do_action, parse_actions_list, #start_driver

Methods included from DriverExecHelper

#action_command_line, #action_is_local?, #action_script_name, failed?, #get_info_from_execution, #initialize_helper, #log, #log_method, #read_configuration, #send_message

Methods inherited from ActionManager

#cancel_action, #register_action, #start_listener, #trigger_action

Constructor Details

#initialize(directory, options = {}) ⇒ VirtualMachineDriver

Register default actions for the protocol.

Parameters:

  • directory (String)

    path inside remotes path where the scripts reside

  • options (Hash) (defaults to: {})

    options for OpenNebula driver (check the available options in OpenNebulaDriver#initialize)

Options Hash (options):

  • :threaded (Boolean) — default: true

    enables or disables threads



74
75
76
77
78
79
80
81
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
# File 'lib/VirtualMachineDriver.rb', line 74

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[:resize_disk].to_sym, method("resize_disk"))
    register_action(ACTION[:update_sg].to_sym, method("update_sg"))
    register_action(ACTION[:update_conf].to_sym, method("update_conf"))
    register_action(ACTION[:resize].to_sym, method("resize"))
    register_action(ACTION[:backup].to_sym, method("backup"))
    register_action(ACTION[:update_nic].to_sym, method("update_nic"))
    register_action(ACTION[:backup_cancel].to_sym, method("backup_cancel"))
end

Instance Method Details

#attach_disk(id, drv_message) ⇒ Object



178
179
180
181
# File 'lib/VirtualMachineDriver.rb', line 178

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



188
189
190
191
# File 'lib/VirtualMachineDriver.rb', line 188

def attach_nic(id, drv_message)
    error = "Action not implemented by driver #{self.class}"
    send_message(ACTION[:attach_nic],RESULT[:failure],id,error)
end

#backup(id, drv_message) ⇒ Object



243
244
245
246
# File 'lib/VirtualMachineDriver.rb', line 243

def backup(id, drv_message)
    error = "Action not implemented by driver #{self.class}"
    send_message(ACTION[:backup],RESULT[:failure],id,error)
end

#backup_cancel(id, drv_message) ⇒ Object



253
254
255
256
# File 'lib/VirtualMachineDriver.rb', line 253

def backup_cancel(id, drv_message)
    error = "Action not implemented by driver #{self.class}"
    send_message(ACTION[:backup_cancel],RESULT[:failure],id,error)
end

#cancel(id, drv_message) ⇒ Object



153
154
155
156
# File 'lib/VirtualMachineDriver.rb', line 153

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



228
229
230
231
# File 'lib/VirtualMachineDriver.rb', line 228

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

Parameters:

  • drv_message (String)

    the driver message

Returns:

  • (REXML::Element)

    the root element of the decoded XML message



115
116
117
118
119
120
# File 'lib/VirtualMachineDriver.rb', line 115

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)



133
134
135
136
# File 'lib/VirtualMachineDriver.rb', line 133

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



183
184
185
186
# File 'lib/VirtualMachineDriver.rb', line 183

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



193
194
195
196
# File 'lib/VirtualMachineDriver.rb', line 193

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



213
214
215
216
# File 'lib/VirtualMachineDriver.rb', line 213

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



128
129
130
# File 'lib/VirtualMachineDriver.rb', line 128

def local_action(command, id, action)
    super(command,id,ACTION[action])
end

#migrate(id, drv_message) ⇒ Object



168
169
170
171
# File 'lib/VirtualMachineDriver.rb', line 168

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



173
174
175
176
# File 'lib/VirtualMachineDriver.rb', line 173

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



143
144
145
146
# File 'lib/VirtualMachineDriver.rb', line 143

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.



123
124
125
# File 'lib/VirtualMachineDriver.rb', line 123

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



148
149
150
151
# File 'lib/VirtualMachineDriver.rb', line 148

def reset(id, drv_message)
    error = "Action not implemented by driver #{self.class}"
    send_message(ACTION[:reset],RESULT[:failure],id,error)
end

#resize(id, drv_message) ⇒ Object



238
239
240
241
# File 'lib/VirtualMachineDriver.rb', line 238

def resize(id, drv_message)
    error = "Action not implemented by driver #{self.class}"
    send_message(ACTION[:resize],RESULT[:failure],id,error)
end

#resize_disk(id, drv_message) ⇒ Object



218
219
220
221
# File 'lib/VirtualMachineDriver.rb', line 218

def resize_disk(id, drv_message)
    error = "Action not implemented by driver #{self.class}"
    send_message(ACTION[:resize_disk],RESULT[:failure],id,error)
end

#restore(id, drv_message) ⇒ Object



163
164
165
166
# File 'lib/VirtualMachineDriver.rb', line 163

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



158
159
160
161
# File 'lib/VirtualMachineDriver.rb', line 158

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



138
139
140
141
# File 'lib/VirtualMachineDriver.rb', line 138

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



198
199
200
201
# File 'lib/VirtualMachineDriver.rb', line 198

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



208
209
210
211
# File 'lib/VirtualMachineDriver.rb', line 208

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



203
204
205
206
# File 'lib/VirtualMachineDriver.rb', line 203

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_conf(id, drv_message) ⇒ Object



233
234
235
236
# File 'lib/VirtualMachineDriver.rb', line 233

def update_conf(id, drv_message)
    error = "Action not implemented by driver #{self.class}"
    send_message(ACTION[:update_conf],RESULT[:failure],id,error)
end

#update_nic(id, drv_message) ⇒ Object



248
249
250
251
# File 'lib/VirtualMachineDriver.rb', line 248

def update_nic(id, drv_message)
    error = "Action not implemented by driver #{self.class}"
    send_message(ACTION[:update_nic],RESULT[:failure],id,error)
end

#update_sg(id, drv_message) ⇒ Object



223
224
225
226
# File 'lib/VirtualMachineDriver.rb', line 223

def update_sg(id, drv_message)
    error = "Action not implemented by driver #{self.class}"
    send_message(ACTION[:update_sg],RESULT[:failure],id,error)
end