floatyhelper 0.9 → 1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd4e929216727f3d55fec2a2ea64388bc5dd369f0a15429111cb731e56a02003
4
- data.tar.gz: fd7dd9c459a81b03302142d764a8574be0148da411e6b64d4a74a8762c6037b9
3
+ metadata.gz: 15888ba1cfc729b4e52f5a0dd5c33e3c7873439e8c6c5422509c17ac264d0878
4
+ data.tar.gz: bae08f4e75b2530ba10d9a028f2346a3c89e5706015fea4258e8f1fd118e2bb6
5
5
  SHA512:
6
- metadata.gz: e28f02671f5be22fb732d63465ce01f2a7f177340ff2d70c619687f4078f45707dc58248c3aab0fc85c57a85d0068d8363d6744683ee194ce4712c15d4ba2971
7
- data.tar.gz: 526ac4fe3c8313e0778bfc4e91681997d47781f04f4bd55d8ffe06dff8f91901de4f88f60f97d03d100eff055c11d387c390becaf6b95708c3ce83051f49d134
6
+ metadata.gz: 888ebc61101ac904f1893d3698edf7adbfc41d31b34c722dbe3a21ac8c9aa538db6711f1485f2297251527787fbb4e13fb5bf1ae066cbe676ba461ac1c360743
7
+ data.tar.gz: 36a956a699d35d51e7af96d6a646392dfb4871605194a924a7843031742b390da071ffdc5df147c7752eb2741473c7be9a146a2d702477b36ac070bd53c3935d
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
@@ -41,7 +41,8 @@ class Floatyhelper
41
41
  c.syntax = 'floatyhelper list'
42
42
  c.summary = 'List all VMs and their associated tags'
43
43
  c.description = 'This lists all VMs currently defined in the status.yaml file, added via the addhosts command, and their associated tags.'
44
- c.action do |args|
44
+ c.option '--nocheck', 'Do not check remaining lifetime of each VM'
45
+ c.action do |args, options|
45
46
  data = Conf.load_data
46
47
  if data['vms'].keys.length == 0
47
48
  puts 'No VM groups are defined'.yellow
@@ -49,7 +50,12 @@ class Floatyhelper
49
50
  data['vms'].each do |tag, hosts|
50
51
  puts "#{tag}:"
51
52
  hosts.each do |host|
52
- puts " #{host}"
53
+ remaining = ''
54
+ unless options.nocheck
55
+ query = VM.query(host)
56
+ remaining = VM.alive(host, query) ? "#{query[host]['remaining']} hours remaining" : "Expired"
57
+ end
58
+ puts " #{host}\t#{remaining}"
53
59
  end
54
60
  end
55
61
  end
@@ -95,10 +101,11 @@ class Floatyhelper
95
101
  c.option '--hosts HOSTS', String, 'Comma separated list of hosts to add instead of reading sut.log'
96
102
  c.option '--file SUTFILE', String, 'Path to a sut.log file to get hosts from'
97
103
  c.action do |args, options|
104
+ disallowed_tags = ['all','All','Unassigned']
98
105
  if args.size == 0
99
106
  puts 'Please add a tag to use.'.red
100
- elsif args[0] == 'all'
101
- puts 'Can not use a tag named "all"'.red
107
+ elsif disallowed_tags.include?(args[0])
108
+ puts "Can not use a tag named #{args[0]}".red
102
109
  else
103
110
  tag = args[0]
104
111
  if options.hosts
@@ -108,9 +115,9 @@ class Floatyhelper
108
115
  hosts = Hosts.get_hosts_from_sut_log(sutlog)
109
116
  end
110
117
  Groups.addhosts(hosts, tag)
118
+ VM.increaselife(tag, nil)
111
119
  puts "Added the following hosts with tag #{tag}:".green
112
120
  hosts.each { |host| puts host }
113
- VM.increaselife(tag, nil)
114
121
  end
115
122
  end
116
123
  end
@@ -141,9 +148,26 @@ class Floatyhelper
141
148
  hosts = Hosts.get_hosts_from_sut_log(sutlog)
142
149
  end
143
150
  Groups.appendhosts(hosts, tag)
