mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 05:28:40 -05:00
(rubocop) Fix Style/StringLiterals
This commit is contained in:
parent
cf2295ccfd
commit
1272343cdd
12 changed files with 181 additions and 181 deletions
|
|
@ -43,7 +43,7 @@ class Vmfloaty
|
|||
force = options.force
|
||||
|
||||
if args.empty?
|
||||
STDERR.puts "No operating systems provided to obtain. See `floaty get --help` for more information on how to get VMs."
|
||||
STDERR.puts 'No operating systems provided to obtain. See `floaty get --help` for more information on how to get VMs.'
|
||||
exit 1
|
||||
end
|
||||
|
||||
|
|
@ -53,12 +53,12 @@ class Vmfloaty
|
|||
large_pool_requests = os_types.select{|_,v| v > max_pool_request}
|
||||
if ! large_pool_requests.empty? and ! force
|
||||
STDERR.puts "Requesting vms over #{max_pool_request} requires a --force flag."
|
||||
STDERR.puts "Try again with `floaty get --force`"
|
||||
STDERR.puts 'Try again with `floaty get --force`'
|
||||
exit 1
|
||||
end
|
||||
|
||||
if os_types.empty?
|
||||
STDERR.puts "No operating systems provided to obtain. See `floaty get --help` for more information on how to get VMs."
|
||||
STDERR.puts 'No operating systems provided to obtain. See `floaty get --help` for more information on how to get VMs.'
|
||||
exit 1
|
||||
end
|
||||
|
||||
|
|
@ -144,10 +144,10 @@ class Vmfloaty
|
|||
modify_all = options.all
|
||||
|
||||
if hostname.nil? and !modify_all
|
||||
STDERR.puts "ERROR: Provide a hostname or specify --all."
|
||||
STDERR.puts 'ERROR: Provide a hostname or specify --all.'
|
||||
exit 1
|
||||
end
|
||||
running_vms = modify_all ? service.list_active(verbose) : hostname.split(",")
|
||||
running_vms = modify_all ? service.list_active(verbose) : hostname.split(',')
|
||||
|
||||
tags = options.tags ? JSON.parse(options.tags) : nil
|
||||
modify_hash = {
|
||||
|
|
@ -171,11 +171,11 @@ class Vmfloaty
|
|||
end
|
||||
if ok
|
||||
if modify_all
|
||||
puts "Successfully modified all VMs."
|
||||
puts 'Successfully modified all VMs.'
|
||||
else
|
||||
puts "Successfully modified VM #{hostname}."
|
||||
end
|
||||
puts "Use `floaty list --active` to see the results."
|
||||
puts 'Use `floaty list --active` to see the results.'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -205,7 +205,7 @@ class Vmfloaty
|
|||
if delete_all
|
||||
running_vms = service.list_active(verbose)
|
||||
if running_vms.empty?
|
||||
STDERR.puts "You have no running VMs."
|
||||
STDERR.puts 'You have no running VMs.'
|
||||
else
|
||||
Utils.pretty_print_hosts(verbose, service, running_vms)
|
||||
# Confirm deletion
|
||||
|
|
@ -236,7 +236,7 @@ class Vmfloaty
|
|||
end
|
||||
end
|
||||
else
|
||||
STDERR.puts "You did not provide any hosts to delete"
|
||||
STDERR.puts 'You did not provide any hosts to delete'
|
||||
exit 1
|
||||
end
|
||||
|
||||
|
|
@ -417,7 +417,7 @@ class Vmfloaty
|
|||
use_token = !options.notoken
|
||||
|
||||
if args.empty?
|
||||
STDERR.puts "No operating systems provided to obtain. See `floaty ssh --help` for more information on how to get VMs."
|
||||
STDERR.puts 'No operating systems provided to obtain. See `floaty ssh --help` for more information on how to get VMs.'
|
||||
exit 1
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@ class Auth
|
|||
def self.get_token(verbose, url, user, password)
|
||||
conn = Http.get_conn_with_auth(verbose, url, user, password)
|
||||
|
||||
resp = conn.post "token"
|
||||
resp = conn.post 'token'
|
||||
|
||||
res_body = JSON.parse(resp.body)
|
||||
if res_body["ok"]
|
||||
return res_body["token"]
|
||||
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
|
||||
|
|
@ -26,7 +26,7 @@ class Auth
|
|||
|
||||
response = conn.delete "token/#{token}"
|
||||
res_body = JSON.parse(response.body)
|
||||
if res_body["ok"]
|
||||
if res_body['ok']
|
||||
return res_body
|
||||
else
|
||||
raise TokenError, "HTTP #{response.status}: There was a problem deleting a token:\n#{res_body}"
|
||||
|
|
@ -43,7 +43,7 @@ class Auth
|
|||
response = conn.get "token/#{token}"
|
||||
res_body = JSON.parse(response.body)
|
||||
|
||||
if res_body["ok"]
|
||||
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}"
|
||||
|
|
|
|||
|
|
@ -1,23 +1,23 @@
|
|||
class AuthError < StandardError
|
||||
def initialize(msg="Could not authenticate to pooler")
|
||||
def initialize(msg='Could not authenticate to pooler')
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
class TokenError < StandardError
|
||||
def initialize(msg="Could not do operation with token provided")
|
||||
def initialize(msg='Could not do operation with token provided')
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
class MissingParamError < StandardError
|
||||
def initialize(msg="Argument provided to function is missing")
|
||||
def initialize(msg='Argument provided to function is missing')
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
class ModifyError < StandardError
|
||||
def initialize(msg="Could not modify VM")
|
||||
def initialize(msg='Could not modify VM')
|
||||
super
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class Http
|
|||
|
||||
def self.get_conn(verbose, url)
|
||||
if url.nil?
|
||||
raise "Did not provide a url to connect to"
|
||||
raise 'Did not provide a url to connect to'
|
||||
end
|
||||
|
||||
unless is_url(url)
|
||||
|
|
@ -36,11 +36,11 @@ class Http
|
|||
|
||||
def self.get_conn_with_auth(verbose, url, user, password)
|
||||
if url.nil?
|
||||
raise "Did not provide a url to connect to"
|
||||
raise 'Did not provide a url to connect to'
|
||||
end
|
||||
|
||||
if user.nil?
|
||||
raise "You did not provide a user to authenticate with"
|
||||
raise 'You did not provide a user to authenticate with'
|
||||
end
|
||||
|
||||
unless is_url(url)
|
||||
|
|
|
|||
|
|
@ -37,24 +37,24 @@ class Pooler
|
|||
conn.headers['X-AUTH-TOKEN'] = token
|
||||
end
|
||||
|
||||
os_string = ""
|
||||
os_string = ''
|
||||
os_type.each do |os,num|
|
||||
num.times do |i|
|
||||
os_string << os+"+"
|
||||
os_string << os+'+'
|
||||
end
|
||||
end
|
||||
|
||||
os_string = os_string.chomp("+")
|
||||
os_string = os_string.chomp('+')
|
||||
|
||||
if os_string.size == 0
|
||||
raise MissingParamError, "No operating systems provided to obtain."
|
||||
raise MissingParamError, 'No operating systems provided to obtain.'
|
||||
end
|
||||
|
||||
response = conn.post "vm/#{os_string}"
|
||||
|
||||
res_body = JSON.parse(response.body)
|
||||
|
||||
if res_body["ok"]
|
||||
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}"
|
||||
|
|
@ -65,7 +65,7 @@ class Pooler
|
|||
|
||||
def self.modify(verbose, url, hostname, token, modify_hash)
|
||||
if token.nil?
|
||||
raise TokenError, "Token provided was nil. Request cannot be made to modify vm"
|
||||
raise TokenError, 'Token provided was nil. Request cannot be made to modify vm'
|
||||
end
|
||||
|
||||
modify_hash.keys.each do |key|
|
||||
|
|
@ -93,7 +93,7 @@ class Pooler
|
|||
|
||||
def self.disk(verbose, url, hostname, token, disk)
|
||||
if token.nil?
|
||||
raise TokenError, "Token provided was nil. Request cannot be made to modify vm"
|
||||
raise TokenError, 'Token provided was nil. Request cannot be made to modify vm'
|
||||
end
|
||||
|
||||
conn = Http.get_conn(verbose, url)
|
||||
|
|
@ -107,7 +107,7 @@ class Pooler
|
|||
|
||||
def self.delete(verbose, url, hosts, token)
|
||||
if token.nil?
|
||||
raise TokenError, "Token provided was nil. Request cannot be made to delete vm"
|
||||
raise TokenError, 'Token provided was nil. Request cannot be made to delete vm'
|
||||
end
|
||||
|
||||
conn = Http.get_conn(verbose, url)
|
||||
|
|
@ -154,7 +154,7 @@ class Pooler
|
|||
|
||||
def self.snapshot(verbose, url, hostname, token)
|
||||
if token.nil?
|
||||
raise TokenError, "Token provided was nil. Request cannot be made to snapshot vm"
|
||||
raise TokenError, 'Token provided was nil. Request cannot be made to snapshot vm'
|
||||
end
|
||||
|
||||
conn = Http.get_conn(verbose, url)
|
||||
|
|
@ -167,7 +167,7 @@ class Pooler
|
|||
|
||||
def self.revert(verbose, url, hostname, token, snapshot_sha)
|
||||
if token.nil?
|
||||
raise TokenError, "Token provided was nil. Request cannot be made to revert vm"
|
||||
raise TokenError, 'Token provided was nil. Request cannot be made to revert vm'
|
||||
end
|
||||
|
||||
conn = Http.get_conn(verbose, url)
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class Service
|
|||
|
||||
def user
|
||||
unless @config['user']
|
||||
puts "Enter your pooler service username:"
|
||||
puts 'Enter your pooler service username:'
|
||||
@config['user'] = STDIN.gets.chomp
|
||||
end
|
||||
@config['user']
|
||||
|
|
@ -39,7 +39,7 @@ class Service
|
|||
|
||||
def token
|
||||
unless @config['token']
|
||||
puts "No token found. Retrieving a token..."
|
||||
puts 'No token found. Retrieving a token...'
|
||||
@config['token'] = get_new_token(nil)
|
||||
end
|
||||
@config['token']
|
||||
|
|
@ -47,13 +47,13 @@ class Service
|
|||
|
||||
def get_new_token(verbose)
|
||||
username = user
|
||||
pass = Commander::UI::password "Enter your pooler service password:", '*'
|
||||
pass = Commander::UI::password 'Enter your pooler service password:', '*'
|
||||
Auth.get_token(verbose, url, username, pass)
|
||||
end
|
||||
|
||||
def delete_token(verbose, token_value = @config['token'])
|
||||
username = user
|
||||
pass = Commander::UI::password "Enter your pooler service password:", '*'
|
||||
pass = Commander::UI::password 'Enter your pooler service password:', '*'
|
||||
Auth.delete_token(verbose, url, username, pass, token_value)
|
||||
end
|
||||
|
||||
|
|
@ -91,9 +91,9 @@ class Service
|
|||
|
||||
def pretty_print_running(verbose, hostnames = [])
|
||||
if hostnames.empty?
|
||||
puts "You have no running VMs."
|
||||
puts 'You have no running VMs.'
|
||||
else
|
||||
puts "Running VMs:"
|
||||
puts 'Running VMs:'
|
||||
@service_object.pretty_print_hosts(verbose, hostnames, url)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -14,19 +14,19 @@ class Ssh
|
|||
end
|
||||
|
||||
def self.ssh(verbose, host_os, token, url)
|
||||
ssh_path = which("ssh")
|
||||
ssh_path = which('ssh')
|
||||
if !ssh_path
|
||||
raise "Could not determine path to ssh"
|
||||
raise 'Could not determine path to ssh'
|
||||
end
|
||||
os_types = {}
|
||||
os_types[host_os] = 1
|
||||
|
||||
response = Pooler.retrieve(verbose, os_types, token, url)
|
||||
if response["ok"] == true
|
||||
if response['ok'] == true
|
||||
if host_os =~ /win/
|
||||
user = "Administrator"
|
||||
user = 'Administrator'
|
||||
else
|
||||
user = "root"
|
||||
user = 'root'
|
||||
end
|
||||
|
||||
hostname = "#{response[host_os]["hostname"]}.#{response["domain"]}"
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ class Utils
|
|||
# ...]
|
||||
os_types = {}
|
||||
os_args.each do |arg|
|
||||
os_arr = arg.split("=")
|
||||
os_arr = arg.split('=')
|
||||
if os_arr.size == 1
|
||||
# assume they didn't specify an = sign if split returns 1 size
|
||||
os_types[os_arr[0]] = 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue