floatyhelper 0.7
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 +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +60 -0
- data/bin/floatyhelper +8 -0
- data/lib/floatyhelper/conf.rb +19 -0
- data/lib/floatyhelper/groups.rb +42 -0
- data/lib/floatyhelper/hosts.rb +39 -0
- data/lib/floatyhelper/version.rb +3 -0
- data/lib/floatyhelper/vm.rb +96 -0
- data/lib/floatyhelper.rb +246 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d87fea5272c6199c1fe2e12fa4f9e54bf8a4ba9f65d9e39c4baa87f0f3c7f01b
|
4
|
+
data.tar.gz: 69f9b66eae8342f09ba670654e1024bbe67ef54ccd65a2dee9c575f5f5dca3b0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7ca2db2811db163499f648fda8e487fe8d55e0e389fdaff1acfa0df652dc39d2fc700de8d7e8cb4cb0c3e91f6565edbc34c03b4219bc48f5162f2e0ed05ef0e4
|
7
|
+
data.tar.gz: 151beb2b41db8554c7f3cb77f219509a6d67922d7f6e8717d0f08a6a5254046e4b9e1355a1193e157564d954e72d9db69067ddb48525a0a6158149f47c5ba09a
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Nick Burgan-Illig
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Floatyhelper
|
2
|
+
|
3
|
+
A CLI app for manipulating groups of VMs provisioned with vmpooler.
|
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.
|
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.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'floatyhelper'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install floatyhelper
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
```
|
30
|
+
floatyhelper <command> <options>
|
31
|
+
```
|
32
|
+
The following commands are currently available:
|
33
|
+
|
34
|
+
`floatyhelper tags` - List all currently tracked tags that specify groups of hosts
|
35
|
+
|
36
|
+
`floatyhelper list` - List all VMs and their associated tags
|
37
|
+
|
38
|
+
`floatyhelper snaplist <tag>` - List all of the snaptags associated with the given VM group tag
|
39
|
+
|
40
|
+
`floatyhelper showconfig` - Dumps the .floatyhelper.yaml file. Primarily used for debug purposes.
|
41
|
+
|
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.
|
43
|
+
|
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.
|
45
|
+
|
46
|
+
`floatyhelper destroy <tag> [--all] [--hosts HOSTS]` - Calls `floaty delete` on the vmpooler hosts with the given tag.
|
47
|
+
|
48
|
+
`floatyhelper increaselife <tag> [options]` - Increases the lifetime of the given host or tagged hosts. Defaults to 100 hours.
|
49
|
+
|
50
|
+
`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
|
+
|
52
|
+
`floatyhelper revert <host|tag> <snaptag>` - Reverts the given VM or host group to the given snaptag.
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nmburgan/floatyhelper.
|
57
|
+
|
58
|
+
## License
|
59
|
+
|
60
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/bin/floatyhelper
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
class Conf
|
4
|
+
|
5
|
+
attr_reader :STATUSFILE
|
6
|
+
|
7
|
+
STATUSFILE = File.expand_path('~/.floatyhelper.yaml')
|
8
|
+
File.write(STATUSFILE, "---\nconfig: {}\nvms: {}\nsnapshots: {}\n") unless File.exist?(STATUSFILE)
|
9
|
+
|
10
|
+
def self.load_data
|
11
|
+
YAML.load_file(STATUSFILE)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.write_data(data)
|
15
|
+
File.write(STATUSFILE, data.to_yaml)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'floatyhelper/conf'
|
2
|
+
|
3
|
+
class Groups
|
4
|
+
def self.is_tag?(id)
|
5
|
+
data = Conf.load_data
|
6
|
+
data['vms'].keys.include?(id)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.delete_tag(tag)
|
10
|
+
data = Conf.load_data
|
11
|
+
data['vms'].delete(tag)
|
12
|
+
data['snapshots'].delete(tag) if data['snapshots'].keys.include?(tag)
|
13
|
+
Conf.write_data(data)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.delete_all
|
17
|
+
data = Conf.load_data
|
18
|
+
data['vms'] = {}
|
19
|
+
data['snapshots'] = {}
|
20
|
+
Conf.write_data(data)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.addhosts(hosts, tag)
|
24
|
+
data = Conf.load_data
|
25
|
+
data['vms'] ||= {}
|
26
|
+
tag = 'Blank Tag' unless tag #Removed the ability to do this
|
27
|
+
hosts.each do |host|
|
28
|
+
data['vms'][tag] ||= []
|
29
|
+
data['vms'][tag] << host unless data['vms'][tag].include?(host)
|
30
|
+
end
|
31
|
+
Conf.write_data(data)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.appendhosts(hosts, tag)
|
35
|
+
data = Conf.load_data
|
36
|
+
hosts.each do |host|
|
37
|
+
data['vms'][tag] << host unless data['vms'][tag].include?(host)
|
38
|
+
end
|
39
|
+
Conf.write_data(data)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'floatyhelper/conf'
|
2
|
+
require 'floatyhelper/groups'
|
3
|
+
|
4
|
+
class Hosts
|
5
|
+
|
6
|
+
def self.get_hosts_from_sut_log(file)
|
7
|
+
hosts = []
|
8
|
+
File.open(file).each do |line|
|
9
|
+
items = line.split("\t")
|
10
|
+
hostname, tag = items[4].split(" ")
|
11
|
+
short_host = hostname.split(".")[0]
|
12
|
+
hosts << short_host
|
13
|
+
end
|
14
|
+
hosts
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.get_options_hosts(hosts)
|
18
|
+
hosts = hosts.split(',')
|
19
|
+
hosts.map { |h| h.split('.')[0] }
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.get_hosts_from_id(id)
|
23
|
+
data = Conf.load_data
|
24
|
+
if id == 'all'
|
25
|
+
hosts = []
|
26
|
+
data['vms'].each do |tag, hostlist|
|
27
|
+
hostlist.each do |host|
|
28
|
+
hosts << host unless hosts.include?(host)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
elsif Groups.is_tag?(id)
|
32
|
+
hosts = data['vms'][id]
|
33
|
+
else
|
34
|
+
hosts = [id].flatten
|
35
|
+
end
|
36
|
+
hosts
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'floatyhelper/groups'
|
2
|
+
require 'floatyhelper/hosts'
|
3
|
+
require 'floatyhelper/conf'
|
4
|
+
|
5
|
+
class VM
|
6
|
+
|
7
|
+
def self.destroy(id)
|
8
|
+
hosts = Hosts.get_hosts_from_id(id)
|
9
|
+
Groups.delete_tag(id) if Groups.is_tag?(id)
|
10
|
+
Groups.delete_all if id == 'all'
|
11
|
+
puts `floaty delete #{hosts.join(',')}`
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.query(host)
|
15
|
+
eval(`floaty query #{host}`)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.get_current_lifetime(host)
|
19
|
+
status = query(host)
|
20
|
+
status['ok'] ? status[host]['lifetime'] : nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.increaselife(id, amount)
|
24
|
+
amount = 100 if amount.nil?
|
25
|
+
hosts = Hosts.get_hosts_from_id(id)
|
26
|
+
hosts.each do |host|
|
27
|
+
if lifetime = get_current_lifetime(host)
|
28
|
+
lifetime += amount
|
29
|
+
print "#{host} to #{lifetime} hours: "
|
30
|
+
puts `floaty modify #{host} --lifetime #{lifetime}`.split("\n")[0]
|
31
|
+
else
|
32
|
+
puts "Could not query host #{host}".red
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.snapshot(id, snaptag)
|
38
|
+
snaptag = 'Blank Snaptag' unless snaptag
|
39
|
+
hosts = Hosts.get_hosts_from_id(id)
|
40
|
+
shas = {}
|
41
|
+
hosts.each do |host|
|
42
|
+
print "#{host}: "
|
43
|
+
result = `floaty snapshot #{host}`
|
44
|
+
message = result.split("\n")[0]
|
45
|
+
answer = eval(result.sub(message,''))
|
46
|
+
sha = answer[host]['snapshot']
|
47
|
+
puts sha
|
48
|
+
shas[host] = sha
|
49
|
+
end
|
50
|
+
|
51
|
+
puts 'Waiting for snapshots to appear in floaty query...'
|
52
|
+
alldone = false
|
53
|
+
while !alldone do
|
54
|
+
alldone = true
|
55
|
+
print "\r"
|
56
|
+
hosts.each do |host|
|
57
|
+
answer = eval(`floaty query #{host}`)[host]
|
58
|
+
done = answer.keys.include?('snapshots') && answer['snapshots'].include?(shas[host])
|
59
|
+
status = done ? 'Done' : 'Wait'
|
60
|
+
print "* #{host}: #{status} *"
|
61
|
+
alldone &= done
|
62
|
+
end
|
63
|
+
sleep(1)
|
64
|
+
end
|
65
|
+
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
|
+
end
|
73
|
+
|
74
|
+
def self.getsnapshot(id, snaptag)
|
75
|
+
data = Conf.load_data
|
76
|
+
data['snapshots'][id][snaptag]
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.snaptag_exists?(id, snaptag)
|
80
|
+
data = Conf.load_data
|
81
|
+
exists = data['snapshots'].keys.include?(id) ? data['snapshots'][id].keys.include?(snaptag) : false
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.revert(id, snaptag)
|
85
|
+
snaptag = 'Blank Snaptag' unless snaptag
|
86
|
+
shas = VM.getsnapshot(id, snaptag)
|
87
|
+
shas.each do |host, sha|
|
88
|
+
print "#{host}: #{sha} --- "
|
89
|
+
puts `floaty revert #{host} #{sha}`
|
90
|
+
end
|
91
|
+
puts 'Waiting 10 seconds for revert to take effect'
|
92
|
+
sleep(10)
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
data/lib/floatyhelper.rb
ADDED
@@ -0,0 +1,246 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'commander'
|
5
|
+
|
6
|
+
require 'floatyhelper/conf'
|
7
|
+
require 'floatyhelper/hosts'
|
8
|
+
require 'floatyhelper/groups'
|
9
|
+
require 'floatyhelper/vm'
|
10
|
+
require 'colorize'
|
11
|
+
|
12
|
+
class Floatyhelper
|
13
|
+
include Commander::Methods
|
14
|
+
|
15
|
+
def run
|
16
|
+
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).
|
22
|
+
EOT
|
23
|
+
|
24
|
+
default_command :help
|
25
|
+
|
26
|
+
command :tags do |c|
|
27
|
+
c.syntax = 'floatyhelper tags'
|
28
|
+
c.summary = 'List all VM group tags'
|
29
|
+
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
|
33
|
+
puts 'No VM groups are defined'.yellow
|
34
|
+
else
|
35
|
+
puts data['vms'].keys
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
command :list do |c|
|
41
|
+
c.syntax = 'floatyhelper list'
|
42
|
+
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.'
|
44
|
+
c.action do |args|
|
45
|
+
data = Conf.load_data
|
46
|
+
if data['vms'].keys.length == 0
|
47
|
+
puts 'No VM groups are defined'.yellow
|
48
|
+
else
|
49
|
+
data['vms'].each do |tag, hosts|
|
50
|
+
puts "#{tag}:"
|
51
|
+
hosts.each do |host|
|
52
|
+
puts " #{host}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
command :snaplist do |c|
|
60
|
+
c.syntax = 'floatyhelper snaplist <tag>'
|
61
|
+
c.summary = 'List all snaptags saved for the given tag'
|
62
|
+
c.description = 'Lists all of the snaptags available for the given VM group tag'
|
63
|
+
c.action do |args|
|
64
|
+
if args.length == 0
|
65
|
+
puts 'Please provide a tag'.red
|
66
|
+
exit 1
|
67
|
+
end
|
68
|
+
data = Conf.load_data
|
69
|
+
if !data['snapshots'].keys.include?(args[0])
|
70
|
+
puts "Could not find any snaptags for VM group tag #{args[0]}".red
|
71
|
+
else
|
72
|
+
data['snapshots'][args[0]].keys.each { |snaptag| puts snaptag }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
command :showconfig do |c|
|
78
|
+
c.syntax = 'floatyhelper showconfig'
|
79
|
+
c.summary = 'Show the .floatyhelper.yaml file'
|
80
|
+
c.description = 'This prints the raw contents of the .floatyhelper.yaml file. Mostly just for debug purposes.'
|
81
|
+
c.action do |args|
|
82
|
+
puts File.read(Conf::STATUSFILE)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
command :addhosts do |c|
|
87
|
+
c.syntax = 'floatyhelper addhosts <tag> [--hosts HOST1,HOST2,...] [--file sutfile]'
|
88
|
+
c.summary = 'Adds hosts to list of hosts floatyhelper is tracking, with the given tag'
|
89
|
+
c.description = <<-EOT
|
90
|
+
This takes all of the hosts defined in a beaker sut.log file, and adds them to the list of hosts floatyhelper is tracking.
|
91
|
+
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.
|
92
|
+
If --file is not specified, this assumes you are inside a pe_acceptance_tests folder and grabs the list of hosts
|
93
|
+
from log/latest/sut.log. If --hosts is specified, it will add the given comma-separated list of hosts.'
|
94
|
+
EOT
|
95
|
+
c.option '--hosts HOSTS', String, 'Comma separated list of hosts to add instead of reading sut.log'
|
96
|
+
c.option '--file SUTFILE', String, 'Path to a sut.log file to get hosts from'
|
97
|
+
c.action do |args, options|
|
98
|
+
if args.size == 0
|
99
|
+
puts 'Please add a tag to use.'.red
|
100
|
+
elsif args[0] == 'all'
|
101
|
+
puts 'Can not use a tag named "all"'.red
|
102
|
+
else
|
103
|
+
tag = args[0]
|
104
|
+
if options.hosts
|
105
|
+
hosts = Hosts.get_options_hosts(options.hosts)
|
106
|
+
else
|
107
|
+
sutlog = options.file ? options.file : "#{Dir.pwd}/log/latest/sut.log"
|
108
|
+
hosts = Hosts.get_hosts_from_sut_log(sutlog)
|
109
|
+
end
|
110
|
+
Groups.addhosts(hosts, tag)
|
111
|
+
puts "Added the following hosts with tag #{tag}:".green
|
112
|
+
hosts.each { |host| puts host }
|
113
|
+
VM.increaselife(tag, nil)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
command :appendhosts do |c|
|
119
|
+
c.syntax = 'floatyhelper appendhosts <tag> [--hosts HOST1,HOST2,...] [--file sutfile]'
|
120
|
+
c.summary = 'Adds additional hosts to the list of hosts floatyhelper is tracking under the given tag'
|
121
|
+
c.description = <<-EOT
|
122
|
+
This is similar to the addhosts command, but adds the given hosts to the list of hosts tracked under a given
|
123
|
+
tag. As with the addhosts command, you may specify the --hosts flag to add a hostname directly, provide a
|
124
|
+
beaker sut.log file with the --file flag, or simply be inside a pe_acceptance_tests folder with the sut.log
|
125
|
+
file under log/latest. Note that this will probably break things if you try reverting a snapshot taken before
|
126
|
+
the hosts were appended. So don't do that.
|
127
|
+
EOT
|
128
|
+
c.option '--hosts HOSTS', String, 'Comma separated list of hosts to add instead of reading sut.log'
|
129
|
+
c.option '--file SUTFILE', String, 'Path to a sut.log file to get hosts from'
|
130
|
+
c.action do |args, options|
|
131
|
+
if args.size == 0
|
132
|
+
puts 'Please add a tag to use.'.red
|
133
|
+
elsif !Groups.is_tag?(args[0])
|
134
|
+
puts "Could not find tag #{args[0]}".red
|
135
|
+
else
|
136
|
+
tag = args[0]
|
137
|
+
if options.hosts
|
138
|
+
hosts = Hosts.get_options_hosts(options.hosts)
|
139
|
+
else
|
140
|
+
sutlog = options.file ? options.file : "#{Dir.pwd}/log/latest/sut.log"
|
141
|
+
hosts = Hosts.get_hosts_from_sut_log(sutlog)
|
142
|
+
end
|
143
|
+
Groups.appendhosts(hosts, tag)
|
144
|
+
puts "Added the following hosts to tag #{tag}".green
|
145
|
+
hosts.each { |host| puts host }
|
146
|
+
VM.increaselife(hosts, nil)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
command :destroy do |c|
|
153
|
+
c.syntax = 'floatyhelper destroy <tag> [options]'
|
154
|
+
c.summary = 'Deletes active VMs'
|
155
|
+
c.description = 'Calls "floaty delete" on the VMPooler hosts with the given tag. Also removes these hosts and the tag from the status file.'
|
156
|
+
c.option '--all', 'Destroys all hosts in status file. USE WITH CAUTION!'
|
157
|
+
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.'
|
158
|
+
c.action do |args, options|
|
159
|
+
if args.length == 0 && !options.all && !options.hosts
|
160
|
+
puts 'Please specify a host or tag'.red
|
161
|
+
else
|
162
|
+
id = options.all ? 'all' : options.hosts ? Hosts.get_options_hosts(options.hosts) : args[0]
|
163
|
+
VM.destroy(id)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
command :destroy_from_token do |c|
|
169
|
+
c.syntax = 'floatyhelper destroy_from_token'
|
170
|
+
c.summary = 'Destroys all VMs assigned to the user\'s token'
|
171
|
+
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.'
|
172
|
+
c.action do |args, options|
|
173
|
+
info = eval(`floaty token status`)
|
174
|
+
info.delete('ok')
|
175
|
+
vms = info[info.keys[0]]['vms']
|
176
|
+
running = vms.nil? ? nil : vms['running']
|
177
|
+
if !running.nil?
|
178
|
+
VM.destroy(running)
|
179
|
+
else
|
180
|
+
puts 'No running VMs assigned to token to delete'.yellow
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
command :increaselife do |c|
|
186
|
+
c.syntax = 'floatyhelper increaselife <tag> [options]'
|
187
|
+
c.summary = 'Increase the lifetime of the given hosts'
|
188
|
+
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.'
|
189
|
+
c.option '--amount HOURS', Integer, 'Amount of hours to increase life. Default = 100'
|
190
|
+
c.option '--all', 'Destroys all hosts in status file. USE WITH CAUTION!'
|
191
|
+
c.option '--hosts HOST', String, 'Comma separated list of hosts to destroy instead of using a tag.'
|
192
|
+
c.action do |args, options|
|
193
|
+
if args.length == 0 && !options.all && !options.hosts
|
194
|
+
puts 'Please specify a host or tag'.red
|
195
|
+
else
|
196
|
+
id = options.all ? 'all' : options.hosts ? Hosts.get_options_hosts(options.hosts) : args[0]
|
197
|
+
VM.increaselife(id,options.amount)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
#command :query do |c|
|
203
|
+
# c.syntax = 'floatyhelper query [options]'
|
204
|
+
# c.summary = ''
|
205
|
+
# c.description = ''
|
206
|
+
# c.example 'description', 'command example'
|
207
|
+
# c.option '--some-switch', 'Some switch that does something'
|
208
|
+
# c.action do |args, options|
|
209
|
+
# # Do something or c.when_called Floatyhelper::Commands::Query
|
210
|
+
# end
|
211
|
+
#end
|
212
|
+
|
213
|
+
command :revert do |c|
|
214
|
+
c.syntax = 'floatyhelper revert <host|tag> <snaptag>'
|
215
|
+
c.summary = 'Revert VM to the given snaptag'
|
216
|
+
c.description = 'Reverts the given VM or host group to given snaptag. This snaptag is created when the snapshot command is run.'
|
217
|
+
c.action do |args, options|
|
218
|
+
if args.length < 2
|
219
|
+
puts "Please specify both a host/tag and a snaptag".red
|
220
|
+
else
|
221
|
+
VM.revert(args[0], args[1])
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
command :snapshot do |c|
|
227
|
+
c.syntax = 'floatyhelper snapshot <host|tag> <snaptag>'
|
228
|
+
c.summary = 'Snapshot the given VM or group of taggedhosts'
|
229
|
+
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.'
|
230
|
+
c.action do |args, options|
|
231
|
+
if args.length < 2
|
232
|
+
puts "Please specify both a host/tag and a snaptag"
|
233
|
+
else
|
234
|
+
if VM.snaptag_exists(args[0], args[1])
|
235
|
+
print "Snaptag #{args[1]} already exists. Are you sure you want to overwrite? [y/N] ".yellow
|
236
|
+
gets response
|
237
|
+
return unless response.capitalize == 'Y'
|
238
|
+
end
|
239
|
+
VM.snapshot(args[0], args[1])
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
run!
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: floatyhelper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.7'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Burgan-Illig
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry-byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: commander
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: vmfloaty
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: colorize
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: This CLI app utilizes Vmfloaty (https://github.com/briancain/vmfloaty)
|
98
|
+
to manipulate sets of VMs. VM groups can be snapshotted and reverted as sets of
|
99
|
+
hosts. This is useful when testing various configurations of Puppet Enterprise.
|
100
|
+
email:
|
101
|
+
- nick.burgan-illig@puppet.com
|
102
|
+
executables:
|
103
|
+
- floatyhelper
|
104
|
+
extensions: []
|
105
|
+
extra_rdoc_files: []
|
106
|
+
files:
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- bin/floatyhelper
|
110
|
+
- lib/floatyhelper.rb
|
111
|
+
- lib/floatyhelper/conf.rb
|
112
|
+
- lib/floatyhelper/groups.rb
|
113
|
+
- lib/floatyhelper/hosts.rb
|
114
|
+
- lib/floatyhelper/version.rb
|
115
|
+
- lib/floatyhelper/vm.rb
|
116
|
+
homepage: https://github.com/nmburgan/floatyhelper
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.7.6
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: CLI tool for manipulating Puppet's vmpooler VMs with Vmfloaty.
|
140
|
+
test_files: []
|