floatyhelper 2.0.2 → 2.0.6
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/lib/floatyhelper/floaty.rb +27 -25
- data/lib/floatyhelper/version.rb +1 -1
- data/lib/floatyhelper/vm.rb +12 -5
- data/lib/floatyhelper.rb +4 -2
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12632be13fdd03beaa837d72ea01a0ba7fff08494a79ed4f839070debfc35e89
|
4
|
+
data.tar.gz: d9ca928fc876f292aca393aa4b1071508797b4883e3e64797a2ff75fb436f12e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec8bc4eedba90e8457588265add5cdf55924f4583f65b9da4e5e1404771d009b1cfb5cbf09abcb8376ff7eeeb5cdf65b8f96d63ad5643fcaf11dcae9663489d1
|
7
|
+
data.tar.gz: 3fa22d4d9a06edae1e6bf5db430b9b383f36549666c59056dfb5a87adc754b652da76af3ed0c1dd35f1222e8ca4f486d6298ce6951fff2cf7f580a122f2d8a8d
|
data/lib/floatyhelper/floaty.rb
CHANGED
@@ -12,7 +12,7 @@ class Floaty
|
|
12
12
|
},
|
13
13
|
'vmpooler' => {
|
14
14
|
'type' => 'vm',
|
15
|
-
'url' => '
|
15
|
+
'url' => 'https://vmpooler-prod.k8s.infracore.puppet.net',
|
16
16
|
},
|
17
17
|
'nspooler' => {
|
18
18
|
'type' => 'nonstandard',
|
@@ -32,6 +32,12 @@ class Floaty
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
def self.vmpooler_url
|
36
|
+
data = load_vmfloaty_config
|
37
|
+
url = data['services'] && data['services']['vmpooler'] ? data['services']['vmpooler']['url'] : nil
|
38
|
+
url || FLOATY_SERVICES['vmpooler']['url']
|
39
|
+
end
|
40
|
+
|
35
41
|
# This adds some stdout printing here which I was trying to avoid, but
|
36
42
|
# I think it makes sense to put it here rather than the main floatyhelper
|
37
43
|
# somewhere.
|
@@ -81,7 +87,7 @@ class Floaty
|
|
81
87
|
def self.check_tokens
|
82
88
|
data = load_vmfloaty_config
|
83
89
|
issues = false
|
84
|
-
FLOATY_SERVICES.each do |service,
|
90
|
+
FLOATY_SERVICES.each do |service, info|
|
85
91
|
if data['services'].nil? || data['services'][service].nil? || data['services'][service]['token'].nil?
|
86
92
|
puts "#{service} service token not found in .vmfloaty.yml".yellow
|
87
93
|
issues = true
|
@@ -93,7 +99,13 @@ class Floaty
|
|
93
99
|
next if result['ok']
|
94
100
|
|
95
101
|
puts "Problem checking #{service} token: #{result['reason']}".red
|
96
|
-
data['services']['token'] = nil
|
102
|
+
data['services'][service]['token'] = nil
|
103
|
+
if result['reason'].include?('Unparseable')
|
104
|
+
# User might have an old URL. Let's make sure to replace it with the latest.
|
105
|
+
# Should probably actually check the output for a 503/404 rather than make the
|
106
|
+
# assumption here.
|
107
|
+
data['services'][service]['url'] = info['url']
|
108
|
+
end
|
97
109
|
issues = true
|
98
110
|
end
|
99
111
|
if issues
|
@@ -108,6 +120,7 @@ class Floaty
|
|
108
120
|
# so ignore it until we reach the hash.
|
109
121
|
lines = output.split("\n")
|
110
122
|
index = lines.index { |l| l[0] == '{' }
|
123
|
+
return { 'ok' => false, 'reason' => 'Unparseable response from floaty' } if index.nil?
|
111
124
|
output = lines[index..-1].join
|
112
125
|
JSON.parse(output.gsub('=>',':'))
|
113
126
|
end
|
@@ -120,35 +133,24 @@ class Floaty
|
|
120
133
|
if use_pty
|
121
134
|
output = ''
|
122
135
|
status = nil
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
line = read.gets
|
136
|
+
IO.popen("/usr/bin/env floaty #{command}", :err => [:child, :out]) do |io|
|
137
|
+
while !Process.waitpid(io.pid, Process::WNOHANG)
|
138
|
+
line = io.gets
|
139
|
+
unless line.nil?
|
128
140
|
puts line
|
129
141
|
output += line
|
130
|
-
rescue EOFError, Errno::EIO
|
131
|
-
# GNU/Linux raises EIO on read operation when pty is closed - see pty.rb docs
|
132
|
-
# Ensure child process finishes and then pass through to ensure below to get status
|
133
|
-
nil
|
134
|
-
rescue IO::WaitReadable, IO::WaitWritable
|
135
|
-
retry
|
136
|
-
ensure
|
137
|
-
status ||= PTY.check(pid)
|
138
142
|
end
|
139
143
|
end
|
140
|
-
|
141
|
-
Process.waitall
|
142
|
-
# Double check we have the status
|
143
|
-
status ||= PTY.check(pid)
|
144
144
|
end
|
145
|
+
# Need to check exit status
|
146
|
+
output
|
145
147
|
else
|
146
148
|
output, status = Open3.capture2e("/usr/bin/env floaty #{command}")
|
149
|
+
if !status.exitstatus.zero? && !ignore_error
|
150
|
+
puts "Error running 'floaty #{command}': #{output}".red
|
151
|
+
exit status.exitstatus
|
152
|
+
end
|
153
|
+
output
|
147
154
|
end
|
148
|
-
if !status.exitstatus.zero? && !ignore_error
|
149
|
-
puts "Error running 'floaty #{command}': #{output}".red
|
150
|
-
exit status.exitstatus
|
151
|
-
end
|
152
|
-
output
|
153
155
|
end
|
154
156
|
end
|
data/lib/floatyhelper/version.rb
CHANGED
data/lib/floatyhelper/vm.rb
CHANGED
@@ -24,16 +24,20 @@ class VM
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.find_pooled_platforms
|
27
|
+
vmpooler_url = Floaty.vmpooler_url
|
27
28
|
begin # rubocop:disable Style/RedundantBegin
|
28
|
-
|
29
|
-
|
29
|
+
uri = URI.parse("#{vmpooler_url}/status")
|
30
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
31
|
+
http.use_ssl = true
|
32
|
+
result = http.get(uri.request_uri)
|
33
|
+
result = JSON.parse(result.body)
|
30
34
|
# Techinally, 'max > 0' tells you if it's a pooled platform, but if
|
31
35
|
# the pool is empty, we'll want to fall back to ABS anyway.
|
32
36
|
result['pools'].select { |_pool, info| info['ready'].positive? }.map { |pool, _info| pool.gsub('-pixa4','') }
|
33
37
|
rescue StandardError
|
34
38
|
# Not a great practice to swallow all errors, but this list is probably
|
35
39
|
# pretty stable, so let's just pass along the default.
|
36
|
-
puts
|
40
|
+
puts "Error looking up pooled platforms from #{vmpooler_url}/status. Using default pooled platform list instead.".yellow
|
37
41
|
pooled_platforms_default
|
38
42
|
end
|
39
43
|
end
|
@@ -109,7 +113,7 @@ class VM
|
|
109
113
|
puts 'Waiting for snapshots to appear in floaty query...'
|
110
114
|
alldone = false
|
111
115
|
until alldone
|
112
|
-
puts `tput cup #{hosts.count+2}` if clr
|
116
|
+
puts `tput cup #{hosts.count + 2}` if clr
|
113
117
|
alldone = true
|
114
118
|
print "\r" unless clr
|
115
119
|
hosts.each do |host|
|
@@ -159,7 +163,10 @@ class VM
|
|
159
163
|
def self.get_vm(platform: 'centos-7-x86_64', force_abs: false)
|
160
164
|
if !find_pooled_platforms.include?(platform.gsub('-pixa4','')) || force_abs
|
161
165
|
response = Floaty.floaty_cmd("get #{platform} --service abs --priority 1", use_pty: true)
|
162
|
-
response.chomp.split('- ')
|
166
|
+
vmlinesplit = response.chomp.split('- ')
|
167
|
+
# When use_pty is true, we've already printed stderr/stdout, so no need to do so again.
|
168
|
+
raise "Error obtaining a VM" if vmlinesplit.count == 1
|
169
|
+
vmlinesplit[1].split[0].split('.')[0]
|
163
170
|
else
|
164
171
|
response = Floaty.floaty_cmd("get #{platform} --service vmpooler")
|
165
172
|
raise "Error obtaining a VM: #{response}" if response.include?('error')
|
data/lib/floatyhelper.rb
CHANGED
@@ -113,8 +113,10 @@ class Floatyhelper
|
|
113
113
|
type = ''
|
114
114
|
if options.check
|
115
115
|
query = VM.query(host)
|
116
|
-
|
117
|
-
|
116
|
+
if query && query['ok']
|
117
|
+
type = query[host]['template'].gsub('-pixa4','')
|
118
|
+
remaining = VM.alive(host, query) ? "#{query[host]['remaining']} hours remaining" : 'Expired'
|
119
|
+
end
|
118
120
|
end
|
119
121
|
puts ' %-15s %-28s %s' % [host, type, remaining]
|
120
122
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: floatyhelper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Burgan-Illig
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -203,8 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
203
|
- !ruby/object:Gem::Version
|
204
204
|
version: '0'
|
205
205
|
requirements: []
|
206
|
-
|
207
|
-
rubygems_version: 2.7.6
|
206
|
+
rubygems_version: 3.1.6
|
208
207
|
signing_key:
|
209
208
|
specification_version: 4
|
210
209
|
summary: CLI tool for manipulating Puppet's vmpooler VMs with Vmfloaty.
|