mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 05:28:40 -05:00
Abstract out getting all active token vms into Utils
This commit is contained in:
parent
2c9ce5644e
commit
586f4f5c05
4 changed files with 42 additions and 33 deletions
|
|
@ -113,21 +113,15 @@ class Vmfloaty
|
||||||
if active
|
if active
|
||||||
# list active vms
|
# list active vms
|
||||||
begin
|
begin
|
||||||
status = Auth.token_status(verbose, url, token)
|
running_vms = Utils.get_all_token_vms(verbose, url, token)
|
||||||
rescue TokenError => e
|
rescue TokenError => e
|
||||||
STDERR.puts e
|
STDERR.puts e
|
||||||
exit 1
|
exit 1
|
||||||
|
rescue Exception => e
|
||||||
|
STDERR.puts e
|
||||||
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
# 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?
|
if ! running_vms.nil?
|
||||||
Utils.prettyprint_hosts(running_vms, verbose, url)
|
Utils.prettyprint_hosts(running_vms, verbose, url)
|
||||||
end
|
end
|
||||||
|
|
@ -167,6 +161,7 @@ class Vmfloaty
|
||||||
c.option '--lifetime INT', Integer, 'VM TTL (Integer, in hours)'
|
c.option '--lifetime INT', Integer, 'VM TTL (Integer, in hours)'
|
||||||
c.option '--disk INT', Integer, 'Increases VM disk space (Integer, in gb)'
|
c.option '--disk INT', Integer, 'Increases VM disk space (Integer, in gb)'
|
||||||
c.option '--tags STRING', String, 'free-form VM tagging (json)'
|
c.option '--tags STRING', String, 'free-form VM tagging (json)'
|
||||||
|
c.option '--all', 'Modifies all vms acquired by a token'
|
||||||
c.action do |args, options|
|
c.action do |args, options|
|
||||||
verbose = options.verbose || config['verbose']
|
verbose = options.verbose || config['verbose']
|
||||||
url = options.url ||= config['url']
|
url = options.url ||= config['url']
|
||||||
|
|
@ -175,21 +170,28 @@ class Vmfloaty
|
||||||
disk = options.disk
|
disk = options.disk
|
||||||
tags = JSON.parse(options.tags) if options.tags
|
tags = JSON.parse(options.tags) if options.tags
|
||||||
token = options.token || config['token']
|
token = options.token || config['token']
|
||||||
|
modify_all = options.all
|
||||||
|
|
||||||
if lifetime || tags
|
if lifetime || tags
|
||||||
begin
|
# All Vs
|
||||||
modify_req = Pooler.modify(verbose, url, hostname, token, lifetime, tags)
|
if modify_all
|
||||||
rescue TokenError => e
|
|
||||||
STDERR.puts e
|
|
||||||
exit 1
|
|
||||||
end
|
|
||||||
|
|
||||||
if modify_req["ok"]
|
|
||||||
puts "Successfully modified vm #{hostname}."
|
|
||||||
else
|
else
|
||||||
STDERR.puts "Could not modify given host #{hostname} at #{url}."
|
# Single Vm
|
||||||
puts modify_req
|
begin
|
||||||
exit 1
|
modify_req = Pooler.modify(verbose, url, hostname, token, lifetime, tags)
|
||||||
|
rescue TokenError => e
|
||||||
|
STDERR.puts e
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if modify_req["ok"]
|
||||||
|
puts "Successfully modified vm #{hostname}."
|
||||||
|
else
|
||||||
|
STDERR.puts "Could not modify given host #{hostname} at #{url}."
|
||||||
|
puts modify_req
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -234,21 +236,15 @@ class Vmfloaty
|
||||||
if delete_all
|
if delete_all
|
||||||
# get vms with token
|
# get vms with token
|
||||||
begin
|
begin
|
||||||
status = Auth.token_status(verbose, url, token)
|
running_vms = Utils.get_all_token_vms(verbose, url, token)
|
||||||
rescue TokenError => e
|
rescue TokenError => e
|
||||||
STDERR.puts e
|
STDERR.puts e
|
||||||
exit 1
|
exit 1
|
||||||
|
rescue Exception => e
|
||||||
|
STDERR.puts e
|
||||||
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
# 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?
|
if ! running_vms.nil?
|
||||||
Utils.prettyprint_hosts(running_vms, verbose, url)
|
Utils.prettyprint_hosts(running_vms, verbose, url)
|
||||||
# query y/n
|
# query y/n
|
||||||
|
|
|
||||||
|
|
@ -79,4 +79,17 @@ class Utils
|
||||||
puts "- #{vm}.#{domain} (#{metadata.join(", ")})"
|
puts "- #{vm}.#{domain} (#{metadata.join(", ")})"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.get_all_token_vms(verbose, url, token)
|
||||||
|
# get vms with token
|
||||||
|
status = Auth.token_status(verbose, url, token)
|
||||||
|
|
||||||
|
vms = status[token]['vms']
|
||||||
|
if vms.nil?
|
||||||
|
raise "You have no running vms"
|
||||||
|
end
|
||||||
|
|
||||||
|
running_vms = vms['running']
|
||||||
|
running_vms
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
class Version
|
class Version
|
||||||
@version = '0.7.1'
|
@version = '0.7.2'
|
||||||
|
|
||||||
def self.get
|
def self.get
|
||||||
@version
|
@version
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = 'vmfloaty'
|
s.name = 'vmfloaty'
|
||||||
s.version = '0.7.1'
|
s.version = '0.7.2'
|
||||||
s.authors = ['Brian Cain']
|
s.authors = ['Brian Cain']
|
||||||
s.email = ['brian.cain@puppetlabs.com']
|
s.email = ['brian.cain@puppetlabs.com']
|
||||||
s.license = 'Apache'
|
s.license = 'Apache'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue