mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
parent
b7fda37436
commit
048364353c
@ -15,6 +15,8 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
require "OpenNebulaDriver"
|
||||
require "CommandManager"
|
||||
require 'base64'
|
||||
require 'rexml/document'
|
||||
|
||||
# Author:: dsa-research.org
|
||||
# Copyright:: (c) 2011 Universidad Computense de Madrid
|
||||
@ -85,26 +87,15 @@ class VirtualMachineDriver < OpenNebulaDriver
|
||||
register_action(ACTION[:poll].to_sym, method("poll"))
|
||||
end
|
||||
|
||||
# Converts a deployment file from its remote path to the local (front-end)
|
||||
# path
|
||||
def get_local_deployment_file(rfile)
|
||||
lfile = nil
|
||||
# Decodes the encoded XML driver message received from the core
|
||||
#
|
||||
# @param [String] drv_message the driver message
|
||||
# @return [REXML::Element] the root element of the decoded XML message
|
||||
def decode(drv_message)
|
||||
message = Base64.decode64(drv_message)
|
||||
xml_doc = REXML::Document.new(message)
|
||||
|
||||
one_location = ENV["ONE_LOCATION"]
|
||||
|
||||
if one_location == nil
|
||||
var_location = "/var/lib/one/"
|
||||
else
|
||||
var_location = one_location + "/var/"
|
||||
end
|
||||
|
||||
m = rfile.match(/.*?\/(\d+)\/images\/(deployment.\d+)$/)
|
||||
|
||||
lfile = "#{var_location}#{m[1]}/#{m[2]}" if m
|
||||
|
||||
lfile = nil if lfile and !File.exists?(lfile)
|
||||
|
||||
return lfile
|
||||
xml_doc.root
|
||||
end
|
||||
|
||||
# Execute a command associated to an action and id in a remote host.
|
||||
|
@ -30,8 +30,6 @@ $: << RUBY_LIB_LOCATION
|
||||
|
||||
require "VirtualMachineDriver"
|
||||
require "CommandManager"
|
||||
require 'base64'
|
||||
require 'rexml/document'
|
||||
|
||||
class DummyDriver < VirtualMachineDriver
|
||||
def initialize
|
||||
@ -41,15 +39,8 @@ class DummyDriver < VirtualMachineDriver
|
||||
)
|
||||
end
|
||||
|
||||
def decode(drv_msg)
|
||||
message = Base64.decode64(drv_msg)
|
||||
xml_doc = REXML::Document.new(message)
|
||||
|
||||
xml_doc.root
|
||||
end
|
||||
|
||||
def deploy(id, drv_msg)
|
||||
msg = decode(drv_msg)
|
||||
def deploy(id, drv_message)
|
||||
msg = decode(drv_message)
|
||||
|
||||
host = msg.elements["HOST"].text
|
||||
name = msg.elements["VM/NAME"].text
|
||||
|
@ -89,9 +89,12 @@ class EC2Driver < VirtualMachineDriver
|
||||
end
|
||||
|
||||
# DEPLOY action, also sets ports and ip if needed
|
||||
def deploy(id, host, remote_dfile, not_used)
|
||||
def deploy(id, drv_message)
|
||||
msg = decode(drv_message)
|
||||
|
||||
local_dfile = get_local_deployment_file(remote_dfile)
|
||||
host = msg.elements["HOST"].text
|
||||
|
||||
local_dfile = msg.elements["LOCAL_DEPLOYMENT_FILE"].text
|
||||
|
||||
if !local_dfile
|
||||
send_message(ACTION[:deploy],RESULT[:failure],id,
|
||||
@ -175,17 +178,31 @@ class EC2Driver < VirtualMachineDriver
|
||||
end
|
||||
|
||||
# Shutdown a EC2 instance
|
||||
def shutdown(id, host, deploy_id, not_used)
|
||||
def shutdown(id, drv_message)
|
||||
msg = decode(drv_message)
|
||||
|
||||
host = msg.elements["HOST"].text
|
||||
deploy_id = msg.elements["DEPLOY_ID"].text
|
||||
|
||||
ec2_terminate(ACTION[:shutdown], id, deploy_id)
|
||||
end
|
||||
|
||||
# Cancel a EC2 instance
|
||||
def cancel(id, host, deploy_id, not_used)
|
||||
def cancel(id, drv_message)
|
||||
msg = decode(drv_message)
|
||||
|
||||
host = msg.elements["HOST"].text
|
||||
deploy_id = msg.elements["DEPLOY_ID"].text
|
||||
|
||||
ec2_terminate(ACTION[:cancel], id, deploy_id)
|
||||
end
|
||||
|
||||
# Get info (IP, and state) for a EC2 instance
|
||||
def poll(id, host, deploy_id, not_used)
|
||||
def poll(id, drv_message)
|
||||
msg = decode(drv_message)
|
||||
|
||||
host = msg.elements["HOST"].text
|
||||
deploy_id = msg.elements["DEPLOY_ID"].text
|
||||
|
||||
info = "#{POLL_ATTRIBUTE[:usedmemory]}=0 " \
|
||||
"#{POLL_ATTRIBUTE[:usedcpu]}=0 " \
|
||||
|
Loading…
x
Reference in New Issue
Block a user