mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 05:28:40 -05:00
(#32) Handle vmpooler responses when token is invalid
This commit adds an errors class to handle when pooler tokens are invalid. The retrieve method in Pooler will raise an AuthError if it gets an HTTP 401 from the vmpooler.
This commit is contained in:
parent
86e1792775
commit
05e9d5a0cc
3 changed files with 20 additions and 1 deletions
5
lib/vmfloaty/errors.rb
Normal file
5
lib/vmfloaty/errors.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class AuthError < StandardError
|
||||
def initialize(msg="Could not authenticate to pooler")
|
||||
super
|
||||
end
|
||||
end
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
require 'faraday'
|
||||
require 'vmfloaty/http'
|
||||
require 'json'
|
||||
require 'vmfloaty/errors'
|
||||
|
||||
class Pooler
|
||||
def self.list(verbose, url, os_filter=nil)
|
||||
|
|
@ -40,10 +41,13 @@ class Pooler
|
|||
response = conn.post "vm/#{os_string}"
|
||||
|
||||
res_body = JSON.parse(response.body)
|
||||
|
||||
if res_body["ok"]
|
||||
res_body
|
||||
elsif response.status == 401
|
||||
raise AuthError, "HTTP #{response.status}: The token provided could not authenticate to the pooler.\n#{res_body}"
|
||||
else
|
||||
raise "Failed to obtain VMs from the pooler at #{url}/vm/#{os_string}. #{res_body}"
|
||||
raise "HTTP #{response.status}: Failed to obtain VMs from the pooler at #{url}/vm/#{os_string}. #{res_body}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue