Skip to content

Commit 302d52a

Browse files
authored
Merge pull request #135 from puppetlabs/rubocop_auto_fix
Run the rubocop auto_correct
2 parents d0fb0f3 + eb99ba1 commit 302d52a

21 files changed

+516
-511
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ source 'https://rubygems.org'
44

55
gemspec
66

7-
gem 'rake', :require => false
7+
gem 'rake', require: false
88

99
group :test do
1010
gem 'coveralls', '~> 0.8.23'

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ RuboCop::RakeTask.new(:rubocop) do |task|
2828
end
2929

3030
# Default task is to run the unit tests
31-
task :default => :spec
31+
task default: :spec

lib/vmfloaty.rb

Lines changed: 50 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class Vmfloaty
2020

2121
def run # rubocop:disable Metrics/AbcSize
2222
program :version, Vmfloaty::VERSION
23-
program :description, "A CLI helper tool for Puppet's vmpooler to help you stay afloat.\n\nConfiguration may be placed in a ~/.vmfloaty.yml file."
23+
program :description,
24+
"A CLI helper tool for Puppet's vmpooler to help you stay afloat.\n\nConfiguration may be placed in a ~/.vmfloaty.yml file."
2425

2526
config = Conf.read_config
2627

@@ -43,9 +44,7 @@ def run # rubocop:disable Metrics/AbcSize
4344
c.option '--loglevel STRING', String, 'the log level to use (debug, info, error)'
4445
c.action do |args, options|
4546
verbose = options.verbose || config['verbose']
46-
if options.loglevel
47-
FloatyLogger.setlevel = options.loglevel
48-
end
47+
FloatyLogger.setlevel = options.loglevel if options.loglevel
4948
service = Service.new(options, config)
5049
use_token = !options.notoken
5150
force = options.force
@@ -100,39 +99,35 @@ def run # rubocop:disable Metrics/AbcSize
10099
c.option '--loglevel STRING', String, 'the log level to use (debug, info, error)'
101100
c.action do |args, options|
102101
verbose = options.verbose || config['verbose']
103-
if options.loglevel
104-
FloatyLogger.setlevel = options.loglevel
105-
end
102+
FloatyLogger.setlevel = options.loglevel if options.loglevel
106103

107104
service = Service.new(options, config)
108105
filter = args[0]
109106

110107
if options.active
111108
# list active vms
112-
if service.type == "ABS"
113-
# this is actually job_ids
114-
running_vms = service.list_active_job_ids(verbose, service.url, service.user)
115-
else
116-
running_vms = service.list_active(verbose)
117-
end
109+
running_vms = if service.type == 'ABS'
110+
# this is actually job_ids
111+
service.list_active_job_ids(verbose, service.url, service.user)
112+
else
113+
service.list_active(verbose)
114+
end
118115
host = URI.parse(service.url).host
119116
if running_vms.empty?
120117
if options.json
121118
puts {}.to_json
122119
else
123120
FloatyLogger.info "You have no running VMs on #{host}"
124121
end
125-
else
126-
if options.json
127-
puts Utils.get_host_data(verbose, service, running_vms).to_json
128-
elsif options.hostnameonly
129-
Utils.get_host_data(verbose, service, running_vms).each do |hostname, host_data|
130-
Utils.print_fqdn_for_host(service, hostname, host_data)
131-
end
132-
else
133-
puts "Your VMs on #{host}:"
134-
Utils.pretty_print_hosts(verbose, service, running_vms)
122+
elsif options.json
123+
puts Utils.get_host_data(verbose, service, running_vms).to_json
124+
elsif options.hostnameonly
125+
Utils.get_host_data(verbose, service, running_vms).each do |hostname, host_data|
126+
Utils.print_fqdn_for_host(service, hostname, host_data)
135127
end
128+
else
129+
puts "Your VMs on #{host}:"
130+
Utils.pretty_print_hosts(verbose, service, running_vms)
136131
end
137132
else
138133
# list available vms from pooler
@@ -164,7 +159,8 @@ def run # rubocop:disable Metrics/AbcSize
164159
c.syntax = 'floaty modify hostname [options]'
165160
c.summary = 'Modify a VM\'s tags, time to live, disk space, or reservation reason'
166161
c.description = 'This command makes modifications to the virtual machines state in the pooler service. You can either append tags to the vm, increase how long it stays active for, or increase the amount of disk space.'
167-
c.example 'Modifies myhost1 to have a TTL of 12 hours and adds a custom tag', 'floaty modify myhost1 --lifetime 12 --url https://myurl --token mytokenstring --tags \'{"tag":"myvalue"}\''
162+
c.example 'Modifies myhost1 to have a TTL of 12 hours and adds a custom tag',
163+
'floaty modify myhost1 --lifetime 12 --url https://myurl --token mytokenstring --tags \'{"tag":"myvalue"}\''
168164
c.option '--verbose', 'Enables verbose output'
169165
c.option '--service STRING', String, 'Configured pooler service name'
170166
c.option '--url STRING', String, 'URL of pooler service'
@@ -185,31 +181,29 @@ def run # rubocop:disable Metrics/AbcSize
185181
exit 1
186182
end
187183
running_vms =
188-
if modify_all
189-
service.list_active(verbose)
190-
else
191-
hostname.split(',')
192-
end
184+
if modify_all
185+
service.list_active(verbose)
186+
else
187+
hostname.split(',')
188+
end
193189

194190
tags = options.tags ? JSON.parse(options.tags) : nil
195191
modify_hash = {
196-
:lifetime => options.lifetime,
197-
:disk => options.disk,
198-
:tags => tags,
199-
:reason => options.reason,
192+
lifetime: options.lifetime,
193+
disk: options.disk,
194+
tags: tags,
195+
reason: options.reason
200196
}
201197
modify_hash.delete_if { |_, value| value.nil? }
202198

203199
unless modify_hash.empty?
204200
ok = true
205201
modified_hash = {}
206202
running_vms.each do |vm|
207-
begin
208-
modified_hash[vm] = service.modify(verbose, vm, modify_hash)
209-
rescue ModifyError => e
210-
FloatyLogger.error e
211-
ok = false
212-
end
203+
modified_hash[vm] = service.modify(verbose, vm, modify_hash)
204+
rescue ModifyError => e
205+
FloatyLogger.error e
206+
ok = false
213207
end
214208
if ok
215209
if modify_all
@@ -241,9 +235,7 @@ def run # rubocop:disable Metrics/AbcSize
241235
c.option '--loglevel STRING', String, 'the log level to use (debug, info, error)'
242236
c.action do |args, options|
243237
verbose = options.verbose || config['verbose']
244-
if options.loglevel
245-
FloatyLogger.setlevel = options.loglevel
246-
end
238+
FloatyLogger.setlevel = options.loglevel if options.loglevel
247239

248240
service = Service.new(options, config)
249241
hostnames = args[0]
@@ -254,17 +246,17 @@ def run # rubocop:disable Metrics/AbcSize
254246
successes = []
255247

256248
if delete_all
257-
if service.type == "ABS"
258-
# this is actually job_ids
259-
running_vms = service.list_active_job_ids(verbose, service.url, service.user)
260-
else
261-
running_vms = service.list_active(verbose)
262-
end
249+
running_vms = if service.type == 'ABS'
250+
# this is actually job_ids
251+
service.list_active_job_ids(verbose, service.url, service.user)
252+
else
253+
service.list_active(verbose)
254+
end
263255
if running_vms.empty?
264256
if options.json
265257
puts {}.to_json
266258
else
267-
FloatyLogger.info "You have no running VMs."
259+
FloatyLogger.info 'You have no running VMs.'
268260
end
269261
else
270262
confirmed = true
@@ -328,7 +320,8 @@ def run # rubocop:disable Metrics/AbcSize
328320
c.syntax = 'floaty snapshot hostname [options]'
329321
c.summary = 'Takes a snapshot of a given vm'
330322
c.description = 'Will request a snapshot be taken of the given hostname in the pooler service. This command is known to take a while depending on how much load is on the pooler service.'
331-
c.example 'Takes a snapshot for a given host', 'floaty snapshot myvm.example.com --url http://vmpooler.example.com --token a9znth9dn01t416hrguu56ze37t790bl'
323+
c.example 'Takes a snapshot for a given host',
324+
'floaty snapshot myvm.example.com --url http://vmpooler.example.com --token a9znth9dn01t416hrguu56ze37t790bl'
332325
c.option '--verbose', 'Enables verbose output'
333326
c.option '--service STRING', String, 'Configured pooler service name'
334327
c.option '--url STRING', String, 'URL of pooler service'
@@ -354,7 +347,8 @@ def run # rubocop:disable Metrics/AbcSize
354347
c.syntax = 'floaty revert hostname snapshot [options]'
355348
c.summary = 'Reverts a vm to a specified snapshot'
356349
c.description = 'Given a snapshot SHA, vmfloaty will request a revert to the pooler service to go back to a previous snapshot.'
357-
c.example 'Reverts to a snapshot for a given host', 'floaty revert myvm.example.com n4eb4kdtp7rwv4x158366vd9jhac8btq --url http://vmpooler.example.com --token a9znth9dn01t416hrguu56ze37t790bl'
350+
c.example 'Reverts to a snapshot for a given host',
351+
'floaty revert myvm.example.com n4eb4kdtp7rwv4x158366vd9jhac8btq --url http://vmpooler.example.com --token a9znth9dn01t416hrguu56ze37t790bl'
358352
c.option '--verbose', 'Enables verbose output'
359353
c.option '--service STRING', String, 'Configured pooler service name'
360354
c.option '--url STRING', String, 'URL of pooler service'
@@ -366,7 +360,9 @@ def run # rubocop:disable Metrics/AbcSize
366360
hostname = args[0]
367361
snapshot_sha = args[1] || options.snapshot
368362

369-
FloatyLogger.info "Two snapshot arguments were given....using snapshot #{snapshot_sha}" if args[1] && options.snapshot
363+
if args[1] && options.snapshot
364+
FloatyLogger.info "Two snapshot arguments were given....using snapshot #{snapshot_sha}"
365+
end
370366

371367
begin
372368
revert_req = service.revert(verbose, hostname, snapshot_sha)
@@ -391,9 +387,7 @@ def run # rubocop:disable Metrics/AbcSize
391387
c.option '--loglevel STRING', String, 'the log level to use (debug, info, error)'
392388
c.action do |_, options|
393389
verbose = options.verbose || config['verbose']
394-
if options.loglevel
395-
FloatyLogger.setlevel = options.loglevel
396-
end
390+
FloatyLogger.setlevel = options.loglevel if options.loglevel
397391
service = Service.new(options, config)
398392
if options.json
399393
pp service.status(verbose)
@@ -527,7 +521,7 @@ def run # rubocop:disable Metrics/AbcSize
527521
c.example 'Print a list of the valid service types', 'floaty service types'
528522
c.example 'Print a sample config file with multiple services', 'floaty service examples'
529523
c.example 'list vms from the service named "nspooler-prod"', 'floaty list --service nspooler-prod'
530-
c.action do |args, options|
524+
c.action do |args, _options|
531525
action = args.first
532526

533527
example_config = Utils.strip_heredoc(<<-CONFIG)

0 commit comments

Comments
 (0)