floatyhelper 1.4 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/floatyhelper.rb CHANGED
@@ -3,10 +3,12 @@
3
3
  require 'rubygems'
4
4
  require 'commander'
5
5
 
6
- require 'floatyhelper/conf'
6
+ require 'floatyhelper/config'
7
7
  require 'floatyhelper/hosts'
8
+ require 'floatyhelper/floaty'
8
9
  require 'floatyhelper/groups'
9
10
  require 'floatyhelper/vm'
11
+ require 'floatyhelper/version'
10
12
  require 'colorize'
11
13
 
12
14
  class Floatyhelper
@@ -14,25 +16,71 @@ class Floatyhelper
14
16
 
15
17
  def run
16
18
  program :name, 'floatyhelper'
17
- program :version, '1.0.0'
19
+ program :version, FloatyhelperVersion::VERSION
18
20
  program :description, <<~EOT
19
- Commands for manipulating vmpooler VMs with floaty. Use the addhosts command from within a pe_acceptance_tests folder
20
- that has recently finished a run to add those hosts to the list of hosts managed by floatyhelper (or specify a sut.log
21
- file directly).
21
+ Commands for manipulating vmpooler VMs with floaty. Use the addhosts command from within a pe_acceptance_tests folder
22
+ that has recently finished a run to add those hosts to the list of hosts managed by floatyhelper (or specify a sut.log
23
+ file directly).
22
24
  EOT
23
25
 
24
26
  default_command :help
25
27
 
28
+ command :config do |c|
29
+ c.syntax = 'floatyhelper config [get <setting>|set <setting> <value>|list]'
30
+ c.summary = 'Get, set, or list floatyhelper configuration options'
31
+ c.description = <<~EOT
32
+ This command will get the current value or set a new value for configuration options, or list all
33
+ available configuration options.
34
+ EOT
35
+ c.action do |args|
36
+ # Need to add type checking and value validation here at some point
37
+ valid_settings = Config::VALID_SETTINGS
38
+ action = args[0]
39
+ setting = args[1]
40
+ value = args[2]
41
+ case action
42
+ when 'get'
43
+ unless setting && valid_settings.keys.include?(setting)
44
+ puts "Please provide a valid config setting to get (floatyhelper get <setting>). For a list of valid settings, use 'floatyhelper config list'.".red
45
+ exit 1
46
+ end
47
+ value = Config.get_config_setting(setting) || ''
48
+ puts value
49
+ when 'set'
50
+ unless setting && value
51
+ puts 'Please provide a config setting and value to set (floatyhelper set <setting> <value>).'.red
52
+ exit 1
53
+ end
54
+ unless valid_settings.keys.include?(setting)
55
+ puts "Please provide a valid config setting to set (floatyhelper get <setting>). For a list of valid settings, use 'floatyhelper config list'.".red
56
+ exit 1
57
+ end
58
+ Config.set_config_setting(setting, value)
59
+ puts "'#{setting}' set to #{value}".green
60
+ when 'list'
61
+ valid_settings.each do |s,info|
62
+ puts "#{s}:"
63
+ puts " #{info['description']}"
64
+ puts " Default: #{info['default']}"
65
+ end
66
+ else
67
+ puts 'Please provide a valid action (get, set, or list) to the config command.'.red
68
+ exit 1
69
+ end
70
+ end
71
+ end
72
+
73
+
26
74
  command :tags do |c|
27
75
  c.syntax = 'floatyhelper tags'
28
76
  c.summary = 'List all VM group tags'
29
77
  c.description = 'This lists all of the VM group tags that are currently defined, added via the addhosts command.'
30
- c.action do |args|
31
- data = Conf.load_data
32
- if data['vms'].keys.length == 0
78
+ c.action do
79
+ tags = Groups.get_tags
80
+ if tags.length.zero?
33
81
  puts 'No VM groups are defined'.yellow
34
82
  else
35
- puts data['vms'].keys
83
+ puts tags
36
84
  end
37
85
  end
38
86
  end
@@ -41,29 +89,34 @@ class Floatyhelper
41
89
  c.syntax = 'floatyhelper list [tag]'
42
90
  c.summary = 'List all VMs and their associated tags'
43
91
  c.description = <<~EOT
44
- This lists all VMs currently defined in the status.yaml file, added via the addhosts command, and their associated tags.
45
- If a tag is specified, it will only lists the hosts in that tag.
92
+ This lists all VMs currently defined in the status.yaml file, added via the addhosts command, and their associated tags.
93
+ If a tag is specified, it will only lists the hosts in that tag.
46
94
  EOT
47
95
  c.option '--check', 'Check remaining lifetime of each VM'
48
96
  c.action do |args, options|
49
- data = Conf.load_data
50
- if data['vms'].keys.length == 0
51
- puts 'No VM groups are defined'.yellow
52
- else
53
- requested_tag = args.count > 0 ? args[0] : nil
54
- data['vms'].each do |tag, hosts|
55
- next if requested_tag && requested_tag != tag
56
- puts "#{tag}:"
57
- hosts.each do |host|
58
- remaining = ''
59
- type = ''
60
- if options.check
61
- query = VM.query(host)
62
- type = query[host]['template'].gsub('-pixa4','')
63
- remaining = VM.alive(host, query) ? "#{query[host]['remaining']} hours remaining" : "Expired"
64
- end
65
- puts " %-15s %-28s %s" % [host, type, remaining]
97
+ tags = Groups.get_tags
98
+ if tags.empty?
99
+ puts 'No hosts are currently managed by floatyhelper. To add a host, use the addhosts command.'.yellow
100
+ exit 0
101
+ end
102
+ requested_tag = args.count.positive? ? args[0] : nil
103
+ if requested_tag && !tags.include?(requested_tag)
104
+ puts "Tag #{requested_tag} not found".red
105
+ exit 1
106
+ end
107
+ tags_to_fetch = requested_tag ? [requested_tag] : tags
108
+ tags_to_fetch.each do |tag|
109
+ puts "#{tag}:"
110
+ hosts = Groups.get_hosts(tag)
111
+ hosts.each do |host|
112
+ remaining = ''
113
+ type = ''
114
+ if options.check
115
+ query = VM.query(host)
116
+ type = query[host]['template'].gsub('-pixa4','')
117
+ remaining = VM.alive(host, query) ? "#{query[host]['remaining']} hours remaining" : 'Expired'
66
118
  end
119
+ puts ' %-15s %-28s %s' % [host, type, remaining]
67
120
  end
68
121
  end
69
122
  end
@@ -73,10 +126,10 @@ class Floatyhelper
73
126
  c.syntax = 'floatyhelper check [tag]'
74
127
  c.summary = 'Checks the remaining lifetime of each tracked VM.'
75
128
  c.description = <<~EOT
76
- Same as floatyhelper list --check. Checks the remaining lifetime of each tracked VM.
77
- If a tag is specified, it will only check hosts in that tag.
129
+ Same as floatyhelper list --check. Checks the remaining lifetime of each tracked VM.
130
+ If a tag is specified, it will only check hosts in that tag.
78
131
  EOT
79
- c.action do |args, options|
132
+ c.action do |args|
80
133
  command(:list).run(*args,'--check')
81
134
  end
82
135
  end
@@ -86,15 +139,20 @@ class Floatyhelper
86
139
  c.summary = 'List all snaptags saved for the given tag'
87
140
  c.description = 'Lists all of the snaptags available for the given VM group tag'
88
141
  c.action do |args|
89
- if args.length == 0
142
+ if args.empty?
90
143
  puts 'Please provide a tag'.red
91
144
  exit 1
92
145
  end
93
- data = Conf.load_data
94
- if !data['snapshots'].keys.include?(args[0])
95
- puts "Could not find any snaptags for VM group tag #{args[0]}".red
146
+ tag = args[0]
147
+ if !Groups.tag?(tag)
148
+ puts "#{tag} is not a valid VM group tag.".red
149
+ exit 1
150
+ end
151
+ snaptags = VM.snaplist(tag)
152
+ if snaptags.empty?
153
+ puts "Could not find any snaptags for VM group tag #{tag}".yellow
96
154
  else
97
- data['snapshots'][args[0]].keys.each { |snaptag| puts snaptag }
155
+ snaptags.each { |snaptag| puts snaptag }
98
156
  end
99
157
  end
100
158
  end
@@ -103,74 +161,46 @@ class Floatyhelper
103
161
  c.syntax = 'floatyhelper showconfig'
104
162
  c.summary = 'Show the .floatyhelper.yaml file'
105
163
  c.description = 'This prints the raw contents of the .floatyhelper.yaml file. Mostly just for debug purposes.'
106
- c.action do |args|
107
- puts File.read(Conf::STATUSFILE)
164
+ c.action do
165
+ puts File.read(Config.fhfile)
108
166
  end
109
167
  end
110
168
 
111
169
  command :addhosts do |c|
112
170
  c.syntax = 'floatyhelper addhosts <tag> [--hosts HOST1,HOST2,...] [--file sutfile]'
113
171
  c.summary = 'Adds hosts to list of hosts floatyhelper is tracking, with the given tag'
114
- c.description = <<-EOT
115
- This takes all of the hosts defined in a beaker sut.log file, and adds them to the list of hosts floatyhelper is tracking.
116
- These hosts will be grouped under the given tag, so that this tag can be used to operate on the whole set of hosts at once.
117
- If --file is not specified, this assumes you are inside a pe_acceptance_tests folder and grabs the list of hosts
118
- from log/latest/sut.log. If --hosts is specified, it will add the given comma-separated list of hosts.'
172
+ c.description = <<~EOT
173
+ This takes all of the hosts defined in a beaker sut.log file, and adds them to the list of hosts floatyhelper is tracking.
174
+ These hosts will be grouped under the given tag, so that this tag can be used to operate on the whole set of hosts at once.
175
+ If --file is not specified, this assumes you are inside a pe_acceptance_tests folder and grabs the list of hosts
176
+ from log/latest/sut.log. If --hosts is specified, it will add the given comma-separated list of hosts. If the tag already exists,
177
+ it will append the given hosts to the given tag.'
119
178
  EOT
120
179
  c.option '--hosts HOSTS', String, 'Comma separated list of hosts to add instead of reading sut.log'
121
180
  c.option '--file SUTFILE', String, 'Path to a sut.log file to get hosts from'
122
181
  c.action do |args, options|
123
182
  disallowed_tags = ['all','All','Unassigned']
124
- if args.size == 0
183
+ if args.empty?
125
184
  puts 'Please add a tag to use.'.red
126
- elsif disallowed_tags.include?(args[0])
127
- puts "Can not use a tag named #{args[0]}".red
128
- else
129
- tag = args[0]
130
- if options.hosts
131
- hosts = Hosts.get_options_hosts(options.hosts)
132
- else
133
- sutlog = options.file ? options.file : "#{Dir.pwd}/log/latest/sut.log"
134
- hosts = Hosts.get_hosts_from_sut_log(sutlog)
135
- end
136
- Groups.addhosts(hosts, tag)
137
- VM.increaselife(tag, nil)
138
- puts "Added the following hosts with tag #{tag}:".green
139
- hosts.each { |host| puts host }
185
+ exit 1
186
+ end
187
+ tag = args[0]
188
+ if disallowed_tags.include?(tag)
189
+ puts "Can not use a tag named #{tag}".red
190
+ exit 1
140
191
  end
141
- end
142
- end
143
192
 
144
- command :appendhosts do |c|
145
- c.syntax = 'floatyhelper appendhosts <tag> [--hosts HOST1,HOST2,...] [--file sutfile]'
146
- c.summary = 'Adds additional hosts to the list of hosts floatyhelper is tracking under the given tag'
147
- c.description = <<-EOT
148
- This is similar to the addhosts command, but adds the given hosts to the list of hosts tracked under a given
149
- tag. As with the addhosts command, you may specify the --hosts flag to add a hostname directly, provide a
150
- beaker sut.log file with the --file flag, or simply be inside a pe_acceptance_tests folder with the sut.log
151
- file under log/latest. Note that this will probably break things if you try reverting a snapshot taken before
152
- the hosts were appended. So don't do that.
153
- EOT
154
- c.option '--hosts HOSTS', String, 'Comma separated list of hosts to add instead of reading sut.log'
155
- c.option '--file SUTFILE', String, 'Path to a sut.log file to get hosts from'
156
- c.action do |args, options|
157
- if args.size == 0
158
- puts 'Please add a tag to use.'.red
159
- elsif !Groups.is_tag?(args[0])
160
- puts "Could not find tag #{args[0]}".red
193
+ if options.hosts
194
+ hosts = Hosts.get_options_hosts(options.hosts)
161
195
  else
162
- tag = args[0]
163
- if options.hosts
164
- hosts = Hosts.get_options_hosts(options.hosts)
165
- else
166
- sutlog = options.file ? options.file : "#{Dir.pwd}/log/latest/sut.log"
167
- hosts = Hosts.get_hosts_from_sut_log(sutlog)
168
- end
169
- Groups.appendhosts(hosts, tag)
170
- VM.increaselife(hosts, nil)
171
- puts "Added the following hosts to tag #{tag}".green
172
- hosts.each { |host| puts host }
196
+ sutlog = options.file || "#{Dir.pwd}/log/latest/sut.log"
197
+ hosts = Hosts.get_hosts_from_sut_log(sutlog)
173
198
  end
