mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-27 14:03:40 +03:00
Add occi-instance-type and verbose mode
This commit is contained in:
parent
8984b1fbb5
commit
d29e97cbab
@ -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"
|
||||
|
@ -75,6 +75,9 @@ Options:
|
||||
--debug, -D
|
||||
Enables verbosity
|
||||
|
||||
--verbose
|
||||
Show resources in verbose mode
|
||||
|
||||
EOT
|
||||
|
||||
require 'occi/OCCIClient'
|
||||
@ -89,7 +92,8 @@ opts = GetoptLong.new(
|
||||
['--password', '-P',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-R',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--timeout', '-T',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--debug', '-D',GetoptLong::NO_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]
|
||||
|
147
src/cloud/occi/bin/occi-instance-type
Executable file
147
src/cloud/occi/bin/occi-instance-type
Executable file
@ -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 <COMMAND> [OPTIONS]
|
||||
|
||||
Commands:
|
||||
|
||||
* list
|
||||
lists available instance types
|
||||
|
||||
Options:
|
||||
|
||||
--help, -h
|
||||
Show help
|
||||
|
||||
--username <id>, -U <id>
|
||||
The username of the user
|
||||
|
||||
--password <key>, -P <key>
|
||||
The password of the user
|
||||
|
||||
--url <url>, -R <url>
|
||||
Set url as the web service url to use
|
||||
|
||||
--timeout <seconds>, -T <seconds>
|
||||
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
|
||||
|
@ -76,13 +76,12 @@ 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
|
||||
@ -94,7 +93,8 @@ opts = GetoptLong.new(
|
||||
['--password', '-P',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-R',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--timeout', '-T',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--debug', '-D',GetoptLong::NO_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]
|
||||
|
@ -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'
|
||||
@ -95,7 +98,8 @@ opts = GetoptLong.new(
|
||||
['--url', '-R',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--debug', '-D',GetoptLong::NO_ARGUMENT],
|
||||
['--timeout', '-T',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--multipart', '-M',GetoptLong::NO_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]
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user