floatyhelper 1.1 → 2.0.3
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.rb +228 -152
- data/lib/floatyhelper/config.rb +75 -0
- data/lib/floatyhelper/floaty.rb +163 -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 +99 -38
- metadata +79 -8
- data/lib/floatyhelper/conf.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 431619b53e0f4ef48e234d613b2bd3c4c9c91e62b5366805e50edbb256f81499
|
4
|
+
data.tar.gz: 213649667596adfeb3d293cd4862f3f9a6eaffd15137fa581039801729d20ae4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db5cc8257144b831c73b76132dfa647bc8d03bc98fcd84ef6a2de1a9613866967e8ffc16ddb3f6961eea62eb08b83e537d07f4fbe5e67cc7475f0b4515df0ece
|
7
|
+
data.tar.gz: 45e795caf7ab69ba2f3d0ff980396cb24220233334fd524a1292cbafad934123c642cfeb2248dfd1b97c5b5a926d8109167b1f8bc7143a1890a3547fa67837bc
|
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/
|
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
|
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
|
-
|
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
|
-
|
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
|
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.
|
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
|
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
|
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
|
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
|
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
|
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
|
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/
|
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
|
-
|
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
|
-
|
65
|
+
To release a new version, update lib/version.rb, then run `bundle exec build release`.
|
74
66
|
|
75
|
-
##
|
76
|
-
|
77
|
-
### 0.9
|
78
|
-
* First release
|
67
|
+
## License
|
79
68
|
|
80
|
-
|
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/
|
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,68 +16,145 @@ class Floatyhelper
|
|
14
16
|
|
15
17
|
def run
|
16
18
|
program :name, 'floatyhelper'
|
17
|
-
program :version,
|
18
|
-
program :description,
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
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
|
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 =
|
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
|
-
|
47
|
-
if
|
48
|
-
puts 'No
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
|
127
|
+
command :check do |c|
|
128
|
+
c.syntax = 'floatyhelper check [tag]'
|
129
|
+
c.summary = 'Checks the remaining lifetime of each tracked VM.'
|
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')
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
65
139
|
command :snaplist do |c|
|
66
140
|
c.syntax = 'floatyhelper snaplist <tag>'
|
67
141
|
c.summary = 'List all snaptags saved for the given tag'
|
68
142
|
c.description = 'Lists all of the snaptags available for the given VM group tag'
|
69
143
|
c.action do |args|
|
70
|
-
if args.
|
144
|
+
if args.empty?
|
71
145
|
puts 'Please provide a tag'.red
|
72
146
|
exit 1
|
73
147
|
end
|
74
|
-
|
75
|
-
if !
|
76
|
-
puts "
|
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
|
77
156
|
else
|
78
|
-
|
157
|
+
snaptags.each { |snaptag| puts snaptag }
|
79
158
|
end
|
80
159
|
end
|
81
160
|
end
|
@@ -84,74 +163,46 @@ class Floatyhelper
|
|
84
163
|
c.syntax = 'floatyhelper showconfig'
|
85
164
|
c.summary = 'Show the .floatyhelper.yaml file'
|
86
165
|
c.description = 'This prints the raw contents of the .floatyhelper.yaml file. Mostly just for debug purposes.'
|
87
|
-
c.action do
|
88
|
-
puts File.read(
|
166
|
+
c.action do
|
167
|
+
puts File.read(Config.fhfile)
|
89
168
|
end
|
90
169
|
end
|
91
170
|
|
92
171
|
command :addhosts do |c|
|
93
172
|
c.syntax = 'floatyhelper addhosts <tag> [--hosts HOST1,HOST2,...] [--file sutfile]'
|
94
173
|
c.summary = 'Adds hosts to list of hosts floatyhelper is tracking, with the given tag'
|
95
|
-
c.description =
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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.'
|
100
180
|
EOT
|
101
181
|
c.option '--hosts HOSTS', String, 'Comma separated list of hosts to add instead of reading sut.log'
|
102
182
|
c.option '--file SUTFILE', String, 'Path to a sut.log file to get hosts from'
|
103
183
|
c.action do |args, options|
|
104
184
|
disallowed_tags = ['all','All','Unassigned']
|
105
|
-
if args.
|
185
|
+
if args.empty?
|
106
186
|
puts 'Please add a tag to use.'.red
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
else
|
114
|
-
sutlog = options.file ? options.file : "#{Dir.pwd}/log/latest/sut.log"
|
115
|
-
hosts = Hosts.get_hosts_from_sut_log(sutlog)
|
116
|
-
end
|
117
|
-
Groups.addhosts(hosts, tag)
|
118
|
-
VM.increaselife(tag, nil)
|
119
|
-
puts "Added the following hosts with tag #{tag}:".green
|
120
|
-
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
|
121
193
|
end
|
122
|
-
end
|
123
|
-
end
|
124
194
|
|
125
|
-
|
126
|
-
|
127
|
-
c.summary = 'Adds additional hosts to the list of hosts floatyhelper is tracking under the given tag'
|
128
|
-
c.description = <<-EOT
|
129
|
-
This is similar to the addhosts command, but adds the given hosts to the list of hosts tracked under a given
|
130
|
-
tag. As with the addhosts command, you may specify the --hosts flag to add a hostname directly, provide a
|
131
|
-
beaker sut.log file with the --file flag, or simply be inside a pe_acceptance_tests folder with the sut.log
|
132
|
-
file under log/latest. Note that this will probably break things if you try reverting a snapshot taken before
|
133
|
-
the hosts were appended. So don't do that.
|
134
|
-
EOT
|
135
|
-
c.option '--hosts HOSTS', String, 'Comma separated list of hosts to add instead of reading sut.log'
|
136
|
-
c.option '--file SUTFILE', String, 'Path to a sut.log file to get hosts from'
|
137
|
-
c.action do |args, options|
|
138
|
-
if args.size == 0
|
139
|
-
puts 'Please add a tag to use.'.red
|
140
|
-
elsif !Groups.is_tag?(args[0])
|
141
|
-
puts "Could not find tag #{args[0]}".red
|
195
|
+
if options.hosts
|
196
|
+
hosts = Hosts.get_options_hosts(options.hosts)
|
142
197
|
else
|
143
|
-
|
144
|
-
|
145
|
-
hosts = Hosts.get_options_hosts(options.hosts)
|
146
|
-
else
|
147
|
-
sutlog = options.file ? options.file : "#{Dir.pwd}/log/latest/sut.log"
|
148
|
-
hosts = Hosts.get_hosts_from_sut_log(sutlog)
|
149
|
-
end
|
150
|
-
Groups.appendhosts(hosts, tag)
|
151
|
-
VM.increaselife(hosts, nil)
|
152
|
-
puts "Added the following hosts to tag #{tag}".green
|
153
|
-
hosts.each { |host| puts host }
|
198
|
+
sutlog = options.file || "#{Dir.pwd}/log/latest/sut.log"
|
199
|
+
hosts = Hosts.get_hosts_from_sut_log(sutlog)
|
154
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 }
|
155
206
|
end
|
156
207
|
end
|
157
208
|
|
@@ -162,13 +213,18 @@ class Floatyhelper
|
|
162
213
|
c.action do |args|
|
163
214
|
if args.size < 2
|
164
215
|
puts 'Please specify both a host and a tag.'.red
|
165
|
-
|
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
|
216
|
+
exit 1
|
171
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
|
223
|
+
end
|
224
|
+
|
225
|
+
Groups.removehosts([host], Groups.host_tag(host))
|
226
|
+
Groups.addhosts([host], tag)
|
227
|
+
puts "Moved #{host} to #{tag}".green
|
172
228
|
end
|
173
229
|
end
|
174
230
|
|
@@ -180,11 +236,16 @@ class Floatyhelper
|
|
180
236
|
c.option '--all', 'Destroys all hosts in status file. USE WITH CAUTION!'
|
181
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.'
|
182
238
|
c.action do |args, options|
|
183
|
-
if args.
|
239
|
+
if args.empty? && !options.all && !options.hosts
|
184
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
|
185
248
|
else
|
186
|
-
id = options.all ? 'all' : options.hosts ? Hosts.get_options_hosts(options.hosts) : args[0]
|
187
|
-
VM.destroy(id)
|
188
249
|
puts "Destroyed hosts in #{id}".green
|
189
250
|
end
|
190
251
|
end
|
@@ -194,15 +255,16 @@ class Floatyhelper
|
|
194
255
|
c.syntax = 'floatyhelper destroy_from_token'
|
195
256
|
c.summary = 'Destroys all VMs assigned to the user\'s token'
|
196
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.'
|
197
|
-
c.action do
|
198
|
-
info =
|
258
|
+
c.action do
|
259
|
+
info = Floaty.floaty_cmd('token status --service vmpooler')
|
260
|
+
info = Floaty.parse_floaty_json_output(info)
|
199
261
|
info.delete('ok')
|
200
262
|
vms = info[info.keys[0]]['vms']
|
201
263
|
running = vms.nil? ? nil : vms['running']
|
202
|
-
if
|
203
|
-
VM.destroy(running)
|
204
|
-
else
|
264
|
+
if running.nil?
|
205
265
|
puts 'No running VMs assigned to token to delete'.yellow
|
266
|
+
else
|
267
|
+
VM.destroy(running)
|
206
268
|
end
|
207
269
|
end
|
208
270
|
end
|
@@ -210,41 +272,37 @@ class Floatyhelper
|
|
210
272
|
command :increaselife do |c|
|
211
273
|
c.syntax = 'floatyhelper increaselife <tag> [options]'
|
212
274
|
c.summary = 'Increase the lifetime of the given hosts'
|
213
|
-
c.description = 'Increases the current life of the given host or tagged hosts. If no host is given, increases all hosts. Defaults to
|
214
|
-
c.option '--amount HOURS', Integer, 'Amount of hours to increase life. Default =
|
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'
|
215
277
|
c.option '--all', 'Destroys all hosts in status file. USE WITH CAUTION!'
|
216
278
|
c.option '--hosts HOST', String, 'Comma separated list of hosts to destroy instead of using a tag.'
|
217
279
|
c.action do |args, options|
|
218
|
-
if args.
|
280
|
+
if args.empty? && !options.all && !options.hosts
|
219
281
|
puts 'Please specify a host or tag'.red
|
220
|
-
|
221
|
-
id = options.all ? 'all' : options.hosts ? Hosts.get_options_hosts(options.hosts) : args[0]
|
222
|
-
VM.increaselife(id,options.amount)
|
282
|
+
exit 1
|
223
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)
|
224
287
|
end
|
225
288
|
end
|
226
289
|
|
227
|
-
#command :query do |c|
|
228
|
-
# c.syntax = 'floatyhelper query [options]'
|
229
|
-
# c.summary = ''
|
230
|
-
# c.description = ''
|
231
|
-
# c.example 'description', 'command example'
|
232
|
-
# c.option '--some-switch', 'Some switch that does something'
|
233
|
-
# c.action do |args, options|
|
234
|
-
# # Do something or c.when_called Floatyhelper::Commands::Query
|
235
|
-
# end
|
236
|
-
#end
|
237
|
-
|
238
290
|
command :revert do |c|
|
239
291
|
c.syntax = 'floatyhelper revert <host|tag> <snaptag>'
|
240
292
|
c.summary = 'Revert VM to the given snaptag'
|
241
293
|
c.description = 'Reverts the given VM or host group to given snaptag. This snaptag is created when the snapshot command is run.'
|
242
|
-
c.action do |args
|
294
|
+
c.action do |args|
|
243
295
|
if args.length < 2
|
244
|
-
puts
|
245
|
-
|
246
|
-
|
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
|
247
304
|
end
|
305
|
+
VM.revert(host_or_tag, snaptag)
|
248
306
|
end
|
249
307
|
end
|
250
308
|
|
@@ -252,16 +310,19 @@ class Floatyhelper
|
|
252
310
|
c.syntax = 'floatyhelper snapshot <host|tag> <snaptag>'
|
253
311
|
c.summary = 'Snapshot the given VM or group of taggedhosts'
|
254
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.'
|
255
|
-
c.action do |args
|
313
|
+
c.action do |args|
|
256
314
|
if args.length < 2
|
257
|
-
puts
|
258
|
-
|
259
|
-
if VM.snaptag_exists?(args[0], args[1])
|
260
|
-
answer = ask "Snaptag #{args[1]} already exists. Are you sure you want to overwrite? [y/N] ".yellow
|
261
|
-
return unless answer.capitalize == 'Y'
|
262
|
-
end
|
263
|
-
VM.snapshot(args[0], args[1])
|
315
|
+
puts 'Please specify both a host/tag and a snaptag'.red
|
316
|
+
exit 1
|
264
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)
|
265
326
|
end
|
266
327
|
end
|
267
328
|
|
@@ -270,55 +331,70 @@ class Floatyhelper
|
|
270
331
|
c.summary = 'Check for any expired VMs, and remove them from the list of hosts floatyhelper is tracking'
|
271
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.'
|
272
333
|
c.option '-y', 'Do not prompt to remove tags with expired VMs'
|
273
|
-
c.action do |
|
274
|
-
data = Conf.load_data
|
334
|
+
c.action do |_args, options|
|
275
335
|
expired = false
|
276
|
-
|
336
|
+
tags = Groups.get_tags
|
337
|
+
tags.each do |tag|
|
277
338
|
expired_hosts = []
|
339
|
+
hosts = Groups.get_hosts(tag)
|
278
340
|
hosts.each do |host|
|
279
341
|
expired_hosts << host unless VM.alive(host)
|
280
342
|
end
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
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
|
296
358
|
end
|
297
359
|
end
|
298
360
|
end
|
299
|
-
puts
|
361
|
+
puts 'No managed VMs have expired'.green unless expired
|
300
362
|
end
|
301
363
|
end
|
302
364
|
|
303
365
|
command :getvm do |c|
|
304
366
|
c.syntax = 'floatyhelper getvm <platform> <tag>'
|
305
367
|
c.summary = 'Request a VM from floaty'
|
306
|
-
c.description =
|
307
|
-
|
308
|
-
|
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'
|
309
376
|
tag = args.length > 1 ? args[1] : 'Unassigned'
|
310
377
|
begin
|
311
|
-
host = VM.get_vm(platform)
|
312
|
-
Groups.
|
378
|
+
host = VM.get_vm(platform: platform, force_abs: options.abs)
|
379
|
+
Groups.addhosts([host], tag)
|
313
380
|
puts "Added #{host} to tag #{tag}".green
|
314
|
-
|
315
|
-
|
316
|
-
|
381
|
+
amount = Config.get_config_setting('increaselife').to_i
|
382
|
+
VM.increaselife(host, amount)
|
383
|
+
rescue StandardError => e
|
384
|
+
puts e.message.red
|
317
385
|
end
|
318
386
|
end
|
319
387
|
end
|
320
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
|
+
|
321
398
|
run!
|
322
399
|
end
|
323
400
|
end
|
324
|
-
|