vmfloaty 0.9.0 → 0.11.1
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 +83 -47
- data/lib/vmfloaty.rb +64 -35
- data/lib/vmfloaty/abs.rb +56 -13
- data/lib/vmfloaty/conf.rb +1 -1
- data/lib/vmfloaty/logger.rb +27 -0
- data/lib/vmfloaty/nonstandard_pooler.rb +2 -2
- data/lib/vmfloaty/pooler.rb +34 -4
- data/lib/vmfloaty/service.rb +12 -17
- data/lib/vmfloaty/ssh.rb +11 -5
- data/lib/vmfloaty/utils.rb +54 -28
- data/lib/vmfloaty/version.rb +1 -1
- data/spec/spec_helper.rb +11 -0
- data/spec/vmfloaty/abs_spec.rb +32 -2
- data/spec/vmfloaty/nonstandard_pooler_spec.rb +2 -2
- data/spec/vmfloaty/pooler_spec.rb +22 -2
- data/spec/vmfloaty/ssh_spec.rb +49 -0
- data/spec/vmfloaty/utils_spec.rb +4 -4
- data/spec/vmfloaty/vmfloaty_services_spec.rb +39 -0
- metadata +27 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ebdafe4b60af0f238330584cbe7ee1a3a5258b1671b7805d45551c16c69465a
|
4
|
+
data.tar.gz: '002138e04b43f670d76d7f0311dbb4770e2153306874a527f0e537c59dfafc9e'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23e7ea9dbb546740ea16418f7a5e00d184df44634bf5dc9ff5421907a7fac55ff65d7d74516f1762a805cf865ff941b97e474e20db101029b176b89f1946d662
|
7
|
+
data.tar.gz: 7ffa31b013b4d332a6e19f56b56a6f55560dbc6a65702cf1b81be7317bc1b59b434af674f7f54ddb13f4dc611e96e27c947aa6c4679031f32b3475b49c1e5e40
|
data/README.md
CHANGED
@@ -1,40 +1,64 @@
|
|
1
|
-
vmfloaty
|
2
|
-
|
3
|
-
|
4
|
-
[](https://badge.fury.io/rb/vmfloaty)
|
4
|
+
[](https://travis-ci.com/puppetlabs/vmfloaty)
|
5
|
+
[](https://coveralls.io/github/puppetlabs/vmfloaty?branch=master)
|
6
|
+
[](https://dependabot.com)
|
7
|
+
|
8
|
+
A CLI helper tool for [Puppet's vmpooler](https://github.com/puppetlabs/vmpooler) to help you stay afloat.
|
9
|
+
|
10
|
+

|
11
|
+
|
12
|
+
- [Install](#install)
|
13
|
+
- [Usage](#usage)
|
14
|
+
- [Example workflow](#example-workflow)
|
15
|
+
- [vmfloaty dotfile](#vmfloaty-dotfile)
|
16
|
+
- [Basic configuration](#basic-configuration)
|
17
|
+
- [Default to Puppet's ABS instead of vmpooler](#default-to-puppets-abs-instead-of-vmpooler)
|
18
|
+
- [Configuring multiple services](#configuring-multiple-services)
|
19
|
+
- [Using a Nonstandard Pooler service](#using-a-nonstandard-pooler-service)
|
20
|
+
- [Valid config keys](#valid-config-keys)
|
21
|
+
- [Tab Completion](#tab-completion)
|
22
|
+
- [vmpooler API](#vmpooler-api)
|
23
|
+
- [Using the Pooler class](#using-the-pooler-class)
|
24
|
+
- [Example Projects](#example-projects)
|
25
|
+
- [Special thanks](#special-thanks)
|
11
26
|
|
12
27
|
## Install
|
13
28
|
|
14
29
|
Grab the latest from ruby gems...
|
15
30
|
|
16
|
-
```
|
17
|
-
|
18
|
-
...
|
19
|
-
...
|
20
|
-
$ floaty --help
|
31
|
+
```bash
|
32
|
+
gem install vmfloaty
|
21
33
|
```
|
22
34
|
|
23
35
|
## Usage
|
24
36
|
|
25
|
-
```
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
```plain
|
38
|
+
$ floaty --help
|
39
|
+
NAME:
|
40
|
+
|
41
|
+
floaty
|
42
|
+
|
43
|
+
DESCRIPTION:
|
44
|
+
|
45
|
+
A CLI helper tool for Puppet's vmpooler to help you stay afloat
|
46
|
+
|
47
|
+
COMMANDS:
|
48
|
+
|
49
|
+
completion Outputs path to completion script
|
50
|
+
delete Schedules the deletion of a host or hosts
|
51
|
+
get Gets a vm or vms based on the os argument
|
52
|
+
help Display global or [command] help documentation
|
53
|
+
list Shows a list of available vms from the pooler or vms obtained with a token
|
54
|
+
modify Modify a VM's tags, time to live, disk space, or reservation reason
|
55
|
+
query Get information about a given vm
|
56
|
+
revert Reverts a vm to a specified snapshot
|
57
|
+
snapshot Takes a snapshot of a given vm
|
58
|
+
ssh Grabs a single vm and sshs into it
|
59
|
+
status Prints the status of pools in the pooler service
|
60
|
+
summary Prints a summary of a pooler service
|
61
|
+
token Retrieves or deletes a token or checks token status
|
38
62
|
|
39
63
|
GLOBAL OPTIONS:
|
40
64
|
|
@@ -52,7 +76,7 @@ $ floaty --help
|
|
52
76
|
|
53
77
|
Grabbing a token for authenticated pooler requests:
|
54
78
|
|
55
|
-
```
|
79
|
+
```bash
|
56
80
|
floaty token get --user username --url https://vmpooler.example.net/api/v1
|
57
81
|
```
|
58
82
|
|
@@ -60,7 +84,7 @@ This command will then ask you to log in. If successful, it will return a token
|
|
60
84
|
|
61
85
|
Grabbing vms:
|
62
86
|
|
63
|
-
```
|
87
|
+
```bash
|
64
88
|
floaty get centos-7-x86_64=2 debian-7-x86_64 windows-10=3 --token mytokenstring --url https://vmpooler.example.net/api/v1
|
65
89
|
```
|
66
90
|
|
@@ -71,7 +95,7 @@ If you do not wish to continually specify various config options with the cli, y
|
|
71
95
|
#### Basic configuration
|
72
96
|
|
73
97
|
```yaml
|
74
|
-
# file at
|
98
|
+
# file at ~/.vmfloaty.yml
|
75
99
|
url: 'https://vmpooler.example.net/api/v1'
|
76
100
|
user: 'brian'
|
77
101
|
token: 'tokenstring'
|
@@ -79,6 +103,16 @@ token: 'tokenstring'
|
|
79
103
|
|
80
104
|
Now vmfloaty will use those config files if no flag was specified.
|
81
105
|
|
106
|
+
#### Default to Puppet's ABS instead of vmpooler
|
107
|
+
|
108
|
+
```yaml
|
109
|
+
# file at ~/.vmfloaty.yml
|
110
|
+
url: 'https://abs.example.net'
|
111
|
+
user: 'brian'
|
112
|
+
token: 'tokenstring'
|
113
|
+
type: 'abs'
|
114
|
+
```
|
115
|
+
|
82
116
|
#### Configuring multiple services
|
83
117
|
|
84
118
|
Most commands allow you to specify a `--service <servicename>` option to allow the use of multiple vmpooler instances. This can be useful when you'd rather not specify a `--url` or `--token` by hand for alternate services.
|
@@ -105,14 +139,16 @@ services:
|
|
105
139
|
Examples using the above configuration:
|
106
140
|
|
107
141
|
List available vm types from our main vmpooler instance:
|
108
|
-
|
142
|
+
|
143
|
+
```bash
|
109
144
|
floaty list --service main
|
110
145
|
# or, since the first configured service is used by default:
|
111
146
|
floaty list
|
112
147
|
```
|
113
148
|
|
114
149
|
List available vm types from our alternate vmpooler instance:
|
115
|
-
|
150
|
+
|
151
|
+
```bash
|
116
152
|
floaty list --service alternate
|
117
153
|
```
|
118
154
|
|
@@ -140,7 +176,7 @@ services:
|
|
140
176
|
|
141
177
|
With this configuration, you could list available OS types from nspooler like this:
|
142
178
|
|
143
|
-
```
|
179
|
+
```bash
|
144
180
|
floaty list --service ns
|
145
181
|
```
|
146
182
|
|
@@ -148,20 +184,16 @@ floaty list --service ns
|
|
148
184
|
|
149
185
|
Here are the keys that vmfloaty currently supports:
|
150
186
|
|
151
|
-
- verbose
|
152
|
-
|
153
|
-
-
|
154
|
-
|
155
|
-
-
|
156
|
-
|
157
|
-
- url
|
158
|
-
+ String
|
159
|
-
- services
|
160
|
-
+ Map
|
187
|
+
- verbose (Boolean)
|
188
|
+
- token (String)
|
189
|
+
- user (String)
|
190
|
+
- url (String)
|
191
|
+
- services (String)
|
192
|
+
- type (String)
|
161
193
|
|
162
194
|
### Tab Completion
|
163
195
|
|
164
|
-
There is a basic completion script for Bash (and possibly other shells) included with the gem in the [extras/completions](https://github.com/
|
196
|
+
There is a basic completion script for Bash (and possibly other shells) included with the gem in the [extras/completions](https://github.com/puppetlabs/vmfloaty/blob/master/extras/completions) folder. To activate, that file simply needs to be sourced somehow in your shell profile.
|
165
197
|
|
166
198
|
For convenience, the path to the completion script for the currently active version of the gem can be found with the `floaty completion` subcommand. This makes it easy to add the completion script to your profile like so:
|
167
199
|
|
@@ -186,6 +218,10 @@ vmfloaty providers a `Pooler` class that gives users the ability to make request
|
|
186
218
|
### Example Projects
|
187
219
|
|
188
220
|
- [John McCabe: vmpooler-bitbar](https://github.com/johnmccabe/vmpooler-bitbar/)
|
189
|
-
|
221
|
+
- vmpooler status and management in your menubar with bitbar
|
190
222
|
- [Brian Cain: vagrant-vmpooler](https://github.com/briancain/vagrant-vmpooler)
|
191
|
-
|
223
|
+
- Use Vagrant to manage your vmpooler instances
|
224
|
+
|
225
|
+
## Special thanks
|
226
|
+
|
227
|
+
Special thanks to [Brian Cain](https://github.com/briancain) as he is the original author of vmfloaty! Vast amounts of this code exist thanks to his efforts.
|
data/lib/vmfloaty.rb
CHANGED
@@ -13,13 +13,14 @@ require 'vmfloaty/conf'
|
|
13
13
|
require 'vmfloaty/utils'
|
14
14
|
require 'vmfloaty/service'
|
15
15
|
require 'vmfloaty/ssh'
|
16
|
+
require 'vmfloaty/logger'
|
16
17
|
|
17
18
|
class Vmfloaty
|
18
19
|
include Commander::Methods
|
19
20
|
|
20
21
|
def run # rubocop:disable Metrics/AbcSize
|
21
22
|
program :version, Vmfloaty::VERSION
|
22
|
-
program :description,
|
23
|
+
program :description, "A CLI helper tool for Puppet's vmpooler to help you stay afloat"
|
23
24
|
|
24
25
|
config = Conf.read_config
|
25
26
|
|
@@ -37,6 +38,7 @@ class Vmfloaty
|
|
37
38
|
c.option '--notoken', 'Makes a request without a token'
|
38
39
|
c.option '--force', 'Forces vmfloaty to get requested vms'
|
39
40
|
c.option '--json', 'Prints retrieved vms in JSON format'
|
41
|
+
c.option '--ondemand', 'Requested vms are provisioned upon receival of the request, tracked by a request ID'
|
40
42
|
c.action do |args, options|
|
41
43
|
verbose = options.verbose || config['verbose']
|
42
44
|
service = Service.new(options, config)
|
@@ -44,7 +46,7 @@ class Vmfloaty
|
|
44
46
|
force = options.force
|
45
47
|
|
46
48
|
if args.empty?
|
47
|
-
|
49
|
+
FloatyLogger.error 'No operating systems provided to obtain. See `floaty get --help` for more information on how to get VMs.'
|
48
50
|
exit 1
|
49
51
|
end
|
50
52
|
|
@@ -53,19 +55,23 @@ class Vmfloaty
|
|
53
55
|
max_pool_request = 5
|
54
56
|
large_pool_requests = os_types.select { |_, v| v > max_pool_request }
|
55
57
|
if !large_pool_requests.empty? && !force
|
56
|
-
|
57
|
-
|
58
|
+
FloatyLogger.error "Requesting vms over #{max_pool_request} requires a --force flag."
|
59
|
+
FloatyLogger.error 'Try again with `floaty get --force`'
|
58
60
|
exit 1
|
59
61
|
end
|
60
62
|
|
61
63
|
if os_types.empty?
|
62
|
-
|
64
|
+
FloatyLogger.error 'No operating systems provided to obtain. See `floaty get --help` for more information on how to get VMs.'
|
63
65
|
exit 1
|
64
66
|
end
|
65
67
|
|
66
|
-
response = service.retrieve(verbose, os_types, use_token)
|
68
|
+
response = service.retrieve(verbose, os_types, use_token, options.ondemand)
|
69
|
+
request_id = response['request_id'] if options.ondemand
|
70
|
+
response = service.wait_for_request(verbose, request_id) if options.ondemand
|
71
|
+
|
67
72
|
hosts = Utils.standardize_hostnames(response)
|
68
|
-
|
73
|
+
|
74
|
+
if options.json || options.ondemand
|
69
75
|
puts JSON.pretty_generate(hosts)
|
70
76
|
else
|
71
77
|
puts Utils.format_host_output(hosts)
|
@@ -81,6 +87,7 @@ class Vmfloaty
|
|
81
87
|
c.option '--verbose', 'Enables verbose output'
|
82
88
|
c.option '--service STRING', String, 'Configured pooler service name'
|
83
89
|
c.option '--active', 'Prints information about active vms for a given token'
|
90
|
+
c.option '--json', 'Prints information as JSON'
|
84
91
|
c.option '--token STRING', String, 'Token for pooler service'
|
85
92
|
c.option '--url STRING', String, 'URL of pooler service'
|
86
93
|
c.action do |args, options|
|
@@ -94,10 +101,18 @@ class Vmfloaty
|
|
94
101
|
running_vms = service.list_active(verbose)
|
95
102
|
host = URI.parse(service.url).host
|
96
103
|
if running_vms.empty?
|
97
|
-
|
104
|
+
if options.json
|
105
|
+
puts {}.to_json
|
106
|
+
else
|
107
|
+
FloatyLogger.info "You have no running VMs on #{host}"
|
108
|
+
end
|
98
109
|
else
|
99
|
-
|
100
|
-
|
110
|
+
if options.json
|
111
|
+
puts Utils.get_host_data(verbose, service, running_vms).to_json
|
112
|
+
else
|
113
|
+
puts "Your VMs on #{host}:"
|
114
|
+
Utils.pretty_print_hosts(verbose, service, running_vms)
|
115
|
+
end
|
101
116
|
end
|
102
117
|
else
|
103
118
|
# list available vms from pooler
|
@@ -146,7 +161,7 @@ class Vmfloaty
|
|
146
161
|
modify_all = options.all
|
147
162
|
|
148
163
|
if hostname.nil? && !modify_all
|
149
|
-
|
164
|
+
FloatyLogger.error 'ERROR: Provide a hostname or specify --all.'
|
150
165
|
exit 1
|
151
166
|
end
|
152
167
|
running_vms = modify_all ? service.list_active(verbose) : hostname.split(',')
|
@@ -167,7 +182,7 @@ class Vmfloaty
|
|
167
182
|
begin
|
168
183
|
modified_hash[vm] = service.modify(verbose, vm, modify_hash)
|
169
184
|
rescue ModifyError => e
|
170
|
-
|
185
|
+
FloatyLogger.error e
|
171
186
|
ok = false
|
172
187
|
end
|
173
188
|
end
|
@@ -185,13 +200,16 @@ class Vmfloaty
|
|
185
200
|
|
186
201
|
command :delete do |c|
|
187
202
|
c.syntax = 'floaty delete hostname,hostname2 [options]'
|
203
|
+
c.syntax += "\n floaty delete job1,job2 [options] (only supported with ABS)"
|
188
204
|
c.summary = 'Schedules the deletion of a host or hosts'
|
189
|
-
c.description = 'Given a comma separated list of hostnames, or --all for all vms, vmfloaty makes a request to the pooler service to schedule the deletion of those vms.'
|
205
|
+
c.description = 'Given a comma separated list of hostnames, or --all for all vms, vmfloaty makes a request to the pooler service to schedule the deletion of those vms. If you are using the ABS service, you can also pass in JobIDs here. Note that passing in a Job ID will delete *all* of the hosts in the job.' # rubocop:disable Layout/LineLength
|
190
206
|
c.example 'Schedules the deletion of a host or hosts', 'floaty delete myhost1,myhost2 --url http://vmpooler.example.com'
|
207
|
+
c.example 'Schedules the deletion of a JobID or JobIDs', 'floaty delete 1579300120799,1579300120800 --url http://abs.example.com'
|
191
208
|
c.option '--verbose', 'Enables verbose output'
|
192
209
|
c.option '--service STRING', String, 'Configured pooler service name'
|
193
210
|
c.option '--all', 'Deletes all vms acquired by a token'
|
194
211
|
c.option '-f', 'Does not prompt user when deleting all vms'
|
212
|
+
c.option '--json', 'Outputs hosts scheduled for deletion as JSON'
|
195
213
|
c.option '--token STRING', String, 'Token for pooler service'
|
196
214
|
c.option '--url STRING', String, 'URL of pooler service'
|
197
215
|
c.action do |args, options|
|
@@ -207,13 +225,18 @@ class Vmfloaty
|
|
207
225
|
if delete_all
|
208
226
|
running_vms = service.list_active(verbose)
|
209
227
|
if running_vms.empty?
|
210
|
-
|
228
|
+
if options.json
|
229
|
+
puts {}.to_json
|
230
|
+
else
|
231
|
+
FloatyLogger.info "You have no running VMs."
|
232
|
+
end
|
211
233
|
else
|
212
|
-
Utils.pretty_print_hosts(verbose, service, running_vms)
|
213
|
-
# Confirm deletion
|
214
|
-
puts
|
215
234
|
confirmed = true
|
216
|
-
|
235
|
+
unless force
|
236
|
+
Utils.pretty_print_hosts(verbose, service, running_vms, true)
|
237
|
+
# Confirm deletion
|
238
|
+
confirmed = agree('Delete all these VMs? [y/N]')
|
239
|
+
end
|
217
240
|
if confirmed
|
218
241
|
response = service.delete(verbose, running_vms)
|
219
242
|
response.each do |hostname, result|
|
@@ -236,23 +259,29 @@ class Vmfloaty
|
|
236
259
|
end
|
237
260
|
end
|
238
261
|
else
|
239
|
-
|
262
|
+
FloatyLogger.info 'You did not provide any hosts to delete'
|
240
263
|
exit 1
|
241
264
|
end
|
242
265
|
|
243
266
|
unless failures.empty?
|
244
|
-
|
267
|
+
FloatyLogger.info 'Unable to delete the following VMs:'
|
245
268
|
failures.each do |hostname|
|
246
|
-
|
269
|
+
FloatyLogger.info "- #{hostname}"
|
247
270
|
end
|
248
|
-
|
271
|
+
FloatyLogger.info 'Check `floaty list --active`; Do you need to specify a different service?'
|
249
272
|
end
|
250
273
|
|
251
274
|
unless successes.empty?
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
275
|
+
FloatyLogger.info unless failures.empty?
|
276
|
+
if options.json
|
277
|
+
puts successes.to_json
|
278
|
+
else
|
279
|
+
puts 'Scheduled the following VMs for deletion:'
|
280
|
+
output = ''
|
281
|
+
successes.each do |hostname|
|
282
|
+
output += "- #{hostname}\n"
|
283
|
+
end
|
284
|
+
puts output
|
256
285
|
end
|
257
286
|
end
|
258
287
|
|
@@ -277,7 +306,7 @@ class Vmfloaty
|
|
277
306
|
begin
|
278
307
|
snapshot_req = service.snapshot(verbose, hostname)
|
279
308
|
rescue TokenError, ModifyError => e
|
280
|
-
|
309
|
+
FloatyLogger.error e
|
281
310
|
exit 1
|
282
311
|
end
|
283
312
|
|
@@ -302,12 +331,12 @@ class Vmfloaty
|
|
302
331
|
hostname = args[0]
|
303
332
|
snapshot_sha = args[1] || options.snapshot
|
304
333
|
|
305
|
-
|
334
|
+
FloatyLogger.info "Two snapshot arguments were given....using snapshot #{snapshot_sha}" if args[1] && options.snapshot
|
306
335
|
|
307
336
|
begin
|
308
337
|
revert_req = service.revert(verbose, hostname, snapshot_sha)
|
309
338
|
rescue TokenError, ModifyError => e
|
310
|
-
|
339
|
+
FloatyLogger.error e
|
311
340
|
exit 1
|
312
341
|
end
|
313
342
|
|
@@ -382,14 +411,14 @@ class Vmfloaty
|
|
382
411
|
status = service.token_status(verbose, token_value)
|
383
412
|
puts status
|
384
413
|
when nil
|
385
|
-
|
414
|
+
FloatyLogger.error 'No action provided'
|
386
415
|
exit 1
|
387
416
|
else
|
388
|
-
|
417
|
+
FloatyLogger.error "Unknown action: #{action}"
|
389
418
|
exit 1
|
390
419
|
end
|
391
420
|
rescue TokenError => e
|
392
|
-
|
421
|
+
FloatyLogger.error e
|
393
422
|
exit 1
|
394
423
|
end
|
395
424
|
exit 0
|
@@ -413,13 +442,13 @@ class Vmfloaty
|
|
413
442
|
use_token = !options.notoken
|
414
443
|
|
415
444
|
if args.empty?
|
416
|
-
|
445
|
+
FloatyLogger.error 'No operating systems provided to obtain. See `floaty ssh --help` for more information on how to get VMs.'
|
417
446
|
exit 1
|
418
447
|
end
|
419
448
|
|
420
449
|
host_os = args.first
|
421
450
|
|
422
|
-
|
451
|
+
FloatyLogger.info "Can't ssh to multiple hosts; Using #{host_os} only..." if args.length > 1
|
423
452
|
|
424
453
|
service.ssh(verbose, host_os, use_token)
|
425
454
|
exit 0
|
@@ -446,7 +475,7 @@ class Vmfloaty
|
|
446
475
|
puts completion_file
|
447
476
|
exit 0
|
448
477
|
else
|
449
|
-
|
478
|
+
FloatyLogger.error "Could not find completion file for '#{shell}': No such file #{completion_file}"
|
450
479
|
exit 1
|
451
480
|
end
|
452
481
|
end
|