1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-12 08:58:17 +03:00

Moved ssh_action method to base class VirtualMachineDriver

git-svn-id: http://svn.opennebula.org/one/trunk@377 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
Rubén S. Montero 2009-02-23 11:55:31 +00:00
parent a6587660d0
commit 78cb777e46
3 changed files with 23 additions and 37 deletions

View File

@ -14,6 +14,7 @@
# limitations under the License. */
# -------------------------------------------------------------------------- */
require "OpenNebulaDriver"
require "CommandManager"
# Author:: dsa-research.org
# Copyright:: (c) 2009 Universidad Computense de Madrid
@ -100,6 +101,24 @@ class VirtualMachineDriver < OpenNebulaDriver
return lfile
end
# -------------------------------------------------------------------------
# Execute a command associated to an action and id in a remote host.
# -------------------------------------------------------------------------
def ssh_action(command, id, host, action)
command_exe = SSHCommand.run(command, host, log_method(id))
if command_exe.code == 0
result = :success
else
result = :failure
end
send_message(ACTION[action],RESULT[result],id)
end
# -------------------------------------------------------------------------
# Virtual Machine Manager Protocol Actions (generic implementation
# -------------------------------------------------------------------------
def deploy(id, host, remote_dfile, not_used)
error = "Action not implemented by driver #{self.class}"
send_message(ACTION[:deploy],RESULT[:failure],id,error)
@ -172,8 +191,8 @@ class TemplateDriver < VirtualMachineDriver
def poll(id, host, deploy_id, not_used)
# monitor_info: string in the form "VAR=VAL VAR=VAL ... VAR=VAL"
# known VAR are in POLL_ATTRIBUTES. VM states VM_STATES
monitor_info = "#{POLL_ATTRIBUTE[:state]}=#{VM_STATE[:active]} \
#{POLL_ATTRIBUTE[:nettx]}=12345"
monitor_info = "#{POLL_ATTRIBUTE[:state]}=#{VM_STATE[:active]} " \
"#{POLL_ATTRIBUTE[:nettx]}=12345"
send_message(ACTION[:poll],RESULT[:success],id,monitor_info)
end

View File

@ -34,12 +34,10 @@ $: << RUBY_LIB_LOCATION
require 'pp'
require "VirtualMachineDriver"
require "CommandManager"
# ---------------------------------------------------------------------------- #
# The main class for the LibVirt driver #
# ---------------------------------------------------------------------------- #
class LibVirtDriver < VirtualMachineDriver
# ------------------------------------------------------------------------ #
@ -169,20 +167,6 @@ class LibVirtDriver < VirtualMachineDriver
send_message(ACTION[:poll], RESULT[:success], id, info)
end
private
def ssh_action(command, id, host, action)
command_exe = SSHCommand.run(command, host, log_method(id))
if command_exe.code == 0
result = :success
else
result = :failure
end
send_message(ACTION[action],RESULT[result],id)
end
end
# ---------------------------------------------------------------------------- #

View File

@ -36,12 +36,10 @@ $: << RUBY_LIB_LOCATION
require 'pp'
require "VirtualMachineDriver"
require "CommandManager"
# ---------------------------------------------------------------------------- #
# The main class for the Xen driver #
# ---------------------------------------------------------------------------- #
class XenDriver < VirtualMachineDriver
# ------------------------------------------------------------------------ #
@ -148,9 +146,8 @@ class XenDriver < VirtualMachineDriver
end
# ------------------------------------------------------------------------ #
# Get info from the Xen Domain. xentop columns chart:
# ------------------------------------------------------------------------ #
# Get info from the Xen Domain. #
# ------------------------------------------------------------------------ #
def poll(id, host, deploy_id, not_used)
exe = SSHCommand.run("#{XEN[:poll]} #{deploy_id}", host, log_method(id))
@ -192,20 +189,6 @@ class XenDriver < VirtualMachineDriver
send_message(ACTION[:poll], RESULT[:success], id, info)
end
private
def ssh_action(command, id, host, action)
command_exe = SSHCommand.run(command, host, log_method(id))
if command_exe.code == 0
result = :success
else
result = :failure
end
send_message(ACTION[action],RESULT[result],id)
end
end
# ---------------------------------------------------------------------------- #