mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 05:28:40 -05:00
(#33) Handle more exceptions in vmfloaty command class
This commit adds more handling to the vmfloaty command class that deals with exceptions thrown from the Pooler class.
This commit is contained in:
parent
478761023d
commit
c62c1c7083
3 changed files with 35 additions and 10 deletions
|
|
@ -45,7 +45,15 @@ class Vmfloaty
|
||||||
|
|
||||||
unless os_types.empty?
|
unless os_types.empty?
|
||||||
if no_token
|
if no_token
|
||||||
response = Pooler.retrieve(verbose, os_types, nil, url)
|
begin
|
||||||
|
response = Pooler.retrieve(verbose, os_types, nil, url)
|
||||||
|
rescue MissingParamError
|
||||||
|
STDERR.puts e
|
||||||
|
STDERR.puts "See `floaty get --help` for more information on how to get VMs."
|
||||||
|
rescue AuthError => e
|
||||||
|
STDERR.puts e
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
puts Utils.format_hosts(response)
|
puts Utils.format_hosts(response)
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
|
|
@ -58,7 +66,7 @@ class Vmfloaty
|
||||||
pass = password "Enter your password please:", '*'
|
pass = password "Enter your password please:", '*'
|
||||||
begin
|
begin
|
||||||
token = Auth.get_token(verbose, url, user, pass)
|
token = Auth.get_token(verbose, url, user, pass)
|
||||||
rescue => e
|
rescue AuthError => e
|
||||||
STDERR.puts e
|
STDERR.puts e
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
@ -67,7 +75,15 @@ class Vmfloaty
|
||||||
puts token
|
puts token
|
||||||
end
|
end
|
||||||
|
|
||||||
response = Pooler.retrieve(verbose, os_types, token, url)
|
begin
|
||||||
|
response = Pooler.retrieve(verbose, os_types, token, url)
|
||||||
|
rescue MissingParamError
|
||||||
|
STDERR.puts e
|
||||||
|
STDERR.puts "See `floaty get --help` for more information on how to get VMs."
|
||||||
|
rescue AuthError => e
|
||||||
|
STDERR.puts e
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
puts Utils.format_hosts(response)
|
puts Utils.format_hosts(response)
|
||||||
exit 0
|
exit 0
|
||||||
end
|
end
|
||||||
|
|
@ -98,7 +114,7 @@ class Vmfloaty
|
||||||
# list active vms
|
# list active vms
|
||||||
begin
|
begin
|
||||||
status = Auth.token_status(verbose, url, token)
|
status = Auth.token_status(verbose, url, token)
|
||||||
rescue => e
|
rescue AuthError => e
|
||||||
STDERR.puts e
|
STDERR.puts e
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
@ -208,7 +224,7 @@ class Vmfloaty
|
||||||
# get vms with token
|
# get vms with token
|
||||||
begin
|
begin
|
||||||
status = Auth.token_status(verbose, url, token)
|
status = Auth.token_status(verbose, url, token)
|
||||||
rescue => e
|
rescue AuthError => e
|
||||||
STDERR.puts e
|
STDERR.puts e
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
@ -357,7 +373,7 @@ class Vmfloaty
|
||||||
pass = password "Enter your password please:", '*'
|
pass = password "Enter your password please:", '*'
|
||||||
begin
|
begin
|
||||||
token = Auth.get_token(verbose, url, user, pass)
|
token = Auth.get_token(verbose, url, user, pass)
|
||||||
rescue => e
|
rescue AuthError => e
|
||||||
STDERR.puts e
|
STDERR.puts e
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
@ -367,7 +383,7 @@ class Vmfloaty
|
||||||
pass = password "Enter your password please:", '*'
|
pass = password "Enter your password please:", '*'
|
||||||
begin
|
begin
|
||||||
result = Auth.delete_token(verbose, url, user, pass, token)
|
result = Auth.delete_token(verbose, url, user, pass, token)
|
||||||
rescue => e
|
rescue AuthError => e
|
||||||
STDERR.puts e
|
STDERR.puts e
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
@ -376,7 +392,7 @@ class Vmfloaty
|
||||||
when "status"
|
when "status"
|
||||||
begin
|
begin
|
||||||
status = Auth.token_status(verbose, url, token)
|
status = Auth.token_status(verbose, url, token)
|
||||||
rescue => e
|
rescue AuthError => e
|
||||||
STDERR.puts e
|
STDERR.puts e
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
@ -423,7 +439,7 @@ class Vmfloaty
|
||||||
pass = password "Enter your password please:", '*'
|
pass = password "Enter your password please:", '*'
|
||||||
begin
|
begin
|
||||||
token = Auth.get_token(verbose, url, user, pass)
|
token = Auth.get_token(verbose, url, user, pass)
|
||||||
rescue => e
|
rescue AuthError => e
|
||||||
STDERR.puts e
|
STDERR.puts e
|
||||||
STDERR.puts 'Could not get token...requesting vm without a token anyway...'
|
STDERR.puts 'Could not get token...requesting vm without a token anyway...'
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -9,3 +9,9 @@ class TokenError < StandardError
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class MissingParamError < StandardError
|
||||||
|
def initialize(msg="Argument provided to function is missing")
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,9 @@ class Pooler
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.retrieve(verbose, os_type, token, url)
|
def self.retrieve(verbose, os_type, token, url)
|
||||||
|
# NOTE:
|
||||||
|
# Developers can use `Utils.generate_os_hash` to
|
||||||
|
# generate the os_type param.
|
||||||
conn = Http.get_conn(verbose, url)
|
conn = Http.get_conn(verbose, url)
|
||||||
if token
|
if token
|
||||||
conn.headers['X-AUTH-TOKEN'] = token
|
conn.headers['X-AUTH-TOKEN'] = token
|
||||||
|
|
@ -35,7 +38,7 @@ class Pooler
|
||||||
os_string = os_string.chomp("+")
|
os_string = os_string.chomp("+")
|
||||||
|
|
||||||
if os_string.size == 0
|
if os_string.size == 0
|
||||||
raise "No operating systems provided to obtain. See `floaty get --help` for more information on how to get VMs."
|
raise MissingParamError, "No operating systems provided to obtain."
|
||||||
end
|
end
|
||||||
|
|
||||||
response = conn.post "vm/#{os_string}"
|
response = conn.post "vm/#{os_string}"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue