vmfloaty 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vmfloaty.rb +23 -23
- data/lib/vmfloaty/abs.rb +9 -9
- data/lib/vmfloaty/conf.rb +1 -1
- data/lib/vmfloaty/logger.rb +27 -0
- data/lib/vmfloaty/pooler.rb +2 -2
- data/lib/vmfloaty/service.rb +5 -14
- data/lib/vmfloaty/utils.rb +6 -7
- data/lib/vmfloaty/version.rb +1 -1
- data/spec/vmfloaty/utils_spec.rb +4 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 248dd5c9a8890b8990a7dad8dd7a21f52c8a8c2b65112c55449a5b5d3ac818af
|
4
|
+
data.tar.gz: 22cf2070b571a0feded3967308e6b11d42b5ea296d94be7c434a73454611f6df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cd836baeb4a37720024616f1ce113046fc6291cc73694edbaf74ee727648c1339ada9e004ba0d630822a315948d69bb9e6c67da1ec04df3ae079bf207a432c7
|
7
|
+
data.tar.gz: 46e15ff3d3d1cecd68cb92ed3fcd5d8240f68f45f704dff9fbf1e87007cae7b95b2d6f9d4b08753979b2c82fa6f412534a93e3bb17b96fb052003e821b31cf94
|
data/lib/vmfloaty.rb
CHANGED
@@ -13,6 +13,7 @@ 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
|
@@ -45,7 +46,7 @@ class Vmfloaty
|
|
45
46
|
force = options.force
|
46
47
|
|
47
48
|
if args.empty?
|
48
|
-
|
49
|
+
FloatyLogger.error 'No operating systems provided to obtain. See `floaty get --help` for more information on how to get VMs.'
|
49
50
|
exit 1
|
50
51
|
end
|
51
52
|
|
@@ -54,13 +55,13 @@ class Vmfloaty
|
|
54
55
|
max_pool_request = 5
|
55
56
|
large_pool_requests = os_types.select { |_, v| v > max_pool_request }
|
56
57
|
if !large_pool_requests.empty? && !force
|
57
|
-
|
58
|
-
|
58
|
+
FloatyLogger.error "Requesting vms over #{max_pool_request} requires a --force flag."
|
59
|
+
FloatyLogger.error 'Try again with `floaty get --force`'
|
59
60
|
exit 1
|
60
61
|
end
|
61
62
|
|
62
63
|
if os_types.empty?
|
63
|
-
|
64
|
+
FloatyLogger.error 'No operating systems provided to obtain. See `floaty get --help` for more information on how to get VMs.'
|
64
65
|
exit 1
|
65
66
|
end
|
66
67
|
|
@@ -151,7 +152,7 @@ class Vmfloaty
|
|
151
152
|
modify_all = options.all
|
152
153
|
|
153
154
|
if hostname.nil? && !modify_all
|
154
|
-
|
155
|
+
FloatyLogger.error 'ERROR: Provide a hostname or specify --all.'
|
155
156
|
exit 1
|
156
157
|
end
|
157
158
|
running_vms = modify_all ? service.list_active(verbose) : hostname.split(',')
|
@@ -172,7 +173,7 @@ class Vmfloaty
|
|
172
173
|
begin
|
173
174
|
modified_hash[vm] = service.modify(verbose, vm, modify_hash)
|
174
175
|
rescue ModifyError => e
|
175
|
-
|
176
|
+
FloatyLogger.error e
|
176
177
|
ok = false
|
177
178
|
end
|
178
179
|
end
|
@@ -214,11 +215,10 @@ class Vmfloaty
|
|
214
215
|
if delete_all
|
215
216
|
running_vms = service.list_active(verbose)
|
216
217
|
if running_vms.empty?
|
217
|
-
|
218
|
+
puts 'You have no running VMs.'
|
218
219
|
else
|
219
|
-
Utils.pretty_print_hosts(verbose, service, running_vms)
|
220
|
+
Utils.pretty_print_hosts(verbose, service, running_vms, true)
|
220
221
|
# Confirm deletion
|
221
|
-
puts
|
222
222
|
confirmed = true
|
223
223
|
confirmed = agree('Delete all these VMs? [y/N]') unless force
|
224
224
|
if confirmed
|
@@ -243,20 +243,20 @@ class Vmfloaty
|
|
243
243
|
end
|
244
244
|
end
|
245
245
|
else
|
246
|
-
|
246
|
+
FloatyLogger.info 'You did not provide any hosts to delete'
|
247
247
|
exit 1
|
248
248
|
end
|
249
249
|
|
250
250
|
unless failures.empty?
|
251
|
-
|
251
|
+
FloatyLogger.info 'Unable to delete the following VMs:'
|
252
252
|
failures.each do |hostname|
|
253
|
-
|
253
|
+
FloatyLogger.info "- #{hostname}"
|
254
254
|
end
|
255
|
-
|
255
|
+
FloatyLogger.info 'Check `floaty list --active`; Do you need to specify a different service?'
|
256
256
|
end
|
257
257
|
|
258
258
|
unless successes.empty?
|
259
|
-
|
259
|
+
FloatyLogger.info unless failures.empty?
|
260
260
|
puts 'Scheduled the following VMs for deletion:'
|
261
261
|
successes.each do |hostname|
|
262
262
|
puts "- #{hostname}"
|
@@ -284,7 +284,7 @@ class Vmfloaty
|
|
284
284
|
begin
|
285
285
|
snapshot_req = service.snapshot(verbose, hostname)
|
286
286
|
rescue TokenError, ModifyError => e
|
287
|
-
|
287
|
+
FloatyLogger.error e
|
288
288
|
exit 1
|
289
289
|
end
|
290
290
|
|
@@ -309,12 +309,12 @@ class Vmfloaty
|
|
309
309
|
hostname = args[0]
|
310
310
|
snapshot_sha = args[1] || options.snapshot
|
311
311
|
|
312
|
-
|
312
|
+
FloatyLogger.info "Two snapshot arguments were given....using snapshot #{snapshot_sha}" if args[1] && options.snapshot
|
313
313
|
|
314
314
|
begin
|
315
315
|
revert_req = service.revert(verbose, hostname, snapshot_sha)
|
316
316
|
rescue TokenError, ModifyError => e
|
317
|
-
|
317
|
+
FloatyLogger.error e
|
318
318
|
exit 1
|
319
319
|
end
|
320
320
|
|
@@ -389,14 +389,14 @@ class Vmfloaty
|
|
389
389
|
status = service.token_status(verbose, token_value)
|
390
390
|
puts status
|
391
391
|
when nil
|
392
|
-
|
392
|
+
FloatyLogger.error 'No action provided'
|
393
393
|
exit 1
|
394
394
|
else
|
395
|
-
|
395
|
+
FloatyLogger.error "Unknown action: #{action}"
|
396
396
|
exit 1
|
397
397
|
end
|
398
398
|
rescue TokenError => e
|
399
|
-
|
399
|
+
FloatyLogger.error e
|
400
400
|
exit 1
|
401
401
|
end
|
402
402
|
exit 0
|
@@ -420,13 +420,13 @@ class Vmfloaty
|
|
420
420
|
use_token = !options.notoken
|
421
421
|
|
422
422
|
if args.empty?
|
423
|
-
|
423
|
+
FloatyLogger.error 'No operating systems provided to obtain. See `floaty ssh --help` for more information on how to get VMs.'
|
424
424
|
exit 1
|
425
425
|
end
|
426
426
|
|
427
427
|
host_os = args.first
|
428
428
|
|
429
|
-
|
429
|
+
FloatyLogger.info "Can't ssh to multiple hosts; Using #{host_os} only..." if args.length > 1
|
430
430
|
|
431
431
|
service.ssh(verbose, host_os, use_token)
|
432
432
|
exit 0
|
@@ -453,7 +453,7 @@ class Vmfloaty
|
|
453
453
|
puts completion_file
|
454
454
|
exit 0
|
455
455
|
else
|
456
|
-
|
456
|
+
FloatyLogger.error "Could not find completion file for '#{shell}': No such file #{completion_file}"
|
457
457
|
exit 1
|
458
458
|
end
|
459
459
|
end
|
data/lib/vmfloaty/abs.rb
CHANGED
@@ -68,7 +68,7 @@ class ABS
|
|
68
68
|
|
69
69
|
ret_val.push(req_hash)
|
70
70
|
rescue NoMethodError
|
71
|
-
|
71
|
+
FloatyLogger.warn "Warning: couldn't parse line returned from abs/status/queue: "
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -85,7 +85,7 @@ class ABS
|
|
85
85
|
conn = Http.get_conn(verbose, url)
|
86
86
|
conn.headers['X-AUTH-TOKEN'] = token if token
|
87
87
|
|
88
|
-
|
88
|
+
FloatyLogger.info "Trying to delete hosts #{hosts}" if verbose
|
89
89
|
requests = get_active_requests(verbose, url, user)
|
90
90
|
|
91
91
|
jobs_to_delete = []
|
@@ -113,7 +113,7 @@ class ABS
|
|
113
113
|
}
|
114
114
|
jobs_to_delete.push(req_hash)
|
115
115
|
else
|
116
|
-
|
116
|
+
FloatyLogger.info "When using ABS you must delete all vms that you requested at the same time: Can't delete #{req_hash['request']['job']['id']}: #{hosts} does not include all of #{req_hash['allocated_resources']}"
|
117
117
|
end
|
118
118
|
end
|
119
119
|
end
|
@@ -127,7 +127,7 @@ class ABS
|
|
127
127
|
'hosts' => job['allocated_resources'],
|
128
128
|
}
|
129
129
|
|
130
|
-
|
130
|
+
FloatyLogger.info "Deleting #{req_obj}" if verbose
|
131
131
|
|
132
132
|
return_result = conn.post 'return', req_obj.to_json
|
133
133
|
req_obj['hosts'].each do |host|
|
@@ -220,11 +220,11 @@ class ABS
|
|
220
220
|
end
|
221
221
|
end
|
222
222
|
|
223
|
-
|
223
|
+
FloatyLogger.info "Posting to ABS #{req_obj.to_json}" if verbose
|
224
224
|
|
225
225
|
# os_string = os_type.map { |os, num| Array(os) * num }.flatten.join('+')
|
226
226
|
# raise MissingParamError, 'No operating systems provided to obtain.' if os_string.empty?
|
227
|
-
|
227
|
+
FloatyLogger.info "Requesting VMs with job_id: #{saved_job_id}. Will retry for up to an hour."
|
228
228
|
res = conn.post 'request', req_obj.to_json
|
229
229
|
|
230
230
|
retries = 360
|
@@ -237,7 +237,7 @@ class ABS
|
|
237
237
|
|
238
238
|
sleep_seconds = 10 if i >= 10
|
239
239
|
sleep_seconds = i if i < 10
|
240
|
-
|
240
|
+
FloatyLogger.info "Waiting #{sleep_seconds} seconds to check if ABS request has been filled. Queue Position: #{queue_place}... (x#{i})"
|
241
241
|
|
242
242
|
sleep(sleep_seconds)
|
243
243
|
end
|
@@ -276,7 +276,7 @@ class ABS
|
|
276
276
|
end
|
277
277
|
|
278
278
|
def self.snapshot(_verbose, _url, _hostname, _token)
|
279
|
-
|
279
|
+
FloatyLogger.info "Can't snapshot with ABS, use '--service vmpooler' (even for vms checked out with ABS)"
|
280
280
|
end
|
281
281
|
|
282
282
|
def self.status(verbose, url)
|
@@ -297,7 +297,7 @@ class ABS
|
|
297
297
|
def self.query(verbose, url, hostname)
|
298
298
|
return @active_hostnames if @active_hostnames
|
299
299
|
|
300
|
-
|
300
|
+
FloatyLogger.info "For vmpooler/snapshot information, use '--service vmpooler' (even for vms checked out with ABS)"
|
301
301
|
conn = Http.get_conn(verbose, url)
|
302
302
|
|
303
303
|
res = conn.get "host/#{hostname}"
|
data/lib/vmfloaty/conf.rb
CHANGED
@@ -8,7 +8,7 @@ class Conf
|
|
8
8
|
begin
|
9
9
|
conf = YAML.load_file("#{Dir.home}/.vmfloaty.yml")
|
10
10
|
rescue StandardError
|
11
|
-
|
11
|
+
FloatyLogger.warn "WARNING: There was no config file at #{Dir.home}/.vmfloaty.yml"
|
12
12
|
end
|
13
13
|
conf
|
14
14
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
class FloatyLogger < ::Logger
|
4
|
+
def self.logger
|
5
|
+
@@logger ||= FloatyLogger.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.info(msg)
|
9
|
+
FloatyLogger.logger.info msg
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.warn(msg)
|
13
|
+
FloatyLogger.logger.warn msg
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.error(msg)
|
17
|
+
FloatyLogger.logger.error msg
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
super(STDERR)
|
22
|
+
self.level = ::Logger::INFO
|
23
|
+
self.formatter = proc do |severity, datetime, progname, msg|
|
24
|
+
"#{msg}\n"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/vmfloaty/pooler.rb
CHANGED
@@ -60,10 +60,10 @@ class Pooler
|
|
60
60
|
while check_ondemandvm(verbose, request_id, url) == false
|
61
61
|
return false if (Time.now - start_time).to_i > timeout
|
62
62
|
|
63
|
-
|
63
|
+
FloatyLogger.info "waiting for request #{request_id} to be fulfilled"
|
64
64
|
sleep 5
|
65
65
|
end
|
66
|
-
|
66
|
+
FloatyLogger.info "The request has been fulfilled"
|
67
67
|
check_ondemandvm(verbose, request_id, url)
|
68
68
|
end
|
69
69
|
|
data/lib/vmfloaty/service.rb
CHANGED
@@ -36,7 +36,7 @@ class Service
|
|
36
36
|
|
37
37
|
def user
|
38
38
|
unless @config['user']
|
39
|
-
|
39
|
+
FloatyLogger.info "Enter your #{@config['url']} service username:"
|
40
40
|
@config['user'] = STDIN.gets.chomp
|
41
41
|
end
|
42
42
|
@config['user']
|
@@ -44,7 +44,7 @@ class Service
|
|
44
44
|
|
45
45
|
def token
|
46
46
|
unless @config['token']
|
47
|
-
|
47
|
+
FloatyLogger.info 'No token found. Retrieving a token...'
|
48
48
|
@config['token'] = get_new_token(nil)
|
49
49
|
end
|
50
50
|
@config['token']
|
@@ -76,7 +76,7 @@ class Service
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def retrieve(verbose, os_types, use_token = true, ondemand = nil)
|
79
|
-
|
79
|
+
FloatyLogger.info 'Requesting a vm without a token...' unless use_token
|
80
80
|
token_value = use_token ? token : nil
|
81
81
|
@service_object.retrieve verbose, os_types, token_value, url, user, @config, ondemand
|
82
82
|
end
|
@@ -91,22 +91,13 @@ class Service
|
|
91
91
|
begin
|
92
92
|
token_value = token || get_new_token(verbose)
|
93
93
|
rescue TokenError => e
|
94
|
-
|
95
|
-
|
94
|
+
FloatyLogger.error e
|
95
|
+
FloatyLogger.info 'Could not get token... requesting vm without a token anyway...'
|
96
96
|
end
|
97
97
|
end
|
98
98
|
Ssh.ssh(verbose, self, host_os, token_value)
|
99
99
|
end
|
100
100
|
|
101
|
-
def pretty_print_running(verbose, hostnames = [])
|
102
|
-
if hostnames.empty?
|
103
|
-
puts 'You have no running VMs.'
|
104
|
-
else
|
105
|
-
puts 'Running VMs:'
|
106
|
-
@service_object.pretty_print_hosts(verbose, hostnames, url)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
101
|
def query(verbose, hostname)
|
111
102
|
@service_object.query verbose, url, hostname
|
112
103
|
end
|
data/lib/vmfloaty/utils.rb
CHANGED
@@ -45,7 +45,6 @@ class Utils
|
|
45
45
|
|
46
46
|
result = {}
|
47
47
|
|
48
|
-
STDOUT.puts "response body is #{response_body}"
|
49
48
|
filtered_response_body = response_body.reject { |key, _| key == 'request_id' || key == 'ready' }
|
50
49
|
filtered_response_body.each do |os, value|
|
51
50
|
hostnames = Array(value['hostname'])
|
@@ -79,7 +78,7 @@ class Utils
|
|
79
78
|
os_types
|
80
79
|
end
|
81
80
|
|
82
|
-
def self.pretty_print_hosts(verbose, service, hostnames = [])
|
81
|
+
def self.pretty_print_hosts(verbose, service, hostnames = [], print_to_stderr = false)
|
83
82
|
hostnames = [hostnames] unless hostnames.is_a? Array
|
84
83
|
hostnames.each do |hostname|
|
85
84
|
begin
|
@@ -110,8 +109,8 @@ class Utils
|
|
110
109
|
raise "Invalid service type #{service.type}"
|
111
110
|
end
|
112
111
|
rescue StandardError => e
|
113
|
-
|
114
|
-
|
112
|
+
FloatyLogger.error("Something went wrong while trying to gather information on #{hostname}:")
|
113
|
+
FloatyLogger.error(e)
|
115
114
|
end
|
116
115
|
end
|
117
116
|
end
|
@@ -135,7 +134,7 @@ class Utils
|
|
135
134
|
char = 'o'
|
136
135
|
puts "#{name.ljust(width)} #{(char * ready).green}#{(char * pending).yellow}#{(char * missing).red}"
|
137
136
|
rescue StandardError => e
|
138
|
-
|
137
|
+
FloatyLogger.error "#{name.ljust(width)} #{e.red}"
|
139
138
|
end
|
140
139
|
end
|
141
140
|
puts message.colorize(status_response['status']['ok'] ? :default : :red)
|
@@ -154,11 +153,11 @@ class Utils
|
|
154
153
|
char = 'o'
|
155
154
|
puts "#{name.ljust(width)} #{(char * ready).green}#{(char * pending).yellow}#{(char * missing).red}"
|
156
155
|
rescue StandardError => e
|
157
|
-
|
156
|
+
FloatyLogger.error "#{name.ljust(width)} #{e.red}"
|
158
157
|
end
|
159
158
|
end
|
160
159
|
when 'ABS'
|
161
|
-
|
160
|
+
FloatyLogger.error 'ABS Not OK' unless status_response
|
162
161
|
puts 'ABS is OK'.green if status_response
|
163
162
|
else
|
164
163
|
raise "Invalid service type #{service.type}"
|
data/lib/vmfloaty/version.rb
CHANGED
data/spec/vmfloaty/utils_spec.rb
CHANGED
@@ -169,7 +169,7 @@ describe Utils do
|
|
169
169
|
} }
|
170
170
|
output = '- mcpy42eqjxli9g2.delivery.mycompany.net (ubuntu-1604-x86_64, 9.66/12 hours)'
|
171
171
|
|
172
|
-
expect(
|
172
|
+
expect(STDOUT).to receive(:puts).with(output)
|
173
173
|
|
174
174
|
service = Service.new(MockOptions.new, 'url' => url)
|
175
175
|
allow(service).to receive(:query)
|
@@ -195,7 +195,7 @@ describe Utils do
|
|
195
195
|
} }
|
196
196
|
output = '- aiydvzpg23r415q.delivery.mycompany.net (redhat-7-x86_64, 7.67/48 hours, user: bob, role: agent)'
|
197
197
|
|
198
|
-
expect(
|
198
|
+
expect(STDOUT).to receive(:puts).with(output)
|
199
199
|
|
200
200
|
service = Service.new(MockOptions.new, 'url' => url)
|
201
201
|
allow(service).to receive(:query)
|
@@ -216,7 +216,7 @@ describe Utils do
|
|
216
216
|
} }
|
217
217
|
output = '- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining)'
|
218
218
|
|
219
|
-
expect(
|
219
|
+
expect(STDOUT).to receive(:puts).with(output)
|
220
220
|
|
221
221
|
service = Service.new(MockOptions.new, 'url' => url, 'type' => 'ns')
|
222
222
|
allow(service).to receive(:query)
|
@@ -237,7 +237,7 @@ describe Utils do
|
|
237
237
|
} }
|
238
238
|
output = '- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining, reason: testing)'
|
239
239
|
|
240
|
-
expect(
|
240
|
+
expect(STDOUT).to receive(:puts).with(output)
|
241
241
|
|
242
242
|
service = Service.new(MockOptions.new, 'url' => url, 'type' => 'ns')
|
243
243
|
allow(service).to receive(:query)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vmfloaty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Cain
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-08-
|
12
|
+
date: 2020-08-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: colorize
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- lib/vmfloaty/conf.rb
|
79
79
|
- lib/vmfloaty/errors.rb
|
80
80
|
- lib/vmfloaty/http.rb
|
81
|
+
- lib/vmfloaty/logger.rb
|
81
82
|
- lib/vmfloaty/nonstandard_pooler.rb
|
82
83
|
- lib/vmfloaty/pooler.rb
|
83
84
|
- lib/vmfloaty/service.rb
|