diff --git a/lib/vmfloaty/auth.rb b/lib/vmfloaty/auth.rb index 091b7c2..a1fdd60 100644 --- a/lib/vmfloaty/auth.rb +++ b/lib/vmfloaty/auth.rb @@ -12,11 +12,8 @@ class Auth resp = conn.post 'token' res_body = JSON.parse(resp.body) - if res_body['ok'] - return res_body['token'] - else - raise TokenError, "HTTP #{resp.status}: There was a problem requesting a token:\n#{res_body}" - end + return res_body['token'] if res_body['ok'] + raise TokenError, "HTTP #{resp.status}: There was a problem requesting a token:\n#{res_body}" end def self.delete_token(verbose, url, user, password, token) @@ -26,11 +23,8 @@ class Auth response = conn.delete "token/#{token}" res_body = JSON.parse(response.body) - if res_body['ok'] - return res_body - else - raise TokenError, "HTTP #{response.status}: There was a problem deleting a token:\n#{res_body}" - end + return res_body if res_body['ok'] + raise TokenError, "HTTP #{response.status}: There was a problem deleting a token:\n#{res_body}" end def self.token_status(verbose, url, token) @@ -41,10 +35,7 @@ class Auth response = conn.get "token/#{token}" res_body = JSON.parse(response.body) - if res_body['ok'] - return res_body - else - raise TokenError, "HTTP #{response.status}: There was a problem getting the status of a token:\n#{res_body}" - end + return res_body if res_body['ok'] + raise TokenError, "HTTP #{response.status}: There was a problem getting the status of a token:\n#{res_body}" end end diff --git a/lib/vmfloaty/ssh.rb b/lib/vmfloaty/ssh.rb index bf9cb76..e20d84d 100644 --- a/lib/vmfloaty/ssh.rb +++ b/lib/vmfloaty/ssh.rb @@ -22,18 +22,15 @@ class Ssh os_types[host_os] = 1 response = Pooler.retrieve(verbose, os_types, token, url) - if response['ok'] == true - user = host_os =~ /win/ ? 'Administrator' : 'root' + raise "Could not get vm from vmpooler:\n #{response}" unless response['ok'] + user = host_os =~ /win/ ? 'Administrator' : 'root' - hostname = "#{response[host_os]['hostname']}.#{response['domain']}" - cmd = "#{ssh_path} #{user}@#{hostname}" + hostname = "#{response[host_os]['hostname']}.#{response['domain']}" + cmd = "#{ssh_path} #{user}@#{hostname}" - # TODO: Should this respect more ssh settings? Can it be configured - # by users ssh config and does this respect those settings? - Kernel.exec(cmd) - else - raise "Could not get vm from vmpooler:\n #{response}" - end + # TODO: Should this respect more ssh settings? Can it be configured + # by users ssh config and does this respect those settings? + Kernel.exec(cmd) nil end end