mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-26 06:50:09 +03:00
Unified client API for cloud
* Added CLI helper to get the command name * Bug in XML generation (OCCI) * Bug in image retrieval (OCCI) * Changed OCCIClient authorization to use the common function and hold it in an array * Added check for malformed authorization data * Added error message when the server is not reachable * Added CloudClient and changed installation script git-svn-id: http://svn.opennebula.org/one/trunk@875 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
parent
ebbb432395
commit
2a126a6d6f
@ -453,6 +453,7 @@ HOOK_SHARE_FILES="share/hooks/ebtables-xen"
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
COMMON_CLOUD_LIB_FILES="src/cloud/common/CloudServer.rb \
|
||||
src/cloud/common/CloudClient.rb \
|
||||
src/cloud/common/Configuration.rb \
|
||||
src/cloud/rm/image.rb \
|
||||
src/cloud/rm/repo_manager.rb"
|
||||
|
84
src/cloud/common/CloudClient.rb
Normal file
84
src/cloud/common/CloudClient.rb
Normal file
@ -0,0 +1,84 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'rubygems'
|
||||
require 'uri'
|
||||
require 'OpenNebula'
|
||||
|
||||
require 'net/https'
|
||||
|
||||
begin
|
||||
require 'curb'
|
||||
CURL_LOADED=true
|
||||
rescue LoadError
|
||||
CURL_LOADED=false
|
||||
end
|
||||
|
||||
begin
|
||||
require 'net/http/post/multipart'
|
||||
rescue LoadError
|
||||
end
|
||||
|
||||
class CloudClient
|
||||
# Gets authorization credentials from ONE_AUTH or default
|
||||
# auth file.
|
||||
#
|
||||
# Raises an error if authorization is not found
|
||||
def get_one_auth
|
||||
if ENV["ONE_AUTH"] and !ENV["ONE_AUTH"].empty? and
|
||||
File.file?(ENV["ONE_AUTH"])
|
||||
one_auth=File.read(ENV["ONE_AUTH"]).strip.split(':')
|
||||
elsif File.file?(ENV["HOME"]+"/.one/one_auth")
|
||||
one_auth=File.read(ENV["HOME"]+"/.one/one_auth").strip.split(':')
|
||||
else
|
||||
raise "No authorization data present"
|
||||
end
|
||||
|
||||
raise "Authorization data malformed" if one_auth.length < 2
|
||||
|
||||
one_auth
|
||||
end
|
||||
|
||||
# Starts an http connection and calls the block provided. SSL flag
|
||||
# is set if needed.
|
||||
def http_start(url, &block)
|
||||
http = Net::HTTP.new(url.host, url.port)
|
||||
if url.scheme=='https'
|
||||
http.use_ssl = true
|
||||
http.verify_mode=OpenSSL::SSL::VERIFY_NONE
|
||||
end
|
||||
|
||||
begin
|
||||
http.start do |connection|
|
||||
block.call(connection)
|
||||
end
|
||||
rescue Errno::ECONNREFUSED => e
|
||||
puts "Error connecting to server (" + e.to_s + ")."
|
||||
puts "Server: #{url.host}:#{url.port}"
|
||||
exit -1
|
||||
end
|
||||
end
|
||||
|
||||
# Command line help functions
|
||||
module CLIHelpers
|
||||
# Returns the command name
|
||||
def cmd_name
|
||||
File.basename($0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
10
src/cloud/common/CloudServer.rb
Normal file → Executable file
10
src/cloud/common/CloudServer.rb
Normal file → Executable file
@ -135,6 +135,7 @@ class CloudServer
|
||||
# uid:: _Integer_ owner of the image
|
||||
# path:: _String_ path of the tmp file
|
||||
# metadata:: Additional metadata for the file
|
||||
# [return] _Image_ Newly created image object
|
||||
def add_image(uid, file, metadata={})
|
||||
image = @rm.add(uid,file.path,metadata)
|
||||
file.unlink
|
||||
@ -143,11 +144,10 @@ class CloudServer
|
||||
end
|
||||
|
||||
# Gets an image from the repository
|
||||
# uid:: _Integer_ owner of the image
|
||||
# path:: _String_ path of the tmp file
|
||||
# metadata:: Additional metadata for the file
|
||||
def get_image(uuid)
|
||||
return @rm.get(uuid)
|
||||
# image_id:: _Integer_ Image identifier
|
||||
# [return] _Image_ Image object
|
||||
def get_image(image_id)
|
||||
return @rm.get(image_id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -52,13 +52,14 @@ end
|
||||
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud/econe"
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
require 'EC2QueryClient'
|
||||
require 'econe/EC2QueryClient'
|
||||
require 'getoptlong'
|
||||
require 'rdoc/usage'
|
||||
require 'pp'
|
||||
|
||||
include CloudClient::CLIHelpers
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
@ -98,14 +99,14 @@ auth = "#{access}:#{secret}" if secret && access
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(auth,url)
|
||||
rescue Exception => e
|
||||
puts "#{$0}: #{e.message}"
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = ec2_client.describe_images()
|
||||
|
||||
if OpenNebula::is_error?(rc)
|
||||
puts "#{$0}: #{rc.message}"
|
||||
puts "#{cmd_name}: #{rc.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
|
@ -51,13 +51,14 @@ else
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud/econe"
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
require 'EC2QueryClient'
|
||||
require 'econe/EC2QueryClient'
|
||||
require 'getoptlong'
|
||||
require 'rdoc/usage'
|
||||
require 'pp'
|
||||
|
||||
include CloudClient::CLIHelpers
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
@ -97,14 +98,14 @@ auth = "#{access}:#{secret}" if secret && access
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(auth,url)
|
||||
rescue Exception => e
|
||||
puts "#{$0}: #{e.message}"
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = ec2_client.describe_instances()
|
||||
|
||||
if OpenNebula::is_error?(rc)
|
||||
puts "#{$0}: #{rc.message}"
|
||||
puts "#{cmd_name}: #{rc.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
|
@ -56,13 +56,14 @@ else
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud/econe"
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
require 'EC2QueryClient'
|
||||
require 'econe/EC2QueryClient'
|
||||
require 'getoptlong'
|
||||
require 'rdoc/usage'
|
||||
require 'pp'
|
||||
|
||||
include CloudClient::CLIHelpers
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
@ -100,7 +101,7 @@ end
|
||||
image_id = ARGV.shift
|
||||
|
||||
if !image_id
|
||||
puts "#{$0}: missing ImageId parameter"
|
||||
puts "#{cmd_name}: missing ImageId parameter"
|
||||
exit -1
|
||||
end
|
||||
|
||||
@ -109,14 +110,14 @@ auth = "#{access}:#{secret}" if secret && access
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(auth,url)
|
||||
rescue Exception => e
|
||||
puts "#{$0}: #{e.message}"
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = ec2_client.register_image(image_id)
|
||||
|
||||
if OpenNebula::is_error?(rc)
|
||||
puts "#{$0}: #{rc.message}"
|
||||
puts "#{cmd_name}: #{rc.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
|
@ -54,13 +54,14 @@ end
|
||||
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud/econe"
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
require 'EC2QueryClient'
|
||||
require 'econe/EC2QueryClient'
|
||||
require 'getoptlong'
|
||||
require 'rdoc/usage'
|
||||
require 'pp'
|
||||
|
||||
include CloudClient::CLIHelpers
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
@ -102,7 +103,7 @@ end
|
||||
image_id = ARGV.shift
|
||||
|
||||
if !image_id
|
||||
puts "#{$0}: missing IMAGE-ID parameter"
|
||||
puts "#{cmd_name}: missing IMAGE-ID parameter"
|
||||
exit -1
|
||||
end
|
||||
|
||||
@ -115,14 +116,14 @@ auth = "#{access}:#{secret}" if secret && access
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(auth,url)
|
||||
rescue Exception => e
|
||||
puts "#{$0}: #{e.message}"
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = ec2_client.run_instances(image_id,type)
|
||||
|
||||
if OpenNebula::is_error?(rc)
|
||||
puts "#{$0}: #{rc.message}"
|
||||
puts "#{cmd_name}: #{rc.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
|
@ -53,13 +53,14 @@ end
|
||||
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud/econe"
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
require 'EC2QueryClient'
|
||||
require 'econe/EC2QueryClient'
|
||||
require 'getoptlong'
|
||||
require 'rdoc/usage'
|
||||
require 'pp'
|
||||
|
||||
include CloudClient::CLIHelpers
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
@ -95,7 +96,7 @@ end
|
||||
instance = ARGV.shift
|
||||
|
||||
if !instance
|
||||
puts "#{$0}: missing INSTANCE-ID parameter"
|
||||
puts "#{cmd_name}: missing INSTANCE-ID parameter"
|
||||
exit -1
|
||||
end
|
||||
|
||||
@ -104,14 +105,14 @@ auth = "#{access}:#{secret}" if secret && access
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(auth,url)
|
||||
rescue Exception => e
|
||||
puts "#{$0}: #{e.message}"
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = ec2_client.terminate_instances(instance)
|
||||
|
||||
if OpenNebula::is_error?(rc)
|
||||
puts "#{$0}: #{rc.message}"
|
||||
puts "#{cmd_name}: #{rc.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
|
@ -53,13 +53,14 @@ else
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud/econe"
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
require 'EC2QueryClient'
|
||||
require 'econe/EC2QueryClient'
|
||||
require 'getoptlong'
|
||||
require 'rdoc/usage'
|
||||
require 'pp'
|
||||
|
||||
include CloudClient::CLIHelpers
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
@ -97,7 +98,7 @@ end
|
||||
image = ARGV.shift
|
||||
|
||||
if !image || !File.exists?(image)
|
||||
puts "#{$0}: missing IMAGE-PATH parameter or file not found"
|
||||
puts "#{cmd_name}: missing IMAGE-PATH parameter or file not found"
|
||||
exit -1
|
||||
end
|
||||
|
||||
@ -106,14 +107,14 @@ auth = "#{access}:#{secret}" if secret && access
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(auth,url)
|
||||
rescue Exception => e
|
||||
puts "#{$0}: #{e.message}"
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = ec2_client.upload_image(image, curb)
|
||||
|
||||
if OpenNebula::is_error?(rc)
|
||||
puts "#{$0}: #{rc.message}"
|
||||
puts "#{cmd_name}: #{rc.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
|
@ -23,29 +23,15 @@ if ENV["EC2_URL"]
|
||||
ENV["EC2_URL"]=nil
|
||||
end
|
||||
|
||||
require 'rubygems'
|
||||
require 'CloudClient'
|
||||
require 'AWS'
|
||||
require 'uri'
|
||||
require 'OpenNebula'
|
||||
|
||||
begin
|
||||
require 'curb'
|
||||
CURL_LOADED=true
|
||||
rescue LoadError
|
||||
CURL_LOADED=false
|
||||
end
|
||||
|
||||
begin
|
||||
require 'net/http/post/multipart'
|
||||
rescue LoadError
|
||||
end
|
||||
|
||||
module EC2QueryClient
|
||||
###########################################################################
|
||||
#
|
||||
#
|
||||
###########################################################################
|
||||
class Client
|
||||
class Client < CloudClient
|
||||
|
||||
API_VERSION = '2008-12-01'
|
||||
|
||||
@ -55,26 +41,25 @@ module EC2QueryClient
|
||||
#######################################################################
|
||||
def initialize(secret=nil, endpoint=nil)
|
||||
# Autentication
|
||||
ec2auth=nil
|
||||
|
||||
if secret
|
||||
ec2auth = secret
|
||||
ec2auth = secret.split(':')
|
||||
elsif ENV["EC2_ACCESS_KEY"] and ENV["EC2_SECRET_KEY"]
|
||||
ec2auth = ENV["EC2_ACCESS_KEY"] + ":" + ENV["EC2_SECRET_KEY"]
|
||||
elsif ENV["ONE_AUTH"] and !ENV["ONE_AUTH"].empty? and File.file?(ENV["ONE_AUTH"])
|
||||
ec2auth=File.read(ENV["ONE_AUTH"]).strip
|
||||
elsif File.file?(ENV["HOME"]+"/.one/one_auth")
|
||||
ec2auth=File.read(ENV["HOME"]+"/.one/one_auth").strip
|
||||
ec2auth = [ENV["EC2_ACCESS_KEY"], ENV["EC2_SECRET_KEY"]]
|
||||
else
|
||||
ec2auth=get_one_auth
|
||||
end
|
||||
|
||||
if !ec2auth
|
||||
raise "No authorization data present"
|
||||
end
|
||||
|
||||
ec2auth=~/(.+?):(.+)/
|
||||
|
||||
@access_key_id = $1
|
||||
@access_key_secret = Digest::SHA1.hexdigest($2)
|
||||
@access_key_id = ec2auth[0]
|
||||
@access_key_secret = Digest::SHA1.hexdigest(ec2auth[1])
|
||||
|
||||
# Server location
|
||||
|
||||
|
||||
if !endpoint
|
||||
if $ec2url
|
||||
endpoint = $ec2url
|
||||
@ -84,12 +69,6 @@ module EC2QueryClient
|
||||
end
|
||||
|
||||
@uri = URI.parse(endpoint)
|
||||
|
||||
#if !@uri.scheme or @uri.scheme != "http"
|
||||
# raise "Only http protocol supported"
|
||||
#elsif !@uri.host
|
||||
# raise "Wrong URI format, host not found"
|
||||
#end
|
||||
|
||||
@ec2_connection = AWS::EC2::Base.new(
|
||||
:access_key_id => @access_key_id,
|
||||
@ -98,20 +77,7 @@ module EC2QueryClient
|
||||
:port => @uri.port,
|
||||
:use_ssl => @uri.scheme == 'https')
|
||||
end
|
||||
|
||||
# Starts an http connection and calls the block provided. SSL flag
|
||||
# is set if needed.
|
||||
def http_start(url, &block)
|
||||
http = Net::HTTP.new(url.host, url.port)
|
||||
if url.scheme=='https'
|
||||
http.use_ssl = true
|
||||
http.verify_mode=OpenSSL::SSL::VERIFY_NONE
|
||||
end
|
||||
|
||||
http.start do |connection|
|
||||
block.call(connection)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
|
@ -77,13 +77,15 @@ else
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud/occi"
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
require 'OCCIClient'
|
||||
require 'occi/OCCIClient'
|
||||
require 'getoptlong'
|
||||
require 'rdoc/usage'
|
||||
require 'pp'
|
||||
|
||||
include CloudClient::CLIHelpers
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--username', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
@ -120,13 +122,13 @@ end
|
||||
begin
|
||||
occi_client = OCCIClient::Client.new(url,username,password,debug)
|
||||
rescue Exception => e
|
||||
puts "#{$0}: #{e.message}"
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
if !ARGV[0]
|
||||
puts "#{$0}: [COMMAND] not present"
|
||||
puts "#{$0}: Execute #{$0} -h for help."
|
||||
puts "#{cmd_name}: [COMMAND] not present"
|
||||
puts "#{cmd_name}: Execute #{cmd_name} -h for help."
|
||||
exit -1
|
||||
end
|
||||
|
||||
@ -138,14 +140,14 @@ when 'create'
|
||||
vm_xml = ARGV[1]
|
||||
|
||||
if !vm_xml || !File.exists?(vm_xml)
|
||||
puts "#{$0} create: missing OCCI-XML parameter or file not found"
|
||||
puts "#{cmd_name} create: missing OCCI-XML parameter or file not found"
|
||||
exit -1
|
||||
end
|
||||
|
||||
begin
|
||||
occi_client = OCCIClient::Client.new(url,username,password,debug)
|
||||
rescue Exception => e
|
||||
puts "#{$0} create: #{e.message}"
|
||||
puts "#{cmd_name} create: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
@ -155,14 +157,14 @@ when 'show'
|
||||
vm_id = ARGV[1]
|
||||
|
||||
if !vm_id
|
||||
puts "#{$0} show: missing VM-ID parameter"
|
||||
puts "#{cmd_name} show: missing VM-ID parameter"
|
||||
exit -1
|
||||
end
|
||||
|
||||
begin
|
||||
occi_client = OCCIClient::Client.new(url,username,password,debug)
|
||||
rescue Exception => e
|
||||
puts "#{$0} show: #{e.message}"
|
||||
puts "#{cmd_name} show: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
@ -172,14 +174,14 @@ when 'update'
|
||||
vm_xml = ARGV[1]
|
||||
|
||||
if !vm_xml || !File.exists?(vm_xml)
|
||||
puts "#{$0} update: missing OCCI-XML parameter or file not found"
|
||||
puts "#{cmd_name} update: missing OCCI-XML parameter or file not found"
|
||||
exit -1
|
||||
end
|
||||
|
||||
begin
|
||||
occi_client = OCCIClient::Client.new(url,username,password,debug)
|
||||
rescue Exception => e
|
||||
puts "#{$0} update: #{e.message}"
|
||||
puts "#{cmd_name} update: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
@ -189,14 +191,14 @@ when 'delete'
|
||||
vm_id = ARGV[1]
|
||||
|
||||
if !vm_id
|
||||
puts "#{$0} delete: missing VM-ID parameter"
|
||||
puts "#{cmd_name} delete: missing VM-ID parameter"
|
||||
exit -1
|
||||
end
|
||||
|
||||
begin
|
||||
occi_client = OCCIClient::Client.new(url,username,password,debug)
|
||||
rescue Exception => e
|
||||
puts "#{$0} delete: #{e.message}"
|
||||
puts "#{cmd_name} delete: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
|
@ -76,13 +76,14 @@ else
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud/occi"
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
require 'OCCIClient'
|
||||
require 'occi/OCCIClient'
|
||||
require 'getoptlong'
|
||||
require 'rdoc/usage'
|
||||
require 'pp'
|
||||
|
||||
include CloudClient::CLIHelpers
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
@ -121,13 +122,13 @@ end
|
||||
begin
|
||||
occi_client = OCCIClient::Client.new(url,username,password,debug)
|
||||
rescue Exception => e
|
||||
puts "#{$0}: #{e.message}"
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
if !ARGV[0]
|
||||
puts "#{$0}: [COMMAND] not present"
|
||||
puts "#{$0}: Execute #{$0} -h for help."
|
||||
puts "#{cmd_name}: [COMMAND] not present"
|
||||
puts "#{cmd_name}: Execute #{cmd_name} -h for help."
|
||||
exit -1
|
||||
end
|
||||
|
||||
@ -137,7 +138,7 @@ when 'create'
|
||||
network_xml = ARGV[1]
|
||||
|
||||
if !network_xml || !File.exists?(network_xml)
|
||||
puts "#{$0} create: missing OCCI-XML parameter or file not found"
|
||||
puts "#{cmd_name} create: missing OCCI-XML parameter or file not found"
|
||||
exit -1
|
||||
end
|
||||
|
||||
@ -150,7 +151,7 @@ when 'show'
|
||||
network_id = ARGV[1]
|
||||
|
||||
if !network_id
|
||||
puts "#{$0} show: missing NETWORK-ID parameter or file not found"
|
||||
puts "#{cmd_name} show: missing NETWORK-ID parameter or file not found"
|
||||
exit -1
|
||||
end
|
||||
|
||||
@ -160,7 +161,7 @@ when 'delete'
|
||||
network_id = ARGV[1]
|
||||
|
||||
if !network_id
|
||||
puts "#{$0} delete: missing NETWORK-ID parameter"
|
||||
puts "#{cmd_name} delete: missing NETWORK-ID parameter"
|
||||
exit -1
|
||||
end
|
||||
|
||||
|
@ -74,13 +74,14 @@ else
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud/occi"
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
require 'OCCIClient'
|
||||
require 'occi/OCCIClient'
|
||||
require 'getoptlong'
|
||||
require 'rdoc/usage'
|
||||
require 'pp'
|
||||
|
||||
include CloudClient::CLIHelpers
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
@ -120,8 +121,8 @@ rescue Exception => e
|
||||
end
|
||||
|
||||
if !ARGV[0]
|
||||
puts "#{$0}: [COMMAND] not present"
|
||||
puts "#{$0}: Execute #{$0} -h for help."
|
||||
puts "#{cmd_name}: [COMMAND] not present"
|
||||
puts "#{cmd_name}: Execute #{cmd_name} -h for help."
|
||||
exit -1
|
||||
end
|
||||
|
||||
@ -129,7 +130,7 @@ end
|
||||
begin
|
||||
occi_client = OCCIClient::Client.new(url,username,password,debug)
|
||||
rescue Exception => e
|
||||
puts "#{$0}: #{e.message}"
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
@ -138,7 +139,7 @@ when 'create'
|
||||
image_xml = ARGV[1]
|
||||
|
||||
if !image_xml || !File.exists?(image_xml)
|
||||
puts "#{$0} create: missing occi xml parameter or file not found"
|
||||
puts "#{cmd_name} create: missing occi xml parameter or file not found"
|
||||
exit -1
|
||||
end
|
||||
|
||||
@ -151,7 +152,7 @@ when 'show'
|
||||
image_id = ARGV[1]
|
||||
|
||||
if !image_id
|
||||
puts "#{$0} show: missing storage id parameter or file not found"
|
||||
puts "#{cmd_name} show: missing storage id parameter or file not found"
|
||||
exit -1
|
||||
end
|
||||
|
||||
|
2
src/cloud/occi/lib/ImagePoolOCCI.rb
Normal file → Executable file
2
src/cloud/occi/lib/ImagePoolOCCI.rb
Normal file → Executable file
@ -24,7 +24,7 @@ class ImagePoolOCCI
|
||||
OCCI_IMAGE_POOL = %q{
|
||||
<STORAGE><%
|
||||
for image in @images do %>
|
||||
<DISK href="<%= base_url%>/storage/<%= image[:id] %>"\><%
|
||||
<DISK href="<%= base_url%>/storage/<%= image[:id] %>"/><%
|
||||
end %>
|
||||
</STORAGE>
|
||||
}.gsub(/^ /, '')
|
||||
|
@ -21,20 +21,7 @@ require 'rubygems'
|
||||
require 'uri'
|
||||
require 'OpenNebula'
|
||||
|
||||
require 'net/https'
|
||||
|
||||
begin
|
||||
require 'curb'
|
||||
CURL_LOADED=true
|
||||
rescue LoadError
|
||||
CURL_LOADED=false
|
||||
end
|
||||
|
||||
begin
|
||||
require 'net/http/post/multipart'
|
||||
rescue LoadError
|
||||
end
|
||||
|
||||
require 'CloudClient'
|
||||
|
||||
|
||||
module OCCIClient
|
||||
@ -42,12 +29,12 @@ module OCCIClient
|
||||
#####################################################################
|
||||
# Client Library to interface with the OpenNebula OCCI Service
|
||||
#####################################################################
|
||||
class Client
|
||||
class Client < CloudClient
|
||||
|
||||
######################################################################
|
||||
# Initialize client library
|
||||
######################################################################
|
||||
def initialize(endpoint_str=nil, user=nil, pass=nil, debug_flag=false)
|
||||
def initialize(endpoint_str=nil, user=nil, pass=nil, debug_flag=true)
|
||||
@debug = debug_flag
|
||||
|
||||
# Server location
|
||||
@ -59,28 +46,18 @@ module OCCIClient
|
||||
@endpoint = "http://localhost:4567"
|
||||
end
|
||||
|
||||
# Autentication
|
||||
# Autentication
|
||||
if user && pass
|
||||
@occiauth = user + ":" + pass
|
||||
one_auth=@occiauth
|
||||
elsif ENV["ONE_AUTH"] and !ENV["ONE_AUTH"].empty? and File.file?(ENV["ONE_AUTH"])
|
||||
one_auth=File.read(ENV["ONE_AUTH"])
|
||||
elsif File.file?(ENV["HOME"]+"/.one/one_auth")
|
||||
one_auth=File.read(ENV["HOME"]+"/.one/one_auth")
|
||||
@occiauth = [user, pass]
|
||||
else
|
||||
raise "No authorization data present"
|
||||
return
|
||||
@occiauth = get_one_auth
|
||||
end
|
||||
|
||||
one_auth=~/(\w+):(\w+)/
|
||||
user = $1
|
||||
pass = $2
|
||||
if !@occiauth
|
||||
raise "No authorization data present"
|
||||
end
|
||||
|
||||
if user && pass
|
||||
@occiauth = user + ":" + Digest::SHA1.hexdigest(pass)
|
||||
else
|
||||
raise "Authorization data malformed"
|
||||
end
|
||||
@occiauth[1] = Digest::SHA1.hexdigest(@occiauth[1])
|
||||
end
|
||||
|
||||
# Starts an http connection and calls the block provided. SSL flag
|
||||
@ -121,8 +98,7 @@ module OCCIClient
|
||||
req = Net::HTTP::Post.new(url.path)
|
||||
req.body=xml
|
||||
|
||||
auth=@occiauth.split(":")
|
||||
req.basic_auth auth[0], auth[1]
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = http_start(url) do |http|
|
||||
http.request(req)
|
||||
@ -138,8 +114,7 @@ module OCCIClient
|
||||
url = URI.parse(@endpoint+"/compute")
|
||||
req = Net::HTTP::Get.new(url.path)
|
||||
|
||||
auth=@occiauth.split(":")
|
||||
req.basic_auth auth[0], auth[1]
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = http_start(url) {|http|
|
||||
http.request(req)
|
||||
@ -159,9 +134,7 @@ module OCCIClient
|
||||
req = Net::HTTP::Post.new(url.path)
|
||||
req.body=xml
|
||||
|
||||
auth=@occiauth.split(":")
|
||||
|
||||
req.basic_auth auth[0], auth[1]
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = http_start(url) do |http|
|
||||
http.request(req)
|
||||
@ -177,8 +150,7 @@ module OCCIClient
|
||||
url = URI.parse(@endpoint+"/network")
|
||||
req = Net::HTTP::Get.new(url.path)
|
||||
|
||||
auth=@occiauth.split(":")
|
||||
req.basic_auth auth[0], auth[1]
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = http_start(url) {|http|
|
||||
http.request(req)
|
||||
@ -205,7 +177,7 @@ module OCCIClient
|
||||
if curb and CURL_LOADED
|
||||
curl=Curl::Easy.new(@endpoint+"/storage")
|
||||
curl.http_auth_types=Curl::CURLAUTH_BASIC
|
||||
curl.userpwd=@occiauth
|
||||
curl.userpwd="#{@occiauth[0]}:#{@occiauth[1]}"
|
||||
curl.verbose=true if @debug
|
||||
curl.multipart_form_post = true
|
||||
|
||||
@ -232,9 +204,7 @@ module OCCIClient
|
||||
|
||||
req = Net::HTTP::Post::Multipart.new(url.path, params)
|
||||
|
||||
auth=@occiauth.split(":")
|
||||
|
||||
req.basic_auth auth[0], auth[1]
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = http_start(url) do |http|
|
||||
http.request(req)
|
||||
@ -252,8 +222,7 @@ module OCCIClient
|
||||
url = URI.parse(@endpoint+"/storage")
|
||||
req = Net::HTTP::Get.new(url.path)
|
||||
|
||||
auth=@occiauth.split(":")
|
||||
req.basic_auth auth[0], auth[1]
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = http_start(url) {|http|
|
||||
http.request(req)
|
||||
@ -272,8 +241,7 @@ module OCCIClient
|
||||
url = URI.parse(@endpoint+"/compute/" + id.to_s)
|
||||
req = Net::HTTP::Get.new(url.path)
|
||||
|
||||
auth=@occiauth.split(":")
|
||||
req.basic_auth auth[0], auth[1]
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = http_start(url) {|http|
|
||||
http.request(req)
|
||||
@ -294,8 +262,7 @@ module OCCIClient
|
||||
req = Net::HTTP::Put.new(url.path)
|
||||
req.body = xml
|
||||
|
||||
auth=@occiauth.split(":")
|
||||
req.basic_auth auth[0], auth[1]
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = http_start(url) do |http|
|
||||
http.request(req)
|
||||
@ -311,8 +278,7 @@ module OCCIClient
|
||||
url = URI.parse(@endpoint+"/compute/" + id.to_s)
|
||||
req = Net::HTTP::Delete.new(url.path)
|
||||
|
||||
auth=@occiauth.split(":")
|
||||
req.basic_auth auth[0], auth[1]
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = http_start(url) {|http|
|
||||
http.request(req)
|
||||
@ -327,8 +293,7 @@ module OCCIClient
|
||||
url = URI.parse(@endpoint+"/network/" + id.to_s)
|
||||
req = Net::HTTP::Get.new(url.path)
|
||||
|
||||
auth=@occiauth.split(":")
|
||||
req.basic_auth auth[0], auth[1]
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = http_start(url) {|http|
|
||||
http.request(req)
|
||||
@ -343,8 +308,7 @@ module OCCIClient
|
||||
url = URI.parse(@endpoint+"/network/" + id.to_s)
|
||||
req = Net::HTTP::Delete.new(url.path)
|
||||
|
||||
auth=@occiauth.split(":")
|
||||
req.basic_auth auth[0], auth[1]
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = http_start(url) {|http|
|
||||
http.request(req)
|
||||
@ -359,8 +323,7 @@ module OCCIClient
|
||||
url = URI.parse(@endpoint+"/storage/"+image_uuid)
|
||||
req = Net::HTTP::Get.new(url.path)
|
||||
|
||||
auth=@occiauth.split(":")
|
||||
req.basic_auth auth[0], auth[1]
|
||||
req.basic_auth @occiauth[0], @occiauth[1]
|
||||
|
||||
res = http_start(url) {|http|
|
||||
http.request(req)
|
||||
@ -369,11 +332,3 @@ module OCCIClient
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
2
src/cloud/occi/lib/OCCIServer.rb
Normal file → Executable file
2
src/cloud/occi/lib/OCCIServer.rb
Normal file → Executable file
@ -468,7 +468,7 @@ class OCCIServer < CloudServer
|
||||
# Get client with user credentials
|
||||
client = get_client(request.env)
|
||||
|
||||
image=$repoman.get(params[:id])
|
||||
image=get_image(params[:id])
|
||||
|
||||
if image
|
||||
image.extend(ImageOCCI)
|
||||
|
Loading…
x
Reference in New Issue
Block a user