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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab5a427189944d8960bab3ac42f1def0053e19fbed5a76d23fe866bef85ea28d
4
- data.tar.gz: acddc4079e86b93b58a3ac1f4df3163fa440595e5f499f130ad5babeaa42f0cd
3
+ metadata.gz: 1829fb78be42701872cbbc6e8960ab3e3ebcd8c20b4b5983a32111e5ee2a7b1c
4
+ data.tar.gz: 551dfec7ca2c9f64d1f975b6c202882de69b8e09f4cd06d66a50e55623a5d680
5
5
  SHA512:
6
- metadata.gz: 97a90ee999e59877c3125cd96611b3de3a5eead211800eb0f233e9e2a9951680583309b053b173a3cb402c2b8ed4f8e7f698fb44e5484c86520e1875f5820604
7
- data.tar.gz: cbb27ccfe2310492034eb123a0bff8c7e39dc681091fc6bec444084a390c581c8e18d8d1b9ffd6a2729e1b591c0c1d52c93d7bb34bdf37e6c460f7d0e428bf6f
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
- type = query[host]['template'].gsub('-pixa4','')
117
- remaining = VM.alive(host, query) ? "#{query[host]['remaining']} hours remaining" : 'Expired'
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
@@ -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, _info|
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
- PTY.spawn("/usr/bin/env floaty #{command}") do |read, write, pid|
124
- write.close
125
- while status.nil?
126
- begin
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
@@ -1,3 +1,3 @@
1
1
  module FloatyhelperVersion
2
- VERSION = '2.0.1'.freeze
2
+ VERSION = '2.0.5'.freeze
3
3
  end
@@ -25,8 +25,11 @@ class VM
25
25
 
26
26
  def self.find_pooled_platforms
27
27
  begin # rubocop:disable Style/RedundantBegin
28
- result = Net::HTTP.get('vmpooler.delivery.puppetlabs.net','/status')
29
- result = JSON.parse(result)
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 4` if clr
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('- ')[1].split[0].split('.')[0]
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.1
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-03-15 00:00:00.000000000 Z
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
- rubyforge_project:
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.