diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index 283830c..05a0fad 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -22,7 +22,7 @@ class Vmfloaty c.syntax = 'floaty get os_type1=x ox_type2=y ...' c.summary = 'Gets a vm or vms based on the os flag' c.description = '' - c.example 'Gets 3 vms', 'floaty get centos=3 debian --user brian --url http://vmpooler.example.com' + c.example 'Gets a few vms', 'floaty get centos=3 debian --user brian --url http://vmpooler.example.com' c.option '--verbose', 'Enables verbose output' c.option '--user STRING', String, 'User to authenticate with' c.option '--url STRING', String, 'URL of vmpooler' @@ -73,14 +73,36 @@ class Vmfloaty c.description = '' c.example 'Filter the list on centos', 'floaty list centos --url http://vmpooler.example.com' c.option '--verbose', 'Enables verbose output' + c.option '--active', 'Prints information about active vms for a given token' + c.option '--token STRING', String, 'Token for vmpooler' c.option '--url STRING', String, 'URL of vmpooler' c.action do |args, options| verbose = options.verbose || config['verbose'] filter = args[0] url = options.url ||= config['url'] + token = options.token || config['token'] + active = options.active - os_list = Pooler.list(verbose, url, filter) - puts os_list + if active + # list active vms + status = Auth.token_status(verbose, url, token) + # print vms + vms = status[token]['vms'] + if vms.nil? + STDERR.puts "You have no running vms" + exit 0 + end + + running_vms = vms['running'] + + if ! running_vms.nil? + Utils.prettyprint_hosts(running_vms, verbose, url) + end + else + # list available vms from pooler + os_list = Pooler.list(verbose, url, filter) + puts os_list + end end end @@ -159,7 +181,7 @@ class Vmfloaty running_vms = vms['running'] if ! running_vms.nil? - Utils.prettyprint_hosts(running_vms) + Utils.prettyprint_hosts(running_vms, verbose, url) # query y/n puts "" ans = agree("Delete all VMs associated with token #{token}? [y/N]") diff --git a/lib/vmfloaty/utils.rb b/lib/vmfloaty/utils.rb index 043ae4d..b44780f 100644 --- a/lib/vmfloaty/utils.rb +++ b/lib/vmfloaty/utils.rb @@ -41,10 +41,18 @@ class Utils os_types end - def self.prettyprint_hosts(hosts) + def self.prettyprint_hosts(hosts, verbose, url) puts "Running VMs:" hosts.each do |vm| - puts "- #{vm}" + vm_info = Pooler.query(verbose, url, vm) + if vm_info['ok'] + domain = vm_info[vm]['domain'] + template = vm_info[vm]['template'] + lifetime = vm_info[vm]['lifetime'] + running = vm_info[vm]['running'] + + puts "- #{vm}.#{domain} (#{template}, #{running}/#{lifetime} hours)" + end end end end diff --git a/lib/vmfloaty/version.rb b/lib/vmfloaty/version.rb index fb632c7..c4dfafc 100644 --- a/lib/vmfloaty/version.rb +++ b/lib/vmfloaty/version.rb @@ -1,6 +1,6 @@ class Version - @version = '0.2.16' + @version = '0.2.17' def self.get @version diff --git a/vmfloaty.gemspec b/vmfloaty.gemspec index cd4f5bc..94193f0 100644 --- a/vmfloaty.gemspec +++ b/vmfloaty.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'vmfloaty' - s.version = '0.2.16' + s.version = '0.2.17' s.authors = ['Brian Cain'] s.email = ['brian.cain@puppetlabs.com'] s.license = 'Apache'