floatyhelper 1.2 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47ee4302416a75ac2d3833651e42e48a78bec672c2b01b71a443c1a757c965ed
4
- data.tar.gz: 03a74f9eb941e32c7d594ecfcb7e618b6de61dc6e14ca26bf5218dd996afba99
3
+ metadata.gz: 4b180846de407899145d32783fbab1321b931441adc29303fc6f6652dcf074a9
4
+ data.tar.gz: 0470b598bae65a844467a8a873f16fb02540637aea45f74b6c45526d6ae7c069
5
5
  SHA512:
6
- metadata.gz: 1fe09821098beea2bb66b3e0629f531728dda29c7da57fe053946ce248bd84df25fc5ff704feaa0e69241320cbbe02fd0f2b30aa476cccc53abe5fcefd56b5ce
7
- data.tar.gz: 025641c3d7e9515258e4e370d4fb598cc6fb4998edd859549981e3214b0aae3d8cfed1f9e12d3cbcece725bd5f15c736635b416755e69d93ae9e26eeffe00d18
6
+ metadata.gz: 67131dfaa118a90be128166ff43d67bb3e2315c3012058d74b4d8e46431877a9113a9be88c0fc48caab6e5b6427c516f41e6d9325b8f230eaca186cf8f03c27d
7
+ data.tar.gz: 4373c7403986df1fdf8e02b196996ef403beefd9180ea786d9adbc9906dc6d008b449dfca49870460df6db360e56e3ff2afc4ccc449e71d3c317d5ba938b3ef8
data/README.md CHANGED
@@ -1,28 +1,14 @@
1
1
  # Floatyhelper
2
2
 
3
- A CLI app for manipulating groups of VMs provisioned with vmpooler. Works on top of https://github.com/briancain/vmfloaty
3
+ A CLI app for manipulating groups of VMs provisioned with vmpooler. Works on top of https://github.com/puppetlabs/vmfloaty
4
4
 
5
- This was written to aid the installer and management team with testing various configurations of Puppet Enterprise. Groups of hosts can be added (either directly from a Beaker run from inside the pe_acceptance_tests folder it was run with, or manually with the --hosts flag) and given a "tag" to refer to the group of hosts by. These hosts can be snapshotted together, with these snapshots given a "snaptag" that can then be reverted to if needed.
5
+ This was written to aid Puppet development teams with testing various configurations of Puppet Enterprise or other Puppet products. Groups of hosts can be added (either directly from a Beaker run from inside the pe_acceptance_tests folder it was run with, or manually with the --hosts flag) and given a "tag" to refer to the group of hosts by. These hosts can be snapshotted together, with these snapshots given a "snaptag" that can then be reverted to if needed.
6
6
 
7
- NOTE: This requires that you have already set up your .vmfloaty file with the appropriate token. The app currently does not check that this is the case.
8
-
9
- This tool could use some specs and linting, probably.
7
+ The app will install vmfloaty for you and ensure your .vmfloaty.yml config file is correct. If no tokens are present in the file, it will request new tokens for you.
10
8
 
11
9
  ## Installation
12
10
 
13
- Add this line to your application's Gemfile:
14
-
15
- ```ruby
16
- gem 'floatyhelper'
17
- ```
18
-
19
- And then execute:
20
-
21
- $ bundle install
22
-
23
- Or install it yourself as:
24
-
25
- $ gem install floatyhelper
11
+ This app lives on RubyGems, so to install, simply run `gem install floatyhelper`
26
12
 
27
13
  ## Usage
28
14
 
@@ -31,21 +17,27 @@ floatyhelper <command> <options>
31
17
  ```
32
18
  The following commands are currently available:
33
19
 
34
- `floatyhelper tags` - List all currently tracked tags that specify groups of hosts
20
+ `floatyhelper config` - Lists, gets, or sets floatyhelper configuration settings.
21
+
22
+ `floatyhelper tags` - List all currently tracked tags that specify groups of hosts.
35
23
 
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.
24
+ `floatyhelper list` - List all VMs and their associated tags, and optionally checks the type and remaining lifetime for each VM.
37
25
 
38
- `floatyhelper snaplist <tag>` - List all of the snaptags associated with the given VM group tag
26
+ `floatyhelper check` - Same as `floatyhelper list --check`.
27
+
28
+ `floatyhelper snaplist <tag>` - List all of the snaptags associated with the given VM group tag.
39
29
 
40
30
  `floatyhelper showconfig` - Dumps the .floatyhelper.yaml file. Primarily used for debug purposes.
41
31
 
42
- `floatyhelper addhosts <tag> [--hosts HOST1,HOST2,...] [--file sutfile]` - Takes all hosts defined in a beaker sut.log file and adds them to the list of hosts floatyhelper is tracking. 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. If `--file` is not specified, this assumes you are inside a pe_acceptance_tests folder and grabs the lsit of hosts from `log/latest/sut.log`. If --hosts is specified, it will add the given comma-separated list of hosts.
32
+ `floatyhelper addhosts <tag> [--hosts HOST1,HOST2,...] [--file sutfile]` - Takes all hosts defined in a beaker sut.log file and adds them to the list of hosts floatyhelper is tracking. 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. If `--file` is not specified, this assumes you are inside a pe_acceptance_tests folder and grabs the list of hosts from `log/latest/sut.log`. If --hosts is specified, it will add the given comma-separated list of hosts.
33
+
34
+ `floatyhelper movehost <host> <tag>` - Moves a host between two different tags.
43
35
 
44
- `floatyhelper appendhosts <tag> [--hosts HOST1,HOST2,...] [--file sutfile]` - Similar to the addhosts command, but adds the given hosts to the list of hosts tracked under a given tag.
36
+ `floatyhelper destroy <tag> [--all] [--hosts HOSTS]` - Calls `floaty delete` on the vmpooler hosts with the given tag, or the given hosts, or all hosts managed by floatyhelper.
45
37
 
46
- `floatyhelper destroy <tag> [--all] [--hosts HOSTS]` - Calls `floaty delete` on the vmpooler hosts with the given tag.
38
+ `floatyhelper destroy_from_token` - This destroys all hosts tied to your vmpooler token. Note that this does not currently remove the hosts from floatyhelper management. This is mostly a helper for when you have been using `floaty` directly to request VMs and you have some that are not managed by floatyhelper.
47
39
 
48
- `floatyhelper increaselife <tag> [options]` - Increases the lifetime of the given host or tagged hosts. Defaults to 100 hours.
40
+ `floatyhelper increaselife <tag> [options]` - Increases the lifetime of the given host or tagged hosts. Defaults to the increaselife config setting value.
49
41
 
50
42
  `floatyhelper snapshot <host|tag> <snaptag>` - Snapshots the given VM or group of tagged hosts, and defines a string to use as a snaptag to refer to this group of snapshots.
51
43
 
@@ -53,13 +45,13 @@ The following commands are currently available:
53
45
 
54
46
  `floatyhelper refresh` - Removes tags that contain only expired VMs. You may pass the -y argument to run non-interactively.
55
47
 
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.
48
+ `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. If requesting a platform that is currently pooled, it will request it from vmpooler. Otherwise, it will request it from ABS (or if the --abs flag is used).
57
49
 
58
- `floatyhelper movehost <host> <tag>` - Moves the given host from its existing tag to the given tag
50
+ `floatyhelper checktokens` - Checks the tokens in .vmfloaty.yml and requests new ones if needed.
59
51
 
60
52
  ## Contributing
61
53
 
62
- Bug reports and pull requests are welcome on GitHub at https://github.com/nmburgan/floatyhelper.
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/puppetlabs/floatyhelper.
63
55
 
64
56
  To build locally,
65
57
  ```
@@ -68,19 +60,10 @@ bundle exec rake build
68
60
  ```
69
61
  This will create the gem in the `pkg` directory. You can then install it locally with `gem install`.
70
62
 
71
- ## License
63
+ Run specs with `bundle exec rake spec` and Rubocop with `bundle exec rake rubocop`. These will be run automatically by Travis on all PRs.
72
64
 
73
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
65
+ To release a new version, update lib/version.rb, then run `bundle exec build release`.
74
66
 
75
- ## Changelog
76
-
77
- ### 0.9
78
- * First release
67
+ ## License
79
68
 
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
69
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
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,60 +16,123 @@ class Floatyhelper
14
16
 
15
17
  def run
16
18
  program :name, 'floatyhelper'
17
- program :version, '1.0.0'
18
- 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).
19
+ program :version, FloatyhelperVersion::VERSION
20
+ program :description, <<~EOT
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
39
87
 
40
88
  command :list do |c|
41
- c.syntax = 'floatyhelper list'
89
+ c.syntax = 'floatyhelper list [tag]'
42
90
  c.summary = 'List all VMs and their associated tags'
43
- c.description = 'This lists all VMs currently defined in the status.yaml file, added via the addhosts command, and their associated tags.'
91
+ c.description = <<~EOT
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.
94
+ EOT
44
95
  c.option '--check', 'Check remaining lifetime of each VM'
45
96
  c.action do |args, options|
46
- data = Conf.load_data
47
- if data['vms'].keys.length == 0
48
- puts 'No VM groups are defined'.yellow
49
- else
50
- data['vms'].each do |tag, hosts|
51
- puts "#{tag}:"
52
- hosts.each do |host|
53
- remaining = ''
54
- if options.check
55
- query = VM.query(host)
56
- remaining = VM.alive(host, query) ? "#{query[host]['remaining']} hours remaining" : "Expired"
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
+ if query && query['ok']
117
+ type = query[host]['template'].gsub('-pixa4','')
118
+ remaining = VM.alive(host, query) ? "#{query[host]['remaining']} hours remaining" : 'Expired'
57
119
  end
58
- puts " %-15s %s" % [host, remaining]
59
120
  end
121
+ puts ' %-15s %-28s %s' % [host, type, remaining]
60
122
  end
61
123
  end
62
124
  end
63
125
  end
64
126
 
65
127
  command :check do |c|
66
- c.syntax = 'floatyhelper check'
128
+ c.syntax = 'floatyhelper check [tag]'
67
129
  c.summary = 'Checks the remaining lifetime of each tracked VM.'
68
- c.description = 'Same as floatyhelper list --check. Checks the remaining lifetime of each tracked VM.'
69
- c.action do |args, options|
70
- command(:list).run('--check')
130
+ c.description = <<~EOT
131
+ Same as floatyhelper list --check. Checks the remaining lifetime of each tracked VM.
132
+ If a tag is specified, it will only check hosts in that tag.
133
+ EOT
134
+ c.action do |args|
135
+ command(:list).run(*args,'--check')
71
136
  end
72
137
  end
73
138
 
@@ -76,15 +141,20 @@ class Floatyhelper
76
141
  c.summary = 'List all snaptags saved for the given tag'
77
142
  c.description = 'Lists all of the snaptags available for the given VM group tag'
78
143
  c.action do |args|
79
- if args.length == 0
144
+ if args.empty?
80
145
  puts 'Please provide a tag'.red
81
146
  exit 1
82
147
  end
83
- data = Conf.load_data
84
- if !data['snapshots'].keys.include?(args[0])
85
- puts "Could not find any snaptags for VM group tag #{args[0]}".red
148
+ tag = args[0]
149
+ if !Groups.tag?(tag)
150
+ puts "#{tag} is not a valid VM group tag.".red
151
+ exit 1
152
+ end
153
+ snaptags = VM.snaplist(tag)
154
+ if snaptags.empty?
155
+ puts "Could not find any snaptags for VM group tag #{tag}".yellow
86
156
  else
87
- data['snapshots'][args[0]].keys.each { |snaptag| puts snaptag }
157
+ snaptags.each { |snaptag| puts snaptag }
88
158
  end
89
159
  end
90
160
  end
@@ -93,74 +163,46 @@ class Floatyhelper
93
163
  c.syntax = 'floatyhelper showconfig'
94
164
  c.summary = 'Show the .floatyhelper.yaml file'
95
165
  c.description = 'This prints the raw contents of the .floatyhelper.yaml file. Mostly just for debug purposes.'
96
- c.action do |args|
97
- puts File.read(Conf::STATUSFILE)
166
+ c.action do
167
+ puts File.read(Config.fhfile)
98
168
  end
99
169
  end
100
170
 
101
171
  command :addhosts do |c|
102
172
  c.syntax = 'floatyhelper addhosts <tag> [--hosts HOST1,HOST2,...] [--file sutfile]'
103
173
  c.summary = 'Adds hosts to list of hosts floatyhelper is tracking, with the given tag'
104
- c.description = <<-EOT
105
- This takes all of the hosts defined in a beaker sut.log file, and adds them to the list of hosts floatyhelper is tracking.
106
- 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.
107
- If --file is not specified, this assumes you are inside a pe_acceptance_tests folder and grabs the list of hosts
108
- from log/latest/sut.log. If --hosts is specified, it will add the given comma-separated list of hosts.'
174
+ c.description = <<~EOT
175
+ This takes all of the hosts defined in a beaker sut.log file, and adds them to the list of hosts floatyhelper is tracking.
176
+ 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.
177
+ If --file is not specified, this assumes you are inside a pe_acceptance_tests folder and grabs the list of hosts
178
+ from log/latest/sut.log. If --hosts is specified, it will add the given comma-separated list of hosts. If the tag already exists,
179
+ it will append the given hosts to the given tag.'
109
180
  EOT
110
181
  c.option '--hosts HOSTS', String, 'Comma separated list of hosts to add instead of reading sut.log'
111
182
  c.option '--file SUTFILE', String, 'Path to a sut.log file to get hosts from'
112
183
  c.action do |args, options|
113
184
  disallowed_tags = ['all','All','Unassigned']
114
- if args.size == 0
185
+ if args.empty?
115
186
  puts 'Please add a tag to use.'.red
116
- elsif disallowed_tags.include?(args[0])
117
- puts "Can not use a tag named #{args[0]}".red
118
- else
119
- tag = args[0]
120
- if options.hosts
121
- hosts = Hosts.get_options_hosts(options.hosts)
122
- else
123
- sutlog = options.file ? options.file : "#{Dir.pwd}/log/latest/sut.log"
124
- hosts = Hosts.get_hosts_from_sut_log(sutlog)
125
- end
126
- Groups.addhosts(hosts, tag)
127
- VM.increaselife(tag, nil)
128
- puts "Added the following hosts with tag #{tag}:".green
129
- hosts.each { |host| puts host }
187
+ exit 1
188
+ end
189
+ tag = args[0]
190
+ if disallowed_tags.include?(tag)
191
+ puts "Can not use a tag named #{tag}".red
192
+ exit 1
130
193
  end
131
- end
132
- end
133
194
 
134
- command :appendhosts do |c|
135
- c.syntax = 'floatyhelper appendhosts <tag> [--hosts HOST1,HOST2,...] [--file sutfile]'
136
- c.summary = 'Adds additional hosts to the list of hosts floatyhelper is tracking under the given tag'
137
- c.description = <<-EOT
138
- This is similar to the addhosts command, but adds the given hosts to the list of hosts tracked under a given
139
- tag. As with the addhosts command, you may specify the --hosts flag to add a hostname directly, provide a
140
- beaker sut.log file with the --file flag, or simply be inside a pe_acceptance_tests folder with the sut.log
141
- file under log/latest. Note that this will probably break things if you try reverting a snapshot taken before
142
- the hosts were appended. So don't do that.
143
- EOT
144
- c.option '--hosts HOSTS', String, 'Comma separated list of hosts to add instead of reading sut.log'
145
- c.option '--file SUTFILE', String, 'Path to a sut.log file to get hosts from'
146
- c.action do |args, options|
147
- if args.size == 0
148
- puts 'Please add a tag to use.'.red
149
- elsif !Groups.is_tag?(args[0])
150
- puts "Could not find tag #{args[0]}".red
195
+ if options.hosts
196
+ hosts = Hosts.get_options_hosts(options.hosts)
151
197
  else
152
- tag = args[0]
153
- if options.hosts
154
- hosts = Hosts.get_options_hosts(options.hosts)
155
- else
156
- sutlog = options.file ? options.file : "#{Dir.pwd}/log/latest/sut.log"
157
- hosts = Hosts.get_hosts_from_sut_log(sutlog)
158
- end
159
- Groups.appendhosts(hosts, tag)
160
- VM.increaselife(hosts, nil)
161
- puts "Added the following hosts to tag #{tag}".green
162
- hosts.each { |host| puts host }
198
+ sutlog = options.file || "#{Dir.pwd}/log/latest/sut.log"
199
+ hosts = Hosts.get_hosts_from_sut_log(sutlog)
163
200
  end
201
+ Groups.addhosts(hosts, tag)
202
+ amount = Config.get_config_setting('increaselife').to_i
203
+ VM.increaselife(tag, amount)
204
+ puts "Added the following hosts with tag #{tag}:".green
205
+ hosts.each { |host| puts host }
164
206
  end
165
207
  end
166
208
 
@@ -171,13 +213,18 @@ class Floatyhelper
171
213
  c.action do |args|
172
214
  if args.size < 2
173
215
  puts 'Please specify both a host and a tag.'.red
174
- elsif !Groups.is_managed_host?(args[0])
175
- puts "Could not find host #{args[0]}".red
176
- else
177
- Groups.removehosts([args[0]], Groups.host_tag(args[0]))
178
- Groups.appendhosts([args[0]], args[1])
179
- puts "Moved #{args[0]} to #{args[1]}".green
216
+ exit 1
217
+ end
218
+ host = args[0]
219
+ tag = args[1]
220
+ if !Groups.managed_host?(host)
221
+ puts "Could not find host #{host}".red
222
+ exit 1
180
223
  end
224
+
225
+ Groups.removehosts([host], Groups.host_tag(host))
226
+ Groups.addhosts([host], tag)
227
+ puts "Moved #{host} to #{tag}".green
181
228
  end
182
229
  end
183
230
 
@@ -189,11 +236,16 @@ class Floatyhelper
189
236
  c.option '--all', 'Destroys all hosts in status file. USE WITH CAUTION!'
190
237
  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.'
191
238
  c.action do |args, options|
192
- if args.length == 0 && !options.all && !options.hosts
239
+ if args.empty? && !options.all && !options.hosts
193
240
  puts 'Please specify a host or tag'.red
241
+ exit 1
242
+ end
243
+ tag = args[0]
244
+ id = options.all ? 'all' : options.hosts ? Hosts.get_options_hosts(options.hosts) : tag
245
+ VM.destroy(id)
246
+ if options.all
247
+ puts 'Destroyed all hosts managed by floatyhelper'.green
194
248
  else
195
- id = options.all ? 'all' : options.hosts ? Hosts.get_options_hosts(options.hosts) : args[0]
196
- VM.destroy(id)
197
249
  puts "Destroyed hosts in #{id}".green
198
250
  end
199
251
  end
@@ -203,15 +255,16 @@ class Floatyhelper
203
255
  c.syntax = 'floatyhelper destroy_from_token'
204
256
  c.summary = 'Destroys all VMs assigned to the user\'s token'
205
257
  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.'
206
- c.action do |args, options|
207
- info = eval(`floaty token status`)
258
+ c.action do
259
+ info = Floaty.floaty_cmd('token status --service vmpooler')
260
+ info = Floaty.parse_floaty_json_output(info)
208
261
  info.delete('ok')
209
262
  vms = info[info.keys[0]]['vms']
210
263
  running = vms.nil? ? nil : vms['running']
211
- if !running.nil?
212
- VM.destroy(running)
213
- else
264
+ if running.nil?
214
265
  puts 'No running VMs assigned to token to delete'.yellow
266
+ else
267
+ VM.destroy(running)
215
268
  end
216
269
  end
217
270
  end
@@ -219,41 +272,37 @@ class Floatyhelper
219
272
  command :increaselife do |c|
220
273
  c.syntax = 'floatyhelper increaselife <tag> [options]'
221
274
  c.summary = 'Increase the lifetime of the given hosts'
222
- 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.'
223
- c.option '--amount HOURS', Integer, 'Amount of hours to increase life. Default = 100'
275
+ 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.'
276
+ c.option '--amount HOURS', Integer, 'Amount of hours to increase life. Default = 12'
224
277
  c.option '--all', 'Destroys all hosts in status file. USE WITH CAUTION!'
225
278
  c.option '--hosts HOST', String, 'Comma separated list of hosts to destroy instead of using a tag.'
226
279
  c.action do |args, options|
227
- if args.length == 0 && !options.all && !options.hosts
280
+ if args.empty? && !options.all && !options.hosts
228
281
  puts 'Please specify a host or tag'.red
229
- else
230
- id = options.all ? 'all' : options.hosts ? Hosts.get_options_hosts(options.hosts) : args[0]
231
- VM.increaselife(id,options.amount)
282
+ exit 1
232
283
  end
284
+ tag = args[0]
285
+ id = options.all ? 'all' : options.hosts ? Hosts.get_options_hosts(options.hosts) : tag
286
+ VM.increaselife(id,options.amount)
233
287
  end
234
288
  end
235
289
 
236
- #command :query do |c|
237
- # c.syntax = 'floatyhelper query [options]'
238
- # c.summary = ''
239
- # c.description = ''
240
- # c.example 'description', 'command example'
241
- # c.option '--some-switch', 'Some switch that does something'
242
- # c.action do |args, options|
243
- # # Do something or c.when_called Floatyhelper::Commands::Query
244
- # end
245
- #end
246
-
247
290
  command :revert do |c|
248
291
  c.syntax = 'floatyhelper revert <host|tag> <snaptag>'
249
292
  c.summary = 'Revert VM to the given snaptag'
250
293
  c.description = 'Reverts the given VM or host group to given snaptag. This snaptag is created when the snapshot command is run.'
251
- c.action do |args, options|
294
+ c.action do |args|
252
295
  if args.length < 2
253
- puts "Please specify both a host/tag and a snaptag".red
254
- else
255
- VM.revert(args[0], args[1])
296
+ puts 'Please specify both a host/tag and a snaptag'.red
297
+ exit 1
298
+ end
299
+ host_or_tag = args[0]
300
+ snaptag = args[1]
301
+ if !VM.snaptag_exists?(host_or_tag, snaptag)
302
+ puts "Snaptag '#{snaptag}' not found for #{host_or_tag}".red
303
+ exit 1
256
304
  end
305
+ VM.revert(host_or_tag, snaptag)
257
306
  end
258
307
  end
259
308
 
@@ -261,16 +310,19 @@ class Floatyhelper
261
310
  c.syntax = 'floatyhelper snapshot <host|tag> <snaptag>'
262
311
  c.summary = 'Snapshot the given VM or group of taggedhosts'
263
312
  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.'
264
- c.action do |args, options|
313
+ c.action do |args|
265
314
  if args.length < 2
266
- puts "Please specify both a host/tag and a snaptag"
267
- else
268
- if VM.snaptag_exists?(args[0], args[1])
269
- answer = ask "Snaptag #{args[1]} already exists. Are you sure you want to overwrite? [y/N] ".yellow
270
- return unless answer.capitalize == 'Y'
271
- end
272
- VM.snapshot(args[0], args[1])
315
+ puts 'Please specify both a host/tag and a snaptag'.red
316
+ exit 1
273
317
  end
318
+
319
+ host_or_tag = args[0]
320
+ snaptag = args[1]
321
+ if VM.snaptag_exists?(host_or_tag, snaptag)
322
+ answer = ask "Snaptag #{snaptag} already exists. Are you sure you want to overwrite? [y/N] ".yellow
323
+ return unless answer.capitalize == 'Y'
324
+ end
325
+ VM.snapshot(host_or_tag, snaptag)
274
326
  end
275
327
  end
276
328
 
@@ -279,55 +331,70 @@ class Floatyhelper
279
331
  c.summary = 'Check for any expired VMs, and remove them from the list of hosts floatyhelper is tracking'
280
332
  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.'
281
333
  c.option '-y', 'Do not prompt to remove tags with expired VMs'
282
- c.action do |args, options|
283
- data = Conf.load_data
334
+ c.action do |_args, options|
284
335
  expired = false
285
- data['vms'].each do |tag, hosts|
336
+ tags = Groups.get_tags
337
+ tags.each do |tag|
286
338
  expired_hosts = []
