floatyhelper 0.8 → 1.4
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 +28 -2
- data/lib/floatyhelper.rb +111 -13
- data/lib/floatyhelper/groups.rb +23 -0
- data/lib/floatyhelper/version.rb +1 -1
- data/lib/floatyhelper/vm.rb +25 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9107871b6337de1b4508247eebc2f59e1250e5ed7b61a4ee358f3e7d920e5e5
|
4
|
+
data.tar.gz: d346fccc76b850c599d9ab7bef16e2a5eebb51897482158e273d45c7082bb9fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23e2932ddc4a3f11edbd8cff698420d83f3e41c9e0e13b92b8391e6eb474cfe5078958542e4b572a9f99728ed2a7fe6832fba17d9f3958d744da153cfb537832
|
7
|
+
data.tar.gz: 1600273e214fb4abf841f64150ccaf393e14088e312e3147af8adb9c2634e4ce4c3642c0974470e03bf96a37147657d7750a5e7ae44940a38fe8bb0b0445747e
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@ gem 'floatyhelper'
|
|
18
18
|
|
19
19
|
And then execute:
|
20
20
|
|
21
|
-
$ bundle
|
21
|
+
$ bundle install
|
22
22
|
|
23
23
|
Or install it yourself as:
|
24
24
|
|
@@ -33,7 +33,7 @@ The following commands are currently available:
|
|
33
33
|
|
34
34
|
`floatyhelper tags` - List all currently tracked tags that specify groups of hosts
|
35
35
|
|
36
|
-
`floatyhelper list` - List all VMs and their associated tags
|
36
|
+
`floatyhelper list` - List all VMs and their associated tags, and checks the remaining lifetime for each VM. If --nocheck is passed, lifetime checking will not occur.
|
37
37
|
|
38
38
|
`floatyhelper snaplist <tag>` - List all of the snaptags associated with the given VM group tag
|
39
39
|
|
@@ -51,10 +51,36 @@ The following commands are currently available:
|
|
51
51
|
|
52
52
|
`floatyhelper revert <host|tag> <snaptag>` - Reverts the given VM or host group to the given snaptag.
|
53
53
|
|
54
|
+
`floatyhelper refresh` - Removes tags that contain only expired VMs. You may pass the -y argument to run non-interactively.
|
55
|
+
|
56
|
+
`floatyhelper getvm [platform] [tag]` - Request a VM from floaty, and add the host to the given tag. Defaults to centos-7-x86_64 if no platform is given, and defaults to "Unassigned" tag.
|
57
|
+
|
58
|
+
`floatyhelper movehost <host> <tag>` - Moves the given host from its existing tag to the given tag
|
59
|
+
|
54
60
|
## Contributing
|
55
61
|
|
56
62
|
Bug reports and pull requests are welcome on GitHub at https://github.com/nmburgan/floatyhelper.
|
57
63
|
|
64
|
+
To build locally,
|
65
|
+
```
|
66
|
+
bundle install
|
67
|
+
bundle exec rake build
|
68
|
+
```
|
69
|
+
This will create the gem in the `pkg` directory. You can then install it locally with `gem install`.
|
70
|
+
|
58
71
|
## License
|
59
72
|
|
60
73
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
74
|
+
|
75
|
+
## Changelog
|
76
|
+
|
77
|
+
### 0.9
|
78
|
+
* First release
|
79
|
+
|
80
|
+
### 1.0
|
81
|
+
* Added refresh command
|
82
|
+
* Added getvm command
|
83
|
+
* Added movehost command
|
84
|
+
* Added functionality to check for remaining VM lifetime with the list command
|
85
|
+
* Added --nocheck option for list command to prevent checking VM lifetime
|
86
|
+
* Tag automatically added if appendhosts is used with a tag that doesn't exist
|
data/lib/floatyhelper.rb
CHANGED
@@ -15,7 +15,7 @@ class Floatyhelper
|
|
15
15
|
def run
|
16
16
|
program :name, 'floatyhelper'
|
17
17
|
program :version, '1.0.0'
|
18
|
-
program :description,
|
18
|
+
program :description, <<~EOT
|
19
19
|
Commands for manipulating vmpooler VMs with floaty. Use the addhosts command from within a pe_acceptance_tests folder
|
20
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
21
|
file directly).
|
@@ -38,24 +38,49 @@ class Floatyhelper
|
|
38
38
|
end
|
39
39
|
|
40
40
|
command :list do |c|
|
41
|
-
c.syntax = 'floatyhelper list'
|
41
|
+
c.syntax = 'floatyhelper list [tag]'
|
42
42
|
c.summary = 'List all VMs and their associated tags'
|
43
|
-
c.description =
|
44
|
-
|
43
|
+
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.
|
46
|
+
EOT
|
47
|
+
c.option '--check', 'Check remaining lifetime of each VM'
|
48
|
+
c.action do |args, options|
|
45
49
|
data = Conf.load_data
|
46
50
|
if data['vms'].keys.length == 0
|
47
51
|
puts 'No VM groups are defined'.yellow
|
48
52
|
else
|
53
|
+
requested_tag = args.count > 0 ? args[0] : nil
|
49
54
|
data['vms'].each do |tag, hosts|
|
55
|
+
next if requested_tag && requested_tag != tag
|
50
56
|
puts "#{tag}:"
|
51
57
|
hosts.each do |host|
|
52
|
-
|
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]
|
53
66
|
end
|
54
67
|
end
|
55
68
|
end
|
56
69
|
end
|
57
70
|
end
|
58
71
|
|
72
|
+
command :check do |c|
|
73
|
+
c.syntax = 'floatyhelper check [tag]'
|
74
|
+
c.summary = 'Checks the remaining lifetime of each tracked VM.'
|
75
|
+
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.
|
78
|
+
EOT
|
79
|
+
c.action do |args, options|
|
80
|
+
command(:list).run(*args,'--check')
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
59
84
|
command :snaplist do |c|
|
60
85
|
c.syntax = 'floatyhelper snaplist <tag>'
|
61
86
|
c.summary = 'List all snaptags saved for the given tag'
|
@@ -95,10 +120,11 @@ class Floatyhelper
|
|
95
120
|
c.option '--hosts HOSTS', String, 'Comma separated list of hosts to add instead of reading sut.log'
|
96
121
|
c.option '--file SUTFILE', String, 'Path to a sut.log file to get hosts from'
|
97
122
|
c.action do |args, options|
|
123
|
+
disallowed_tags = ['all','All','Unassigned']
|
98
124
|
if args.size == 0
|
99
125
|
puts 'Please add a tag to use.'.red
|
100
|
-
elsif args[0]
|
101
|
-
puts
|
126
|
+
elsif disallowed_tags.include?(args[0])
|
127
|
+
puts "Can not use a tag named #{args[0]}".red
|
102
128
|
else
|
103
129
|
tag = args[0]
|
104
130
|
if options.hosts
|
@@ -108,9 +134,9 @@ class Floatyhelper
|
|
108
134
|
hosts = Hosts.get_hosts_from_sut_log(sutlog)
|
109
135
|
end
|
110
136
|
Groups.addhosts(hosts, tag)
|
137
|
+
VM.increaselife(tag, nil)
|
111
138
|
puts "Added the following hosts with tag #{tag}:".green
|
112
139
|
hosts.each { |host| puts host }
|
113
|
-
VM.increaselife(tag, nil)
|
114
140
|
end
|
115
141
|
end
|
116
142
|
end
|
@@ -141,9 +167,26 @@ class Floatyhelper
|
|
141
167
|
hosts = Hosts.get_hosts_from_sut_log(sutlog)
|
142
168
|
end
|
143
169
|
Groups.appendhosts(hosts, tag)
|
170
|
+
VM.increaselife(hosts, nil)
|
144
171
|
puts "Added the following hosts to tag #{tag}".green
|
145
172
|
hosts.each { |host| puts host }
|
146
|
-
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
command :movehost do |c|
|
178
|
+
c.syntax = 'floatyhelper movehost <host> <tag>'
|
179
|
+
c.summary = 'Moves given host into the given tag group'
|
180
|
+
c.description = 'Moves the given host from its existing tag group to the given tag group. Will throw an error if either the host is not currently being managed by floatyhelper. Note that snapshots will NOT be migrated to the new group.'
|
181
|
+
c.action do |args|
|
182
|
+
if args.size < 2
|
183
|
+
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
|
147
190
|
end
|
148
191
|
end
|
149
192
|
end
|
@@ -161,6 +204,7 @@ class Floatyhelper
|
|
161
204
|
else
|
162
205
|
id = options.all ? 'all' : options.hosts ? Hosts.get_options_hosts(options.hosts) : args[0]
|
163
206
|
VM.destroy(id)
|
207
|
+
puts "Destroyed hosts in #{id}".green
|
164
208
|
end
|
165
209
|
end
|
166
210
|
end
|
@@ -227,19 +271,73 @@ class Floatyhelper
|
|
227
271
|
c.syntax = 'floatyhelper snapshot <host|tag> <snaptag>'
|
228
272
|
c.summary = 'Snapshot the given VM or group of taggedhosts'
|
229
273
|
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.'
|
230
275
|
c.action do |args, options|
|
231
276
|
if args.length < 2
|
232
277
|
puts "Please specify both a host/tag and a snaptag"
|
233
278
|
else
|
234
279
|
if VM.snaptag_exists?(args[0], args[1])
|
235
|
-
|
236
|
-
|
237
|
-
|
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)
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
command :refresh do |c|
|
289
|
+
c.syntax = 'floatyhelper refresh'
|
290
|
+
c.summary = 'Check for any expired VMs, and remove them from the list of hosts floatyhelper is tracking'
|
291
|
+
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
|
+
c.option '-y', 'Do not prompt to remove tags with expired VMs'
|
293
|
+
c.action do |args, options|
|
294
|
+
data = Conf.load_data
|
295
|
+
expired = false
|
296
|
+
data['vms'].each do |tag, hosts|
|
297
|
+
expired_hosts = []
|
298
|
+
hosts.each do |host|
|
299
|
+
expired_hosts << host unless VM.alive(host)
|
238
300
|
end
|
239
|
-
|
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
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
319
|
+
puts "No managed VMs have expired".green unless expired
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
command :getvm do |c|
|
324
|
+
c.syntax = 'floatyhelper getvm <platform> <tag>'
|
325
|
+
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'
|
329
|
+
tag = args.length > 1 ? args[1] : 'Unassigned'
|
330
|
+
begin
|
331
|
+
host = VM.get_vm(platform)
|
332
|
+
Groups.appendhosts([host], tag)
|
333
|
+
puts "Added #{host} to tag #{tag}".green
|
334
|
+
VM.increaselife(host, nil)
|
335
|
+
rescue => exception
|
336
|
+
puts exception.message.red
|
240
337
|
end
|
241
338
|
end
|
242
339
|
end
|
340
|
+
|
243
341
|
run!
|
244
342
|
end
|
245
343
|
end
|
data/lib/floatyhelper/groups.rb
CHANGED
@@ -34,9 +34,32 @@ class Groups
|
|
34
34
|
def self.appendhosts(hosts, tag)
|
35
35
|
data = Conf.load_data
|
36
36
|
hosts.each do |host|
|
37
|
+
data['vms'][tag] ||= []
|
37
38
|
data['vms'][tag] << host unless data['vms'][tag].include?(host)
|
38
39
|
end
|
39
40
|
Conf.write_data(data)
|
40
41
|
end
|
42
|
+
|
43
|
+
def self.removehosts(hosts, tag)
|
44
|
+
data = Conf.load_data
|
45
|
+
hosts.each do |host|
|
46
|
+
data['vms'][tag] ||= []
|
47
|
+
data['vms'][tag].delete(host)
|
48
|
+
data['vms'].delete(tag) if data['vms'][tag].empty?
|
49
|
+
end
|
50
|
+
Conf.write_data(data)
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.is_managed_host?(host)
|
54
|
+
data = Conf.load_data
|
55
|
+
data['vms'].any? { |tag, hosts| hosts.include?(host) }
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.host_tag(host)
|
59
|
+
data = Conf.load_data
|
60
|
+
raise 'Host not found' unless is_managed_host?(host)
|
61
|
+
tags = data['vms'].select { |tag, hosts| hosts.include?(host) }.keys
|
62
|
+
tags[0]
|
63
|
+
end
|
41
64
|
|
42
65
|
end
|
data/lib/floatyhelper/version.rb
CHANGED
data/lib/floatyhelper/vm.rb
CHANGED
@@ -8,7 +8,8 @@ class VM
|
|
8
8
|
hosts = Hosts.get_hosts_from_id(id)
|
9
9
|
Groups.delete_tag(id) if Groups.is_tag?(id)
|
10
10
|
Groups.delete_all if id == 'all'
|
11
|
-
|
11
|
+
hosts = hosts.select { |host| alive(host) }
|
12
|
+
puts `floaty delete #{hosts.join(',')}` unless hosts.empty?
|
12
13
|
end
|
13
14
|
|
14
15
|
def self.query(host)
|
@@ -20,6 +21,11 @@ class VM
|
|
20
21
|
status['ok'] ? status[host]['lifetime'] : nil
|
21
22
|
end
|
22
23
|
|
24
|
+
def self.alive(host, query=nil)
|
25
|
+
query ||= query(host)
|
26
|
+
query['ok'] && query[host]['state'] == 'running'
|
27
|
+
end
|
28
|
+
|
23
29
|
def self.increaselife(id, amount)
|
24
30
|
amount = 100 if amount.nil?
|
25
31
|
hosts = Hosts.get_hosts_from_id(id)
|
@@ -34,7 +40,7 @@ class VM
|
|
34
40
|
end
|
35
41
|
end
|
36
42
|
|
37
|
-
def self.snapshot(id, snaptag)
|
43
|
+
def self.snapshot(id, snaptag, clr=false)
|
38
44
|
snaptag = 'Blank Snaptag' unless snaptag
|
39
45
|
hosts = Hosts.get_hosts_from_id(id)
|
40
46
|
shas = {}
|
@@ -48,27 +54,30 @@ class VM
|
|
48
54
|
shas[host] = sha
|
49
55
|
end
|
50
56
|
|
57
|
+
data = Conf.load_data
|
58
|
+
data['snapshots'] ||= {}
|
59
|
+
data['snapshots'][id] ||= {}
|
60
|
+
data['snapshots'][id][snaptag] = shas
|
61
|
+
Conf.write_data(data)
|
62
|
+
|
63
|
+
puts `tput clear` if clr
|
51
64
|
puts 'Waiting for snapshots to appear in floaty query...'
|
52
65
|
alldone = false
|
53
66
|
while !alldone do
|
67
|
+
puts `tput cup 1` if clr
|
54
68
|
alldone = true
|
55
|
-
print "\r"
|
69
|
+
print "\r" unless clr
|
56
70
|
hosts.each do |host|
|
57
71
|
answer = eval(`floaty query #{host}`)[host]
|
58
72
|
done = answer.keys.include?('snapshots') && answer['snapshots'].include?(shas[host])
|
59
73
|
status = done ? 'Done' : 'Wait'
|
60
|
-
print "* #{host}: #{status} *"
|
74
|
+
print "* #{host}: #{status} *" unless clr
|
75
|
+
puts "* #{host}: #{status} *" if clr
|
61
76
|
alldone &= done
|
62
77
|
end
|
63
78
|
sleep(1)
|
64
79
|
end
|
65
80
|
puts ''
|
66
|
-
|
67
|
-
data = Conf.load_data
|
68
|
-
data['snapshots'] ||= {}
|
69
|
-
data['snapshots'][id] ||= {}
|
70
|
-
data['snapshots'][id][snaptag] = shas
|
71
|
-
Conf.write_data(data)
|
72
81
|
end
|
73
82
|
|
74
83
|
def self.getsnapshot(id, snaptag)
|
@@ -92,5 +101,11 @@ class VM
|
|
92
101
|
sleep(10)
|
93
102
|
end
|
94
103
|
|
104
|
+
def self.get_vm(platform='centos-7-x86_64')
|
105
|
+
response = `floaty get #{platform} 2>&1`
|
106
|
+
raise "Error obtaining a VM: #{response}" if response.include?('error')
|
107
|
+
return response.split(' ')[1].split('.')[0]
|
108
|
+
end
|
109
|
+
|
95
110
|
end
|
96
111
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: floatyhelper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '
|
4
|
+
version: '1.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Burgan-Illig
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|