151
+ VM.increaselife(hosts, nil)
144
152
  puts "Added the following hosts to tag #{tag}".green
145
153
  hosts.each { |host| puts host }
146
- VM.increaselife(hosts, nil)
154
+ end
155
+ end
156
+ end
157
+
158
+ command :movehost do |c|
159
+ c.syntax = 'floatyhelper movehost <host> <tag>'
160
+ c.summary = 'Moves given host into the given tag group'
161
+ 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.'
162
+ c.action do |args|
163
+ if args.size < 2
164
+ puts 'Please specify both a host and a tag.'.red
165
+ elsif !Groups.is_managed_host?(args[0])
166
+ puts "Could not find host #{args[0]}".red
167
+ else
168
+ Groups.removehosts([args[0]], Groups.host_tag(args[0]))
169
+ Groups.appendhosts([args[0]], args[1])
170
+ puts "Moved #{args[0]} to #{args[1]}".green
147
171
  end
148
172
  end
149
173
  end
@@ -161,6 +185,7 @@ class Floatyhelper
161
185
  else
162
186
  id = options.all ? 'all' : options.hosts ? Hosts.get_options_hosts(options.hosts) : args[0]
163
187
  VM.destroy(id)
188
+ puts "Destroyed hosts in #{id}".green
164
189
  end
165
190
  end
166
191
  end
@@ -239,6 +264,55 @@ class Floatyhelper
239
264
  end
240
265
  end
241
266
  end
267
+
268
+ command :refresh do |c|
269
+ c.syntax = 'floatyhelper refresh'
270
+ c.summary = 'Check for any expired VMs, and remove them from the list of hosts floatyhelper is tracking'
271
+ 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.'
272
+ c.option '-y', 'Do not prompt to remove tags with expired VMs'
273
+ c.action do |args, options|
274
+ data = Conf.load_data
275
+ expired = false
276
+ data['vms'].each do |tag, hosts|
277
+ is_alive = false
278
+ hosts.each do |host|
279
+ is_alive |= VM.alive(host)
280
+ end
281
+ unless is_alive
282
+ expired = true
283
+ if options.y
284
+ answer = 'y'
285
+ else
286
+ answer = ask "All hosts in tag #{tag} have expired. Delete this tag? [Y/n] ".yellow
287
+ end
288
+ if answer.empty? || answer.capitalize == 'Y'
289
+ Groups.delete_tag(tag)
290
+ puts "Tag #{tag} deleted".green
291
+ end
292
+ end
293
+ end
294
+ puts "No managed VMs have expired".green unless expired
295
+ end
296
+ end
297
+
298
+ command :getvm do |c|
299
+ c.syntax = 'floatyhelper getvm <platform> <tag>'
300
+ c.summary = 'Request a VM from floaty'
301
+ 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.'
302
+ c.action do |args|
303
+ platform = args.length > 0 ? args[0] : 'centos-7-x86_64'
304
+ tag = args.length > 1 ? args[1] : 'Unassigned'
305
+ begin
306
+ host = VM.get_vm(platform)
307
+ Groups.appendhosts([host], tag)
308
+ puts "Added #{host} to tag #{tag}".green
309
+ VM.increaselife(host, nil)
310
+ rescue => exception
311
+ puts exception.message.red
312
+ end
313
+ end
314
+ end
315
+
242
316
  run!
243
317
  end
244
318
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Floatyhelper
2
- VERSION = "0.9"
2
+ VERSION = "1.0"
3
3
  end
@@ -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
- puts `floaty delete #{hosts.join(',')}`
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)
@@ -92,5 +98,11 @@ class VM
92
98
  sleep(10)
93
99
  end
94
100
 
101
+ def self.get_vm(platform='centos-7-x86_64')
102
+ response = `floaty get #{platform} 2>&1`
103
+ raise "Error obtaining a VM: #{response}" if response.include?('error')
104
+ return response.split(' ')[1].split('.')[0]
105
+ end
106
+
95
107
  end
96
108
 
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: '0.9'
4
+ version: '1.0'
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: 2019-08-19 00:00:00.000000000 Z
11
+ date: 2019-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler