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.
- checksums.yaml +4 -4
- data/README.md +24 -41
- data/lib/floatyhelper/config.rb +75 -0
- data/lib/floatyhelper/floaty.rb +154 -0
- data/lib/floatyhelper/groups.rb +42 -31
- data/lib/floatyhelper/hosts.rb +9 -9
- data/lib/floatyhelper/version.rb +2 -2
- data/lib/floatyhelper/vm.rb +95 -37
- data/lib/floatyhelper.rb +214 -160
- metadata +79 -8
- data/lib/floatyhelper/conf.rb +0 -19
data/lib/floatyhelper.rb
CHANGED
@@ -3,10 +3,12 @@
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'commander'
|
5
5
|
|
6
|
-
require 'floatyhelper/
|
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,
|
19
|
+
program :version, FloatyhelperVersion::VERSION
|
18
20
|
program :description, <<~EOT
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
31
|
-
|
32
|
-
if
|
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
|
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
|
-
|
45
|
-
|
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
|
-
|
50
|
-
if
|
51
|
-
puts 'No
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
77
|
-
|
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
|
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.
|
142
|
+
if args.empty?
|
90
143
|
puts 'Please provide a tag'.red
|
91
144
|
exit 1
|
92
145
|
end
|
93
|
-
|
94
|
-
if !
|
95
|
-
puts "
|
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
|
-
|
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
|
107
|
-
puts File.read(
|
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 =
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
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.
|
183
|
+
if args.empty?
|
125
184
|
puts 'Please add a tag to use.'.red
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
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
|
-
|
145
|
-
|
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
|
-
|
163
|
-
|
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
|
-
|
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.
|
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
|
217
|
-
info =
|
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
|
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
|
233
|
-
c.option '--amount HOURS', Integer, 'Amount of hours to increase life. Default =
|
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.
|
278
|
+
if args.empty? && !options.all && !options.hosts
|
238
279
|
puts 'Please specify a host or tag'.red
|
239
|
-
|
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
|
292
|
+
c.action do |args|
|
262
293
|
if args.length < 2
|
263
|
-
puts
|
264
|
-
|
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.
|
275
|
-
c.action do |args, options|
|
311
|
+
c.action do |args|
|
276
312
|
if args.length < 2
|
277
|
-
puts
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
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 |
|
294
|
-
data = Conf.load_data
|
332
|
+
c.action do |_args, options|
|
295
333
|
expired = false
|
296
|
-
|
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
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
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
|
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 =
|
327
|
-
|
328
|
-
|
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.
|
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
|
-
|
335
|
-
|
336
|
-
|
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
|
-
|