diff --git a/src/oca/ec2/econe-register b/src/oca/ec2/econe-register new file mode 100755 index 0000000000..631056397a --- /dev/null +++ b/src/oca/ec2/econe-register @@ -0,0 +1,131 @@ +#!/usr/bin/env ruby + +# == Synopsis +# econe-register +# +# Register a previously uploaded image for use with an +# OpenNebula Cloud. +# +# == Usage +# +# econe-register [OPTIONS] IMAGE-ID +# +# -h, --help: +# show help +# +# --access-key , -K : +# The username of the user +# +# --secret-key , -K : +# The password of the user +# +# --url , -U : +# Set url as the web service url to use +# +# --headers, -H: +# Display column headers +# +# IMAGE-ID: The image identification as returned by +# the econe-upload command + + + +# -------------------------------------------------------------------------- # +# Copyright 2002-2009, Distributed Systems Architecture Group, Universidad # +# Complutense de Madrid (dsa-research.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +ONE_LOCATION=ENV["ONE_LOCATION"] + +if !ONE_LOCATION + RUBY_LIB_LOCATION="/usr/lib/one/ruby" +else + RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" +end + + +$: << RUBY_LIB_LOCATION + +require 'EC2QueryClient' +require 'getoptlong' +require 'rdoc/usage' +require 'pp' + + +opts = GetoptLong.new( + ['--help', '-h',GetoptLong::NO_ARGUMENT], + ['--access-key', '-K',GetoptLong::REQUIRED_ARGUMENT], + ['--secret-key', '-S',GetoptLong::REQUIRED_ARGUMENT], + ['--url', '-U',GetoptLong::REQUIRED_ARGUMENT], + ['--headers', '-H',GetoptLong::NO_ARGUMENT] + ) + +headers = false +url = nil +access = nil +secret = nil +auth = nil + +begin + opts.each do |opt, arg| + case opt + when '--help' + RDoc::usage + when '--access-key' + access = arg + when '--secret-key' + secret = arg + when '--url' + url = arg + when '--headers' + headers = true + end + end +rescue Exception => e + exit -1 +end + +image_id = ARGV.shift + +if !image_id + puts "#{$0}: missing IMAGE-ID parameter" + exit -1 +end + +auth = "#{access}:#{secret}" if secret && access + +begin +ec2_client = EC2QueryClient::Client.new(auth,url) +rescue Exception => e + puts "#{$0}: #{e.message}" + exit -1 +end + +rc = ec2_client.register_image(image_id) + +if OpenNebula::is_error?(rc) + puts "#{$0}: #{rc.message}" + exit -1 +end + +puts "Success: Image_id #{rc['imageId']}" + +exit 0 + + + + + + diff --git a/src/oca/ec2/lib/EC2QueryClient.rb b/src/oca/ec2/lib/EC2QueryClient.rb index 3fb07eda49..894d59ba0f 100644 --- a/src/oca/ec2/lib/EC2QueryClient.rb +++ b/src/oca/ec2/lib/EC2QueryClient.rb @@ -1,18 +1,5 @@ #!/usr/bin/ruby -require 'pp' - - -ONE_LOCATION=ENV["ONE_LOCATION"] - -if !ONE_LOCATION - RUBY_LIB_LOCATION="/usr/lib/one/ruby" -else - RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" -end - -$: << RUBY_LIB_LOCATION - @@ec2url = nil if ENV["EC2_URL"] @@ -72,11 +59,6 @@ module EC2QueryClient elsif !@uri.host raise "Wrong URI format, host not found" end - - pp @access_key_id - pp @access_key_secret - pp @uri.port - pp @uri.host @ec2_connection = EC2::Base.new( :access_key_id => @access_key_id,