mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
Merge remote-tracking branch 'origin/feature-1190'
Conflicts: src/cli/command_parser.rb src/cloud/ec2/bin/econe-allocate-address src/cloud/ec2/bin/econe-describe-addresses src/cloud/ec2/bin/econe-describe-images src/cloud/ec2/bin/econe-describe-instances
This commit is contained in:
commit
bf4dbddb9d
@ -621,7 +621,7 @@ module CommandParser
|
||||
puts
|
||||
} if command[:desc]
|
||||
|
||||
unless !command[:options] || command[:options].empty?
|
||||
if command[:options] && !command[:options].empty?
|
||||
opts_str=command[:options].flatten.collect{|o|
|
||||
o[:name]
|
||||
}.join(', ')
|
||||
|
@ -23,103 +23,51 @@ else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
end
|
||||
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
COMMANDS_HELP=<<-EOT
|
||||
econe-describe-images
|
||||
|
||||
Allocate a new elastic IP address for the user
|
||||
|
||||
Usage:
|
||||
econe-allocate-address [OPTIONS]
|
||||
|
||||
Options:
|
||||
--help, -h
|
||||
Show help
|
||||
|
||||
--access-key <id>, -K <id>
|
||||
The username of the user
|
||||
|
||||
--secret-key <key>, -S <key>
|
||||
The password of the user
|
||||
|
||||
--url <url>, -U <url>
|
||||
Set url as the web service url to use
|
||||
|
||||
--headers, -H
|
||||
Display column headers
|
||||
|
||||
EOT
|
||||
|
||||
require 'cli/command_parser'
|
||||
require 'cli/cli_helper'
|
||||
require 'econe/EC2QueryClient'
|
||||
require 'CloudClient'
|
||||
require 'getoptlong'
|
||||
|
||||
include CloudCLI
|
||||
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
usage "econe-allocate-address [OPTIONS]"
|
||||
description "Allocate a new elastic IP address for the user"
|
||||
version CloudCLI.version_text
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--version', '-v',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]
|
||||
)
|
||||
option [
|
||||
CommandParser::VERBOSE,
|
||||
CommandParser::HELP,
|
||||
EC2QueryClient::ACCESS_KEY,
|
||||
EC2QueryClient::SECRET_KEY,
|
||||
EC2QueryClient::URL
|
||||
]
|
||||
|
||||
headers = false
|
||||
url = nil
|
||||
access = nil
|
||||
secret = nil
|
||||
auth = nil
|
||||
main do
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(
|
||||
options[:access_key],
|
||||
options[:secret_key],
|
||||
options[:url])
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
puts COMMANDS_HELP
|
||||
return
|
||||
when '--version'
|
||||
puts CloudCLI.version_text
|
||||
exit 0
|
||||
when '--access-key'
|
||||
access = arg
|
||||
when '--secret-key'
|
||||
secret = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--headers'
|
||||
headers = true
|
||||
addr = ec2_client.allocate_address
|
||||
|
||||
if CloudClient::is_error?(addr)
|
||||
[-1, "#{cmd_name}: #{addr.message}"]
|
||||
else
|
||||
exit_code 0
|
||||
|
||||
if options[:headers]
|
||||
CLIHelper.print_header("publicIP")
|
||||
end
|
||||
|
||||
puts addr['publicIP']
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
auth = "#{access}:#{secret}" if secret && access
|
||||
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(auth,url)
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
addr = ec2_client.allocate_address
|
||||
|
||||
if CloudClient::is_error?(addr)
|
||||
puts "#{cmd_name}: #{addr.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
if headers
|
||||
puts "publicIp"
|
||||
puts "------------------------------------------------------------------------------"
|
||||
end
|
||||
|
||||
puts addr['publicIp']
|
||||
|
||||
exit 0
|
||||
|
||||
|
@ -23,113 +23,49 @@ else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
end
|
||||
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
COMMANDS_HELP=<<-EOT
|
||||
econe-associate-address
|
||||
|
||||
Associate a publicIP of the user with a given instance
|
||||
|
||||
Usage:
|
||||
econe-associate-address [OPTIONS] PUBLIC-IP INSTANCE-ID
|
||||
|
||||
Options:
|
||||
|
||||
--help, -h
|
||||
Show help
|
||||
|
||||
--access-key <id>, -K <id>
|
||||
The username of the user
|
||||
|
||||
--secret-key <key>, -S <key>
|
||||
The password of the user
|
||||
|
||||
--url <url>, -U <url>
|
||||
Set url as the web service url to use
|
||||
|
||||
--headers, -H
|
||||
Display column headers
|
||||
|
||||
PUBLIC-IP: ElasticIP owned by the user. To see the list of ips use econe-describe-addresses
|
||||
INSTANCE-ID: Id of the instance to be associated with the ElasticIP
|
||||
|
||||
EOT
|
||||
|
||||
require 'cli/command_parser'
|
||||
require 'cli/cli_helper'
|
||||
require 'econe/EC2QueryClient'
|
||||
require 'CloudClient'
|
||||
require 'getoptlong'
|
||||
|
||||
include CloudCLI
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--version', '-v',GetoptLong::NO_ARGUMENT],
|
||||
['--access-key', '-K',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--secret-key', '-S',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--type', '-t',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--user-data', '-d',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--headers', '-H',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
usage "econe-associate-address [OPTIONS] PUBLIC-IP INSTANCE-ID"
|
||||
version CloudCLI.version_text
|
||||
description <<-EOT
|
||||
Associate a publicIP of the user with a given instance
|
||||
PUBLIC-IP: ElasticIP owned by the user. To see the list of ips use econe-describe-addresses
|
||||
INSTANCE-ID: Id of the instance to be associated with the ElasticIP
|
||||
EOT
|
||||
|
||||
headers = false
|
||||
url = nil
|
||||
access = nil
|
||||
secret = nil
|
||||
auth = nil
|
||||
option [
|
||||
CommandParser::VERBOSE,
|
||||
CommandParser::HELP,
|
||||
EC2QueryClient::ACCESS_KEY,
|
||||
EC2QueryClient::SECRET_KEY,
|
||||
EC2QueryClient::URL
|
||||
]
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
puts COMMANDS_HELP
|
||||
return
|
||||
when '--version'
|
||||
puts CloudCLI.version_text
|
||||
exit 0
|
||||
when '--access-key'
|
||||
access = arg
|
||||
when '--secret-key'
|
||||
secret = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--headers'
|
||||
headers = true
|
||||
main :public_ip, :instance_id do
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(
|
||||
options[:access_key],
|
||||
options[:secret_key],
|
||||
options[:url])
|
||||
rescue Exception => e
|
||||
exit_with_code -1, "#{cmd_name}: #{e.message}"
|
||||
end
|
||||
|
||||
rc = ec2_client.associate_address(args[0], args[1])
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
exit_with_code -1, "#{cmd_name}: #{rc.message}"
|
||||
else
|
||||
exit_with_code 0
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
public_ip = ARGV.shift
|
||||
instance_id = ARGV.shift
|
||||
|
||||
if !public_ip
|
||||
puts "#{cmd_name}: missing publicIP parameter"
|
||||
exit -1
|
||||
end
|
||||
|
||||
if !instance_id
|
||||
puts "#{cmd_name}: missing instanceID parameter"
|
||||
exit -1
|
||||
end
|
||||
|
||||
auth = "#{access}:#{secret}" if secret && access
|
||||
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(auth,url)
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = ec2_client.associate_address(public_ip, instance_id)
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
puts "#{cmd_name}: #{rc.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
exit 0
|
||||
end
|
@ -23,112 +23,59 @@ else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
end
|
||||
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
COMMANDS_HELP=<<-EOT
|
||||
econe-describe-images
|
||||
|
||||
List elastic IP addresses
|
||||
|
||||
Usage:
|
||||
econe-describe-addresses [OPTIONS]
|
||||
|
||||
Options:
|
||||
--help, -h
|
||||
Show help
|
||||
|
||||
--access-key <id>, -K <id>
|
||||
The username of the user
|
||||
|
||||
--secret-key <key>, -S <key>
|
||||
The password of the user
|
||||
|
||||
--url <url>, -U <url>
|
||||
Set url as the web service url to use
|
||||
|
||||
--headers, -H
|
||||
Display column headers
|
||||
|
||||
EOT
|
||||
|
||||
require 'cli/command_parser'
|
||||
require 'cli/cli_helper'
|
||||
require 'econe/EC2QueryClient'
|
||||
require 'CloudClient'
|
||||
require 'getoptlong'
|
||||
|
||||
include CloudCLI
|
||||
|
||||
TABLE = CLIHelper::ShowTable.new(nil, self) do
|
||||
column :publicIP, "publicIP", :size=>10 do |d|
|
||||
d["publicIP"]
|
||||
end
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--version', '-v',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]
|
||||
)
|
||||
column :instanceID, "instanceID", :size=>25 do |d|
|
||||
d["instanceID"]
|
||||
end
|
||||
|
||||
headers = false
|
||||
url = nil
|
||||
access = nil
|
||||
secret = nil
|
||||
auth = nil
|
||||
default :publicIP, :instanceID
|
||||
end
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
puts COMMANDS_HELP
|
||||
return
|
||||
when '--version'
|
||||
puts CloudCLI.version_text
|
||||
exit 0
|
||||
when '--access-key'
|
||||
access = arg
|
||||
when '--secret-key'
|
||||
secret = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--headers'
|
||||
headers = true
|
||||
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
usage "econe-describe-addresses [OPTIONS]"
|
||||
version CloudCLI.version_text
|
||||
description "List elastic IP addresses"
|
||||
|
||||
option [
|
||||
CommandParser::VERBOSE,
|
||||
CommandParser::HELP,
|
||||
EC2QueryClient::ACCESS_KEY,
|
||||
EC2QueryClient::SECRET_KEY,
|
||||
EC2QueryClient::URL
|
||||
]
|
||||
|
||||
main do
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(
|
||||
options[:access_key],
|
||||
options[:secret_key],
|
||||
options[:url])
|
||||
rescue Exception => e
|
||||
exit_with_code -1, "#{cmd_name}: #{e.message}"
|
||||
end
|
||||
|
||||
rc = ec2_client.describe_addresses
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
exit_with_code -1, "#{cmd_name}: #{rc.message}"
|
||||
else
|
||||
TABLE.show(rc['addressesSet']['item'] || [])
|
||||
exit_with_code 0
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
auth = "#{access}:#{secret}" if secret && access
|
||||
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(auth,url)
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = ec2_client.describe_addresses
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
puts "#{cmd_name}: #{rc.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
addresses = []
|
||||
if rc['addressesSet']
|
||||
addresses = rc['addressesSet']['item']
|
||||
end
|
||||
|
||||
fmt = "%-12s %s"
|
||||
|
||||
if headers
|
||||
puts fmt % ["publicIP", "instanceId"]
|
||||
puts "------------------------------------------------------------------------------"
|
||||
end
|
||||
|
||||
addresses.each { |addr|
|
||||
puts fmt % [addr['publicIp'],addr['instanceId']]
|
||||
}
|
||||
|
||||
exit 0
|
||||
|
||||
|
@ -23,118 +23,71 @@ else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
end
|
||||
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
COMMANDS_HELP=<<-EOT
|
||||
econe-describe-images
|
||||
|
||||
List and describe previously uploaded images of a user to be
|
||||
used with an OpenNebula Cloud.
|
||||
|
||||
Usage:
|
||||
econe-describe-images [OPTIONS]
|
||||
|
||||
Options:
|
||||
--help, -h
|
||||
Show help
|
||||
|
||||
--access-key <id>, -K <id>
|
||||
The username of the user
|
||||
|
||||
--secret-key <key>, -S <key>
|
||||
The password of the user
|
||||
|
||||
--url <url>, -U <url>
|
||||
Set url as the web service url to use
|
||||
|
||||
--headers, -H
|
||||
Display column headers
|
||||
|
||||
EOT
|
||||
|
||||
require 'cli/command_parser'
|
||||
require 'cli/cli_helper'
|
||||
require 'econe/EC2QueryClient'
|
||||
require 'CloudClient'
|
||||
require 'getoptlong'
|
||||
|
||||
include CloudCLI
|
||||
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--version', '-v',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]
|
||||
)
|
||||
TABLE = CLIHelper::ShowTable.new(nil, self) do
|
||||
column :Owner, "Owner", :size=>12 do |d|
|
||||
d["imageOwnerId"]
|
||||
end
|
||||
|
||||
headers = false
|
||||
url = nil
|
||||
access = nil
|
||||
secret = nil
|
||||
auth = nil
|
||||
column :ImageId, "ImageId", :size=>13 do |d|
|
||||
d["imageId"]
|
||||
end
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
puts COMMANDS_HELP
|
||||
return
|
||||
when '--version'
|
||||
puts CloudCLI.version_text
|
||||
exit 0
|
||||
when '--access-key'
|
||||
access = arg
|
||||
when '--secret-key'
|
||||
secret = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--headers'
|
||||
headers = true
|
||||
column :Status, "Status", :size=>14 do |d|
|
||||
d["imageState"]
|
||||
end
|
||||
|
||||
column :Visibility, "Visibility", :size=>12 do |d|
|
||||
d['isPublic'] == 'true' ? "public" : "private"
|
||||
end
|
||||
|
||||
column :Location, "Location", :size=>20 do |d|
|
||||
d["imageLocation"]
|
||||
end
|
||||
|
||||
default :Owner, :ImageId, :Status, :Visibility, :Location
|
||||
end
|
||||
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
usage "econe-describe-images [OPTIONS]"
|
||||
version CloudCLI.version_text
|
||||
description "List and describe previously uploaded images of a user to be
|
||||
used with an OpenNebula Cloud."
|
||||
|
||||
option [
|
||||
CommandParser::VERBOSE,
|
||||
CommandParser::HELP,
|
||||
EC2QueryClient::ACCESS_KEY,
|
||||
EC2QueryClient::SECRET_KEY,
|
||||
EC2QueryClient::URL
|
||||
]
|
||||
|
||||
main do
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(
|
||||
options[:access_key],
|
||||
options[:secret_key],
|
||||
options[:url])
|
||||
rescue Exception => e
|
||||
exit_with_code -1, "#{cmd_name}: #{e.message}"
|
||||
end
|
||||
|
||||
rc = ec2_client.describe_images
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
exit_with_code -1, "#{cmd_name}: #{rc.message}"
|
||||
else
|
||||
TABLE.show(rc['imagesSet']['item'] || [])
|
||||
exit_with_code 0
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
auth = "#{access}:#{secret}" if secret && access
|
||||
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(auth,url)
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = ec2_client.describe_images()
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
puts "#{cmd_name}: #{rc.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
images = []
|
||||
if rc['imagesSet']
|
||||
images = rc['imagesSet']['item']
|
||||
end
|
||||
|
||||
fmt = "%-12s %-13s %-14s %-12s %s"
|
||||
|
||||
if headers
|
||||
puts fmt % ["Owner", "ImageId", "Status", "Visibility", "Location"]
|
||||
puts "------------------------------------------------------------------------------"
|
||||
end
|
||||
|
||||
images.each { |img|
|
||||
if img['isPublic'] == 'true'
|
||||
visibility = "public"
|
||||
elsif img['isPublic'] == 'false'
|
||||
visibility = "private"
|
||||
end
|
||||
puts fmt % [img['imageOwnerId'],img['imageId'], img['imageState'], visibility,img['imageLocation']]
|
||||
}
|
||||
|
||||
exit 0
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
@ -26,110 +25,67 @@ end
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
COMMANDS_HELP=<<-EOT
|
||||
econe-describe-instances
|
||||
|
||||
List and describe running instances
|
||||
|
||||
Usage:
|
||||
econe-describe-instances [OPTIONS]
|
||||
|
||||
Options:
|
||||
|
||||
--help, -h
|
||||
Show help
|
||||
|
||||
--access-key <id>, -K <id>
|
||||
The username of the user
|
||||
|
||||
--secret-key <key>, -S <key>
|
||||
The password of the user
|
||||
|
||||
--url <url>, -U <url>
|
||||
Set url as the web service url to use
|
||||
|
||||
--headers, -H
|
||||
Display column headers
|
||||
|
||||
EOT
|
||||
|
||||
require 'cli/command_parser'
|
||||
require 'cli/cli_helper'
|
||||
require 'econe/EC2QueryClient'
|
||||
require 'CloudClient'
|
||||
require 'getoptlong'
|
||||
|
||||
include CloudCLI
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--version', '-v',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]
|
||||
)
|
||||
TABLE = CLIHelper::ShowTable.new(nil, self) do
|
||||
column :instanceId, "instanceId", :size=>12 do |d|
|
||||
d["instanceId"]
|
||||
end
|
||||
|
||||
headers = false
|
||||
url = nil
|
||||
access = nil
|
||||
secret = nil
|
||||
auth = nil
|
||||
column :ImageId, "ImageId", :size=>13 do |d|
|
||||
d["imageId"]
|
||||
end
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
puts COMMANDS_HELP
|
||||
return
|
||||
when '--version'
|
||||
puts CloudCLI.version_text
|
||||
exit 0
|
||||
when '--access-key'
|
||||
access = arg
|
||||
when '--secret-key'
|
||||
secret = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--headers'
|
||||
headers = true
|
||||
column :State, "State", :size=>14 do |d|
|
||||
d["instanceState"]['name']
|
||||
end
|
||||
|
||||
column :IP, "IP", :size=>12 do |d|
|
||||
d['dnsName']
|
||||
end
|
||||
|
||||
column :instanceType, "instanceType", :size=>20 do |d|
|
||||
d["instanceType"]
|
||||
end
|
||||
|
||||
default :instanceId, :ImageId, :State, :IP, :instanceType
|
||||
end
|
||||
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
usage "econe-describe-instances [OPTIONS]"
|
||||
version CloudCLI.version_text
|
||||
description "List and describe running instances"
|
||||
|
||||
option [
|
||||
CommandParser::VERBOSE,
|
||||
CommandParser::HELP,
|
||||
EC2QueryClient::ACCESS_KEY,
|
||||
EC2QueryClient::SECRET_KEY,
|
||||
EC2QueryClient::URL
|
||||
]
|
||||
|
||||
main do
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(
|
||||
options[:access_key],
|
||||
options[:secret_key],
|
||||
options[:url])
|
||||
rescue Exception => e
|
||||
exit_with_code -1, "#{cmd_name}: #{e.message}"
|
||||
end
|
||||
|
||||
rc = ec2_client.describe_instances
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
exit_with_code -1, "#{cmd_name}: #{rc.message}"
|
||||
else
|
||||
TABLE.show(rc['reservationSet']['item'][0]['instancesSet']['item'] || [])
|
||||
exit_with_code 0
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
auth = "#{access}:#{secret}" if secret && access
|
||||
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(auth,url)
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = ec2_client.describe_instances()
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
puts "#{cmd_name}: #{rc.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
instances = []
|
||||
if rc['reservationSet']['item'][0]['instancesSet']
|
||||
instances = rc['reservationSet']['item'][0]['instancesSet']['item']
|
||||
end
|
||||
|
||||
owner = rc['reservationSet']['item'][0]['ownerId']
|
||||
|
||||
fmt = "%-10s %-11s %-13s %-11s %-15s %-10s"
|
||||
|
||||
if headers
|
||||
puts fmt % ["Owner", "Id", "ImageId", "State", "IP", "Type"]
|
||||
puts "-----------------------------------------------------------------------------------"
|
||||
end
|
||||
|
||||
|
||||
instances.each { |img|
|
||||
puts fmt % [owner, img['instanceId'],img['imageId'],img['instanceState']['name'],img['dnsName'],img['instanceType']]
|
||||
}
|
||||
|
||||
exit 0
|
||||
|
@ -23,106 +23,49 @@ else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
end
|
||||
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
COMMANDS_HELP=<<-EOT
|
||||
econe-disasociate-address
|
||||
|
||||
Disasociate a publicIP of the user currently associated with an instance
|
||||
|
||||
Usage:
|
||||
econe-disasociate-address [OPTIONS] PUBLIC-IP
|
||||
|
||||
Options:
|
||||
|
||||
--help, -h
|
||||
Show help
|
||||
|
||||
--access-key <id>, -K <id>
|
||||
The username of the user
|
||||
|
||||
--secret-key <key>, -S <key>
|
||||
The password of the user
|
||||
|
||||
--url <url>, -U <url>
|
||||
Set url as the web service url to use
|
||||
|
||||
--headers, -H
|
||||
Display column headers
|
||||
|
||||
PUBLIC-IP: ElasticIP owned by the user. To see the list of ips use econe-describe-addresses
|
||||
|
||||
EOT
|
||||
|
||||
require 'cli/command_parser'
|
||||
require 'cli/cli_helper'
|
||||
require 'econe/EC2QueryClient'
|
||||
require 'CloudClient'
|
||||
require 'getoptlong'
|
||||
|
||||
include CloudCLI
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--version', '-v',GetoptLong::NO_ARGUMENT],
|
||||
['--access-key', '-K',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--secret-key', '-S',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--type', '-t',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--user-data', '-d',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--headers', '-H',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
usage "econe-disasociate-address [OPTIONS] PUBLIC-IP"
|
||||
version CloudCLI.version_text
|
||||
description "<<-EOT
|
||||
Disasociate a publicIP of the user currently associated with an instance
|
||||
PUBLIC-IP: ElasticIP owned by the user. To see the list of ips use econe-describe-addresses
|
||||
EOT"
|
||||
|
||||
headers = false
|
||||
url = nil
|
||||
access = nil
|
||||
secret = nil
|
||||
auth = nil
|
||||
option [
|
||||
CommandParser::VERBOSE,
|
||||
CommandParser::HELP,
|
||||
EC2QueryClient::ACCESS_KEY,
|
||||
EC2QueryClient::SECRET_KEY,
|
||||
EC2QueryClient::URL
|
||||
]
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
puts COMMANDS_HELP
|
||||
return
|
||||
when '--version'
|
||||
puts CloudCLI.version_text
|
||||
exit 0
|
||||
when '--access-key'
|
||||
access = arg
|
||||
when '--secret-key'
|
||||
secret = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--headers'
|
||||
headers = true
|
||||
main :public_ip do
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(
|
||||
options[:access_key],
|
||||
options[:secret_key],
|
||||
options[:url])
|
||||
rescue Exception => e
|
||||
exit_with_code -1, "#{cmd_name}: #{e.message}"
|
||||
end
|
||||
|
||||
rc = ec2_client.disassociate_address(args[0])
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
exit_with_code -1, "#{cmd_name}: #{rc.message}"
|
||||
else
|
||||
exit_with_code 0
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
public_ip = ARGV.shift
|
||||
|
||||
if !public_ip
|
||||
puts "#{cmd_name}: missing publicIP parameter"
|
||||
exit -1
|
||||
end
|
||||
|
||||
auth = "#{access}:#{secret}" if secret && access
|
||||
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(auth,url)
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = ec2_client.disassociate_address(public_ip)
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
puts "#{cmd_name}: #{rc.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
exit 0
|
||||
|
@ -26,104 +26,45 @@ end
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
COMMANDS_HELP=<<-EOT
|
||||
econe-register
|
||||
|
||||
Register a previously uploaded image for use with an
|
||||
OpenNebula Cloud.
|
||||
|
||||
Usage:
|
||||
econe-register [OPTIONS] IMAGE-ID
|
||||
|
||||
Options:
|
||||
|
||||
--help, -h
|
||||
Show help
|
||||
|
||||
--access-key <id>, -K <id>
|
||||
The username of the user
|
||||
|
||||
--secret-key <key>, -S <key>
|
||||
The password of the user
|
||||
|
||||
--url <url>, -U <url>
|
||||
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
|
||||
|
||||
EOT
|
||||
|
||||
require 'cli/command_parser'
|
||||
require 'cli/cli_helper'
|
||||
require 'econe/EC2QueryClient'
|
||||
require 'CloudClient'
|
||||
require 'getoptlong'
|
||||
|
||||
include CloudCLI
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--version', '-v',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]
|
||||
)
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
usage "econe-register [OPTIONS] IMAGE-ID"
|
||||
version CloudCLI.version_text
|
||||
description "<<-EOT
|
||||
Register a previously uploaded image for use with an OpenNebula Cloud.
|
||||
IMAGE-ID: The image identification as returned by the econe-upload command
|
||||
EOT"
|
||||
|
||||
headers = false
|
||||
url = nil
|
||||
access = nil
|
||||
secret = nil
|
||||
auth = nil
|
||||
option [
|
||||
CommandParser::VERBOSE,
|
||||
CommandParser::HELP,
|
||||
EC2QueryClient::ACCESS_KEY,
|
||||
EC2QueryClient::SECRET_KEY,
|
||||
EC2QueryClient::URL
|
||||
]
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
puts COMMANDS_HELP
|
||||
return
|
||||
when '--version'
|
||||
puts CloudCLI.version_text
|
||||
exit 0
|
||||
when '--access-key'
|
||||
access = arg
|
||||
when '--secret-key'
|
||||
secret = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--headers'
|
||||
headers = true
|
||||
main :public_ip, :instance_id do
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(
|
||||
options[:access_key],
|
||||
options[:secret_key],
|
||||
options[:url])
|
||||
rescue Exception => e
|
||||
exit_with_code -1, "#{cmd_name}: #{e.message}"
|
||||
end
|
||||
|
||||
rc = ec2_client.register_image(args[0])
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
exit_with_code -1, "#{cmd_name}: #{rc.message}"
|
||||
else
|
||||
exit_with_code 0, "Success: ImageId #{rc['imageId']}"
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
image_id = ARGV.shift
|
||||
|
||||
if !image_id
|
||||
puts "#{cmd_name}: missing ImageId parameter"
|
||||
exit -1
|
||||
end
|
||||
|
||||
auth = "#{access}:#{secret}" if secret && access
|
||||
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(auth,url)
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = ec2_client.register_image(image_id)
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
puts "#{cmd_name}: #{rc.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
puts "Success: ImageId #{rc['imageId']}"
|
||||
|
||||
exit 0
|
||||
|
@ -23,106 +23,57 @@ else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
end
|
||||
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
COMMANDS_HELP=<<-EOT
|
||||
econe-release-address
|
||||
|
||||
Release a publicIP of the user
|
||||
|
||||
Usage:
|
||||
econe-release-address [OPTIONS] PUBLIC-IP
|
||||
|
||||
Options:
|
||||
|
||||
--help, -h
|
||||
Show help
|
||||
|
||||
--access-key <id>, -K <id>
|
||||
The username of the user
|
||||
|
||||
--secret-key <key>, -S <key>
|
||||
The password of the user
|
||||
|
||||
--url <url>, -U <url>
|
||||
Set url as the web service url to use
|
||||
|
||||
--headers, -H
|
||||
Display column headers
|
||||
|
||||
PUBLIC-IP: ElasticIP owned by the user. To see the list of ips use econe-describe-addresses
|
||||
|
||||
EOT
|
||||
|
||||
require 'cli/command_parser'
|
||||
require 'cli/cli_helper'
|
||||
require 'econe/EC2QueryClient'
|
||||
require 'CloudClient'
|
||||
require 'getoptlong'
|
||||
|
||||
include CloudCLI
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--version', '-v',GetoptLong::NO_ARGUMENT],
|
||||
['--access-key', '-K',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--secret-key', '-S',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--type', '-t',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--user-data', '-d',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--headers', '-H',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
usage "econe-release-address [OPTIONS] PUBLIC-IP"
|
||||
version CloudCLI.version_text
|
||||
description <<-EOT
|
||||
Release a publicIP of the user"
|
||||
PUBLIC-IP: ElasticIP owned by the user. To see the list of ips use econe-describe-addresses
|
||||
EOT
|
||||
|
||||
headers = false
|
||||
url = nil
|
||||
access = nil
|
||||
secret = nil
|
||||
auth = nil
|
||||
option [
|
||||
CommandParser::VERBOSE,
|
||||
CommandParser::HELP,
|
||||
EC2QueryClient::ACCESS_KEY,
|
||||
EC2QueryClient::SECRET_KEY,
|
||||
EC2QueryClient::URL
|
||||
]
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
puts COMMANDS_HELP
|
||||
return
|
||||
when '--version'
|
||||
puts CloudCLI.version_text
|
||||
exit 0
|
||||
when '--access-key'
|
||||
access = arg
|
||||
when '--secret-key'
|
||||
secret = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--headers'
|
||||
headers = true
|
||||
main :public_ip do
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(
|
||||
options[:access_key],
|
||||
options[:secret_key],
|
||||
options[:url])
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = ec2_client.release_address(args[0])
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
[-1, "#{cmd_name}: #{rc.message}"]
|
||||
else
|
||||
exit_code 0
|
||||
|
||||
if options[:headers]
|
||||
CLIHelper.print_header("publicIP")
|
||||
end
|
||||
|
||||
puts rc['publicIP']
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
public_ip = ARGV.shift
|
||||
|
||||
if !public_ip
|
||||
puts "#{cmd_name}: missing publicIP parameter"
|
||||
exit -1
|
||||
end
|
||||
|
||||
auth = "#{access}:#{secret}" if secret && access
|
||||
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(auth,url)
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = ec2_client.release_address(public_ip)
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
puts "#{cmd_name}: #{rc.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
exit 0
|
||||
|
@ -23,137 +23,99 @@ else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
end
|
||||
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
COMMANDS_HELP=<<-EOT
|
||||
econe-run-instances
|
||||
|
||||
Runs an instance of a particular image
|
||||
|
||||
Usage:
|
||||
econe-run-instances [OPTIONS] IMAGE-ID
|
||||
|
||||
Options:
|
||||
|
||||
--help, -h
|
||||
Show help
|
||||
|
||||
--access-key <id>, -K <id>
|
||||
The username of the user
|
||||
|
||||
--secret-key <key>, -S <key>
|
||||
The password of the user
|
||||
|
||||
--url <url>, -U <url>
|
||||
Set url as the web service url to use
|
||||
|
||||
--type <type>, -t <type>
|
||||
OpenNebula template in which is based this instance
|
||||
|
||||
--user-data, -d
|
||||
Specifies Base64-encoded MIME user data to be made
|
||||
available to the instance
|
||||
|
||||
--headers, -H
|
||||
Display column headers
|
||||
|
||||
IMAGE-ID: The image identification as returned by
|
||||
the econe-upload command
|
||||
|
||||
EOT
|
||||
|
||||
require 'cli/command_parser'
|
||||
require 'cli/cli_helper'
|
||||
require 'econe/EC2QueryClient'
|
||||
require 'CloudClient'
|
||||
require 'getoptlong'
|
||||
|
||||
include CloudCLI
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--version', '-v',GetoptLong::NO_ARGUMENT],
|
||||
['--access-key', '-K',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--secret-key', '-S',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--type', '-t',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--user-data', '-d',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--headers', '-H',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
headers = false
|
||||
url = nil
|
||||
access = nil
|
||||
secret = nil
|
||||
auth = nil
|
||||
type = nil
|
||||
user_data = nil
|
||||
USER_DATA = {
|
||||
:name => "user_data",
|
||||
:short => "-d data",
|
||||
:large => "--user-data data",
|
||||
:description => "Specifies Base64-encoded MIME user data to be made
|
||||
available to the instance",
|
||||
:format => String
|
||||
}
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
puts COMMANDS_HELP
|
||||
return
|
||||
when '--version'
|
||||
puts CloudCLI.version_text
|
||||
exit 0
|
||||
when '--access-key'
|
||||
access = arg
|
||||
when '--secret-key'
|
||||
secret = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--type'
|
||||
type = arg
|
||||
when '--headers'
|
||||
headers = true
|
||||
when '--user-data'
|
||||
user_data = arg
|
||||
TYPE = {
|
||||
:name => "type",
|
||||
:short => "-t type",
|
||||
:large => "--type type",
|
||||
:description => "OpenNebula template in which is based this instance",
|
||||
:format => String
|
||||
}
|
||||
|
||||
|
||||
TABLE = CLIHelper::ShowTable.new(nil, self) do
|
||||
column :instanceId, "instanceId", :size=>12 do |d|
|
||||
d["instanceId"]
|
||||
end
|
||||
|
||||
column :ImageId, "ImageId", :size=>13 do |d|
|
||||
d["imageId"]
|
||||
end
|
||||
|
||||
column :State, "State", :size=>14 do |d|
|
||||
d["instanceState"]['name']
|
||||
end
|
||||
|
||||
column :IP, "IP", :size=>12 do |d|
|
||||
d['dnsName']
|
||||
end
|
||||
|
||||
column :instanceType, "instanceType", :size=>20 do |d|
|
||||
d["instanceType"]
|
||||
end
|
||||
|
||||
default :instanceId, :ImageId, :State, :IP, :instanceType
|
||||
end
|
||||
|
||||
|
||||
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
usage "econe-run-instances [OPTIONS] IMAGE-ID"
|
||||
version CloudCLI.version_text
|
||||
description <<-EOT
|
||||
Runs an instance of a particular image
|
||||
IMAGE-ID: The image identification as returned by the econe-upload command
|
||||
EOT
|
||||
|
||||
option [
|
||||
CommandParser::VERBOSE,
|
||||
CommandParser::HELP,
|
||||
EC2QueryClient::ACCESS_KEY,
|
||||
EC2QueryClient::SECRET_KEY,
|
||||
EC2QueryClient::URL,
|
||||
USER_DATA,
|
||||
TYPE
|
||||
]
|
||||
|
||||
main :image_id do
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(
|
||||
options[:access_key],
|
||||
options[:secret_key],
|
||||
options[:url])
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
options[:type] ||= "m1.small"
|
||||
rc = ec2_client.run_instances(args[0], options[:type], options[:user_data])
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
exit_with_code -1, "#{cmd_name}: #{rc.message}"
|
||||
else
|
||||
TABLE.show(rc['instancesSet']['item'] || [])
|
||||
exit_with_code 0
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
image_id = ARGV.shift
|
||||
|
||||
if !image_id
|
||||
puts "#{cmd_name}: missing IMAGE-ID parameter"
|
||||
exit -1
|
||||
end
|
||||
|
||||
if !type
|
||||
type = "m1.small"
|
||||
end
|
||||
|
||||
auth = "#{access}:#{secret}" if secret && access
|
||||
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(auth,url)
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = ec2_client.run_instances(image_id,type, user_data)
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
puts "#{cmd_name}: #{rc.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
images = rc['instancesSet']['item']
|
||||
|
||||
fmt = "%-12s %-13s %-14s %s"
|
||||
|
||||
if headers
|
||||
puts fmt % ["Owner", "ImageId", "InstanceId", "InstanceType"]
|
||||
puts "------------------------------------------------------------------------------"
|
||||
end
|
||||
|
||||
images.each { |img|
|
||||
puts fmt % [rc['ownerId'],img['imageId'],img['instanceId'],img['instanceType']]
|
||||
}
|
||||
|
||||
exit 0
|
||||
|
@ -23,104 +23,55 @@ else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
end
|
||||
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
COMMANDS_HELP=<<-EOT
|
||||
econe-terminate-instances
|
||||
|
||||
Terminate the selected running instance
|
||||
|
||||
Usage:
|
||||
econe-register [OPTIONS] INSTANCE-ID
|
||||
|
||||
Options:
|
||||
|
||||
--help, -h
|
||||
Show help
|
||||
|
||||
--access-key <id>, -K <id>
|
||||
The username of the user
|
||||
|
||||
--secret-key <key>, -S <key>
|
||||
The password of the user
|
||||
|
||||
--url <url>, -U <url>
|
||||
Set url as the web service url to use
|
||||
|
||||
INSTANCE-ID: The instance identification as returned by
|
||||
the econe-run-instances command
|
||||
|
||||
EOT
|
||||
|
||||
require 'cli/command_parser'
|
||||
require 'cli/cli_helper'
|
||||
require 'econe/EC2QueryClient'
|
||||
require 'CloudClient'
|
||||
require 'getoptlong'
|
||||
|
||||
include CloudCLI
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--version', '-v',GetoptLong::NO_ARGUMENT],
|
||||
['--access-key', '-K',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--secret-key', '-S',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-U',GetoptLong::REQUIRED_ARGUMENT]
|
||||
)
|
||||
|
||||
url = nil
|
||||
access = nil
|
||||
secret = nil
|
||||
auth = nil
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
usage "econe-terminate-instances [OPTIONS] INSTANCE-ID"
|
||||
version CloudCLI.version_text
|
||||
description <<-EOT
|
||||
Terminate the selected running instance
|
||||
INSTANCE-ID: The instance identification as returned by the econe-run-instances command
|
||||
EOT
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
puts COMMANDS_HELP
|
||||
return
|
||||
when '--version'
|
||||
puts CloudCLI.version_text
|
||||
exit 0
|
||||
when '--access-key'
|
||||
access = arg
|
||||
when '--secret-key'
|
||||
secret = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--headers'
|
||||
headers = true
|
||||
option [
|
||||
CommandParser::VERBOSE,
|
||||
CommandParser::HELP,
|
||||
EC2QueryClient::ACCESS_KEY,
|
||||
EC2QueryClient::SECRET_KEY,
|
||||
EC2QueryClient::URL,
|
||||
USER_DATA,
|
||||
TYPE
|
||||
]
|
||||
|
||||
main :image_id do
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(
|
||||
options[:access_key],
|
||||
options[:secret_key],
|
||||
options[:url])
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = ec2_client.terminate_instances(args[0])
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
exit_with_code -1, "#{cmd_name}: #{rc.message}"
|
||||
else
|
||||
result = rc['instancesSet']['item'][0]
|
||||
puts "Success: Terminating #{result['instanceId']} in \
|
||||
#{result['previousState']['name']} state"
|
||||
exit_with_code 0
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
instance = ARGV.shift
|
||||
|
||||
if !instance
|
||||
puts "#{cmd_name}: missing INSTANCE-ID parameter"
|
||||
exit -1
|
||||
end
|
||||
|
||||
auth = "#{access}:#{secret}" if secret && access
|
||||
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(auth,url)
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = ec2_client.terminate_instances(instance)
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
puts "#{cmd_name}: #{rc.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
result = rc['instancesSet']['item'][0]
|
||||
|
||||
puts "Success: Terminating #{result['instanceId']} in #{result['previousState']['name']} state"
|
||||
|
||||
exit 0
|
||||
end
|
@ -26,104 +26,58 @@ end
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
COMMANDS_HELP=<<-EOT
|
||||
econe-upload
|
||||
|
||||
Uploads an image for use with an OpenNebula Cloud. This image should
|
||||
be later register with econe-register using the returned ImageId
|
||||
|
||||
Usage:
|
||||
econe-upload [OPTIONS] IMAGE-PATH
|
||||
|
||||
Options:
|
||||
|
||||
--help, -h
|
||||
Show help
|
||||
|
||||
--access-key <id>, -K <id>
|
||||
The username of the user
|
||||
|
||||
--secret-key <key>, -S <key>
|
||||
The password of the user
|
||||
|
||||
--url <url>, -U <url>
|
||||
Set url as the web service url to use
|
||||
|
||||
--multipart, -M
|
||||
Use 'multipart-post' library instead of Curb/Curl
|
||||
|
||||
IMAGE-PATH: Path to the image to upload
|
||||
|
||||
EOT
|
||||
|
||||
require 'cli/command_parser'
|
||||
require 'cli/cli_helper'
|
||||
require 'econe/EC2QueryClient'
|
||||
require 'CloudClient'
|
||||
require 'getoptlong'
|
||||
|
||||
include CloudCLI
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--version', '-v',GetoptLong::NO_ARGUMENT],
|
||||
['--access-key', '-K',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--secret-key', '-S',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--multipart', '-M',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
MULTIPART = {
|
||||
:name => "multipart",
|
||||
:short => "-M",
|
||||
:large => "--multipart",
|
||||
:description => "Use 'multipart-post' library instead of Curb/Curl"
|
||||
}
|
||||
|
||||
url = nil
|
||||
access = nil
|
||||
secret = nil
|
||||
auth = nil
|
||||
curb = true
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
puts COMMANDS_HELP
|
||||
return
|
||||
when '--version'
|
||||
puts CloudCLI.version_text
|
||||
exit 0
|
||||
when '--access-key'
|
||||
access = arg
|
||||
when '--secret-key'
|
||||
secret = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--multipart'
|
||||
curb = false
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
usage "econe-upload [OPTIONS] IMAGE-PATH"
|
||||
version CloudCLI.version_text
|
||||
description <<-EOT
|
||||
Uploads an image for use with an OpenNebula Cloud. This image should
|
||||
be later register with econe-register using the returned ImageId
|
||||
IMAGE-PATH: Path to the image to upload
|
||||
EOT
|
||||
|
||||
option [
|
||||
CommandParser::VERBOSE,
|
||||
CommandParser::HELP,
|
||||
EC2QueryClient::ACCESS_KEY,
|
||||
EC2QueryClient::SECRET_KEY,
|
||||
EC2QueryClient::URL,
|
||||
USER_DATA,
|
||||
TYPE
|
||||
]
|
||||
|
||||
main :file do
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(
|
||||
options[:access_key],
|
||||
options[:secret_key],
|
||||
options[:url])
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = ec2_client.upload_image(args[0], !options[:multipart])
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
exit_with_code -1, "#{cmd_name}: #{rc.message}"
|
||||
else
|
||||
puts "Success: ImageId #{rc['imageId']}"
|
||||
exit_with_code 0
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
image = ARGV.shift
|
||||
|
||||
if !image || !File.exists?(image)
|
||||
puts "#{cmd_name}: missing IMAGE-PATH parameter or file not found"
|
||||
exit -1
|
||||
end
|
||||
|
||||
auth = "#{access}:#{secret}" if secret && access
|
||||
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(auth,url)
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = ec2_client.upload_image(image, curb)
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
puts "#{cmd_name}: #{rc.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
puts "Success: ImageId #{rc['imageId']}"
|
||||
|
||||
exit 0
|
||||
|
||||
|
@ -25,6 +25,39 @@ require 'CloudClient'
|
||||
require 'AWS'
|
||||
|
||||
module EC2QueryClient
|
||||
|
||||
ACCESS_KEY = {
|
||||
:name => "access_key",
|
||||
:short => "-K id",
|
||||
:large => "--access-key id",
|
||||
:description => "The username of the user",
|
||||
:format => String
|
||||
}
|
||||
|
||||
SECRET_KEY = {
|
||||
:name => "sercret_key",
|
||||
:short => "-S key",
|
||||
:large => "--sercret-key key",
|
||||
:description => "The sha1 hashed password of the user",
|
||||
:format => String
|
||||
}
|
||||
|
||||
URL = {
|
||||
:name => "url",
|
||||
:short => "-U url",
|
||||
:large => "--url url",
|
||||
:description => "Set url as the web service url to use",
|
||||
:format => String
|
||||
}
|
||||
|
||||
HEADERS = {
|
||||
:name => "headers",
|
||||
:short => "-H",
|
||||
:large => "--headers",
|
||||
:description => "Display column headers"
|
||||
}
|
||||
|
||||
|
||||
##########################################################################
|
||||
#
|
||||
#
|
||||
@ -37,13 +70,13 @@ module EC2QueryClient
|
||||
#
|
||||
#
|
||||
######################################################################
|
||||
def initialize(secret=nil, endpoint=nil, timeout=nil)
|
||||
def initialize(access=nil, secret=nil, endpoint=nil, timeout=nil)
|
||||
# Autentication
|
||||
ec2auth = nil
|
||||
@timeout = nil
|
||||
|
||||
if secret
|
||||
ec2auth = secret.split(':')
|
||||
if access && secret
|
||||
ec2auth = access, secret
|
||||
elsif ENV["EC2_ACCESS_KEY"] and ENV["EC2_SECRET_KEY"]
|
||||
ec2auth = [ENV["EC2_ACCESS_KEY"], ENV["EC2_SECRET_KEY"]]
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user