mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 05:28:40 -05:00
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:
parent
7fb07a9a69
commit
9fc9820120
2 changed files with 15 additions and 14 deletions
|
|
@ -25,12 +25,20 @@ class Vmfloaty
|
||||||
c.option '--url STRING', String, 'URL of vmpooler'
|
c.option '--url STRING', String, 'URL of vmpooler'
|
||||||
c.option '--token STRING', String, 'Token for vmpooler'
|
c.option '--token STRING', String, 'Token for vmpooler'
|
||||||
c.option '--os STRING', String, 'Operating systems to retrieve'
|
c.option '--os STRING', String, 'Operating systems to retrieve'
|
||||||
|
c.option '--notoken', 'Makes a request without a token'
|
||||||
c.action do |args, options|
|
c.action do |args, options|
|
||||||
verbose = options.verbose || config['verbose']
|
verbose = options.verbose || config['verbose']
|
||||||
token = options.token || config['token']
|
token = options.token || config['token']
|
||||||
user = options.user ||= config['user']
|
user = options.user ||= config['user']
|
||||||
url = options.url ||= config['url']
|
url = options.url ||= config['url']
|
||||||
os_types = options.os
|
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
|
unless options.token
|
||||||
pass = password "Enter your password please:", '*'
|
pass = password "Enter your password please:", '*'
|
||||||
|
|
|
||||||
|
|
@ -19,22 +19,15 @@ class Pooler
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.retrieve(verbose, os_type, token, url)
|
def self.retrieve(verbose, os_type, token, url)
|
||||||
os = os_type.split(',')
|
os = os_type.gsub(',','+')
|
||||||
conn = Http.get_conn_with_token(verbose, url, token)
|
if token.nil?
|
||||||
os_body = {}
|
conn = Http.get_conn(verbose, url)
|
||||||
|
else
|
||||||
os.each do |os_type|
|
conn = Http.get_conn_with_token(verbose, url, token)
|
||||||
unless os_body.has_key?(os_type)
|
conn.headers['X-AUTH-TOKEN']
|
||||||
os_body[os_type] = 1
|
|
||||||
else
|
|
||||||
os_body[os_type] += 1
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
response = conn.post do |req|
|
response = conn.post "/vm/#{os}"
|
||||||
req.url '/vm'
|
|
||||||
req.body = os_body
|
|
||||||
end
|
|
||||||
|
|
||||||
res_body = JSON.parse(response.body)
|
res_body = JSON.parse(response.body)
|
||||||
res_body
|
res_body
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue