floatyhelper 2.0.1 → 2.0.5
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.rb +4 -2
- data/lib/floatyhelper/floaty.rb +20 -24
- data/lib/floatyhelper/version.rb +1 -1
- data/lib/floatyhelper/vm.rb +10 -4
- 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: 1829fb78be42701872cbbc6e8960ab3e3ebcd8c20b4b5983a32111e5ee2a7b1c
|
4
|
+
data.tar.gz: 551dfec7ca2c9f64d1f975b6c202882de69b8e09f4cd06d66a50e55623a5d680
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5300396a677ea5076639329b4d7fc5cf5ec07c267ad59c840d782f4f997484a704b0e4cfdccfb1b64c1c6ef1937a58d287ce1832936ed6cfeb71d5403e0a335b
|
7
|
+
data.tar.gz: 91aec17eede5c0241b47e96653556580d476ebe17bdd8d0caae7df0b8f51094917b484f5b3e8c504b8b6669929da333f4bbdde7c1c3c9809965c487d3bce446b
|
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
|
data/lib/floatyhelper/floaty.rb
CHANGED
@@ -81,7 +81,7 @@ class Floaty
|
|
81
81
|
def self.check_tokens
|
82
82
|
data = load_vmfloaty_config
|
83
83
|
issues = false
|
84
|
-
FLOATY_SERVICES.each do |service,
|
84
|
+
FLOATY_SERVICES.each do |service, info|
|
85
85
|
if data['services'].nil? || data['services'][service].nil? || data['services'][service]['token'].nil?
|
86
86
|
puts "#{service} service token not found in .vmfloaty.yml".yellow
|
87
87
|
issues = true
|
@@ -93,7 +93,13 @@ class Floaty
|
|
93
93
|
next if result['ok']
|
94
94
|
|
95
95
|
puts "Problem checking #{service} token: #{result['reason']}".red
|
96
|
-
data['services']['token'] = nil
|
96
|
+
data['services'][service]['token'] = nil
|
97
|
+
if result['reason'].include?('Unparseable')
|
98
|
+
# User might have an old URL. Let's make sure to replace it with the latest.
|
99
|
+
# Should probably actually check the output for a 503/404 rather than make the
|
100
|
+
# assumption here.
|
101
|
+
data['services'][service]['url'] = info['url']
|
102
|
+
end
|
97
103
|
issues = true
|
98
104
|
end
|
99
105
|
if issues
|
@@ -108,6 +114,7 @@ class Floaty
|
|
108
114
|
# so ignore it until we reach the hash.
|
109
115
|
lines = output.split("\n")
|
110
116
|
index = lines.index { |l| l[0] == '{' }
|
117
|
+
return { 'ok' => false, 'reason' => 'Unparseable response from floaty' } if index.nil?
|
111
118
|
output = lines[index..-1].join
|
112
119
|
JSON.parse(output.gsub('=>',':'))
|
113
120
|
end
|
@@ -120,35 +127,24 @@ class Floaty
|
|
120
127
|
if use_pty
|
121
128
|
output = ''
|
122
129
|
status = nil
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
line = read.gets
|
130
|
+
IO.popen("/usr/bin/env floaty #{command}", :err => [:child, :out]) do |io|
|
131
|
+
while !Process.waitpid(io.pid, Process::WNOHANG)
|
132
|
+
line = io.gets
|
133
|
+
unless line.nil?
|
128
134
|
puts line
|
129
135
|
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
136
|
end
|
139
137
|
end
|
140
|
-
|
141
|
-
Process.waitall
|
142
|
-
# Double check we have the status
|
143
|
-
status ||= PTY.check(pid)
|
144
138
|
end
|
139
|
+
# Need to check exit status
|
140
|
+
output
|
145
141
|
else
|
146
142
|
output, status = Open3.capture2e("/usr/bin/env floaty #{command}")
|
143
|
+
if !status.exitstatus.zero? && !ignore_error
|
144
|
+
puts "Error running 'floaty #{command}': #{output}".red
|
145
|
+
exit status.exitstatus
|
146
|
+
end
|
147
|
+
output
|
147
148
|
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
149
|
end
|
154
150
|
end
|
data/lib/floatyhelper/version.rb
CHANGED
data/lib/floatyhelper/vm.rb
CHANGED
@@ -25,8 +25,11 @@ class VM
|
|
25
25
|
|
26
26
|
def self.find_pooled_platforms
|
27
27
|
begin # rubocop:disable Style/RedundantBegin
|
28
|
-
|
29
|
-
|
28
|
+
uri = URI.parse('https://vmpooler.delivery.puppetlabs.net/status')
|
29
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
30
|
+
http.use_ssl = true
|
31
|
+
result = http.get(uri.request_uri)
|
32
|
+
result = JSON.parse(result.body)
|
30
33
|
# Techinally, 'max > 0' tells you if it's a pooled platform, but if
|
31
34
|
# the pool is empty, we'll want to fall back to ABS anyway.
|
32
35
|
result['pools'].select { |_pool, info| info['ready'].positive? }.map { |pool, _info| pool.gsub('-pixa4','') }
|
@@ -109,7 +112,7 @@ class VM
|
|
109
112
|
puts 'Waiting for snapshots to appear in floaty query...'
|
110
113
|
alldone = false
|
111
114
|
until alldone
|
112
|
-
puts `tput cup
|
115
|
+
puts `tput cup #{hosts.count + 2}` if clr
|
113
116
|
alldone = true
|
114
117
|
print "\r" unless clr
|
115
118
|
hosts.each do |host|
|
@@ -159,7 +162,10 @@ class VM
|
|
159
162
|
def self.get_vm(platform: 'centos-7-x86_64', force_abs: false)
|
160
163
|
if !find_pooled_platforms.include?(platform.gsub('-pixa4','')) || force_abs
|
161
164
|
response = Floaty.floaty_cmd("get #{platform} --service abs --priority 1", use_pty: true)
|
162
|
-
response.chomp.split('- ')
|
165
|
+
vmlinesplit = response.chomp.split('- ')
|
166
|
+
# When use_pty is true, we've already printed stderr/stdout, so no need to do so again.
|
167
|
+
raise "Error obtaining a VM" if vmlinesplit.count == 1
|
168
|
+
vmlinesplit[1].split[0].split('.')[0]
|
163
169
|
else
|
164
170
|
response = Floaty.floaty_cmd("get #{platform} --service vmpooler")
|
165
171
|
raise "Error obtaining a VM: #{response}" if response.include?('error')
|
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.5
|
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-07-29 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.2
|
208
207
|
signing_key:
|
209
208
|
specification_version: 4
|
210
209
|
summary: CLI tool for manipulating Puppet's vmpooler VMs with Vmfloaty.
|