199
+ Groups.addhosts(hosts, tag)
200
+ amount = Config.get_config_setting('increaselife').to_i
201
+ VM.increaselife(tag, amount)
202
+ puts "Added the following hosts with tag #{tag}:".green
203
+ hosts.each { |host| puts host }
174
204
  end
175
205
  end
176
206
 
@@ -181,13 +211,18 @@ class Floatyhelper
181
211
  c.action do |args|
182
212
  if args.size < 2
183
213
  puts 'Please specify both a host and a tag.'.red
184
- elsif !Groups.is_managed_host?(args[0])
185
- puts "Could not find host #{args[0]}".red
186
- else
187
- Groups.removehosts([args[0]], Groups.host_tag(args[0]))
188
- Groups.appendhosts([args[0]], args[1])
189
- puts "Moved #{args[0]} to #{args[1]}".green
214
+ exit 1
190
215
  end
216
+ host = args[0]
217
+ tag = args[1]
218
+ if !Groups.managed_host?(host)
219
+ puts "Could not find host #{host}".red
220
+ exit 1
221
+ end
222
+
223
+ Groups.removehosts([host], Groups.host_tag(host))
224
+ Groups.addhosts([host], tag)
225
+ puts "Moved #{host} to #{tag}".green
191
226
  end
192
227
  end
193
228
 
@@ -199,11 +234,16 @@ class Floatyhelper
199
234
  c.option '--all', 'Destroys all hosts in status file. USE WITH CAUTION!'
200
235
  c.option '--hosts HOSTS', String, 'Comma separated list of hosts to destroy instead of using a tag. Note that this will NOT remove the hosts from the status file.'
201
236
  c.action do |args, options|
202
- if args.length == 0 && !options.all && !options.hosts
237
+ if args.empty? && !options.all && !options.hosts
203
238
  puts 'Please specify a host or tag'.red
239
+ exit 1
240
+ end
241
+ tag = args[0]
242
+ id = options.all ? 'all' : options.hosts ? Hosts.get_options_hosts(options.hosts) : tag
243
+ VM.destroy(id)
244
+ if options.all
245
+ puts 'Destroyed all hosts managed by floatyhelper'.green
204
246
  else
205
- id = options.all ? 'all' : options.hosts ? Hosts.get_options_hosts(options.hosts) : args[0]
206
- VM.destroy(id)
207
247
  puts "Destroyed hosts in #{id}".green
208
248
  end
209
249
  end
@@ -213,15 +253,16 @@ class Floatyhelper
213
253
  c.syntax = 'floatyhelper destroy_from_token'
214
254
  c.summary = 'Destroys all VMs assigned to the user\'s token'
215
255
  c.description = 'This runs a "floaty token status" to get all VMs currently assigned to the user\'s token, and then deletes them all. Use with care.'
216
- c.action do |args, options|
217
- info = eval(`floaty token status`)
256
+ c.action do
257
+ info = Floaty.floaty_cmd('token status --service vmpooler')
258
+ info = Floaty.parse_floaty_json_output(info)
218
259
  info.delete('ok')
219
260
  vms = info[info.keys[0]]['vms']
220
261
  running = vms.nil? ? nil : vms['running']
221
- if !running.nil?
222
- VM.destroy(running)
223
- else
262
+ if running.nil?
224
263
  puts 'No running VMs assigned to token to delete'.yellow
264
+ else
265
+ VM.destroy(running)
225
266
  end
226
267
  end
227
268
  end
@@ -229,41 +270,37 @@ class Floatyhelper
229
270
  command :increaselife do |c|
230
271
  c.syntax = 'floatyhelper increaselife <tag> [options]'
231
272
  c.summary = 'Increase the lifetime of the given hosts'
232
- c.description = 'Increases the current life of the given host or tagged hosts. If no host is given, increases all hosts. Defaults to 100 hours. May be used with the --hosts flag instead of a tag.'
233
- c.option '--amount HOURS', Integer, 'Amount of hours to increase life. Default = 100'
273
+ c.description = 'Increases the current life of the given host or tagged hosts. If no host is given, increases all hosts. Defaults to 12 hours. May be used with the --hosts flag instead of a tag.'
274
+ c.option '--amount HOURS', Integer, 'Amount of hours to increase life. Default = 12'
234
275
  c.option '--all', 'Destroys all hosts in status file. USE WITH CAUTION!'
235
276
  c.option '--hosts HOST', String, 'Comma separated list of hosts to destroy instead of using a tag.'
236
277
  c.action do |args, options|
237
- if args.length == 0 && !options.all && !options.hosts
278
+ if args.empty? && !options.all && !options.hosts
238
279
  puts 'Please specify a host or tag'.red
239
- else
240
- id = options.all ? 'all' : options.hosts ? Hosts.get_options_hosts(options.hosts) : args[0]
241
- VM.increaselife(id,options.amount)
280
+ exit 1
242
281
  end
282
+ tag = args[0]
283
+ id = options.all ? 'all' : options.hosts ? Hosts.get_options_hosts(options.hosts) : tag
284
+ VM.increaselife(id,options.amount)
243
285
  end
244
286
  end
245
287
 
246
- #command :query do |c|
247
- # c.syntax = 'floatyhelper query [options]'
248
- # c.summary = ''
249
- # c.description = ''
250
- # c.example 'description', 'command example'
251
- # c.option '--some-switch', 'Some switch that does something'
252
- # c.action do |args, options|
253
- # # Do something or c.when_called Floatyhelper::Commands::Query
254
- # end
255
- #end
256
-
257
288
  command :revert do |c|
258
289
  c.syntax = 'floatyhelper revert <host|tag> <snaptag>'
259
290
  c.summary = 'Revert VM to the given snaptag'
260
291
  c.description = 'Reverts the given VM or host group to given snaptag. This snaptag is created when the snapshot command is run.'
261
- c.action do |args, options|
292
+ c.action do |args|
262
293
  if args.length < 2
263
- puts "Please specify both a host/tag and a snaptag".red
264
- else
265
- VM.revert(args[0], args[1])
294
+ puts 'Please specify both a host/tag and a snaptag'.red
295
+ exit 1
266
296
  end
297
+ host_or_tag = args[0]
298
+ snaptag = args[1]
299
+ if !VM.snaptag_exists?(host_or_tag, snaptag)
300
+ puts "Snaptag '#{snaptag}' not found for #{host_or_tag}".red
301
+ exit 1
302
+ end
303
+ VM.revert(host_or_tag, snaptag)
267
304
  end
268
305
  end
269
306
 
@@ -271,17 +308,19 @@ class Floatyhelper
271
308
  c.syntax = 'floatyhelper snapshot <host|tag> <snaptag>'
272
309
  c.summary = 'Snapshot the given VM or group of taggedhosts'
273
310
  c.description = 'Creates a snapshot of a host or group of tagged hosts, and defines a string to use as a "snaptag" to refer to this group of snapshots.'
274
- c.option '--clr', 'Clear screen and show VMs in a column when checking status, rather than a single line.'
275
- c.action do |args, options|
311
+ c.action do |args|
276
312
  if args.length < 2
277
- puts "Please specify both a host/tag and a snaptag"
278
- else
279
- if VM.snaptag_exists?(args[0], args[1])
280
- answer = ask "Snaptag #{args[1]} already exists. Are you sure you want to overwrite? [y/N] ".yellow
281
- return unless answer.capitalize == 'Y'
282
- end
283
- VM.snapshot(args[0], args[1], options.clr)
313
+ puts 'Please specify both a host/tag and a snaptag'.red
314
+ exit 1
315
+ end
316
+
317
+ host_or_tag = args[0]
318
+ snaptag = args[1]
319
+ if VM.snaptag_exists?(host_or_tag, snaptag)
320
+ answer = ask "Snaptag #{snaptag} already exists. Are you sure you want to overwrite? [y/N] ".yellow
321
+ return unless answer.capitalize == 'Y'
284
322
  end
323
+ VM.snapshot(host_or_tag, snaptag)
285
324
  end
286
325
  end
287
326
 
@@ -290,55 +329,70 @@ class Floatyhelper
290
329
  c.summary = 'Check for any expired VMs, and remove them from the list of hosts floatyhelper is tracking'
291
330
  c.description = 'Runs floaty query on VMs that floatyhelper is tracking, to check for any expired VMs, and allows the user to remove tags that contain only expired VMs.'
292
331
  c.option '-y', 'Do not prompt to remove tags with expired VMs'
293
- c.action do |args, options|
294
- data = Conf.load_data
332
+ c.action do |_args, options|
295
333
  expired = false
296
- data['vms'].each do |tag, hosts|
334
+ tags = Groups.get_tags
335
+ tags.each do |tag|
297
336
  expired_hosts = []
337
+ hosts = Groups.get_hosts(tag)
298
338
  hosts.each do |host|
299
339
  expired_hosts << host unless VM.alive(host)
300
340
  end
301
- unless expired_hosts.empty?
302
- expired = true
303
- if expired_hosts & hosts == hosts
304
- answer = options.y ? 'y' : ask("All hosts in tag #{tag} have expired. Delete this tag? [Y/n] ".yellow)
305
- if answer.empty? || answer.capitalize == 'Y'
306
- Groups.delete_tag(tag)
307
- puts "Tag #{tag} deleted".green
308
- end
309
- else
310
- expired_hosts.each { |host| puts "#{host}".yellow } unless options.y
311
- answer = options.y ? 'y' : ask("The above hosts in tag #{tag} have expired. Delete these hosts from the tag? [Y/n]".yellow)
312
- if answer.empty? || answer.capitalize == 'Y'
313
- Groups.removehosts(expired_hosts, tag)
314
- puts "Expired hosts from #{tag} deleted".green
315
- end
341
+ next if expired_hosts.empty?
342
+
343
+ expired = true
344
+ if expired_hosts & hosts == hosts
345
+ answer = options.y ? 'y' : ask("All hosts in tag #{tag} have expired. Delete this tag? [Y/n] ".yellow)
346
+ if answer.empty? || answer.capitalize == 'Y'
347
+ Groups.delete_tag(tag)
348
+ puts "Tag #{tag} deleted".green
349
+ end
350
+ else
351
+ expired_hosts.each { |host| puts host.yellow } unless options.y
352
+ answer = options.y ? 'y' : ask("The above hosts in tag #{tag} have expired. Delete these hosts from the tag? [Y/n]".yellow)
353
+ if answer.empty? || answer.capitalize == 'Y'
354
+ Groups.removehosts(expired_hosts, tag)
355
+ puts "Expired hosts from #{tag} deleted".green
316
356
  end
317
357
  end
318
358
  end
319
- puts "No managed VMs have expired".green unless expired
359
+ puts 'No managed VMs have expired'.green unless expired
320
360
  end
321
361
  end
322
362
 
323
363
  command :getvm do |c|
324
364
  c.syntax = 'floatyhelper getvm <platform> <tag>'
325
365
  c.summary = 'Request a VM from floaty'
326
- c.description = 'Request a VM of the given platform type from floaty, and add the host to either the given tag or the Unassigned tag, if none is given. If no platform is given, default to centos-7-x86_64.'
327
- c.action do |args|
328
- platform = args.length > 0 ? args[0] : 'centos-7-x86_64'
366
+ c.description = <<~EOT
367
+ Request a VM of the given platform type from floaty, and add the host to either the given tag or the Unassigned tag, if none is given.
368
+ If no platform is given, default to centos-7-x86_64. This will use vmpooler for pooled platforms, and ABS otherwise. Force usage of
369
+ ABS with the --abs flag.
370
+ EOT
371
+ c.option '--abs', 'Force use of ABS to get platform, even if platform is pooled.'
372
+ c.action do |args, options|
373
+ platform = args[0] || 'centos-7-x86_64'
329
374
  tag = args.length > 1 ? args[1] : 'Unassigned'
330
375
  begin
331
- host = VM.get_vm(platform)
332
- Groups.appendhosts([host], tag)
376
+ host = VM.get_vm(platform: platform, force_abs: options.abs)
377
+ Groups.addhosts([host], tag)
333
378
  puts "Added #{host} to tag #{tag}".green
334
- VM.increaselife(host, nil)
335
- rescue => exception
336
- puts exception.message.red
379
+ amount = Config.get_config_setting('increaselife').to_i
380
+ VM.increaselife(host, amount)
381
+ rescue StandardError => e
382
+ puts e.message.red
337
383
  end
338
384
  end
339
385
  end
340
386
 
387
+ command :checktokens do |c|
388
+ c.syntax = 'floatyhelper checktokens'
389
+ c.summary = 'Verify tokens for all services are valid'
390
+ c.description = 'Verify that tokens for abs, vmpooler, and nspooler are valid in .vmfloaty.yml. If they are not, get new tokens.'
391
+ c.action do
392
+ Floaty.check_tokens
393
+ end
394
+ end
395
+
341
396
  run!
342
397
  end
343
398
  end
344
-