From 9fc9820120c73eb756982c33157b043395fcb02e Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Tue, 15 Sep 2015 13:05:57 -0700 Subject: [PATCH] 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. --- lib/vmfloaty.rb | 8 ++++++++ lib/vmfloaty/pooler.rb | 21 +++++++-------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index a8fc29f..b7e104c 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -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:", '*' diff --git a/lib/vmfloaty/pooler.rb b/lib/vmfloaty/pooler.rb index 5eda873..25b79c7 100644 --- a/lib/vmfloaty/pooler.rb +++ b/lib/vmfloaty/pooler.rb @@ -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 - else - os_body[os_type] += 1 - end + os = os_type.gsub(',','+') + if token.nil? + conn = Http.get_conn(verbose, url) + else + 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