diff --git a/lib/vmfloaty/utils.rb b/lib/vmfloaty/utils.rb index 9478d04..f6d69ef 100644 --- a/lib/vmfloaty/utils.rb +++ b/lib/vmfloaty/utils.rb @@ -85,6 +85,8 @@ class Utils end def self.pretty_print_hosts(verbose, service, hostnames = [], print_to_stderr = false, indent = 0) + output_target = print_to_stderr ? $stderr : $stdout + fetched_data = self.get_host_data(verbose, service, hostnames) fetched_data.each do |hostname, host_data| case service.type @@ -96,7 +98,8 @@ class Utils vmpooler_service = service.clone vmpooler_service.silent = true vmpooler_service.maybe_use_vmpooler - puts "- [JobID:#{host_data['request']['job']['id']}] <#{host_data['state']}>" + output_target.puts "- [JobID:#{host_data['request']['job']['id']}] <#{host_data['state']}>" + host_data['allocated_resources'].each do |vm_name, _i| self.pretty_print_hosts(verbose, vmpooler_service, vm_name['hostname'].split('.')[0], print_to_stderr, indent+2) end @@ -105,13 +108,13 @@ class Utils tag_pairs = host_data['tags'].map { |key, value| "#{key}: #{value}" } unless host_data['tags'].nil? duration = "#{host_data['running']}/#{host_data['lifetime']} hours" metadata = [host_data['template'], duration, *tag_pairs] - puts "- #{hostname}.#{host_data['domain']} (#{metadata.join(', ')})".gsub(/^/, ' ' * indent) + output_target.puts "- #{hostname}.#{host_data['domain']} (#{metadata.join(', ')})".gsub(/^/, ' ' * indent) when 'NonstandardPooler' line = "- #{host_data['fqdn']} (#{host_data['os_triple']}" line += ", #{host_data['hours_left_on_reservation']}h remaining" line += ", reason: #{host_data['reserved_for_reason']}" unless host_data['reserved_for_reason'].empty? line += ')' - puts line + output_target.puts line else raise "Invalid service type #{service.type}" end