vmfloaty 0.9.1 → 0.9.2

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: 3f04ad5dd857d55ff4d7dfa42eb344952bb2eac10d4601a911d8e7255e212d09
4
- data.tar.gz: 6b2b56d9cd35e5d48062116a7c17129ed0c4404d2fe9c00461fbc6ab90570181
3
+ metadata.gz: 19668270f1933ad365a4ee6c6ae0df7328c91dc9dc8500af7e127d7bc93e5f8b
4
+ data.tar.gz: c0134595ed849c2d81f769473e2bc7c52604ac405d4f3bd5add34b61456c317c
5
5
  SHA512:
6
- metadata.gz: b1785b87fc949e6088f0a8d0d17ce0a599a75bf6d117758adba8583c6aeeb88ff56b4ab3dff217cfc8029ae2115254a3a7a02e864db29a60ab6dac6d7b1eb597
7
- data.tar.gz: 2d5ebc3d83665e5fcf5f6bc7ef362f5d8a340e95e456ca859579264eae7d8fa3cd447f880355efec03e31a6de4daba2a816ad46b4e0bf69b5a692949e71ba753
6
+ metadata.gz: 3225e02bcddf4c2e16dd5f6e26f0daa797bd266ac7078d133ab225e6e317e6a4912ab4d360c96dabd34fccb45d7b79dec9e3b8302fd28d0d8eac9070e9c02134
7
+ data.tar.gz: 75f4363eb6339d58bf9750d304c47f32b85420c4dd2171a0405b659050c19fb07356619f917cb877133af3bfca92714b745d34391822a8940601e954cad19f6a
@@ -185,9 +185,11 @@ class Vmfloaty
185
185
 
186
186
  command :delete do |c|
187
187
  c.syntax = 'floaty delete hostname,hostname2 [options]'
188
+ c.syntax += "\n floaty delete job1,job2 [options] (only supported with ABS)"
188
189
  c.summary = 'Schedules the deletion of a host or hosts'
189
- c.description = 'Given a comma separated list of hostnames, or --all for all vms, vmfloaty makes a request to the pooler service to schedule the deletion of those vms.'
190
+ c.description = 'Given a comma separated list of hostnames, or --all for all vms, vmfloaty makes a request to the pooler service to schedule the deletion of those vms. If you are using the ABS service, you can also pass in JobIDs here. Note that passing in a Job ID will delete *all* of the hosts in the job.' # rubocop:disable Layout/LineLength
190
191
  c.example 'Schedules the deletion of a host or hosts', 'floaty delete myhost1,myhost2 --url http://vmpooler.example.com'
192
+ c.example 'Schedules the deletion of a JobID or JobIDs', 'floaty delete 1579300120799,1579300120800 --url http://abs.example.com'
191
193
  c.option '--verbose', 'Enables verbose output'
192
194
  c.option '--service STRING', String, 'Configured pooler service name'
193
195
  c.option '--all', 'Deletes all vms acquired by a token'
@@ -100,6 +100,11 @@ class ABS
100
100
  requests.each do |req_hash|
101
101
  next unless req_hash['state'] == 'allocated' || req_hash['state'] == 'filled'
102
102
 
103
+ if hosts.include? req_hash['request']['job']['id']
104
+ jobs_to_delete.push(req_hash)
105
+ next
106
+ end
107
+
103
108
  req_hash['allocated_resources'].each do |vm_name, _i|
104
109
  if hosts.include? vm_name['hostname']
105
110
  if all_job_resources_accounted_for(req_hash['allocated_resources'], hosts)
@@ -91,7 +91,7 @@ class Service
91
91
  STDERR.puts 'Could not get token... requesting vm without a token anyway...'
92
92
  end
93
93
  end
94
- Ssh.ssh(verbose, host_os, token_value, url)
94
+ Ssh.ssh(verbose, self, host_os, token_value)
95
95
  end
96
96
 
97
97
  def pretty_print_running(verbose, hostnames = [])
@@ -14,21 +14,27 @@ class Ssh
14
14
  nil
15
15
  end
16
16
 
17
- def self.ssh(verbose, host_os, token, url)
17
+ def self.command_string(verbose, service, host_os, use_token)
18
18
  ssh_path = which('ssh')
19
19
  raise 'Could not determine path to ssh' unless ssh_path
20
20
 
21
21
  os_types = {}
22
22
  os_types[host_os] = 1
23
23
 
