mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 13:28:42 -05:00
commit
e50c9ec4ca
3 changed files with 29 additions and 18 deletions
|
|
@ -64,7 +64,7 @@ class ABS
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_active_requests(verbose, url, user)
|
def self.get_active_requests(verbose, url, user)
|
||||||
conn = Http.get_conn(verbose, url)
|
conn = Http.get_conn(verbose, supported_abs_url(url))
|
||||||
res = conn.get 'status/queue'
|
res = conn.get 'status/queue'
|
||||||
if valid_json?(res.body)
|
if valid_json?(res.body)
|
||||||
requests = JSON.parse(res.body)
|
requests = JSON.parse(res.body)
|
||||||
|
|
@ -105,7 +105,7 @@ class ABS
|
||||||
|
|
||||||
def self.delete(verbose, url, hosts, token, user)
|
def self.delete(verbose, url, hosts, token, user)
|
||||||
# In ABS terms, this is a "returned" host.
|
# In ABS terms, this is a "returned" host.
|
||||||
conn = Http.get_conn(verbose, url)
|
conn = Http.get_conn(verbose, supported_abs_url(url))
|
||||||
conn.headers['X-AUTH-TOKEN'] = token if token
|
conn.headers['X-AUTH-TOKEN'] = token if token
|
||||||
|
|
||||||
FloatyLogger.info "Trying to delete hosts #{hosts}" if verbose
|
FloatyLogger.info "Trying to delete hosts #{hosts}" if verbose
|
||||||
|
|
@ -163,7 +163,7 @@ class ABS
|
||||||
|
|
||||||
# List available VMs in ABS
|
# List available VMs in ABS
|
||||||
def self.list(verbose, url, os_filter = nil)
|
def self.list(verbose, url, os_filter = nil)
|
||||||
conn = Http.get_conn(verbose, url)
|
conn = Http.get_conn(verbose, supported_abs_url(url))
|
||||||
|
|
||||||
os_list = []
|
os_list = []
|
||||||
|
|
||||||
|
|
@ -245,7 +245,7 @@ class ABS
|
||||||
# }
|
# }
|
||||||
# }
|
# }
|
||||||
|
|
||||||
conn = Http.get_conn(verbose, url)
|
conn = Http.get_conn(verbose, supported_abs_url(url))
|
||||||
conn.headers['X-AUTH-TOKEN'] = token if token
|
conn.headers['X-AUTH-TOKEN'] = token if token
|
||||||
|
|
||||||
saved_job_id = user + "-" + DateTime.now.strftime('%Q')
|
saved_job_id = user + "-" + DateTime.now.strftime('%Q')
|
||||||
|
|
@ -348,7 +348,7 @@ class ABS
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.status(verbose, url)
|
def self.status(verbose, url)
|
||||||
conn = Http.get_conn(verbose, url)
|
conn = Http.get_conn(verbose, supported_abs_url(url))
|
||||||
|
|
||||||
res = conn.get 'status'
|
res = conn.get 'status'
|
||||||
|
|
||||||
|
|
@ -366,7 +366,7 @@ class ABS
|
||||||
return @active_hostnames if @active_hostnames && !@active_hostnames.empty?
|
return @active_hostnames if @active_hostnames && !@active_hostnames.empty?
|
||||||
|
|
||||||
# If using the cli query job_id
|
# If using the cli query job_id
|
||||||
conn = Http.get_conn(verbose, url)
|
conn = Http.get_conn(verbose, supported_abs_url(url))
|
||||||
queue_info_res = conn.get "status/queue/info/#{job_id}"
|
queue_info_res = conn.get "status/queue/info/#{job_id}"
|
||||||
if valid_json?(queue_info_res.body)
|
if valid_json?(queue_info_res.body)
|
||||||
queue_info = JSON.parse(queue_info_res.body)
|
queue_info = JSON.parse(queue_info_res.body)
|
||||||
|
|
@ -411,4 +411,15 @@ class ABS
|
||||||
rescue TypeError, JSON::ParserError => e
|
rescue TypeError, JSON::ParserError => e
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# when missing, adds the required api/v2 in the url
|
||||||
|
def self.supported_abs_url(url)
|
||||||
|
expected_ending = "api/v2"
|
||||||
|
if !url.include?(expected_ending)
|
||||||
|
# add a slash if missing
|
||||||
|
expected_ending = "/#{expected_ending}" if url[-1] != "/"
|
||||||
|
url = "#{url}#{expected_ending}"
|
||||||
|
end
|
||||||
|
url
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Vmfloaty
|
class Vmfloaty
|
||||||
VERSION = '1.0.0'
|
VERSION = '1.1.1'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,11 @@ describe ABS do
|
||||||
|
|
||||||
describe '#list' do
|
describe '#list' do
|
||||||
it 'skips empty platforms and lists aws' do
|
it 'skips empty platforms and lists aws' do
|
||||||
stub_request(:get, "http://foo/status/platforms/vmpooler").
|
stub_request(:get, "http://foo/api/v2/status/platforms/vmpooler").
|
||||||
to_return(:status => 200, :body => "", :headers => {})
|
to_return(:status => 200, :body => "", :headers => {})
|
||||||
stub_request(:get, "http://foo/status/platforms/ondemand_vmpooler").
|
stub_request(:get, "http://foo/api/v2/status/platforms/ondemand_vmpooler").
|
||||||
to_return(:status => 200, :body => "", :headers => {})
|
to_return(:status => 200, :body => "", :headers => {})
|
||||||
stub_request(:get, "http://foo/status/platforms/nspooler").
|
stub_request(:get, "http://foo/api/v2/status/platforms/nspooler").
|
||||||
to_return(:status => 200, :body => "", :headers => {})
|
to_return(:status => 200, :body => "", :headers => {})
|
||||||
body = '{
|
body = '{
|
||||||
"aws_platforms": [
|
"aws_platforms": [
|
||||||
|
|
@ -26,7 +26,7 @@ describe ABS do
|
||||||
"redhat-8-arm64"
|
"redhat-8-arm64"
|
||||||
]
|
]
|
||||||
}'
|
}'
|
||||||
stub_request(:get, "http://foo/status/platforms/aws").
|
stub_request(:get, "http://foo/api/v2/status/platforms/aws").
|
||||||
to_return(:status => 200, :body => body, :headers => {})
|
to_return(:status => 200, :body => body, :headers => {})
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -35,16 +35,16 @@ describe ABS do
|
||||||
expect(results).to include("amazon-6-x86_64", "amazon-7-x86_64", "amazon-7-arm64", "centos-7-x86-64-west", "redhat-8-arm64")
|
expect(results).to include("amazon-6-x86_64", "amazon-7-x86_64", "amazon-7-arm64", "centos-7-x86-64-west", "redhat-8-arm64")
|
||||||
end
|
end
|
||||||
it 'legacy JSON string, prior to PR 306' do
|
it 'legacy JSON string, prior to PR 306' do
|
||||||
stub_request(:get, "http://foo/status/platforms/vmpooler").
|
stub_request(:get, "http://foo/api/v2/status/platforms/vmpooler").
|
||||||
to_return(:status => 200, :body => "", :headers => {})
|
to_return(:status => 200, :body => "", :headers => {})
|
||||||
stub_request(:get, "http://foo/status/platforms/ondemand_vmpooler").
|
stub_request(:get, "http://foo/api/v2/status/platforms/ondemand_vmpooler").
|
||||||
to_return(:status => 200, :body => "", :headers => {})
|
to_return(:status => 200, :body => "", :headers => {})
|
||||||
stub_request(:get, "http://foo/status/platforms/nspooler").
|
stub_request(:get, "http://foo/api/v2/status/platforms/nspooler").
|
||||||
to_return(:status => 200, :body => "", :headers => {})
|
to_return(:status => 200, :body => "", :headers => {})
|
||||||
body = '{
|
body = '{
|
||||||
"aws_platforms": "[\"amazon-6-x86_64\",\"amazon-7-x86_64\",\"amazon-7-arm64\",\"centos-7-x86-64-west\",\"redhat-8-arm64\"]"
|
"aws_platforms": "[\"amazon-6-x86_64\",\"amazon-7-x86_64\",\"amazon-7-arm64\",\"centos-7-x86-64-west\",\"redhat-8-arm64\"]"
|
||||||
}'
|
}'
|
||||||
stub_request(:get, "http://foo/status/platforms/aws").
|
stub_request(:get, "http://foo/api/v2/status/platforms/aws").
|
||||||
to_return(:status => 200, :body => body, :headers => {})
|
to_return(:status => 200, :body => body, :headers => {})
|
||||||
|
|
||||||
results = ABS.list(false, "http://foo")
|
results = ABS.list(false, "http://foo")
|
||||||
|
|
@ -125,7 +125,7 @@ describe ABS do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'will skip a line with a null value returned from abs' do
|
it 'will skip a line with a null value returned from abs' do
|
||||||
stub_request(:get, 'https://abs.example.com/status/queue')
|
stub_request(:get, 'https://abs.example.com/api/v2/status/queue')
|
||||||
.to_return(:status => 200, :body => @active_requests_response, :headers => {})
|
.to_return(:status => 200, :body => @active_requests_response, :headers => {})
|
||||||
|
|
||||||
ret = ABS.get_active_requests(false, @abs_url, @test_user)
|
ret = ABS.get_active_requests(false, @abs_url, @test_user)
|
||||||
|
|
@ -156,9 +156,9 @@ describe ABS do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'will delete the whole job' do
|
it 'will delete the whole job' do
|
||||||
stub_request(:get, 'https://abs.example.com/status/queue')
|
stub_request(:get, 'https://abs.example.com/api/v2/status/queue')
|
||||||
.to_return(:status => 200, :body => @active_requests_response, :headers => {})
|
.to_return(:status => 200, :body => @active_requests_response, :headers => {})
|
||||||
stub_request(:post, 'https://abs.example.com/return')
|
stub_request(:post, 'https://abs.example.com/api/v2/return')
|
||||||
.with(:body => @return_request)
|
.with(:body => @return_request)
|
||||||
.to_return(:status => 200, :body => 'OK', :headers => {})
|
.to_return(:status => 200, :body => 'OK', :headers => {})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue