1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-16 22:50:10 +03:00

Added describe and run instances for econe

git-svn-id: http://svn.opennebula.org/one/trunk@732 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
Constantino Vázquez Blanco 2009-07-22 15:54:33 +00:00
parent eb51119165
commit 4ec61f483a
2 changed files with 278 additions and 0 deletions

View File

@ -0,0 +1,131 @@
#!/usr/bin/env ruby
# == Synopsis
# econe-describe-instances
#
# List and describe previously uploaded images of a user for use
# with an OpenNebula Cloud.
#
# == Usage
#
# econe-describe-images [OPTIONS]
#
# -h, --help:
# 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
# -------------------------------------------------------------------------- #
# Copyright 2002-2009, Distributed Systems Architecture Group, Universidad #
# Complutense de Madrid (dsa-research.org) #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"]
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
end
$: << RUBY_LIB_LOCATION
require 'EC2QueryClient'
require 'getoptlong'
require 'rdoc/usage'
require 'pp'
opts = GetoptLong.new(
['--help', '-h',GetoptLong::NO_ARGUMENT],
['--access-key', '-K',GetoptLong::REQUIRED_ARGUMENT],
['--secret-key', '-S',GetoptLong::REQUIRED_ARGUMENT],
['--url', '-U',GetoptLong::REQUIRED_ARGUMENT],
['--headers', '-H',GetoptLong::NO_ARGUMENT]
)
headers = false
url = nil
access = nil
secret = nil
auth = nil
begin
opts.each do |opt, arg|
case opt
when '--help'
RDoc::usage
when '--access-key'
access = arg
when '--secret-key'
secret = arg
when '--url'
url = arg
when '--headers'
headers = true
end
end
rescue Exception => e
exit -1
end
auth = "#{access}:#{secret}" if secret && access
begin
ec2_client = EC2QueryClient::Client.new(auth,url)
rescue Exception => e
puts "#{$0}: #{e.message}"
exit -1
end
rc = ec2_client.describe_instances()
if OpenNebula::is_error?(rc)
puts "#{$0}: #{rc.message}"
exit -1
end
instances = rc['reservationSet']['item'][0]['instancesSet']['item']
owner = rc['reservationSet']['item'][0]['ownerId']
fmt = "%-10s %-4s %-36s %-13s %-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

147
src/oca/ec2/econe-run-instances Executable file
View File

@ -0,0 +1,147 @@
#!/usr/bin/env ruby
# == Synopsis
# econe-run-instances
#
# List and describe previously uploaded images of a user for use
# with an OpenNebula Cloud.
#
# == Usage
#
# econe-describe-images [OPTIONS]
#
# -h, --help:
# 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>
#
# --headers, -H:
# Display column headers
# -------------------------------------------------------------------------- #
# Copyright 2002-2009, Distributed Systems Architecture Group, Universidad #
# Complutense de Madrid (dsa-research.org) #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"]
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
end
$: << RUBY_LIB_LOCATION
require 'EC2QueryClient'
require 'getoptlong'
require 'rdoc/usage'
require 'pp'
opts = GetoptLong.new(
['--help', '-h',GetoptLong::NO_ARGUMENT],
['--access-key', '-K',GetoptLong::REQUIRED_ARGUMENT],
['--secret-key', '-S',GetoptLong::REQUIRED_ARGUMENT],
['--url', '-U',GetoptLong::REQUIRED_ARGUMENT],
['--type', '-t',GetoptLong::REQUIRED_ARGUMENT],
['--headers', '-H',GetoptLong::NO_ARGUMENT]
)
headers = false
url = nil
access = nil
secret = nil
auth = nil
type = nil
begin
opts.each do |opt, arg|
case opt
when '--help'
RDoc::usage
when '--access-key'
access = arg
when '--secret-key'
secret = arg
when '--url'
url = arg
when '--type'
type = arg
when '--headers'
headers = true
end
end
rescue Exception => e
exit -1
end
image_id = ARGV.shift
if !image_id
puts "#{$0}: missing IMAGE-ID parameter"
exit -1
end
if !type
type = "m1.small"
end
auth = "#{access}:#{secret}" if secret && access
begin
ec2_client = EC2QueryClient::Client.new(auth,url)
rescue Exception => e
puts "#{$0}: #{e.message}"
exit -1
end
rc = ec2_client.run_instances(image_id,type)
if OpenNebula::is_error?(rc)
puts "#{$0}: #{rc.message}"
exit -1
end
images = rc['instancesSet']['item']
fmt = "%-10s %-36s %-10s %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