1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-05 21:57:24 +03:00

feature #595: cleanup comments and code

This commit is contained in:
Javi Fontan 2011-06-13 16:16:48 +02:00
parent c57a0959d1
commit 62bb25a2e0

View File

@ -15,9 +15,7 @@
# limitations under the License. # # limitations under the License. #
# ---------------------------------------------------------------------------- # # ---------------------------------------------------------------------------- #
# ---------------------------------------------------------------------------- # # Set up the environment for the driver
# Set up the environment for the driver #
# ---------------------------------------------------------------------------- #
EC2_LOCATION = ENV["EC2_HOME"] EC2_LOCATION = ENV["EC2_HOME"]
@ -45,15 +43,10 @@ require "VirtualMachineDriver"
require "CommandManager" require "CommandManager"
require "rexml/document" require "rexml/document"
# ---------------------------------------------------------------------------- # # The main class for the EC2 driver
# The main class for the EC2 driver #
# ---------------------------------------------------------------------------- #
class EC2Driver < VirtualMachineDriver class EC2Driver < VirtualMachineDriver
# ------------------------------------------------------------------------ # # EC2 commands constants
# EC2 commands constants #
# ------------------------------------------------------------------------ #
EC2 = { EC2 = {
:run => "#{EC2_LOCATION}/bin/ec2-run-instances", :run => "#{EC2_LOCATION}/bin/ec2-run-instances",
:terminate => "#{EC2_LOCATION}/bin/ec2-terminate-instances", :terminate => "#{EC2_LOCATION}/bin/ec2-terminate-instances",
@ -62,11 +55,9 @@ class EC2Driver < VirtualMachineDriver
:authorize => "#{EC2_LOCATION}bin/ec2-authorize" :authorize => "#{EC2_LOCATION}bin/ec2-authorize"
} }
# ------------------------------------------------------------------------ # # EC2 constructor, loads defaults for the EC2Driver
# EC2 constructor, loads defaults for the EC2Driver #
# ------------------------------------------------------------------------ #
def initialize(ec2_conf = nil) def initialize(ec2_conf = nil)
if !EC2_JVM_CONCURRENCY if !EC2_JVM_CONCURRENCY
concurrency = 5 concurrency = 5
else else
@ -90,16 +81,14 @@ class EC2Driver < VirtualMachineDriver
ec2 = xml.root.elements["EC2"] ec2 = xml.root.elements["EC2"]
return if !ec2 return if !ec2
@defaults["KEYPAIR"] = ec2_value(ec2,"KEYPAIR") @defaults["KEYPAIR"] = ec2_value(ec2,"KEYPAIR")
@defaults["AUTHORIZEDPORTS"] = ec2_value(ec2,"AUTHORIZEDPORTS") @defaults["AUTHORIZEDPORTS"] = ec2_value(ec2,"AUTHORIZEDPORTS")
@defaults["INSTANCETYPE"] = ec2_value(ec2,"INSTANCETYPE") @defaults["INSTANCETYPE"] = ec2_value(ec2,"INSTANCETYPE")
end end
end end
# ------------------------------------------------------------------------ # # DEPLOY action, also sets ports and ip if needed
# DEPLOY action, also sets ports and ip if needed #
# ------------------------------------------------------------------------ #
def deploy(id, host, remote_dfile, not_used) def deploy(id, host, remote_dfile, not_used)
local_dfile = get_local_deployment_file(remote_dfile) local_dfile = get_local_deployment_file(remote_dfile)
@ -113,12 +102,12 @@ class EC2Driver < VirtualMachineDriver
tmp = File.new(local_dfile) tmp = File.new(local_dfile)
xml = REXML::Document.new tmp xml = REXML::Document.new tmp
tmp.close() tmp.close()
ec2 = nil ec2 = nil
all_ec2_elements = xml.root.get_elements("EC2") all_ec2_elements = xml.root.get_elements("EC2")
# First, let's see if we have an EC2 site that matches # First, let's see if we have an EC2 site that matches
# our desired host name # our desired host name
all_ec2_elements.each { |element| all_ec2_elements.each { |element|
cloud=element.elements["CLOUD"] cloud=element.elements["CLOUD"]
@ -128,14 +117,15 @@ class EC2Driver < VirtualMachineDriver
} }
if !ec2 if !ec2
# If we don't find the EC2 site, and ONE just # If we don't find the EC2 site, and ONE just
# knows about one EC2 site, let's use that # knows about one EC2 site, let's use that
if all_ec2_elements.size == 1 if all_ec2_elements.size == 1
ec2 = all_ec2_elements[0] ec2 = all_ec2_elements[0]
else else
send_message(ACTION[:deploy],RESULT[:failure],id, send_message(ACTION[:deploy],RESULT[:failure],id,
"Can not find EC2 element in deployment file #{local_dfile}" + "Can not find EC2 element in deployment file "<<
" or couldn't find any EC2 site matching one of the template.") "#{local_dfile} or couldn't find any EC2 site matching "<<
"one of the template.")
return return
end end
end end
@ -184,23 +174,17 @@ class EC2Driver < VirtualMachineDriver
send_message(ACTION[:deploy],RESULT[:success],id,deploy_id) send_message(ACTION[:deploy],RESULT[:success],id,deploy_id)
end end
# ------------------------------------------------------------------------ # # Shutdown a EC2 instance
# Shutdown a EC2 instance #
# ------------------------------------------------------------------------ #
def shutdown(id, host, deploy_id, not_used) def shutdown(id, host, deploy_id, not_used)
ec2_terminate(ACTION[:shutdown], id, deploy_id) ec2_terminate(ACTION[:shutdown], id, deploy_id)
end end
# ------------------------------------------------------------------------ # # Cancel a EC2 instance
# Cancel a EC2 instance #
# ------------------------------------------------------------------------ #
def cancel(id, host, deploy_id, not_used) def cancel(id, host, deploy_id, not_used)
ec2_terminate(ACTION[:cancel], id, deploy_id) ec2_terminate(ACTION[:cancel], id, deploy_id)
end end
# ------------------------------------------------------------------------ # # Get info (IP, and state) for a EC2 instance
# Get info (IP, and state) for a EC2 instance #
# ------------------------------------------------------------------------ #
def poll(id, host, deploy_id, not_used) def poll(id, host, deploy_id, not_used)
info = "#{POLL_ATTRIBUTE[:usedmemory]}=0 " \ info = "#{POLL_ATTRIBUTE[:usedmemory]}=0 " \
@ -227,8 +211,8 @@ class EC2Driver < VirtualMachineDriver
when "pending" when "pending"
info << " #{POLL_ATTRIBUTE[:state]}=#{VM_STATE[:active]}" info << " #{POLL_ATTRIBUTE[:state]}=#{VM_STATE[:active]}"
when "running" when "running"
info << " #{POLL_ATTRIBUTE[:state]}=#{VM_STATE[:active]}" \ info<<" #{POLL_ATTRIBUTE[:state]}=#{VM_STATE[:active]}"<<
" IP=#{monitor_data[1]}" " IP=#{monitor_data[1]}"
when "shutting-down","terminated" when "shutting-down","terminated"
info << " #{POLL_ATTRIBUTE[:state]}=#{VM_STATE[:deleted]}" info << " #{POLL_ATTRIBUTE[:state]}=#{VM_STATE[:deleted]}"
end end
@ -265,9 +249,7 @@ private
end end
end end
# ---------------------------------------------------------------------------- #
# EC2Driver Main program # EC2Driver Main program
# ---------------------------------------------------------------------------- #
ec2_conf = ARGV.last ec2_conf = ARGV.last