diff --git a/install.sh b/install.sh index b046b2da3b..6e08149835 100755 --- a/install.sh +++ b/install.sh @@ -1070,10 +1070,12 @@ OCCI_LIB_CLIENT_FILES="src/cloud/occi/lib/OCCIClient.rb" OCCI_BIN_FILES="src/cloud/occi/bin/occi-server \ src/cloud/occi/bin/occi-compute \ src/cloud/occi/bin/occi-network \ + src/cloud/occi/bin/occi-instance-type \ src/cloud/occi/bin/occi-storage" OCCI_BIN_CLIENT_FILES="src/cloud/occi/bin/occi-compute \ src/cloud/occi/bin/occi-network \ + src/cloud/occi/bin/occi-instance-type \ src/cloud/occi/bin/occi-storage" OCCI_ETC_FILES="src/cloud/occi/etc/occi-server.conf" diff --git a/src/cloud/occi/bin/occi-compute b/src/cloud/occi/bin/occi-compute index 63b813ddb8..85277961e4 100755 --- a/src/cloud/occi/bin/occi-compute +++ b/src/cloud/occi/bin/occi-compute @@ -75,6 +75,9 @@ Options: --debug, -D Enables verbosity +--verbose + Show resources in verbose mode + EOT require 'occi/OCCIClient' @@ -83,13 +86,14 @@ require 'getoptlong' include CloudCLI opts = GetoptLong.new( - ['--help', '-h',GetoptLong::NO_ARGUMENT], - ['--version', '-v',GetoptLong::NO_ARGUMENT], - ['--username', '-U',GetoptLong::REQUIRED_ARGUMENT], - ['--password', '-P',GetoptLong::REQUIRED_ARGUMENT], - ['--url', '-R',GetoptLong::REQUIRED_ARGUMENT], - ['--timeout', '-T',GetoptLong::REQUIRED_ARGUMENT], - ['--debug', '-D',GetoptLong::NO_ARGUMENT] + ['--help', '-h',GetoptLong::NO_ARGUMENT], + ['--version', '-v',GetoptLong::NO_ARGUMENT], + ['--username', '-U',GetoptLong::REQUIRED_ARGUMENT], + ['--password', '-P',GetoptLong::REQUIRED_ARGUMENT], + ['--url', '-R',GetoptLong::REQUIRED_ARGUMENT], + ['--timeout', '-T',GetoptLong::REQUIRED_ARGUMENT], + ['--debug', '-D',GetoptLong::NO_ARGUMENT], + ['--verbose', GetoptLong::NO_ARGUMENT] ) url = nil @@ -98,6 +102,7 @@ password = nil auth = nil timeout = nil debug = false +verbose = false begin opts.each do |opt, arg| @@ -118,6 +123,8 @@ begin timeout = arg when '--debug' debug = true + when '--verbose' + verbose = true end end rescue Exception => e @@ -139,7 +146,7 @@ end case ARGV[0].downcase when 'list' - rc = occi_client.get_vms + rc = occi_client.get_vms(verbose) when 'create' vm_xml = ARGV[1] diff --git a/src/cloud/occi/bin/occi-instance-type b/src/cloud/occi/bin/occi-instance-type new file mode 100755 index 0000000000..f4482fabc9 --- /dev/null +++ b/src/cloud/occi/bin/occi-instance-type @@ -0,0 +1,147 @@ +#!/usr/bin/env ruby +# -------------------------------------------------------------------------- # +# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.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" + TEMPLATES_LOCATION=ONE_LOCATION+"/etc/occi_templates" + CONF_LOCATION=ONE_LOCATION+"/etc" +end + +$: << RUBY_LIB_LOCATION +$: << RUBY_LIB_LOCATION+"/cloud" + +COMMANDS_HELP=<<-EOT +occi-instance-type - Retrieve instance types + +Usage: + occi-instance-type [OPTIONS] + +Commands: + +* list + lists available instance types + +Options: + +--help, -h + Show help + +--username , -U + The username of the user + +--password , -P + The password of the user + +--url , -R + Set url as the web service url to use + +--timeout , -T + Sets a timeout for the http connection + +--debug, -D + Enables verbosity + +--verbose + Show resources in verbose mode + +EOT + +require 'occi/OCCIClient' +require 'getoptlong' + +include CloudCLI + +opts = GetoptLong.new( + ['--help', '-h',GetoptLong::NO_ARGUMENT], + ['--version', '-v',GetoptLong::NO_ARGUMENT], + ['--username', '-U',GetoptLong::REQUIRED_ARGUMENT], + ['--password', '-P',GetoptLong::REQUIRED_ARGUMENT], + ['--url', '-R',GetoptLong::REQUIRED_ARGUMENT], + ['--timeout', '-T',GetoptLong::REQUIRED_ARGUMENT], + ['--debug', '-D',GetoptLong::NO_ARGUMENT], + ['--verbose', GetoptLong::NO_ARGUMENT] + ) + +url = nil +username = nil +password = nil +auth = nil +timeout = nil +debug = false +verbose = false + +begin + opts.each do |opt, arg| + case opt + when '--help' + puts COMMANDS_HELP + return + when '--version' + puts CloudCLI.version_text + exit 0 + when '--username' + username = arg + when '--password' + password = arg + when '--url' + url = arg + when '--timeout' + timeout = arg + when '--debug' + debug = true + when '--verbose' + verbose = true + end + end +rescue Exception => e + exit(-1) +end + +begin + occi_client = OCCIClient::Client.new(url,username,password, timeout, debug) +rescue Exception => e + puts "#{cmd_name}: #{e.message}" + exit(-1) +end + +if !ARGV[0] + puts "#{cmd_name}: [COMMAND] not present" + puts "#{cmd_name}: Execute #{cmd_name} -h for help." + exit(-1) +end + +case ARGV[0].downcase + when 'list' + rc = occi_client.get_instance_types(verbose) + else + puts "Command #{ARGV[0]} not valid." + exit(-1) +end + +if CloudClient::is_error?(rc) + puts rc.to_s() + exit(-1) +else + str, code = print_xml(rc) + puts str + exit(code) +end + diff --git a/src/cloud/occi/bin/occi-network b/src/cloud/occi/bin/occi-network index 7ab3548fa1..d2377bb31c 100755 --- a/src/cloud/occi/bin/occi-network +++ b/src/cloud/occi/bin/occi-network @@ -76,25 +76,25 @@ Options: --debug, -D Enables verbosity ---multipart, -M - Use 'multipart-post' library instead of Curb/Curl +--verbose + Show resources in verbose mode EOT require 'occi/OCCIClient' -require 'CloudClient' require 'getoptlong' include CloudCLI opts = GetoptLong.new( - ['--help', '-h',GetoptLong::NO_ARGUMENT], - ['--version', '-v',GetoptLong::NO_ARGUMENT], - ['--username', '-U',GetoptLong::REQUIRED_ARGUMENT], - ['--password', '-P',GetoptLong::REQUIRED_ARGUMENT], - ['--url', '-R',GetoptLong::REQUIRED_ARGUMENT], - ['--timeout', '-T',GetoptLong::REQUIRED_ARGUMENT], - ['--debug', '-D',GetoptLong::NO_ARGUMENT] + ['--help', '-h',GetoptLong::NO_ARGUMENT], + ['--version', '-v',GetoptLong::NO_ARGUMENT], + ['--username', '-U',GetoptLong::REQUIRED_ARGUMENT], + ['--password', '-P',GetoptLong::REQUIRED_ARGUMENT], + ['--url', '-R',GetoptLong::REQUIRED_ARGUMENT], + ['--timeout', '-T',GetoptLong::REQUIRED_ARGUMENT], + ['--debug', '-D',GetoptLong::NO_ARGUMENT], + ['--verbose', GetoptLong::NO_ARGUMENT] ) url = nil @@ -103,6 +103,7 @@ password = nil auth = nil timeout = nil debug = false +verbose = false begin opts.each do |opt, arg| @@ -123,13 +124,14 @@ begin timeout = arg when '--debug' debug = true + when '--verbose' + verbose = true end end rescue Exception => e exit(-1) end - begin occi_client = OCCIClient::Client.new(url,username,password,timeout,debug) rescue Exception => e @@ -156,7 +158,7 @@ case ARGV[0].downcase rc = occi_client.post_network(network_xml) when 'list' - rc = occi_client.get_networks + rc = occi_client.get_networks(verbose) when 'show' network_id = ARGV[1] diff --git a/src/cloud/occi/bin/occi-storage b/src/cloud/occi/bin/occi-storage index af4cb9f4a8..fb9eddb375 100755 --- a/src/cloud/occi/bin/occi-storage +++ b/src/cloud/occi/bin/occi-storage @@ -79,6 +79,9 @@ Options: --multipart, -M Use 'multipart-post' library instead of Curb/Curl +--verbose + Show resources in verbose mode + EOT require 'occi/OCCIClient' @@ -88,14 +91,15 @@ require 'getoptlong' include CloudCLI opts = GetoptLong.new( - ['--help', '-h',GetoptLong::NO_ARGUMENT], - ['--version', '-v',GetoptLong::NO_ARGUMENT], - ['--username', '-U',GetoptLong::REQUIRED_ARGUMENT], - ['--password', '-P',GetoptLong::REQUIRED_ARGUMENT], - ['--url', '-R',GetoptLong::REQUIRED_ARGUMENT], - ['--debug', '-D',GetoptLong::NO_ARGUMENT], - ['--timeout', '-T',GetoptLong::REQUIRED_ARGUMENT], - ['--multipart', '-M',GetoptLong::NO_ARGUMENT] + ['--help', '-h',GetoptLong::NO_ARGUMENT], + ['--version', '-v',GetoptLong::NO_ARGUMENT], + ['--username', '-U',GetoptLong::REQUIRED_ARGUMENT], + ['--password', '-P',GetoptLong::REQUIRED_ARGUMENT], + ['--url', '-R',GetoptLong::REQUIRED_ARGUMENT], + ['--debug', '-D',GetoptLong::NO_ARGUMENT], + ['--timeout', '-T',GetoptLong::REQUIRED_ARGUMENT], + ['--multipart', '-M',GetoptLong::NO_ARGUMENT], + ['--verbose', GetoptLong::NO_ARGUMENT] ) url = nil @@ -105,6 +109,7 @@ auth = nil timeout = nil debug = false curb = true +verbose = false begin opts.each do |opt, arg| @@ -127,6 +132,8 @@ begin debug = true when '--multipart' curb = false + when '--verbose' + verbose = true end end rescue Exception => e @@ -159,7 +166,7 @@ case ARGV[0].downcase rc = occi_client.post_image(image_xml, curb) when 'list' - rc = occi_client.get_images + rc = occi_client.get_images(verbose) when 'show' image_id = ARGV[1] diff --git a/src/cloud/occi/lib/OCCIClient.rb b/src/cloud/occi/lib/OCCIClient.rb index c600599a18..1844d90e58 100755 --- a/src/cloud/occi/lib/OCCIClient.rb +++ b/src/cloud/occi/lib/OCCIClient.rb @@ -74,8 +74,8 @@ module OCCIClient ###################################################################### # Retieves the available Instance types ###################################################################### - def get_instance_types - get('/instance_type') + def get_instance_types(verbose=false) + get('/instance_type', verbose) end ###################################################################### @@ -89,8 +89,8 @@ module OCCIClient ###################################################################### # Retieves the pool of Virtual Machines ###################################################################### - def get_vms - get('/compute') + def get_vms(verbose=false) + get('/compute', verbose) end ###################################################################### @@ -104,8 +104,8 @@ module OCCIClient ###################################################################### # Retieves the pool of Virtual Networks ###################################################################### - def get_networks - get('/network') + def get_networks(verbose=false) + get('/network', verbose) end ###################################################################### @@ -202,8 +202,8 @@ module OCCIClient ###################################################################### # Retieves the pool of Images owned by the user ###################################################################### - def get_images - get('/storage') + def get_images(verbose=false) + get('/storage', verbose) end @@ -281,7 +281,8 @@ module OCCIClient private - def get(path) + def get(path, verbose=false) + path += "?verbose=true" if verbose url = URI.parse(@endpoint+path) req = Net::HTTP::Get.new(url.path)