mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 05:28:40 -05:00
(rubocop) Fix Style/IfUnlessModifier
This commit is contained in:
parent
426e9ce96b
commit
6e1f626d7b
4 changed files with 19 additions and 57 deletions
|
|
@ -300,9 +300,7 @@ class Vmfloaty
|
||||||
hostname = args[0]
|
hostname = args[0]
|
||||||
snapshot_sha = args[1] || options.snapshot
|
snapshot_sha = args[1] || options.snapshot
|
||||||
|
|
||||||
if args[1] && options.snapshot
|
STDERR.puts "Two snapshot arguments were given....using snapshot #{snapshot_sha}" if args[1] && options.snapshot
|
||||||
STDERR.puts "Two snapshot arguments were given....using snapshot #{snapshot_sha}"
|
|
||||||
end
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
revert_req = service.revert(verbose, hostname, snapshot_sha)
|
revert_req = service.revert(verbose, hostname, snapshot_sha)
|
||||||
|
|
@ -419,9 +417,7 @@ class Vmfloaty
|
||||||
|
|
||||||
host_os = args.first
|
host_os = args.first
|
||||||
|
|
||||||
if args.length > 1
|
STDERR.puts "Can't ssh to multiple hosts; Using #{host_os} only..." if args.length > 1
|
||||||
STDERR.puts "Can't ssh to multiple hosts; Using #{host_os} only..."
|
|
||||||
end
|
|
||||||
|
|
||||||
service.ssh(verbose, host_os, use_token)
|
service.ssh(verbose, host_os, use_token)
|
||||||
exit 0
|
exit 0
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,7 @@ class NonstandardPooler
|
||||||
conn.headers['X-AUTH-TOKEN'] = token if token
|
conn.headers['X-AUTH-TOKEN'] = token if token
|
||||||
|
|
||||||
os_string = os_type.map { |os, num| Array(os) * num }.flatten.join('+')
|
os_string = os_type.map { |os, num| Array(os) * num }.flatten.join('+')
|
||||||
if os_string.empty?
|
raise MissingParamError, 'No operating systems provided to obtain.' if os_string.empty?
|
||||||
raise MissingParamError, 'No operating systems provided to obtain.'
|
|
||||||
end
|
|
||||||
|
|
||||||
response = conn.post "host/#{os_string}"
|
response = conn.post "host/#{os_string}"
|
||||||
|
|
||||||
|
|
@ -45,14 +43,10 @@ class NonstandardPooler
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.modify(verbose, url, hostname, token, modify_hash)
|
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' if token.nil?
|
||||||
raise TokenError, 'Token provided was nil; Request cannot be made to modify VM'
|
|
||||||
end
|
|
||||||
|
|
||||||
modify_hash.each do |key, _value|
|
modify_hash.each do |key, _value|
|
||||||
unless %i[reason reserved_for_reason].include? key
|
raise ModifyError, "Configured service type does not support modification of #{key}" unless %i[reason reserved_for_reason].include? key
|
||||||
raise ModifyError, "Configured service type does not support modification of #{key}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if modify_hash[:reason]
|
if modify_hash[:reason]
|
||||||
|
|
@ -84,9 +78,7 @@ class NonstandardPooler
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.delete(verbose, url, hosts, token)
|
def self.delete(verbose, url, hosts, token)
|
||||||
if token.nil?
|
raise TokenError, 'Token provided was nil; Request cannot be made to delete VM' if token.nil?
|
||||||
raise TokenError, 'Token provided was nil; Request cannot be made to delete VM'
|
|
||||||
end
|
|
||||||
|
|
||||||
conn = Http.get_conn(verbose, url)
|
conn = Http.get_conn(verbose, url)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,7 @@ class Pooler
|
||||||
def self.list_active(verbose, url, token)
|
def self.list_active(verbose, url, token)
|
||||||
status = Auth.token_status(verbose, url, token)
|
status = Auth.token_status(verbose, url, token)
|
||||||
vms = []
|
vms = []
|
||||||
if status[token] && status[token]['vms']
|
vms = status[token]['vms']['running'] if status[token] && status[token]['vms']
|
||||||
vms = status[token]['vms']['running']
|
|
||||||
end
|
|
||||||
vms
|
vms
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -38,9 +36,7 @@ class Pooler
|
||||||
conn.headers['X-AUTH-TOKEN'] = token if token
|
conn.headers['X-AUTH-TOKEN'] = token if token
|
||||||
|
|
||||||
os_string = os_type.map { |os, num| Array(os) * num }.flatten.join('+')
|
os_string = os_type.map { |os, num| Array(os) * num }.flatten.join('+')
|
||||||
if os_string.empty?
|
raise MissingParamError, 'No operating systems provided to obtain.' if os_string.empty?
|
||||||
raise MissingParamError, 'No operating systems provided to obtain.'
|
|
||||||
end
|
|
||||||
|
|
||||||
response = conn.post "vm/#{os_string}"
|
response = conn.post "vm/#{os_string}"
|
||||||
|
|
||||||
|
|
@ -56,14 +52,10 @@ class Pooler
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.modify(verbose, url, hostname, token, modify_hash)
|
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' if token.nil?
|
||||||
raise TokenError, 'Token provided was nil. Request cannot be made to modify vm'
|
|
||||||
end
|
|
||||||
|
|
||||||
modify_hash.keys.each do |key|
|
modify_hash.keys.each do |key|
|
||||||
unless %i[tags lifetime disk].include? key
|
raise ModifyError, "Configured service type does not support modification of #{key}." unless %i[tags lifetime disk].include? key
|
||||||
raise ModifyError, "Configured service type does not support modification of #{key}."
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
conn = Http.get_conn(verbose, url)
|
conn = Http.get_conn(verbose, url)
|
||||||
|
|
@ -84,9 +76,7 @@ class Pooler
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.disk(verbose, url, hostname, token, disk)
|
def self.disk(verbose, url, hostname, token, disk)
|
||||||
if token.nil?
|
raise TokenError, 'Token provided was nil. Request cannot be made to modify vm' if token.nil?
|
||||||
raise TokenError, 'Token provided was nil. Request cannot be made to modify vm'
|
|
||||||
end
|
|
||||||
|
|
||||||
conn = Http.get_conn(verbose, url)
|
conn = Http.get_conn(verbose, url)
|
||||||
conn.headers['X-AUTH-TOKEN'] = token
|
conn.headers['X-AUTH-TOKEN'] = token
|
||||||
|
|
@ -98,9 +88,7 @@ class Pooler
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.delete(verbose, url, hosts, token)
|
def self.delete(verbose, url, hosts, token)
|
||||||
if token.nil?
|
raise TokenError, 'Token provided was nil. Request cannot be made to delete vm' if token.nil?
|
||||||
raise TokenError, 'Token provided was nil. Request cannot be made to delete vm'
|
|
||||||
end
|
|
||||||
|
|
||||||
conn = Http.get_conn(verbose, url)
|
conn = Http.get_conn(verbose, url)
|
||||||
|
|
||||||
|
|
@ -143,9 +131,7 @@ class Pooler
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.snapshot(verbose, url, hostname, token)
|
def self.snapshot(verbose, url, hostname, token)
|
||||||
if token.nil?
|
raise TokenError, 'Token provided was nil. Request cannot be made to snapshot vm' if token.nil?
|
||||||
raise TokenError, 'Token provided was nil. Request cannot be made to snapshot vm'
|
|
||||||
end
|
|
||||||
|
|
||||||
conn = Http.get_conn(verbose, url)
|
conn = Http.get_conn(verbose, url)
|
||||||
conn.headers['X-AUTH-TOKEN'] = token
|
conn.headers['X-AUTH-TOKEN'] = token
|
||||||
|
|
@ -156,16 +142,12 @@ class Pooler
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.revert(verbose, url, hostname, token, snapshot_sha)
|
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' if token.nil?
|
||||||
raise TokenError, 'Token provided was nil. Request cannot be made to revert vm'
|
|
||||||
end
|
|
||||||
|
|
||||||
conn = Http.get_conn(verbose, url)
|
conn = Http.get_conn(verbose, url)
|
||||||
conn.headers['X-AUTH-TOKEN'] = token
|
conn.headers['X-AUTH-TOKEN'] = token
|
||||||
|
|
||||||
if snapshot_sha.nil?
|
raise "Snapshot SHA provided was nil, could not revert #{hostname}" if snapshot_sha.nil?
|
||||||
raise "Snapshot SHA provided was nil, could not revert #{hostname}"
|
|
||||||
end
|
|
||||||
|
|
||||||
response = conn.post "vm/#{hostname}/snapshot/#{snapshot_sha}"
|
response = conn.post "vm/#{hostname}/snapshot/#{snapshot_sha}"
|
||||||
res_body = JSON.parse(response.body)
|
res_body = JSON.parse(response.body)
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,7 @@ class Utils
|
||||||
# }
|
# }
|
||||||
# }
|
# }
|
||||||
|
|
||||||
unless response_body.delete('ok')
|
raise ArgumentError, "Bad GET response passed to format_hosts: #{response_body.to_json}" unless response_body.delete('ok')
|
||||||
raise ArgumentError, "Bad GET response passed to format_hosts: #{response_body.to_json}"
|
|
||||||
end
|
|
||||||
|
|
||||||
# vmpooler reports the domain separately from the hostname
|
# vmpooler reports the domain separately from the hostname
|
||||||
domain = response_body.delete('domain')
|
domain = response_body.delete('domain')
|
||||||
|
|
@ -81,18 +79,14 @@ class Utils
|
||||||
case service.type
|
case service.type
|
||||||
when 'Pooler'
|
when 'Pooler'
|
||||||
tag_pairs = []
|
tag_pairs = []
|
||||||
unless host_data['tags'].nil?
|
tag_pairs = host_data['tags'].map { |key, value| "#{key}: #{value}" } unless host_data['tags'].nil?
|
||||||
tag_pairs = host_data['tags'].map { |key, value| "#{key}: #{value}" }
|
|
||||||
end
|
|
||||||
duration = "#{host_data['running']}/#{host_data['lifetime']} hours"
|
duration = "#{host_data['running']}/#{host_data['lifetime']} hours"
|
||||||
metadata = [host_data['template'], duration, *tag_pairs]
|
metadata = [host_data['template'], duration, *tag_pairs]
|
||||||
puts "- #{hostname}.#{host_data['domain']} (#{metadata.join(', ')})"
|
puts "- #{hostname}.#{host_data['domain']} (#{metadata.join(', ')})"
|
||||||
when 'NonstandardPooler'
|
when 'NonstandardPooler'
|
||||||
line = "- #{host_data['fqdn']} (#{host_data['os_triple']}"
|
line = "- #{host_data['fqdn']} (#{host_data['os_triple']}"
|
||||||
line += ", #{host_data['hours_left_on_reservation']}h remaining"
|
line += ", #{host_data['hours_left_on_reservation']}h remaining"
|
||||||
unless host_data['reserved_for_reason'].empty?
|
line += ", reason: #{host_data['reserved_for_reason']}" unless host_data['reserved_for_reason'].empty?
|
||||||
line += ", reason: #{host_data['reserved_for_reason']}"
|
|
||||||
end
|
|
||||||
line += ')'
|
line += ')'
|
||||||
puts line
|
puts line
|
||||||
else
|
else
|
||||||
|
|
@ -185,9 +179,7 @@ class Utils
|
||||||
service_config.merge! values
|
service_config.merge! values
|
||||||
else
|
else
|
||||||
# If the user provided a service name at the command line, use that service if posible, or fail
|
# If the user provided a service name at the command line, use that service if posible, or fail
|
||||||
unless config['services'][options.service]
|
raise ArgumentError, "Could not find a configured service named '#{options.service}' in ~/.vmfloaty.yml" unless config['services'][options.service]
|
||||||
raise ArgumentError, "Could not find a configured service named '#{options.service}' in ~/.vmfloaty.yml"
|
|
||||||
end
|
|
||||||
|
|
||||||
# If the service is configured but some values are missing, use the top-level defaults to fill them in
|
# If the service is configured but some values are missing, use the top-level defaults to fill them in
|
||||||
service_config.merge! config['services'][options.service]
|
service_config.merge! config['services'][options.service]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue