From 6447a5f2172e16f3ec71377a3bc6a33a86b26b76 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Sun, 15 Nov 2015 15:12:06 -0800 Subject: [PATCH 1/3] (#12) List active vms for a given token This commit updates the list command to add a flag --active. It will list all active vms based on the given token as well as what template they are and how long they've been running for. As a result, this also updates how the delete --all command formats running vms. --- lib/vmfloaty.rb | 30 ++++++++++++++++++++++++++---- lib/vmfloaty/utils.rb | 12 ++++++++++-- 2 files changed, 36 insertions(+), 6 deletions(-) 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..307d4dc 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} (#{running}/#{lifetime} hours)" + end end end end From 53f3c7db038c52ccd7d1829231e6c8c7270cfda9 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Mon, 16 Nov 2015 09:24:45 -0800 Subject: [PATCH 2/3] Fixup how vms are printed on list command --- lib/vmfloaty/utils.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vmfloaty/utils.rb b/lib/vmfloaty/utils.rb index 307d4dc..b44780f 100644 --- a/lib/vmfloaty/utils.rb +++ b/lib/vmfloaty/utils.rb @@ -51,7 +51,7 @@ class Utils lifetime = vm_info[vm]['lifetime'] running = vm_info[vm]['running'] - puts "- #{vm}#{domain} (#{running}/#{lifetime} hours)" + puts "- #{vm}.#{domain} (#{template}, #{running}/#{lifetime} hours)" end end end From e3218a0fc9eaf143d0a6f6f227a30599828ca6dc Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Mon, 16 Nov 2015 09:39:25 -0800 Subject: [PATCH 3/3] Bump to version 0.2.17 --- lib/vmfloaty/version.rb | 2 +- vmfloaty.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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'