mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 05:28:40 -05:00
(#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.
This commit is contained in:
parent
2a5e5ba9bb
commit
6447a5f217
2 changed files with 36 additions and 6 deletions
|
|
@ -22,7 +22,7 @@ class Vmfloaty
|
||||||
c.syntax = 'floaty get os_type1=x ox_type2=y ...'
|
c.syntax = 'floaty get os_type1=x ox_type2=y ...'
|
||||||
c.summary = 'Gets a vm or vms based on the os flag'
|
c.summary = 'Gets a vm or vms based on the os flag'
|
||||||
c.description = ''
|
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 '--verbose', 'Enables verbose output'
|
||||||
c.option '--user STRING', String, 'User to authenticate with'
|
c.option '--user STRING', String, 'User to authenticate with'
|
||||||
c.option '--url STRING', String, 'URL of vmpooler'
|
c.option '--url STRING', String, 'URL of vmpooler'
|
||||||
|
|
@ -73,14 +73,36 @@ class Vmfloaty
|
||||||
c.description = ''
|
c.description = ''
|
||||||
c.example 'Filter the list on centos', 'floaty list centos --url http://vmpooler.example.com'
|
c.example 'Filter the list on centos', 'floaty list centos --url http://vmpooler.example.com'
|
||||||
c.option '--verbose', 'Enables verbose output'
|
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.option '--url STRING', String, 'URL of vmpooler'
|
||||||
c.action do |args, options|
|
c.action do |args, options|
|
||||||
verbose = options.verbose || config['verbose']
|
verbose = options.verbose || config['verbose']
|
||||||
filter = args[0]
|
filter = args[0]
|
||||||
url = options.url ||= config['url']
|
url = options.url ||= config['url']
|
||||||
|
token = options.token || config['token']
|
||||||
|
active = options.active
|
||||||
|
|
||||||
os_list = Pooler.list(verbose, url, filter)
|
if active
|
||||||
puts os_list
|
# 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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -159,7 +181,7 @@ class Vmfloaty
|
||||||
running_vms = vms['running']
|
running_vms = vms['running']
|
||||||
|
|
||||||
if ! running_vms.nil?
|
if ! running_vms.nil?
|
||||||
Utils.prettyprint_hosts(running_vms)
|
Utils.prettyprint_hosts(running_vms, verbose, url)
|
||||||
# query y/n
|
# query y/n
|
||||||
puts ""
|
puts ""
|
||||||
ans = agree("Delete all VMs associated with token #{token}? [y/N]")
|
ans = agree("Delete all VMs associated with token #{token}? [y/N]")
|
||||||
|
|
|
||||||
|
|
@ -41,10 +41,18 @@ class Utils
|
||||||
os_types
|
os_types
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.prettyprint_hosts(hosts)
|
def self.prettyprint_hosts(hosts, verbose, url)
|
||||||
puts "Running VMs:"
|
puts "Running VMs:"
|
||||||
hosts.each do |vm|
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue