Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions lib/vmfloaty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def run
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'
Expand Down Expand Up @@ -73,14 +73,36 @@ def run
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

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']

os_list = Pooler.list(verbose, url, filter)
puts os_list
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

Expand Down Expand Up @@ -159,7 +181,7 @@ def run
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]")
Expand Down
12 changes: 10 additions & 2 deletions lib/vmfloaty/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,18 @@ def self.generate_os_hash(os_args)
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
2 changes: 1 addition & 1 deletion lib/vmfloaty/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

class Version
@version = '0.2.16'
@version = '0.2.17'

def self.get
@version
Expand Down
2 changes: 1 addition & 1 deletion vmfloaty.gemspec
Original file line number Diff line number Diff line change
@@ -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'
Expand Down