From 54893cf5fb42320063e2bee4b18d8046286794aa Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Fri, 9 Oct 2015 22:06:14 -0700 Subject: [PATCH] Improve how to retrieve vms This commit changes the get command to have users request vms by specifying the hosts they want and then the number of hosts rather than having to say each one separated by a comma. --- README.md | 2 +- lib/vmfloaty.rb | 12 +++++++++--- lib/vmfloaty/pooler.rb | 12 ++++++++++-- lib/vmfloaty/version.rb | 2 +- vmfloaty.gemspec | 2 +- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 659cefd..168c812 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ This command will then ask you to log in. If successful, it will return a token Grabbing vms: ``` -floaty get centos-7,debian-7,windows-10 --token mytokenstring --url https://vmpooler.mycompany.net +floaty get centos-7-x86_64=2 debian-7-x86_64=1 windows-10=3 --token mytokenstring --url https://vmpooler.mycompany.net ``` ### vmfloaty dotfile diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index 4e89705..9b459e7 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -18,10 +18,10 @@ class Vmfloaty config = Conf.read_config command :get do |c| - c.syntax = 'floaty get [hostname,...]' + c.syntax = 'floaty get os_type1=x ox_type2=y ...' c.summary = 'Gets a vm or vms based on the os flag' c.description = '' - c.example 'Gets 3 vms', 'floaty get centos,centos,debian --user brian --url http://vmpooler.example.com' + c.example 'Gets 3 vms', 'floaty get centos=3 debian=1 --user brian --url http://vmpooler.example.com' c.option '--verbose', 'Enables verbose output' c.option '--user STRING', String, 'User to authenticate with' c.option '--url STRING', String, 'URL of vmpooler' @@ -32,7 +32,13 @@ class Vmfloaty token = options.token || config['token'] user = options.user ||= config['user'] url = options.url ||= config['url'] - os_types = args[0] + + os_types = {} + args.each do |arg| + os_arr = arg.split("=") + os_types[os_arr[0]] = os_arr[1].to_i + end + no_token = options.notoken if no_token diff --git a/lib/vmfloaty/pooler.rb b/lib/vmfloaty/pooler.rb index 2c82e6c..0be14a9 100644 --- a/lib/vmfloaty/pooler.rb +++ b/lib/vmfloaty/pooler.rb @@ -19,13 +19,21 @@ class Pooler end def self.retrieve(verbose, os_type, token, url) - os = os_type.gsub(',','+') conn = Http.get_conn(verbose, url) if token conn.headers['X-AUTH-TOKEN'] = token end - response = conn.post "/vm/#{os}" + os_string = "" + os_type.each do |os,num| + num.times do |i| + os_string << os+"+" + end + end + + os_string = os_string.chomp("+") + + response = conn.post "/vm/#{os_string}" res_body = JSON.parse(response.body) res_body diff --git a/lib/vmfloaty/version.rb b/lib/vmfloaty/version.rb index 2e021a9..cb841ee 100644 --- a/lib/vmfloaty/version.rb +++ b/lib/vmfloaty/version.rb @@ -1,6 +1,6 @@ class Version - @version = '0.2.6' + @version = '0.2.7' def self.get @version diff --git a/vmfloaty.gemspec b/vmfloaty.gemspec index 9b703a0..2a6f877 100644 --- a/vmfloaty.gemspec +++ b/vmfloaty.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'vmfloaty' - s.version = '0.2.6' + s.version = '0.2.7' s.authors = ['Brian Cain'] s.email = ['brian.cain@puppetlabs.com'] s.license = 'Apache'