mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-25 21:28:40 -05:00
Improve formatting of cli tool
This commit is contained in:
parent
beeac3858c
commit
221e5db6b5
5 changed files with 31 additions and 14 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
require 'commander'
|
require 'commander'
|
||||||
|
require 'pp'
|
||||||
require 'vmfloaty/auth'
|
require 'vmfloaty/auth'
|
||||||
require 'vmfloaty/pooler'
|
require 'vmfloaty/pooler'
|
||||||
require 'vmfloaty/version'
|
require 'vmfloaty/version'
|
||||||
|
|
@ -54,7 +55,7 @@ class Vmfloaty
|
||||||
|
|
||||||
unless os_types.nil?
|
unless os_types.nil?
|
||||||
response = Pooler.retrieve(verbose, os_types, token, url)
|
response = Pooler.retrieve(verbose, os_types, token, url)
|
||||||
puts response
|
Format.get_hosts(response)
|
||||||
else
|
else
|
||||||
puts 'You did not provide an OS to get'
|
puts 'You did not provide an OS to get'
|
||||||
end
|
end
|
||||||
|
|
@ -90,8 +91,8 @@ class Vmfloaty
|
||||||
url = options.url ||= config['url']
|
url = options.url ||= config['url']
|
||||||
hostname = args[0]
|
hostname = args[0]
|
||||||
|
|
||||||
query = Pooler.query(verbose, url, hostname)
|
query_req = Pooler.query(verbose, url, hostname)
|
||||||
puts query
|
pp query_req
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -113,8 +114,10 @@ class Vmfloaty
|
||||||
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']
|
||||||
|
|
||||||
res_body = Pooler.modify(verbose, url, hostname, token, lifetime, tags)
|
modify_req = Pooler.modify(verbose, url, hostname, token, lifetime, tags)
|
||||||
puts res_body
|
if modify_req["ok"]
|
||||||
|
puts "Successfully modified vm #{hostname}."
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -150,8 +153,8 @@ class Vmfloaty
|
||||||
hostname = args[0]
|
hostname = args[0]
|
||||||
token = options.token ||= config['token']
|
token = options.token ||= config['token']
|
||||||
|
|
||||||
res_body = Pooler.snapshot(verbose, url, hostname, token)
|
snapshot_req = Pooler.snapshot(verbose, url, hostname, token)
|
||||||
puts res_body
|
pp snapshot_req
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -171,8 +174,8 @@ class Vmfloaty
|
||||||
token = options.token || config['token']
|
token = options.token || config['token']
|
||||||
snapshot_sha = options.snapshot
|
snapshot_sha = options.snapshot
|
||||||
|
|
||||||
res_body = Pooler.revert(verbose, url, hostname, token, snapshot_sha)
|
revert_req = Pooler.revert(verbose, url, hostname, token, snapshot_sha)
|
||||||
puts res_body
|
pp revert_req
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -188,7 +191,7 @@ class Vmfloaty
|
||||||
url = options.url ||= config['url']
|
url = options.url ||= config['url']
|
||||||
|
|
||||||
status = Pooler.status(verbose, url)
|
status = Pooler.status(verbose, url)
|
||||||
puts status
|
pp status
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -204,7 +207,7 @@ class Vmfloaty
|
||||||
url = options.url ||= config['url']
|
url = options.url ||= config['url']
|
||||||
|
|
||||||
summary = Pooler.summary(verbose, url)
|
summary = Pooler.summary(verbose, url)
|
||||||
puts summary
|
pp summary
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,5 +3,13 @@ class Format
|
||||||
# TODO: Takes the json response body from an HTTP GET
|
# TODO: Takes the json response body from an HTTP GET
|
||||||
# request and "pretty prints" it
|
# request and "pretty prints" it
|
||||||
def self.get_hosts(hostname_hash)
|
def self.get_hosts(hostname_hash)
|
||||||
|
host_hash = {}
|
||||||
|
|
||||||
|
hostname_hash.delete("ok")
|
||||||
|
hostname_hash.each do |type, hosts|
|
||||||
|
host_hash[type] = hosts["hostname"]
|
||||||
|
end
|
||||||
|
|
||||||
|
puts host_hash.to_json
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,13 @@ class Pooler
|
||||||
response = conn.post "/vm/#{os_string}"
|
response = conn.post "/vm/#{os_string}"
|
||||||
|
|
||||||
res_body = JSON.parse(response.body)
|
res_body = JSON.parse(response.body)
|
||||||
res_body
|
if res_body["ok"]
|
||||||
|
res_body
|
||||||
|
else
|
||||||
|
STDERR.puts "There was a problem with your request"
|
||||||
|
STDERR.puts res_body
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.modify(verbose, url, hostname, token, lifetime, tags)
|
def self.modify(verbose, url, hostname, token, lifetime, tags)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
class Version
|
class Version
|
||||||
@version = '0.2.7'
|
@version = '0.2.10'
|
||||||
|
|
||||||
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.2.7'
|
s.version = '0.2.10'
|
||||||
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