Add verbose to methods

This commit is contained in:
Brian Cain 2015-09-14 21:45:33 -07:00
parent 44c5315bfd
commit 201f59c376
4 changed files with 39 additions and 39 deletions

View file

@ -35,11 +35,11 @@ class Vmfloaty
pass = password "Enter your password please:", '*' pass = password "Enter your password please:", '*'
unless options.token unless options.token
token = Auth.get_token(url, user, pass) token = Auth.get_token(verbose, url, user, pass)
end end
unless os_types.nil? unless os_types.nil?
response = Pooler.retrieve(os_types, token, url) response = Pooler.retrieve(verbose, os_types, token, url)
puts response puts response
else else
puts 'You did not provide an OS to get' puts 'You did not provide an OS to get'
@ -60,7 +60,7 @@ class Vmfloaty
filter = options.filter filter = options.filter
url = options.url ||= config['url'] url = options.url ||= config['url']
os_list = Pooler.list(url, filter) os_list = Pooler.list(verbose, url, filter)
puts os_list puts os_list
end end
end end
@ -78,7 +78,7 @@ class Vmfloaty
url = options.url ||= config['url'] url = options.url ||= config['url']
hostname = options.hostname hostname = options.hostname
query = Pooler.query(url, hostname) query = Pooler.query(verbose, url, hostname)
puts query puts query
end end
end end
@ -102,7 +102,7 @@ class Vmfloaty
tags = options.tags tags = options.tags
token = options.token token = options.token
res_body = Pooler.modify(url, hostname, token, lifetime, tags) res_body = Pooler.modify(verbose, url, hostname, token, lifetime, tags)
puts res_body puts res_body
end end
end end
@ -120,7 +120,7 @@ class Vmfloaty
hosts = options.hosts hosts = options.hosts
url = options.url ||= config['url'] url = options.url ||= config['url']
Pool.delete(url, hosts) Pool.delete(verbose, url, hosts)
end end
end end
@ -139,7 +139,7 @@ class Vmfloaty
hostname = options.hostname hostname = options.hostname
token = options.token token = options.token
res_body = Pooler.snapshot(url, hostname, token) res_body = Pooler.snapshot(verbose, url, hostname, token)
puts res_body puts res_body
end end
end end
@ -161,7 +161,7 @@ class Vmfloaty
token = options.token token = options.token
snapshot_sha = options.snapshot snapshot_sha = options.snapshot
res_body = Pooler.revert(url, hostname, token, snapshot_sha) res_body = Pooler.revert(verbose, url, hostname, token, snapshot_sha)
puts res_body puts res_body
end end
end end
@ -177,7 +177,7 @@ class Vmfloaty
verbose = options.verbose || config['verbose'] verbose = options.verbose || config['verbose']
url = options.url ||= config['url'] url = options.url ||= config['url']
status = Pooler.status(url) status = Pooler.status(verbose, url)
puts status puts status
end end
end end
@ -193,7 +193,7 @@ class Vmfloaty
verbose = options.verbose || config['verbose'] verbose = options.verbose || config['verbose']
url = options.url ||= config['url'] url = options.url ||= config['url']
summary = Pooler.summary(url) summary = Pooler.summary(verbose, url)
puts summary puts summary
end end
end end
@ -217,11 +217,11 @@ class Vmfloaty
case action case action
when "get" when "get"
puts Auth.get_token(url, user, pass) puts Auth.get_token(verbose, url, user, pass)
when "delete" when "delete"
Auth.delete_token(url, user, pass, token) Auth.delete_token(verbose, url, user, pass, token)
when "status" when "status"
Auth.token_status(url, user, pass, token) Auth.token_status(verbose, url, user, pass, token)
else else
puts "Unknown action: #{action}" puts "Unknown action: #{action}"
end end

View file

@ -3,8 +3,8 @@ require 'json'
require 'vmfloaty/http' require 'vmfloaty/http'
class Auth class Auth
def self.get_token(url, user, password) def self.get_token(verbose, url, user, password)
conn = Http.get_conn(url) conn = Http.get_conn(verbose, url)
resp = conn.post do |req| resp = conn.post do |req|
req.url '/v1/token' req.url '/v1/token'
@ -15,26 +15,26 @@ class Auth
resp_body resp_body
end end
def self.delete_token(url, user, pass, token) def self.delete_token(verbose, url, user, pass, token)
if token.nil? if token.nil?
puts 'You did not provide a token' puts 'You did not provide a token'
return return
end end
conn = Http.get_conn(url) conn = Http.get_conn(verbose, url)
response = conn.delete "/v1/token/#{token}" response = conn.delete "/v1/token/#{token}"
res_body = JSON.parse(response) res_body = JSON.parse(response)
puts res_body puts res_body
end end
def self.token_status(url, user, pass, token) def self.token_status(verbose, url, user, pass, token)
if token.nil? if token.nil?
puts 'You did not provide a token' puts 'You did not provide a token'
return return
end end
conn = Http.get_conn(url) conn = Http.get_conn(verbose, url)
response = conn.get "/v1/token/#{token}" response = conn.get "/v1/token/#{token}"
res_body = JSON.parse(response.body) res_body = JSON.parse(response.body)

View file

@ -1,10 +1,10 @@
require 'faraday' require 'faraday'
class Http class Http
def self.get_conn(url) def self.get_conn(verbose, url)
conn = Faraday.new(:url => url) do |faraday| conn = Faraday.new(:url => url) do |faraday|
faraday.request :url_encoded faraday.request :url_encoded
faraday.response :logger faraday.response :logger if verbose
faraday.adapter Faraday.default_adapter faraday.adapter Faraday.default_adapter
end end

View file

@ -3,8 +3,8 @@ require 'vmfloaty/http'
require 'json' require 'json'
class Pooler class Pooler
def self.list(url, os_filter=nil) def self.list(verbose, url, os_filter=nil)
conn = Http.get_conn(url) conn = Http.get_conn(verbose, url)
response = conn.get '/vm' response = conn.get '/vm'
response_body = JSON.parse(response.body) response_body = JSON.parse(response.body)
@ -18,9 +18,9 @@ class Pooler
hosts hosts
end end
def self.retrieve(os_type, token, url) def self.retrieve(verbose, os_type, token, url)
os = os_type.split(',') os = os_type.split(',')
conn = Http.get_conn(url) conn = Http.get_conn(verbose, url)
os_body = {} os_body = {}
os.each do |os_type| os.each do |os_type|
@ -41,9 +41,9 @@ class Pooler
res_body res_body
end end
def self.modify(url, hostname, token, lifetime, tags) def self.modify(verbose, url, hostname, token, lifetime, tags)
modify_body = {'lifetime'=>lifetime, 'tags'=>tags} modify_body = {'lifetime'=>lifetime, 'tags'=>tags}
conn = Http.get_conn(url) conn = Http.get_conn(verbose, url)
# need to use token # need to use token
response = conn.put "/#{hostname}" response = conn.put "/#{hostname}"
@ -52,9 +52,9 @@ class Pooler
res_body res_body
end end
def self.delete(url, hostname) def self.delete(verbose, url, hostname)
hosts = hostnames.split(',') hosts = hostnames.split(',')
conn = Http.get_conn(url) conn = Http.get_conn(verbose, url)
hosts.each do |host| hosts.each do |host|
puts "Scheduling host #{host} for deletion" puts "Scheduling host #{host} for deletion"
@ -64,24 +64,24 @@ class Pooler
end end
end end
def self.status(url) def self.status(verbose, url)
conn = Http.get_conn(url) conn = Http.get_conn(verbose, url)
response = conn.get '/status' response = conn.get '/status'
res_body = JSON.parse(response.body) res_body = JSON.parse(response.body)
res_body res_body
end end
def self.summary(url) def self.summary(verbose, url)
conn = Http.get_conn(url) conn = Http.get_conn(verbose, url)
response = conn.get '/summary' response = conn.get '/summary'
res_body = JSON.parse(response.body) res_body = JSON.parse(response.body)
res_body res_body
end end
def self.query(url, hostname) def self.query(verbose, url, hostname)
conn = Http.get_conn(url) conn = Http.get_conn(verbose, url)
response = conn.get "/vm/#{hostname}" response = conn.get "/vm/#{hostname}"
res_body = JSON.parse(response.body) res_body = JSON.parse(response.body)
@ -89,8 +89,8 @@ class Pooler
res_body res_body
end end
def self.snapshot(url, hostname, token) def self.snapshot(verbose, url, hostname, token)
conn = Http.get_conn(url) conn = Http.get_conn(verbose, url)
# need to use token # need to use token
response = conn.post "/#{hostname}/snapshot" response = conn.post "/#{hostname}/snapshot"
@ -98,8 +98,8 @@ class Pooler
res_body res_body
end end
def self.revert(url, hostname, token, snapshot_sha) def self.revert(verbose, url, hostname, token, snapshot_sha)
conn = Http.get_conn(url) conn = Http.get_conn(verbose, url)
# need to use token # need to use token
response = conn.post "/#{hostname}/snapshot/#{snapshot}" response = conn.post "/#{hostname}/snapshot/#{snapshot}"