1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

F #5136 Changes the way of create amazon ec2 hosts, ONECLI (#371)

* F #5136 (ONECLI)Type option added, displaying help to create hybrid hosts

* F #5136 added cli argument to parse file path in -t option, change comments

* F #5136 catch blocks, cod restructure
This commit is contained in:
Sergio Semedi Barranco 2017-07-06 16:17:46 +02:00 committed by Javi Fontan
parent 1f571426ab
commit 8cd7d0df6b
10 changed files with 73 additions and 54 deletions

View File

@ -20,6 +20,32 @@ require 'rubygems'
class OneHostHelper < OpenNebulaHelper::OneHelper
TEMPLATE_XPATH = '//HOST/TEMPLATE'
HYBRID = {
:ec2 => {
:help => <<-EOT.unindent,
#-----------------------------------------------------------------------
# Supported EC2 AUTH ATTRIBUTTES:
#
# REGION_NAME = <the name of the ec2 region>
#
# EC2_ACCESS = <Your ec2 access key id>
# EC2_SECRET = <Your ec2 secret key>
#
# CAPACITY = [
# M1SMALL = <number of machines m1.small>,
# M1XLARGE = <number of machines m1.xlarge>,
# M1LARGE = <number of machines m1.large>
# ]
#
# You can set any machine type supported by ec2
# See your ec2_driver.conf for more information
#
#-----------------------------------------------------------------------
EOT
}
}
VERSION_XPATH = "#{TEMPLATE_XPATH}/VERSION"
def self.rname
@ -164,6 +190,12 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
table
end
def set_hybrid(type, path)
k = type.to_sym
if HYBRID.key?(k)
str = path.nil? ? OpenNebulaHelper.editor_input(HYBRID[k][:help]): File.read(path)
end
end
NUM_THREADS = 15
def sync(host_ids, options)

View File

@ -79,21 +79,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do
" rsync command must be installed in the frontend and nodes."
}
EC2_ACCESS = {
:name => "ec2access",
:large => "--ec2access id",
:description => "Set the id access for EC2 Driver",
TYPE = {
:name => "type",
:short => "-t remote_provider",
:large => "--type remote_provider",
:description => "Use type to create a host using Cloud Bursting ",
:format => String
}
EC2_SECRET = {
:name => "ec2secret",
:large => "--ec2secret key",
:description => "Set the secret key for EC2 Driver",
:format => String
}
CREAT_OPTIONS = [ IM, VMM, OneClusterHelper::CLUSTER, EC2_ACCESS, EC2_SECRET ]
CREAT_OPTIONS = [ IM, VMM, OneClusterHelper::CLUSTER, TYPE ]
SYNC_OPTIONS = [ OneClusterHelper::CLUSTER, FORCE, RSYNC ]
########################################################################
@ -116,7 +110,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
Creates a new Host
EOT
command :create, create_desc, :hostname, :options=>CREAT_OPTIONS do
command :create, create_desc, :hostname, [:file, nil], :options=>CREAT_OPTIONS do
if options[:im].nil? || options[:vm].nil?
STDERR.puts "Drivers are mandatory to create a host:"
STDERR.puts "\t -i information driver"
@ -124,20 +118,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do
exit -1
end
ec2_host = !options[:ec2access].nil? && !options[:ec2secret].nil?
cid = options[:cluster] || ClusterPool::NONE_CLUSTER_ID
helper.create_resource(options) do |host|
rc = host.allocate(args[0], options[:im], options[:vm], cid)
if !options[:type].nil?
str = helper.set_hybrid(options[:type], args[1])
end
rc = host.allocate(args[0], options[:im], options[:vm], cid)
host.update(str, true) if !OpenNebula.is_error?(rc) && !options[:type].nil?
if ec2_host && !OpenNebula.is_error?(rc)
template = "EC2_ACCESS=\"#{options[:ec2access]}\"\n"\
"EC2_SECRET=\"#{options[:ec2secret]}\"\n"\
rc = host.update(template, true)
end
rc
rc
end
end

View File

@ -32,10 +32,10 @@ require 'ec2_driver'
deploy_id = ARGV[0]
host = ARGV[1]
ec2_drv = EC2Driver.new(host)
begin
ec2_drv = EC2Driver.new(host)
ec2_drv.cancel(deploy_id)
rescue Exception => e
handle_exception("Cancel", e, host, deploy_id)

View File

@ -34,20 +34,19 @@ dfile = ARGV[0]
host = ARGV[1]
id = ARGV[2]
vm = OpenNebula::VirtualMachine.new_with_id(id, OpenNebula::Client.new)
vm.info
lcm_state = vm.lcm_state_str
deploy_id = vm.deploy_id
ec2_drv = EC2Driver.new(host)
text=File.read(dfile)
begin
vm = OpenNebula::VirtualMachine.new_with_id(id, OpenNebula::Client.new)
vm.info
lcm_state = vm.lcm_state_str
deploy_id = vm.deploy_id
ec2_drv = EC2Driver.new(host)
text=File.read(dfile)
puts ec2_drv.deploy(id, host, text, lcm_state, deploy_id)
rescue Exception => e
handle_exception("Deploy", e, host, deploy_id, id, dfile)
end

View File

@ -273,7 +273,6 @@ class EC2Driver
# to retrieve connection information
# needed for Amazon
def get_connect_info(host)
conn_opts={}
client = OpenNebula::Client.new
@ -284,16 +283,15 @@ class EC2Driver
system = OpenNebula::System.new(client)
config = system.get_configuration
if OpenNebula.is_error?(config)
puts "Error getting oned configuration : #{config.message}"
exit -1
end
raise "Error getting oned configuration : #{config.message}" if OpenNebula.is_error?(config)
token = config["ONE_KEY"]
conn_opts = {
:access => xmlhost["TEMPLATE/EC2_ACCESS"],
:secret => xmlhost["TEMPLATE/EC2_SECRET"]
}
begin
conn_opts = OpenNebula.decrypt(conn_opts, token)
conn_opts[:region] = xmlhost["TEMPLATE/REGION_NAME"]
@ -479,6 +477,8 @@ class EC2Driver
totalmemory += mem * value.to_i
totalcpu += cpu * value.to_i
}
else
raise "you must define CAPACITY section properly! check the template"
end
host_info = "HYPERVISOR=ec2\n"

View File

@ -33,9 +33,9 @@ deploy_id = ARGV[0]
host = ARGV[1]
id = ARGV[2]
ec2_drv = EC2Driver.new(host)
begin
begin
ec2_drv = EC2Driver.new(host)
ec2_drv.poll(id, deploy_id)
rescue Excetion => e
handle_exception("Poll", e, host, deploy_id, id)

View File

@ -32,10 +32,9 @@ require 'ec2_driver'
deploy_id = ARGV[0]
host = ARGV[1]
ec2_drv = EC2Driver.new(host)
begin
ec2_drv = EC2Driver.new(host)
ec2_drv.reboot(deploy_id)
rescue Exception => e
handle_exception("Reboot", e, host, deploy_id)

View File

@ -33,9 +33,9 @@ checkpoint_file = ARGV[0]
host = ARGV[1]
deploy_id = ARGV[2]
ec2_drv = EC2Driver.new(host)
begin
ec2_drv = EC2Driver.new(host)
ec2_drv.restore(deploy_id)
rescue Exception => e
handle_exception("Restore", e, host, deploy_id)

View File

@ -33,9 +33,9 @@ deploy_id = ARGV[0]
file = ARGV[1]
host = ARGV[2]
ec2_drv = EC2Driver.new(host)
begin
ec2_drv = EC2Driver.new(host)
ec2_drv.save(deploy_id)
rescue Exception => e
handle_exception("Save", e, host, deploy_id, nil, file)

View File

@ -34,14 +34,14 @@ deploy_id = ARGV[0]
host = ARGV[1]
vm_id = ARGV[2]
vm = OpenNebula::VirtualMachine.new_with_id(vm_id, OpenNebula::Client.new)
vm.info
lcm_state = vm.lcm_state_str
ec2_drv = EC2Driver.new(host)
begin
vm = OpenNebula::VirtualMachine.new_with_id(vm_id, OpenNebula::Client.new)
vm.info
lcm_state = vm.lcm_state_str
ec2_drv = EC2Driver.new(host)
ec2_drv.shutdown(deploy_id, lcm_state)
rescue Exception => e
handle_exception("Save", e, host, deploy_id, vm_id)