mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 13:28:42 -05:00
Print all non-success output to STDERR
This commit is contained in:
parent
d843066a56
commit
4755343df2
5 changed files with 47 additions and 56 deletions
|
|
@ -71,9 +71,9 @@ class Vmfloaty
|
||||||
hosts = Utils.standardize_hostnames(response)
|
hosts = Utils.standardize_hostnames(response)
|
||||||
|
|
||||||
if options.json || options.ondemand
|
if options.json || options.ondemand
|
||||||
puts JSON.pretty_generate(hosts)
|
STDOUT.puts JSON.pretty_generate(hosts)
|
||||||
else
|
else
|
||||||
puts Utils.format_host_output(hosts)
|
STDOUT.puts Utils.format_host_output(hosts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -99,15 +99,15 @@ class Vmfloaty
|
||||||
running_vms = service.list_active(verbose)
|
running_vms = service.list_active(verbose)
|
||||||
host = URI.parse(service.url).host
|
host = URI.parse(service.url).host
|
||||||
if running_vms.empty?
|
if running_vms.empty?
|
||||||
puts "You have no running VMs on #{host}"
|
STDOUT.puts "You have no running VMs on #{host}"
|
||||||
else
|
else
|
||||||
puts "Your VMs on #{host}:"
|
STDOUT.puts "Your VMs on #{host}:"
|
||||||
Utils.pretty_print_hosts(verbose, service, running_vms)
|
Utils.pretty_print_hosts(verbose, service, running_vms)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
# list available vms from pooler
|
# list available vms from pooler
|
||||||
os_list = service.list(verbose, filter)
|
os_list = service.list(verbose, filter)
|
||||||
puts os_list
|
STDOUT.puts os_list
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -178,11 +178,11 @@ class Vmfloaty
|
||||||
end
|
end
|
||||||
if ok
|
if ok
|
||||||
if modify_all
|
if modify_all
|
||||||
puts 'Successfully modified all VMs.'
|
STDOUT.puts 'Successfully modified all VMs.'
|
||||||
else
|
else
|
||||||
puts "Successfully modified VM #{hostname}."
|
STDOUT.puts "Successfully modified VM #{hostname}."
|
||||||
end
|
end
|
||||||
puts 'Use `floaty list --active` to see the results.'
|
STDOUT.puts 'Use `floaty list --active` to see the results.'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -214,11 +214,11 @@ class Vmfloaty
|
||||||
if delete_all
|
if delete_all
|
||||||
running_vms = service.list_active(verbose)
|
running_vms = service.list_active(verbose)
|
||||||
if running_vms.empty?
|
if running_vms.empty?
|
||||||
STDERR.puts 'You have no running VMs.'
|
STDOUT.puts 'You have no running VMs.'
|
||||||
else
|
else
|
||||||
Utils.pretty_print_hosts(verbose, service, running_vms)
|
Utils.pretty_print_hosts(verbose, service, running_vms, true)
|
||||||
# Confirm deletion
|
# Confirm deletion
|
||||||
puts
|
STDERR.puts
|
||||||
confirmed = true
|
confirmed = true
|
||||||
confirmed = agree('Delete all these VMs? [y/N]') unless force
|
confirmed = agree('Delete all these VMs? [y/N]') unless force
|
||||||
if confirmed
|
if confirmed
|
||||||
|
|
@ -256,10 +256,10 @@ class Vmfloaty
|
||||||
end
|
end
|
||||||
|
|
||||||
unless successes.empty?
|
unless successes.empty?
|
||||||
puts unless failures.empty?
|
STDERR.puts unless failures.empty?
|
||||||
puts 'Scheduled the following VMs for deletion:'
|
STDOUT.puts 'Scheduled the following VMs for deletion:'
|
||||||
successes.each do |hostname|
|
successes.each do |hostname|
|
||||||
puts "- #{hostname}"
|
STDOUT.puts "- #{hostname}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -288,7 +288,7 @@ class Vmfloaty
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "Snapshot pending. Use `floaty query #{hostname}` to determine when snapshot is valid."
|
STDOUT.puts "Snapshot pending. Use `floaty query #{hostname}` to determine when snapshot is valid."
|
||||||
pp snapshot_req
|
pp snapshot_req
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -379,15 +379,15 @@ class Vmfloaty
|
||||||
case action
|
case action
|
||||||
when 'get'
|
when 'get'
|
||||||
token = service.get_new_token(verbose)
|
token = service.get_new_token(verbose)
|
||||||
puts token
|
STDOUT.puts token
|
||||||
when 'delete'
|
when 'delete'
|
||||||
result = service.delete_token(verbose, options.token)
|
result = service.delete_token(verbose, options.token)
|
||||||
puts result
|
STDOUT.puts result
|
||||||
when 'status'
|
when 'status'
|
||||||
token_value = options.token
|
token_value = options.token
|
||||||
token_value = args[1] if token_value.nil?
|
token_value = args[1] if token_value.nil?
|
||||||
status = service.token_status(verbose, token_value)
|
status = service.token_status(verbose, token_value)
|
||||||
puts status
|
STDOUT.puts status
|
||||||
when nil
|
when nil
|
||||||
STDERR.puts 'No action provided'
|
STDERR.puts 'No action provided'
|
||||||
exit 1
|
exit 1
|
||||||
|
|
@ -450,7 +450,7 @@ class Vmfloaty
|
||||||
completion_file = File.expand_path(File.join('..', '..', 'extras', 'completions', "floaty.#{shell}"), __FILE__)
|
completion_file = File.expand_path(File.join('..', '..', 'extras', 'completions', "floaty.#{shell}"), __FILE__)
|
||||||
|
|
||||||
if File.exist?(completion_file)
|
if File.exist?(completion_file)
|
||||||
puts completion_file
|
STDOUT.puts completion_file
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
STDERR.puts "Could not find completion file for '#{shell}': No such file #{completion_file}"
|
STDERR.puts "Could not find completion file for '#{shell}': No such file #{completion_file}"
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ class ABS
|
||||||
|
|
||||||
ret_val.push(req_hash)
|
ret_val.push(req_hash)
|
||||||
rescue NoMethodError
|
rescue NoMethodError
|
||||||
puts "Warning: couldn't parse line returned from abs/status/queue: ".yellow
|
STDERR.puts "Warning: couldn't parse line returned from abs/status/queue: ".yellow
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -85,7 +85,7 @@ class ABS
|
||||||
conn = Http.get_conn(verbose, url)
|
conn = Http.get_conn(verbose, url)
|
||||||
conn.headers['X-AUTH-TOKEN'] = token if token
|
conn.headers['X-AUTH-TOKEN'] = token if token
|
||||||
|
|
||||||
puts "Trying to delete hosts #{hosts}" if verbose
|
STDERR.puts "Trying to delete hosts #{hosts}" if verbose
|
||||||
requests = get_active_requests(verbose, url, user)
|
requests = get_active_requests(verbose, url, user)
|
||||||
|
|
||||||
jobs_to_delete = []
|
jobs_to_delete = []
|
||||||
|
|
@ -113,7 +113,7 @@ class ABS
|
||||||
}
|
}
|
||||||
jobs_to_delete.push(req_hash)
|
jobs_to_delete.push(req_hash)
|
||||||
else
|
else
|
||||||
puts "When using ABS you must delete all vms that you requested at the same time: Can't delete #{req_hash['request']['job']['id']}: #{hosts} does not include all of #{req_hash['allocated_resources']}"
|
STDERR.puts "When using ABS you must delete all vms that you requested at the same time: Can't delete #{req_hash['request']['job']['id']}: #{hosts} does not include all of #{req_hash['allocated_resources']}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -127,7 +127,7 @@ class ABS
|
||||||
'hosts' => job['allocated_resources'],
|
'hosts' => job['allocated_resources'],
|
||||||
}
|
}
|
||||||
|
|
||||||
puts "Deleting #{req_obj}" if verbose
|
STDERR.puts "Deleting #{req_obj}" if verbose
|
||||||
|
|
||||||
return_result = conn.post 'return', req_obj.to_json
|
return_result = conn.post 'return', req_obj.to_json
|
||||||
req_obj['hosts'].each do |host|
|
req_obj['hosts'].each do |host|
|
||||||
|
|
@ -220,11 +220,11 @@ class ABS
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "Posting to ABS #{req_obj.to_json}" if verbose
|
STDERR.puts "Posting to ABS #{req_obj.to_json}" if verbose
|
||||||
|
|
||||||
# os_string = os_type.map { |os, num| Array(os) * num }.flatten.join('+')
|
# os_string = os_type.map { |os, num| Array(os) * num }.flatten.join('+')
|
||||||
# raise MissingParamError, 'No operating systems provided to obtain.' if os_string.empty?
|
# raise MissingParamError, 'No operating systems provided to obtain.' if os_string.empty?
|
||||||
puts "Requesting VMs with job_id: #{saved_job_id}. Will retry for up to an hour."
|
STDERR.puts "Requesting VMs with job_id: #{saved_job_id}. Will retry for up to an hour."
|
||||||
res = conn.post 'request', req_obj.to_json
|
res = conn.post 'request', req_obj.to_json
|
||||||
|
|
||||||
retries = 360
|
retries = 360
|
||||||
|
|
@ -237,7 +237,7 @@ class ABS
|
||||||
|
|
||||||
sleep_seconds = 10 if i >= 10
|
sleep_seconds = 10 if i >= 10
|
||||||
sleep_seconds = i if i < 10
|
sleep_seconds = i if i < 10
|
||||||
puts "Waiting #{sleep_seconds} seconds to check if ABS request has been filled. Queue Position: #{queue_place}... (x#{i})"
|
STDERR.puts "Waiting #{sleep_seconds} seconds to check if ABS request has been filled. Queue Position: #{queue_place}... (x#{i})"
|
||||||
|
|
||||||
sleep(sleep_seconds)
|
sleep(sleep_seconds)
|
||||||
end
|
end
|
||||||
|
|
@ -276,7 +276,7 @@ class ABS
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.snapshot(_verbose, _url, _hostname, _token)
|
def self.snapshot(_verbose, _url, _hostname, _token)
|
||||||
puts "Can't snapshot with ABS, use '--service vmpooler' (even for vms checked out with ABS)"
|
STDERR.puts "Can't snapshot with ABS, use '--service vmpooler' (even for vms checked out with ABS)"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.status(verbose, url)
|
def self.status(verbose, url)
|
||||||
|
|
@ -297,7 +297,7 @@ class ABS
|
||||||
def self.query(verbose, url, hostname)
|
def self.query(verbose, url, hostname)
|
||||||
return @active_hostnames if @active_hostnames
|
return @active_hostnames if @active_hostnames
|
||||||
|
|
||||||
puts "For vmpooler/snapshot information, use '--service vmpooler' (even for vms checked out with ABS)"
|
STDERR.puts "For vmpooler/snapshot information, use '--service vmpooler' (even for vms checked out with ABS)"
|
||||||
conn = Http.get_conn(verbose, url)
|
conn = Http.get_conn(verbose, url)
|
||||||
|
|
||||||
res = conn.get "host/#{hostname}"
|
res = conn.get "host/#{hostname}"
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ class Service
|
||||||
|
|
||||||
def user
|
def user
|
||||||
unless @config['user']
|
unless @config['user']
|
||||||
puts "Enter your #{@config['url']} service username:"
|
STDERR.puts "Enter your #{@config['url']} service username:"
|
||||||
@config['user'] = STDIN.gets.chomp
|
@config['user'] = STDIN.gets.chomp
|
||||||
end
|
end
|
||||||
@config['user']
|
@config['user']
|
||||||
|
|
@ -44,7 +44,7 @@ class Service
|
||||||
|
|
||||||
def token
|
def token
|
||||||
unless @config['token']
|
unless @config['token']
|
||||||
puts 'No token found. Retrieving a token...'
|
STDERR.puts 'No token found. Retrieving a token...'
|
||||||
@config['token'] = get_new_token(nil)
|
@config['token'] = get_new_token(nil)
|
||||||
end
|
end
|
||||||
@config['token']
|
@config['token']
|
||||||
|
|
@ -76,7 +76,7 @@ class Service
|
||||||
end
|
end
|
||||||
|
|
||||||
def retrieve(verbose, os_types, use_token = true, ondemand = nil)
|
def retrieve(verbose, os_types, use_token = true, ondemand = nil)
|
||||||
puts 'Requesting a vm without a token...' unless use_token
|
STDERR.puts 'Requesting a vm without a token...' unless use_token
|
||||||
token_value = use_token ? token : nil
|
token_value = use_token ? token : nil
|
||||||
@service_object.retrieve verbose, os_types, token_value, url, user, @config, ondemand
|
@service_object.retrieve verbose, os_types, token_value, url, user, @config, ondemand
|
||||||
end
|
end
|
||||||
|
|
@ -98,15 +98,6 @@ class Service
|
||||||
Ssh.ssh(verbose, self, host_os, token_value)
|
Ssh.ssh(verbose, self, host_os, token_value)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pretty_print_running(verbose, hostnames = [])
|
|
||||||
if hostnames.empty?
|
|
||||||
puts 'You have no running VMs.'
|
|
||||||
else
|
|
||||||
puts 'Running VMs:'
|
|
||||||
@service_object.pretty_print_hosts(verbose, hostnames, url)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def query(verbose, hostname)
|
def query(verbose, hostname)
|
||||||
@service_object.query verbose, url, hostname
|
@service_object.query verbose, url, hostname
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ class Utils
|
||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
|
|
||||||
STDOUT.puts "response body is #{response_body}"
|
STDERR.puts "response body is #{response_body}"
|
||||||
filtered_response_body = response_body.reject { |key, _| key == 'request_id' || key == 'ready' }
|
filtered_response_body = response_body.reject { |key, _| key == 'request_id' || key == 'ready' }
|
||||||
filtered_response_body.each do |os, value|
|
filtered_response_body.each do |os, value|
|
||||||
hostnames = Array(value['hostname'])
|
hostnames = Array(value['hostname'])
|
||||||
|
|
@ -79,7 +79,7 @@ class Utils
|
||||||
os_types
|
os_types
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.pretty_print_hosts(verbose, service, hostnames = [])
|
def self.pretty_print_hosts(verbose, service, hostnames = [], print_to_stderr = false)
|
||||||
hostnames = [hostnames] unless hostnames.is_a? Array
|
hostnames = [hostnames] unless hostnames.is_a? Array
|
||||||
hostnames.each do |hostname|
|
hostnames.each do |hostname|
|
||||||
begin
|
begin
|
||||||
|
|
@ -91,7 +91,7 @@ class Utils
|
||||||
# For ABS, 'hostname' variable is the jobID
|
# For ABS, 'hostname' variable is the jobID
|
||||||
if host_data['state'] == 'allocated' || host_data['state'] == 'filled'
|
if host_data['state'] == 'allocated' || host_data['state'] == 'filled'
|
||||||
host_data['allocated_resources'].each do |vm_name, _i|
|
host_data['allocated_resources'].each do |vm_name, _i|
|
||||||
puts "- [JobID:#{host_data['request']['job']['id']}] #{vm_name['hostname']} (#{vm_name['type']}) <#{host_data['state']}>"
|
STDOUT.puts "- [JobID:#{host_data['request']['job']['id']}] #{vm_name['hostname']} (#{vm_name['type']}) <#{host_data['state']}>"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
when 'Pooler'
|
when 'Pooler'
|
||||||
|
|
@ -99,13 +99,13 @@ class Utils
|
||||||
tag_pairs = host_data['tags'].map { |key, value| "#{key}: #{value}" } unless host_data['tags'].nil?
|
tag_pairs = host_data['tags'].map { |key, value| "#{key}: #{value}" } unless host_data['tags'].nil?
|
||||||
duration = "#{host_data['running']}/#{host_data['lifetime']} hours"
|
duration = "#{host_data['running']}/#{host_data['lifetime']} hours"
|
||||||
metadata = [host_data['template'], duration, *tag_pairs]
|
metadata = [host_data['template'], duration, *tag_pairs]
|
||||||
puts "- #{hostname}.#{host_data['domain']} (#{metadata.join(', ')})"
|
STDOUT.puts "- #{hostname}.#{host_data['domain']} (#{metadata.join(', ')})"
|
||||||
when 'NonstandardPooler'
|
when 'NonstandardPooler'
|
||||||
line = "- #{host_data['fqdn']} (#{host_data['os_triple']}"
|
line = "- #{host_data['fqdn']} (#{host_data['os_triple']}"
|
||||||
line += ", #{host_data['hours_left_on_reservation']}h remaining"
|
line += ", #{host_data['hours_left_on_reservation']}h remaining"
|
||||||
line += ", reason: #{host_data['reserved_for_reason']}" unless host_data['reserved_for_reason'].empty?
|
line += ", reason: #{host_data['reserved_for_reason']}" unless host_data['reserved_for_reason'].empty?
|
||||||
line += ')'
|
line += ')'
|
||||||
puts line
|
STDOUT.puts line
|
||||||
else
|
else
|
||||||
raise "Invalid service type #{service.type}"
|
raise "Invalid service type #{service.type}"
|
||||||
end
|
end
|
||||||
|
|
@ -133,12 +133,12 @@ class Utils
|
||||||
pending = pool['pending']
|
pending = pool['pending']
|
||||||
missing = max - ready - pending
|
missing = max - ready - pending
|
||||||
char = 'o'
|
char = 'o'
|
||||||
puts "#{name.ljust(width)} #{(char * ready).green}#{(char * pending).yellow}#{(char * missing).red}"
|
STDOUT.puts "#{name.ljust(width)} #{(char * ready).green}#{(char * pending).yellow}#{(char * missing).red}"
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
puts "#{name.ljust(width)} #{e.red}"
|
STDERR.puts "#{name.ljust(width)} #{e.red}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
puts message.colorize(status_response['status']['ok'] ? :default : :red)
|
STDOUT.puts message.colorize(status_response['status']['ok'] ? :default : :red)
|
||||||
when 'NonstandardPooler'
|
when 'NonstandardPooler'
|
||||||
pools = status_response
|
pools = status_response
|
||||||
pools.delete 'ok'
|
pools.delete 'ok'
|
||||||
|
|
@ -152,14 +152,14 @@ class Utils
|
||||||
pending = pool['pending'] || 0 # not available for nspooler
|
pending = pool['pending'] || 0 # not available for nspooler
|
||||||
missing = max - ready - pending
|
missing = max - ready - pending
|
||||||
char = 'o'
|
char = 'o'
|
||||||
puts "#{name.ljust(width)} #{(char * ready).green}#{(char * pending).yellow}#{(char * missing).red}"
|
STDOUT.puts "#{name.ljust(width)} #{(char * ready).green}#{(char * pending).yellow}#{(char * missing).red}"
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
puts "#{name.ljust(width)} #{e.red}"
|
STDERR.puts "#{name.ljust(width)} #{e.red}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
when 'ABS'
|
when 'ABS'
|
||||||
puts 'ABS Not OK'.red unless status_response
|
STDERR.puts 'ABS Not OK'.red unless status_response
|
||||||
puts 'ABS is OK'.green if status_response
|
STDOUT.puts 'ABS is OK'.green if status_response
|
||||||
else
|
else
|
||||||
raise "Invalid service type #{service.type}"
|
raise "Invalid service type #{service.type}"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -169,7 +169,7 @@ describe Utils do
|
||||||
} }
|
} }
|
||||||
output = '- mcpy42eqjxli9g2.delivery.mycompany.net (ubuntu-1604-x86_64, 9.66/12 hours)'
|
output = '- mcpy42eqjxli9g2.delivery.mycompany.net (ubuntu-1604-x86_64, 9.66/12 hours)'
|
||||||
|
|
||||||
expect(Utils).to receive(:puts).with(output)
|
expect(STDOUT).to receive(:puts).with(output)
|
||||||
|
|
||||||
service = Service.new(MockOptions.new, 'url' => url)
|
service = Service.new(MockOptions.new, 'url' => url)
|
||||||
allow(service).to receive(:query)
|
allow(service).to receive(:query)
|
||||||
|
|
@ -195,7 +195,7 @@ describe Utils do
|
||||||
} }
|
} }
|
||||||
output = '- aiydvzpg23r415q.delivery.mycompany.net (redhat-7-x86_64, 7.67/48 hours, user: bob, role: agent)'
|
output = '- aiydvzpg23r415q.delivery.mycompany.net (redhat-7-x86_64, 7.67/48 hours, user: bob, role: agent)'
|
||||||
|
|
||||||
expect(Utils).to receive(:puts).with(output)
|
expect(STDOUT).to receive(:puts).with(output)
|
||||||
|
|
||||||
service = Service.new(MockOptions.new, 'url' => url)
|
service = Service.new(MockOptions.new, 'url' => url)
|
||||||
allow(service).to receive(:query)
|
allow(service).to receive(:query)
|
||||||
|
|
@ -216,7 +216,7 @@ describe Utils do
|
||||||
} }
|
} }
|
||||||
output = '- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining)'
|
output = '- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining)'
|
||||||
|
|
||||||
expect(Utils).to receive(:puts).with(output)
|
expect(STDOUT).to receive(:puts).with(output)
|
||||||
|
|
||||||
service = Service.new(MockOptions.new, 'url' => url, 'type' => 'ns')
|
service = Service.new(MockOptions.new, 'url' => url, 'type' => 'ns')
|
||||||
allow(service).to receive(:query)
|
allow(service).to receive(:query)
|
||||||
|
|
@ -237,7 +237,7 @@ describe Utils do
|
||||||
} }
|
} }
|
||||||
output = '- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining, reason: testing)'
|
output = '- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining, reason: testing)'
|
||||||
|
|
||||||
expect(Utils).to receive(:puts).with(output)
|
expect(STDOUT).to receive(:puts).with(output)
|
||||||
|
|
||||||
service = Service.new(MockOptions.new, 'url' => url, 'type' => 'ns')
|
service = Service.new(MockOptions.new, 'url' => url, 'type' => 'ns')
|
||||||
allow(service).to receive(:query)
|
allow(service).to receive(:query)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue