vmfloaty 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf8e6d210de6ae23fdd371025ace279b939768d1f197b81b2226f326263bc204
4
- data.tar.gz: 7da421b68bb4377e31c4e5784e394ab672adb616ce8be4376e55f0006dd81849
3
+ metadata.gz: 259a0672eabcb43fbb7fddd8205341050ab60f902e7842cb520f81bab1f139eb
4
+ data.tar.gz: 22fdda03271053a921f305c6e547d09308d1d734bc77dfbd60bbbf47483e4137
5
5
  SHA512:
6
- metadata.gz: 846823d38e3b7dc5cfa066efcda72a6f58ad11ce875529a3ac6443551a138fbc3e05e262226e3dd756e93e8d31c9fa5c3bb4639f139158f5903a95c43bfb9b40
7
- data.tar.gz: e693187229fb1b845e4a2b24f9bf9b22e7b0e4244887f8c1fc6042e64d6082638266b56421e04a46948b2efc92e4abd3e4d0ccdf28e345e30a89a77909872022
6
+ metadata.gz: 3c0ca6bc4d734b7b0712001d7bd33b8b493cdf2e588712d422383631ef9a749f8b98964ff6a8b05dd2c4c465fb0726af3af88692bc4baa94278c546461614bc4
7
+ data.tar.gz: 072a4ab26891877393d3b70bc71d409b0a7dccd930bc6271fe6cf6bd7e16fe10e5fcd250b8313112afb9e8e9f25043c41d5173ad6bc0fb121d7e1f8255e74d4d
data/README.md CHANGED
@@ -19,6 +19,9 @@ A CLI helper tool for [Puppet's VMPooler](https://github.com/puppetlabs/vmpooler
19
19
  - [VMPooler API](#vmpooler-api)
20
20
  - [Using the Pooler class](#using-the-pooler-class)
21
21
  - [Example Projects](#example-projects)
22
+ - [Contributing](#contributing)
23
+ - [Code Reviews](#code-reviews)
24
+ - [Releasing](#releasing)
22
25
  - [Special thanks](#special-thanks)
23
26
 
24
27
  ## Install
@@ -164,6 +167,21 @@ vmfloaty providers a `Pooler` class that gives users the ability to make request
164
167
  - [Brian Cain: vagrant-vmpooler](https://github.com/briancain/vagrant-vmpooler)
165
168
  - Use Vagrant to manage your vmpooler instances
166
169
 
170
+ ## Contributing
171
+
172
+ PR's are welcome! We always love to see how others think this tool can be made better.
173
+
174
+ ### Code Reviews
175
+
176
+ Please wait for multiple code owners to sign off on any notable change.
177
+
178
+ ## Releasing
179
+
180
+ Releasing is a two step process:
181
+
182
+ 1. Submit a release prep PR that updates `lib/vmfloaty/version.rb` to the desired new version and get that merged
183
+ 2. Navigate to <https://github.com/puppetlabs/vmfloaty/actions/workflows/release.yml> --> Run workflow --> select "main" branch --> Run workflow. This will publish a GitHub release, build, and push the gem to RubyGems.
184
+
167
185
  ## Special thanks
168
186
 
169
187
  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.
@@ -87,7 +87,7 @@ class Service
87
87
  @service_object.wait_for_request verbose, requestid, url
88
88
  end
89
89
 
90
- def ssh(verbose, host_os, use_token = true)
90
+ def ssh(verbose, host_os, use_token = true, ondemand = nil)
91
91
  token_value = nil
92
92
  if use_token
93
93
  begin
@@ -97,7 +97,7 @@ class Service
97
97
  FloatyLogger.info 'Could not get token... requesting vm without a token anyway...'
98
98
  end
99
99
  end
100
- Ssh.ssh(verbose, self, host_os, token_value)
100
+ Ssh.ssh(verbose, self, host_os, token_value, ondemand)
101
101
  end
102
102
 
103
103
  def query(verbose, hostname)
data/lib/vmfloaty/ssh.rb CHANGED
@@ -14,27 +14,45 @@ class Ssh
14
14
  nil
15
15
  end
16
16
 
17
- def self.command_string(verbose, service, host_os, use_token)
17
+ def self.command_string(verbose, service, host_os, use_token, ondemand = nil)
18
18
  ssh_path = which('ssh')
19
19
  raise 'Could not determine path to ssh' unless ssh_path
20
-
21
- os_types = {}
20
+ os_types = Utils.generate_os_hash([host_os])
22
21
  os_types[host_os] = 1
23
22
 
24
- response = service.retrieve(verbose, os_types, use_token)
23
+ response = service.retrieve(verbose, os_types, use_token, ondemand)
25
24
  raise "Could not get vm from #{service.type}:\n #{response}" unless response['ok']
26
25
 
27
26
  user = /win/.match?(host_os) ? 'Administrator' : 'root'
28
27
 
29
- hostname = response[host_os]['hostname']
30
- hostname = response[host_os]['hostname'][0] if response[host_os]['hostname'].is_a?(Array)
31
- hostname = "#{hostname}.#{response['domain']}" unless hostname.end_with?('puppetlabs.net')
28
+ if ondemand
29
+ requestid = response['request_id']
30
+ service.wait_for_request(verbose, requestid)
31
+ hosts = service.check_ondemandvm(verbose, requestid, service.url)
32
+ if hosts['domain'].nil?
33
+ hostname = hosts[host_os]['hostname']
34
+ hostname = hosts[host_os]['hostname'][0] if hosts[host_os]['hostname'].is_a?(Array)
35
+ else
36
+ # Provides backwards compatibility with VMPooler API v1
37
+ hostname = "#{hosts[host_os]['hostname']}.#{hosts['domain']}"
38
+ hostname = "#{hosts[host_os]['hostname'][0]}.#{hosts['domain']}" if hosts[host_os]['hostname'].is_a?(Array)
39
+ end
40
+ else
41
+ if response['domain'].nil?
42
+ hostname = response[host_os]['hostname']
43
+ hostname = response[host_os]['hostname'][0] if response[host_os]['hostname'].is_a?(Array)
44
+ else
45
+ # Provides backwards compatibility with VMPooler API v1
46
+ hostname = "#{response[host_os]['hostname']}.#{response['domain']}"
47
+ hostname = "#{response[host_os]['hostname'][0]}.#{response['domain']}" if response[host_os]['hostname'].is_a?(Array)
48
+ end
49
+ end
32
50
 
33
51
  "#{ssh_path} #{user}@#{hostname}"
34
52
  end
35
53
 
36
- def self.ssh(verbose, service, host_os, use_token)
37
- cmd = command_string(verbose, service, host_os, use_token)
54
+ def self.ssh(verbose, service, host_os, use_token, ondemand)
55
+ cmd = command_string(verbose, service, host_os, use_token, ondemand)
38
56
  # TODO: Should this respect more ssh settings? Can it be configured
39
57
  # by users ssh config and does this respect those settings?
40
58
  Kernel.exec(cmd)
@@ -9,7 +9,7 @@ class Utils
9
9
  # TODO: Takes the json response body from an HTTP GET
10
10
  # request and "pretty prints" it
11
11
  def self.standardize_hostnames(response_body)
12
- # vmpooler response body example when `floaty get` arguments are `ubuntu-1610-x86_64=2 centos-7-x86_64`:
12
+ # vmpooler api v1 response body example when `floaty get` arguments are `ubuntu-1610-x86_64=2 centos-7-x86_64`:
13
13
  # {
14
14
  # "ok": true,
15
15
  # "domain": "delivery.mycompany.net",
@@ -21,6 +21,17 @@ class Utils
21
21
  # }
22
22
  # }
23
23
 
24
+ # vmpooler api v2 response body example when `floaty get` arguments are `ubuntu-1610-x86_64=2 centos-7-x86_64`:
25
+ # {
26
+ # "ok": true,
27
+ # "ubuntu-1610-x86_64": {
28
+ # "hostname": ["gdoy8q3nckuob0i.pooler.example.com", "ctnktsd0u11p9tm.pooler.example.com"]
29
+ # },
30
+ # "centos-7-x86_64": {
31
+ # "hostname": "dlgietfmgeegry2.pooler.example.com"
32
+ # }
33
+ # }
34
+
24
35
  # nonstandard pooler response body example when `floaty get` arguments are `solaris-11-sparc=2 ubuntu-16.04-power8`:
25
36
  # {
26
37
  # "ok": true,
@@ -98,7 +109,11 @@ class Utils
98
109
 
99
110
  puts abs_hostnames.join("\n")
100
111
  when 'Pooler'
101
- puts "#{hostname}.#{host_data['domain']}"
112
+ if host_data['domain'].nil?
113
+ puts hostname
114
+ else
115
+ puts "#{hostname}.#{host_data['domain']}"
116
+ end
102
117
  when 'NonstandardPooler'
103
118
  puts host_data['fqdn']
104
119
  else
@@ -197,9 +212,9 @@ class Utils
197
212
  pending = pool['pending']
198
213
  missing = max - ready - pending
199
214
  char = 'o'
200
- puts "#{name.ljust(width)} #{(char * ready).green}#{(char * pending).yellow}#{(char * missing).red}"
215
+ puts "#{name.ljust(width)} #{(char * ready)}#{(char * pending)}#{(char * missing)}"
201
216
  rescue StandardError => e
202
- FloatyLogger.error "#{name.ljust(width)} #{e.red}"
217
+ FloatyLogger.error "#{name.ljust(width)} #{e}"
203
218
  end
204
219
  puts message
205
220
  when 'NonstandardPooler'
@@ -214,13 +229,13 @@ class Utils
214
229
  pending = pool['pending'] || 0 # not available for nspooler
215
230
  missing = max - ready - pending
216
231
  char = 'o'
217
- puts "#{name.ljust(width)} #{(char * ready).green}#{(char * pending).yellow}#{(char * missing).red}"
232
+ puts "#{name.ljust(width)} #{(char * ready)}#{(char * pending)}#{(char * missing)}"
218
233
  rescue StandardError => e
219
- FloatyLogger.error "#{name.ljust(width)} #{e.red}"
234
+ FloatyLogger.error "#{name.ljust(width)} #{e}"
220
235
  end
221
236
  when 'ABS'
222
237
  FloatyLogger.error 'ABS Not OK' unless status_response
223
- puts 'ABS is OK'.green if status_response
238
+ puts 'ABS is OK' if status_response
224
239
  else
225
240
  raise "Invalid service type #{service.type}"
226
241
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Vmfloaty
4
- VERSION = '1.6.0'
4
+ VERSION = '1.7.0'
5
5
  end
data/lib/vmfloaty.rb CHANGED
@@ -484,7 +484,7 @@ class Vmfloaty
484
484
 
485
485
  FloatyLogger.info "Can't ssh to multiple hosts; Using #{host_os} only..." if args.length > 1
486
486
 
487
- service.ssh(verbose, host_os, use_token)
487
+ service.ssh(verbose, host_os, use_token, options.ondemand)
488
488
  exit 0
489
489
  end
490
490
  end
@@ -4,24 +4,35 @@ require 'spec_helper'
4
4
  require 'vmfloaty/ssh'
5
5
 
6
6
  class ServiceStub
7
- def retrieve(_verbose, os_types, _use_token)
7
+ def retrieve(_verbose, os_types, _use_token, ondemand)
8
8
  if os_types.keys[0] == 'abs_host_string'
9
9
  return {
10
10
  os_types.keys[0] => { 'hostname' => ['abs-hostname.delivery.puppetlabs.net'] },
11
11
  'ok' => true
12
12
  }
13
- end
14
13
 
15
- {
16
- os_types.keys[0] => { 'hostname' => 'vmpooler-hostname' },
17
- 'domain' => 'delivery.puppetlabs.net',
18
- 'ok' => true
19
- }
14
+ elsif os_types.keys[0] == 'vmpooler_api_v2_host_string'
15
+ return {
16
+ os_types.keys[0] => { 'hostname' => ['vmpooler-v2-hostname.delivery.puppetlabs.net'] },
17
+ 'ok' => true
18
+ }
19
+
20
+ else
21
+ return {
22
+ os_types.keys[0] => { 'hostname' => 'vmpooler-v1-hostname' },
23
+ 'domain' => 'delivery.puppetlabs.net',
24
+ 'ok' => true
25
+ }
26
+ end
20
27
  end
21
28
 
22
29
  def type
23
30
  return 'abs' if os_types == 'abs_host_string'
24
- return 'vmpooler' if os_types == 'vmpooler_host_string'
31
+ return 'vmpooler' if os_types == 'vmpooler_api_v1_host_string' || os_types == 'vmpooler_api_v2_host_string'
32
+ end
33
+
34
+ def wait_for_request(verbose, requestid)
35
+ return true
25
36
  end
26
37
  end
27
38
 
@@ -29,21 +40,73 @@ describe Ssh do
29
40
  before :each do
30
41
  end
31
42
 
32
- it 'gets a hostname string for abs' do
33
- verbose = false
34
- service = ServiceStub.new
35
- host_os = 'abs_host_string'
36
- use_token = false
37
- cmd = Ssh.command_string(verbose, service, host_os, use_token)
38
- expect(cmd).to match(/ssh root@abs-hostname.delivery.puppetlabs.net/)
43
+ context "for pooled requests" do
44
+ it 'gets a hostname string for abs' do
45
+ verbose = false
46
+ service = ServiceStub.new
47
+ host_os = 'abs_host_string'
48
+ use_token = false
49
+ cmd = Ssh.command_string(verbose, service, host_os, use_token)
50
+ expect(cmd).to match(/ssh root@abs-hostname.delivery.puppetlabs.net/)
51
+ end
52
+
53
+ it 'gets a hostname string for vmpooler api v1' do
54
+ verbose = true
55
+ service = ServiceStub.new
56
+ host_os = 'vmpooler_api_v1_host_string'
57
+ use_token = false
58
+ cmd = Ssh.command_string(verbose, service, host_os, use_token)
59
+ expect(cmd).to match(/ssh root@vmpooler-v1-hostname.delivery.puppetlabs.net/)
60
+ end
61
+
62
+ it 'gets a hostname string for vmpooler api v2' do
63
+ verbose = false
64
+ service = ServiceStub.new
65
+ host_os = 'vmpooler_api_v2_host_string'
66
+ use_token = false
67
+ cmd = Ssh.command_string(verbose, service, host_os, use_token)
68
+ expect(cmd).to match(/ssh root@vmpooler-v2-hostname.delivery.puppetlabs.net/)
69
+ end
39
70
  end
40
71
 
41
- it 'gets a hostname string for vmpooler' do
42
- verbose = false
43
- service = ServiceStub.new
44
- host_os = 'vmpooler_host_string'
45
- use_token = false
46
- cmd = Ssh.command_string(verbose, service, host_os, use_token)
47
- expect(cmd).to match(/ssh root@vmpooler-hostname.delivery.puppetlabs.net/)
72
+ context "for ondemand requests" do
73
+ let(:service) { ServiceStub.new }
74
+ let(:url) { 'http://pooler.example.com' }
75
+
76
+ it 'gets a hostname string for abs' do
77
+ verbose = false
78
+ host_os = 'abs_host_string'
79
+ use_token = false
80
+ ondemand = true
81
+ response = {'abs_host_string' => { 'hostname' => ['abs-hostname.delivery.puppetlabs.net']}}
82
+ allow(service).to receive(:url)
83
+ allow(service).to receive(:check_ondemandvm).and_return(response)
84
+ cmd = Ssh.command_string(verbose, service, host_os, use_token, ondemand)
85
+ expect(cmd).to match(/ssh root@abs-hostname.delivery.puppetlabs.net/)
86
+ end
87
+
88
+ it 'gets a hostname string for abs' do
89
+ verbose = false
90
+ host_os = 'vmpooler_api_v1_host_string'
91
+ use_token = false
92
+ ondemand = true
93
+ response = {'vmpooler_api_v1_host_string' => { 'hostname' => ['vmpooler_api_v1_host_string.delivery.puppetlabs.net']}}
94
+ allow(service).to receive(:url)
95
+ allow(service).to receive(:check_ondemandvm).and_return(response)
96
+ cmd = Ssh.command_string(verbose, service, host_os, use_token, ondemand)
97
+ expect(cmd).to match(/ssh root@vmpooler_api_v1_host_string.delivery.puppetlabs.net/)
98
+ end
99
+
100
+ it 'gets a hostname string for abs' do
101
+ verbose = false
102
+ host_os = 'vmpooler_api_v2_host_string'
103
+ use_token = false
104
+ ondemand = true
105
+ response = {'vmpooler_api_v2_host_string' => { 'hostname' => ['vmpooler_api_v2_host_string.delivery.puppetlabs.net']}}
106
+ allow(service).to receive(:url)
107
+ allow(service).to receive(:check_ondemandvm).and_return(response)
108
+ cmd = Ssh.command_string(verbose, service, host_os, use_token, ondemand)
109
+ expect(cmd).to match(/ssh root@vmpooler_api_v2_host_string.delivery.puppetlabs.net/)
110
+ end
48
111
  end
49
112
  end
@@ -13,7 +13,7 @@ end
13
13
  describe Utils do
14
14
  describe '#standardize_hostnames' do
15
15
  before :each do
16
- @vmpooler_response_body = '{
16
+ @vmpooler_api_v1_response_body = '{
17
17
  "ok": true,
18
18
  "domain": "delivery.mycompany.net",
19
19
  "ubuntu-1610-x86_64": {
@@ -23,6 +23,15 @@ describe Utils do
23
23
  "hostname": "dlgietfmgeegry2"
24
24
  }
25
25
  }'
26
+ @vmpooler_api_v2_response_body = '{
27
+ "ok": true,
28
+ "ubuntu-1610-x86_64": {
29
+ "hostname": ["gdoy8q3nckuob0i.delivery.mycompany.net", "ctnktsd0u11p9tm.delivery.mycompany.net"]
30
+ },
31
+ "centos-7-x86_64": {
32
+ "hostname": "dlgietfmgeegry2.delivery.mycompany.net"
33
+ }
34
+ }'
26
35
  @nonstandard_response_body = '{
27
36
  "ok": true,
28
37
  "solaris-10-sparc": {
@@ -34,8 +43,15 @@ describe Utils do
34
43
  }'
35
44
  end
36
45
 
37
- it 'formats a result from vmpooler into a hash of os to hostnames' do
38
- result = Utils.standardize_hostnames(JSON.parse(@vmpooler_response_body))
46
+ it 'formats a result from vmpooler v1 api into a hash of os to hostnames' do
47
+ result = Utils.standardize_hostnames(JSON.parse(@vmpooler_api_v1_response_body))
48
+ expect(result).to eq('centos-7-x86_64' => ['dlgietfmgeegry2.delivery.mycompany.net'],
49
+ 'ubuntu-1610-x86_64' => ['gdoy8q3nckuob0i.delivery.mycompany.net',
50
+ 'ctnktsd0u11p9tm.delivery.mycompany.net'])
51
+ end
52
+
53
+ it 'formats a result from vmpooler v2 api into a hash of os to hostnames' do
54
+ result = Utils.standardize_hostnames(JSON.parse(@vmpooler_api_v2_response_body))
39
55
  expect(result).to eq('centos-7-x86_64' => ['dlgietfmgeegry2.delivery.mycompany.net'],
40
56
  'ubuntu-1610-x86_64' => ['gdoy8q3nckuob0i.delivery.mycompany.net',
41
57
  'ctnktsd0u11p9tm.delivery.mycompany.net'])
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: 1.6.0
4
+ version: 1.7.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: 2022-02-16 00:00:00.000000000 Z
12
+ date: 2022-04-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: commander
@@ -52,9 +52,7 @@ dependencies:
52
52
  - !ruby/object:Gem::Version
53
53
  version: 1.5.1
54
54
  description: A helper tool for vmpooler to help you stay afloat
55
- email:
56
- - brianccain@gmail.com
57
- - dio-gems@puppet.com
55
+ email: dio-gems@puppet.com
58
56
  executables:
59
57
  - floaty
60
58
  extensions: []