diff --git a/src/cli/one_helper/onehost_helper.rb b/src/cli/one_helper/onehost_helper.rb index 899f914923..f557bdb05b 100644 --- a/src/cli/one_helper/onehost_helper.rb +++ b/src/cli/one_helper/onehost_helper.rb @@ -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 = + # + # EC2_ACCESS = + # EC2_SECRET = + # + # CAPACITY = [ + # M1SMALL = , + # M1XLARGE = , + # M1LARGE = + # ] + # + # 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) diff --git a/src/cli/onehost b/src/cli/onehost index f1eafef508..447542d44f 100755 --- a/src/cli/onehost +++ b/src/cli/onehost @@ -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 diff --git a/src/vmm_mad/remotes/ec2/cancel b/src/vmm_mad/remotes/ec2/cancel index 641eb403b6..1a5b386cd7 100755 --- a/src/vmm_mad/remotes/ec2/cancel +++ b/src/vmm_mad/remotes/ec2/cancel @@ -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) diff --git a/src/vmm_mad/remotes/ec2/deploy b/src/vmm_mad/remotes/ec2/deploy index be464d3861..7f4e9ecce6 100755 --- a/src/vmm_mad/remotes/ec2/deploy +++ b/src/vmm_mad/remotes/ec2/deploy @@ -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 diff --git a/src/vmm_mad/remotes/ec2/ec2_driver.rb b/src/vmm_mad/remotes/ec2/ec2_driver.rb index 6b55ba3cf7..49139a4eff 100755 --- a/src/vmm_mad/remotes/ec2/ec2_driver.rb +++ b/src/vmm_mad/remotes/ec2/ec2_driver.rb @@ -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" diff --git a/src/vmm_mad/remotes/ec2/poll b/src/vmm_mad/remotes/ec2/poll index b673c4c099..77eeef0727 100755 --- a/src/vmm_mad/remotes/ec2/poll +++ b/src/vmm_mad/remotes/ec2/poll @@ -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) diff --git a/src/vmm_mad/remotes/ec2/reboot b/src/vmm_mad/remotes/ec2/reboot index ac18c490b4..6185f0a692 100755 --- a/src/vmm_mad/remotes/ec2/reboot +++ b/src/vmm_mad/remotes/ec2/reboot @@ -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) diff --git a/src/vmm_mad/remotes/ec2/restore b/src/vmm_mad/remotes/ec2/restore index 9938c44842..a55a3c58de 100755 --- a/src/vmm_mad/remotes/ec2/restore +++ b/src/vmm_mad/remotes/ec2/restore @@ -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) diff --git a/src/vmm_mad/remotes/ec2/save b/src/vmm_mad/remotes/ec2/save index 9041586a03..322b4ce4cb 100755 --- a/src/vmm_mad/remotes/ec2/save +++ b/src/vmm_mad/remotes/ec2/save @@ -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) diff --git a/src/vmm_mad/remotes/ec2/shutdown b/src/vmm_mad/remotes/ec2/shutdown index 4de0f65fd3..6b8cd90d55 100755 --- a/src/vmm_mad/remotes/ec2/shutdown +++ b/src/vmm_mad/remotes/ec2/shutdown @@ -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)