339
+ hosts = Groups.get_hosts(tag)
287
340
  hosts.each do |host|
288
341
  expired_hosts << host unless VM.alive(host)
289
342
  end
290
- unless expired_hosts.empty?
291
- expired = true
292
- if expired_hosts & hosts == hosts
293
- answer = options.y ? 'y' : ask("All hosts in tag #{tag} have expired. Delete this tag? [Y/n] ".yellow)
294
- if answer.empty? || answer.capitalize == 'Y'
295
- Groups.delete_tag(tag)
296
- puts "Tag #{tag} deleted".green
297
- end
298
- else
299
- expired_hosts.each { |host| puts "#{host}".yellow } unless options.y
300
- answer = options.y ? 'y' : ask("The above hosts in tag #{tag} have expired. Delete these hosts from the tag? [Y/n]".yellow)
301
- if answer.empty? || answer.capitalize == 'Y'
302
- Groups.removehosts(expired_hosts, tag)
303
- puts "Expired hosts from #{tag} deleted".green
304
- end
343
+ next if expired_hosts.empty?
344
+
345
+ expired = true
346
+ if expired_hosts & hosts == hosts
347
+ answer = options.y ? 'y' : ask("All hosts in tag #{tag} have expired. Delete this tag? [Y/n] ".yellow)
348
+ if answer.empty? || answer.capitalize == 'Y'
349
+ Groups.delete_tag(tag)
350
+ puts "Tag #{tag} deleted".green
351
+ end
352
+ else
353
+ expired_hosts.each { |host| puts host.yellow } unless options.y
354
+ answer = options.y ? 'y' : ask("The above hosts in tag #{tag} have expired. Delete these hosts from the tag? [Y/n]".yellow)
355
+ if answer.empty? || answer.capitalize == 'Y'
356
+ Groups.removehosts(expired_hosts, tag)
357
+ puts "Expired hosts from #{tag} deleted".green
305
358
  end
306
359
  end
307
360
  end
308
- puts "No managed VMs have expired".green unless expired
361
+ puts 'No managed VMs have expired'.green unless expired
309
362
  end
310
363
  end
311
364
 
312
365
  command :getvm do |c|
313
366
  c.syntax = 'floatyhelper getvm <platform> <tag>'
314
367
  c.summary = 'Request a VM from floaty'
315
- 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.'
316
- c.action do |args|
317
- platform = args.length > 0 ? args[0] : 'centos-7-x86_64'
368
+ c.description = <<~EOT
369
+ 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.
370
+ If no platform is given, default to centos-7-x86_64. This will use vmpooler for pooled platforms, and ABS otherwise. Force usage of
371
+ ABS with the --abs flag.
372
+ EOT
373
+ c.option '--abs', 'Force use of ABS to get platform, even if platform is pooled.'
374
+ c.action do |args, options|
375
+ platform = args[0] || 'centos-7-x86_64'
318
376
  tag = args.length > 1 ? args[1] : 'Unassigned'
319
377
  begin
320
- host = VM.get_vm(platform)
321
- Groups.appendhosts([host], tag)
378
+ host = VM.get_vm(platform: platform, force_abs: options.abs)
379
+ Groups.addhosts([host], tag)
322
380
  puts "Added #{host} to tag #{tag}".green
323
- VM.increaselife(host, nil)
324
- rescue => exception
325
- puts exception.message.red
381
+ amount = Config.get_config_setting('increaselife').to_i
382
+ VM.increaselife(host, amount)
383
+ rescue StandardError => e
384
+ puts e.message.red
326
385
  end
327
386
  end
328
387
  end
329
388
 
389
+ command :checktokens do |c|
390
+ c.syntax = 'floatyhelper checktokens'
391
+ c.summary = 'Verify tokens for all services are valid'
392
+ c.description = 'Verify that tokens for abs, vmpooler, and nspooler are valid in .vmfloaty.yml. If they are not, get new tokens.'
393
+ c.action do
394
+ Floaty.check_tokens
395
+ end
396
+ end
397
+
330
398
  run!
331
399
  end
332
400
  end
333
-