mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-25 21:28:40 -05:00
Merge pull request #16 from briancain/add-list-active-vms-flag
(#12) List active vms for a given token
This commit is contained in:
commit
af11d88c07
4 changed files with 38 additions and 8 deletions
|
|
@ -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]")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
class Version
|
||||
@version = '0.2.16'
|
||||
@version = '0.2.17'
|
||||
|
||||
def self.get
|
||||
@version
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue