Simplify how floaty gets vms

Instead of building a json hash for each requested vm, sub the host
strings commas with + and append it to the request url.
This commit is contained in:
Brian Cain 2015-09-15 13:05:57 -07:00
parent 7fb07a9a69
commit 9fc9820120
2 changed files with 15 additions and 14 deletions

View file

@ -25,12 +25,20 @@ class Vmfloaty
c.option '--url STRING', String, 'URL of vmpooler'
c.option '--token STRING', String, 'Token for vmpooler'
c.option '--os STRING', String, 'Operating systems to retrieve'
c.option '--notoken', 'Makes a request without a token'
c.action do |args, options|
verbose = options.verbose || config['verbose']
token = options.token || config['token']
user = options.user ||= config['user']
url = options.url ||= config['url']
os_types = options.os
no_token = options.notoken
unless no_token.nil?
response = Pooler.retrieve(verbose, os_types, token, url)
puts response
return
end
unless options.token
pass = password "Enter your password please:", '*'

View file

@ -19,22 +19,15 @@ class Pooler
end
def self.retrieve(verbose, os_type, token, url)
os = os_type.split(',')
conn = Http.get_conn_with_token(verbose, url, token)
os_body = {}
os.each do |os_type|
unless os_body.has_key?(os_type)
os_body[os_type] = 1
os = os_type.gsub(',','+')
if token.nil?
conn = Http.get_conn(verbose, url)
else
os_body[os_type] += 1
end
conn = Http.get_conn_with_token(verbose, url, token)
conn.headers['X-AUTH-TOKEN']
end
response = conn.post do |req|
req.url '/vm'
req.body = os_body
end
response = conn.post "/vm/#{os}"
res_body = JSON.parse(response.body)
res_body