24
- response = Pooler.retrieve(verbose, os_types, token, url)
25
- raise "Could not get vm from vmpooler:\n #{response}" unless response['ok']
24
+ response = service.retrieve(verbose, os_types, use_token)
25
+ raise "Could not get vm from #{service.type}:\n #{response}" unless response['ok']
26
26
 
27
27
  user = /win/.match?(host_os) ? 'Administrator' : 'root'
28
28
 
29
- hostname = "#{response[host_os]['hostname']}.#{response['domain']}"
30
- cmd = "#{ssh_path} #{user}@#{hostname}"
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')
31
32
 
33
+ "#{ssh_path} #{user}@#{hostname}"
34
+ end
35
+
36
+ def self.ssh(verbose, service, host_os, use_token)
37
+ cmd = command_string(verbose, service, host_os, use_token)
32
38
  # TODO: Should this respect more ssh settings? Can it be configured
33
39
  # by users ssh config and does this respect those settings?
34
40
  Kernel.exec(cmd)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Vmfloaty
4
- VERSION = '0.9.1'
4
+ VERSION = '0.9.2'
5
5
  end
@@ -65,14 +65,14 @@ describe ABS do
65
65
 
66
66
  describe '#test_abs_status_queue_endpoint' do
67
67
  before :each do
68
- # rubocop:disable Metrics/LineLength
68
+ # rubocop:disable Layout/LineLength
69
69
  @active_requests_response = '
70
70
  [
71
71
  "{ \"state\":\"allocated\",\"last_processed\":\"2019-12-16 23:00:34 +0000\",\"allocated_resources\":[{\"hostname\":\"take-this.delivery.puppetlabs.net\",\"type\":\"win-2012r2-x86_64\",\"engine\":\"vmpooler\"}],\"audit_log\":{\"2019-12-13 16:45:29 +0000\":\"Allocated take-this.delivery.puppetlabs.net for job 1576255517241\"},\"request\":{\"resources\":{\"win-2012r2-x86_64\":1},\"job\":{\"id\":\"1576255517241\",\"tags\":{\"user\":\"test-user\"},\"user\":\"test-user\",\"time-received\":1576255519},\"priority\":1}}",
72
72
  "null",
73
73
  "{\"state\":\"allocated\",\"last_processed\":\"2019-12-16 23:00:34 +0000\",\"allocated_resources\":[{\"hostname\":\"not-this.delivery.puppetlabs.net\",\"type\":\"win-2012r2-x86_64\",\"engine\":\"vmpooler\"}],\"audit_log\":{\"2019-12-13 16:46:14 +0000\":\"Allocated not-this.delivery.puppetlabs.net for job 1576255565159\"},\"request\":{\"resources\":{\"win-2012r2-x86_64\":1},\"job\":{\"id\":\"1576255565159\",\"tags\":{\"user\":\"not-test-user\"},\"user\":\"not-test-user\",\"time-received\":1576255566},\"priority\":1}}"
74
74
  ]'
75
- # rubocop:enable Metrics/LineLength
75
+ # rubocop:enable Layout/LineLength
76
76
  @token = 'utpg2i2xswor6h8ttjhu3d47z53yy47y'
77
77
  @test_user = 'test-user'
78
78
  end
@@ -92,5 +92,35 @@ describe ABS do
92
92
  )
93
93
  end
94
94
  end
95
+
96
+ describe '#test_abs_delete_jobid' do
97
+ before :each do
98
+ # rubocop:disable Layout/LineLength
99
+ @active_requests_response = '
100
+ [
101
+ "{ \"state\":\"allocated\", \"last_processed\":\"2020-01-17 22:29:13 +0000\", \"allocated_resources\":[{\"hostname\":\"craggy-chord.delivery.puppetlabs.net\", \"type\":\"centos-7-x86_64\", \"engine\":\"vmpooler\"}, {\"hostname\":\"visible-revival.delivery.puppetlabs.net\", \"type\":\"centos-7-x86_64\", \"engine\":\"vmpooler\"}], \"audit_log\":{\"2020-01-17 22:28:45 +0000\":\"Allocated craggy-chord.delivery.puppetlabs.net, visible-revival.delivery.puppetlabs.net for job 1579300120799\"}, \"request\":{\"resources\":{\"centos-7-x86_64\":2}, \"job\":{\"id\":\"1579300120799\", \"tags\":{\"user\":\"test-user\"}, \"user\":\"test-user\", \"time-received\":1579300120}, \"priority\":3}}"
102
+ ]'
103
+ @return_request = { '{"job_id":"1579300120799","hosts":{"hostname":"craggy-chord.delivery.puppetlabs.net","type":"centos-7-x86_64","engine":"vmpooler"},{"hostname":"visible-revival.delivery.puppetlabs.net","type":"centos-7-x86_64","engine":"vmpooler"}}'=>true }
104
+ # rubocop:enable Layout/LineLength
105
+ @token = 'utpg2i2xswor6h8ttjhu3d47z53yy47y'
106
+ @test_user = 'test-user'
107
+ # Job ID
108
+ @hosts = ['1579300120799']
109
+ end
110
+
111
+ it 'will delete the whole job' do
112
+ stub_request(:get, 'https://abs.example.com/status/queue')
113
+ .to_return(:status => 200, :body => @active_requests_response, :headers => {})
114
+ stub_request(:post, 'https://abs.example.com/return')
115
+ .with(:body => @return_request)
116
+ .to_return(:status => 200, :body => 'OK', :headers => {})
117
+
118
+ ret = ABS.delete(false, @abs_url, @hosts, @token, @test_user)
119
+
120
+ expect(ret).to include(
121
+ 'craggy-chord.delivery.puppetlabs.net' => { 'ok'=>true }, 'visible-revival.delivery.puppetlabs.net' => { 'ok'=>true },
122
+ )
123
+ end
124
+ end
95
125
  end
96
126
  end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'vmfloaty/ssh'
5
+
6
+ class ServiceStub
7
+ def retrieve(_verbose, os_types, _use_token)
8
+ if os_types.keys[0] == 'abs_host_string'
9
+ return {
10
+ os_types.keys[0] => { 'hostname' => ['abs-hostname.delivery.puppetlabs.net'] },
11
+ 'ok' => true,
12
+ }
13
+ end
14
+
15
+ {
16
+ os_types.keys[0] => { 'hostname' => 'vmpooler-hostname' },
17
+ 'domain' => 'delivery.puppetlabs.net',
18
+ 'ok' => true,
19
+ }
20
+ end
21
+
22
+ def type
23
+ return 'abs' if os_types == 'abs_host_string'
24
+ return 'vmpooler' if os_types == 'vmpooler_host_string'
25
+ end
26
+ end
27
+
28
+ describe Ssh do
29
+ before :each do
30
+ end
31
+
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/)
39
+ end
40
+
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/)
48
+ end
49
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vmfloaty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Cain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-14 00:00:00.000000000 Z
11
+ date: 2020-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.15.0
47
+ version: 0.17.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.15.0
54
+ version: 0.17.0
55
55
  description: A helper tool for vmpooler to help you stay afloat
56
56
  email:
57
57
  - brianccain@gmail.com
@@ -83,6 +83,7 @@ files:
83
83
  - spec/vmfloaty/nonstandard_pooler_spec.rb
84
84
  - spec/vmfloaty/pooler_spec.rb
85
85
  - spec/vmfloaty/service_spec.rb
86
+ - spec/vmfloaty/ssh_spec.rb
86
87
  - spec/vmfloaty/utils_spec.rb
87
88
  - spec/vmfloaty/vmfloaty_services_spec.rb
88
89
  homepage: https://github.com/briancain/vmfloaty
@@ -104,18 +105,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
105
  - !ruby/object:Gem::Version
105
106
  version: '0'
106
107
  requirements: []
107
- rubyforge_project:
108
- rubygems_version: 2.7.7
108
+ rubygems_version: 3.0.3
109
109
  signing_key:
110
110
  specification_version: 4
111
111
  summary: CLI application to interface with vmpooler
112
112
  test_files:
113
113
  - spec/spec_helper.rb
114
- - spec/vmfloaty/service_spec.rb
115
- - spec/vmfloaty/utils_spec.rb
116
114
  - spec/vmfloaty/auth_spec.rb
115
+ - spec/vmfloaty/utils_spec.rb
117
116
  - spec/vmfloaty/nonstandard_pooler_spec.rb
118
- - spec/vmfloaty/abs_spec.rb
117
+ - spec/vmfloaty/ssh_spec.rb
118
+ - spec/vmfloaty/service_spec.rb
119
119
  - spec/vmfloaty/pooler_spec.rb
120
- - spec/vmfloaty/vmfloaty_services_spec.rb
121
120
  - spec/vmfloaty/abs/auth_spec.rb
121
+ - spec/vmfloaty/abs_spec.rb
122
+ - spec/vmfloaty/vmfloaty_services_spec.rb