mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Merge branch 'main' into dependabot/bundler/opentelemetry-instrumentation-http_client-0.19.4
This commit is contained in:
commit
a3244a6a5d
7 changed files with 101 additions and 29 deletions
|
|
@ -66,6 +66,7 @@ Style/Next:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
Metrics/ParameterLists:
|
Metrics/ParameterLists:
|
||||||
Max: 10
|
Max: 10
|
||||||
|
MaxOptionalParameters: 10
|
||||||
Style/GuardClause:
|
Style/GuardClause:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
|
|
|
||||||
26
Gemfile.lock
26
Gemfile.lock
|
|
@ -64,7 +64,7 @@ GEM
|
||||||
google-cloud-env (1.6.0)
|
google-cloud-env (1.6.0)
|
||||||
faraday (>= 0.17.3, < 3.0)
|
faraday (>= 0.17.3, < 3.0)
|
||||||
method_source (1.0.0)
|
method_source (1.0.0)
|
||||||
mock_redis (0.30.0)
|
mock_redis (0.31.0)
|
||||||
ruby2_keywords
|
ruby2_keywords
|
||||||
multipart-post (2.1.1)
|
multipart-post (2.1.1)
|
||||||
mustermann (1.1.1)
|
mustermann (1.1.1)
|
||||||
|
|
@ -112,7 +112,7 @@ GEM
|
||||||
opentelemetry-semantic_conventions (1.8.0)
|
opentelemetry-semantic_conventions (1.8.0)
|
||||||
opentelemetry-api (~> 1.0)
|
opentelemetry-api (~> 1.0)
|
||||||
parallel (1.22.1)
|
parallel (1.22.1)
|
||||||
parser (3.1.1.0)
|
parser (3.1.2.0)
|
||||||
ast (~> 2.4.1)
|
ast (~> 2.4.1)
|
||||||
pickup (0.0.11)
|
pickup (0.0.11)
|
||||||
prometheus-client (2.1.0)
|
prometheus-client (2.1.0)
|
||||||
|
|
@ -123,9 +123,9 @@ GEM
|
||||||
coderay (~> 1.1)
|
coderay (~> 1.1)
|
||||||
method_source (~> 1.0)
|
method_source (~> 1.0)
|
||||||
spoon (~> 0.0)
|
spoon (~> 0.0)
|
||||||
puma (5.6.2)
|
puma (5.6.4)
|
||||||
nio4r (~> 2.0)
|
nio4r (~> 2.0)
|
||||||
puma (5.6.2-java)
|
puma (5.6.4-java)
|
||||||
nio4r (~> 2.0)
|
nio4r (~> 2.0)
|
||||||
racc (1.6.0)
|
racc (1.6.0)
|
||||||
racc (1.6.0-java)
|
racc (1.6.0-java)
|
||||||
|
|
@ -137,7 +137,7 @@ GEM
|
||||||
rainbow (3.1.1)
|
rainbow (3.1.1)
|
||||||
rake (13.0.6)
|
rake (13.0.6)
|
||||||
redis (4.6.0)
|
redis (4.6.0)
|
||||||
regexp_parser (2.2.1)
|
regexp_parser (2.3.1)
|
||||||
rexml (3.2.5)
|
rexml (3.2.5)
|
||||||
rspec (3.11.0)
|
rspec (3.11.0)
|
||||||
rspec-core (~> 3.11.0)
|
rspec-core (~> 3.11.0)
|
||||||
|
|
@ -152,16 +152,16 @@ GEM
|
||||||
diff-lcs (>= 1.2.0, < 2.0)
|
diff-lcs (>= 1.2.0, < 2.0)
|
||||||
rspec-support (~> 3.11.0)
|
rspec-support (~> 3.11.0)
|
||||||
rspec-support (3.11.0)
|
rspec-support (3.11.0)
|
||||||
rubocop (1.1.0)
|
rubocop (1.28.2)
|
||||||
parallel (~> 1.10)
|
parallel (~> 1.10)
|
||||||
parser (>= 2.7.1.5)
|
parser (>= 3.1.0.0)
|
||||||
rainbow (>= 2.2.2, < 4.0)
|
rainbow (>= 2.2.2, < 4.0)
|
||||||
regexp_parser (>= 1.8)
|
regexp_parser (>= 1.8, < 3.0)
|
||||||
rexml
|
rexml
|
||||||
rubocop-ast (>= 1.0.1)
|
rubocop-ast (>= 1.17.0, < 2.0)
|
||||||
ruby-progressbar (~> 1.7)
|
ruby-progressbar (~> 1.7)
|
||||||
unicode-display_width (>= 1.4.0, < 2.0)
|
unicode-display_width (>= 1.4.0, < 3.0)
|
||||||
rubocop-ast (1.16.0)
|
rubocop-ast (1.17.0)
|
||||||
parser (>= 3.1.1.0)
|
parser (>= 3.1.1.0)
|
||||||
ruby-progressbar (1.11.0)
|
ruby-progressbar (1.11.0)
|
||||||
ruby2_keywords (0.0.5)
|
ruby2_keywords (0.0.5)
|
||||||
|
|
@ -184,7 +184,7 @@ GEM
|
||||||
thor (1.2.1)
|
thor (1.2.1)
|
||||||
thrift (0.16.0)
|
thrift (0.16.0)
|
||||||
tilt (2.0.10)
|
tilt (2.0.10)
|
||||||
unicode-display_width (1.8.0)
|
unicode-display_width (2.1.0)
|
||||||
yarjuf (2.0.0)
|
yarjuf (2.0.0)
|
||||||
builder
|
builder
|
||||||
rspec (~> 3)
|
rspec (~> 3)
|
||||||
|
|
@ -199,7 +199,7 @@ DEPENDENCIES
|
||||||
pry
|
pry
|
||||||
rack-test (>= 0.6)
|
rack-test (>= 0.6)
|
||||||
rspec (>= 3.2)
|
rspec (>= 3.2)
|
||||||
rubocop (~> 1.1.0)
|
rubocop (~> 1.28.2)
|
||||||
simplecov (>= 0.11.2)
|
simplecov (>= 0.11.2)
|
||||||
thor (~> 1.0, >= 1.0.1)
|
thor (~> 1.0, >= 1.0.1)
|
||||||
vmpooler!
|
vmpooler!
|
||||||
|
|
|
||||||
|
|
@ -181,14 +181,9 @@ module Vmpooler
|
||||||
/^\d{4}-\d{2}-\d{2}$/ === date_str
|
/^\d{4}-\d{2}-\d{2}$/ === date_str
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# NOTE: domain is not needed here, so we should update the callers of this method
|
||||||
def hostname_shorten(hostname, domain=nil)
|
def hostname_shorten(hostname, domain=nil)
|
||||||
if domain && hostname =~ /^[\w-]+\.#{domain}$/
|
hostname[/[^.]+/]
|
||||||
hostname = hostname[/[^.]+/]
|
|
||||||
elsif hostname =~ /^[\w-]+\..+$/
|
|
||||||
hostname = hostname[/[^.]+/]
|
|
||||||
end
|
|
||||||
|
|
||||||
hostname
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_task_times(backend, task, date_str)
|
def get_task_times(backend, task, date_str)
|
||||||
|
|
|
||||||
|
|
@ -1519,7 +1519,7 @@ module Vmpooler
|
||||||
|
|
||||||
post "#{api_prefix}/vm/:hostname/snapshot/:snapshot/?" do
|
post "#{api_prefix}/vm/:hostname/snapshot/:snapshot/?" do
|
||||||
content_type :json
|
content_type :json
|
||||||
metrics.increment('http_requests_vm_total.post.vm.disksize')
|
metrics.increment('http_requests_vm_total.post.vm.snapshot')
|
||||||
|
|
||||||
need_token! if Vmpooler::API.settings.config[:auth]
|
need_token! if Vmpooler::API.settings.config[:auth]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -258,6 +258,82 @@ module Vmpooler
|
||||||
JSON.pretty_generate(result)
|
JSON.pretty_generate(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get "#{api_prefix}/vm/:hostname/?" do
|
||||||
|
content_type :json
|
||||||
|
metrics.increment('http_requests_vm_total.get.vm.hostname')
|
||||||
|
|
||||||
|
result = {}
|
||||||
|
|
||||||
|
status 404
|
||||||
|
result['ok'] = false
|
||||||
|
|
||||||
|
params[:hostname] = hostname_shorten(params[:hostname], nil)
|
||||||
|
|
||||||
|
rdata = backend.hgetall("vmpooler__vm__#{params[:hostname]}")
|
||||||
|
unless rdata.empty?
|
||||||
|
status 200
|
||||||
|
result['ok'] = true
|
||||||
|
|
||||||
|
result[params[:hostname]] = {}
|
||||||
|
|
||||||
|
result[params[:hostname]]['template'] = rdata['template']
|
||||||
|
result[params[:hostname]]['lifetime'] = (rdata['lifetime'] || config['vm_lifetime']).to_i
|
||||||
|
|
||||||
|
if rdata['destroy']
|
||||||
|
result[params[:hostname]]['running'] = ((Time.parse(rdata['destroy']) - Time.parse(rdata['checkout'])) / 60 / 60).round(2) if rdata['checkout']
|
||||||
|
result[params[:hostname]]['state'] = 'destroyed'
|
||||||
|
elsif rdata['checkout']
|
||||||
|
result[params[:hostname]]['running'] = ((Time.now - Time.parse(rdata['checkout'])) / 60 / 60).round(2)
|
||||||
|
result[params[:hostname]]['remaining'] = ((Time.parse(rdata['checkout']) + rdata['lifetime'].to_i*60*60 - Time.now) / 60 / 60).round(2)
|
||||||
|
result[params[:hostname]]['start_time'] = Time.parse(rdata['checkout']).to_datetime.rfc3339
|
||||||
|
result[params[:hostname]]['end_time'] = (Time.parse(rdata['checkout']) + rdata['lifetime'].to_i*60*60).to_datetime.rfc3339
|
||||||
|
result[params[:hostname]]['state'] = 'running'
|
||||||
|
elsif rdata['check']
|
||||||
|
result[params[:hostname]]['state'] = 'ready'
|
||||||
|
else
|
||||||
|
result[params[:hostname]]['state'] = 'pending'
|
||||||
|
end
|
||||||
|
|
||||||
|
rdata.keys.each do |key|
|
||||||
|
if key.match('^tag\:(.+?)$')
|
||||||
|
result[params[:hostname]]['tags'] ||= {}
|
||||||
|
result[params[:hostname]]['tags'][$1] = rdata[key]
|
||||||
|
end
|
||||||
|
|
||||||
|
if key.match('^snapshot\:(.+?)$')
|
||||||
|
result[params[:hostname]]['snapshots'] ||= []
|
||||||
|
result[params[:hostname]]['snapshots'].push($1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if rdata['disk']
|
||||||
|
result[params[:hostname]]['disk'] = rdata['disk'].split(':')
|
||||||
|
end
|
||||||
|
|
||||||
|
# Look up IP address of the hostname
|
||||||
|
begin
|
||||||
|
ipAddress = TCPSocket.gethostbyname(params[:hostname])[3]
|
||||||
|
rescue StandardError
|
||||||
|
ipAddress = ""
|
||||||
|
end
|
||||||
|
|
||||||
|
result[params[:hostname]]['ip'] = ipAddress
|
||||||
|
|
||||||
|
if rdata['pool']
|
||||||
|
vmdomain = Parsing.get_domain_for_pool(full_config, rdata['pool'])
|
||||||
|
if vmdomain
|
||||||
|
result[params[:hostname]]['fqdn'] = "#{params[:hostname]}.#{vmdomain}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
result[params[:hostname]]['host'] = rdata['host'] if rdata['host']
|
||||||
|
result[params[:hostname]]['migrated'] = rdata['migrated'] if rdata['migrated']
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
JSON.pretty_generate(result)
|
||||||
|
end
|
||||||
|
|
||||||
post "#{api_prefix}/ondemandvm/?" do
|
post "#{api_prefix}/ondemandvm/?" do
|
||||||
content_type :json
|
content_type :json
|
||||||
metrics.increment('http_requests_vm_total.post.ondemand.requestid')
|
metrics.increment('http_requests_vm_total.post.ondemand.requestid')
|
||||||
|
|
|
||||||
|
|
@ -1596,19 +1596,19 @@ module Vmpooler
|
||||||
$config[:pools].each do |pool|
|
$config[:pools].each do |pool|
|
||||||
provider_name = pool['provider']
|
provider_name = pool['provider']
|
||||||
# The provider_class parameter can be defined in the provider's data eg
|
# The provider_class parameter can be defined in the provider's data eg
|
||||||
#:providers:
|
# :providers:
|
||||||
# :vsphere:
|
# :vsphere:
|
||||||
# provider_class: 'vsphere'
|
# provider_class: 'vsphere'
|
||||||
# :another-vsphere:
|
# :another-vsphere:
|
||||||
# provider_class: 'vsphere'
|
# provider_class: 'vsphere'
|
||||||
# the above would create two providers/vsphere.rb class objects named 'vsphere' and 'another-vsphere'
|
# the above would create two providers/vsphere.rb class objects named 'vsphere' and 'another-vsphere'
|
||||||
# each pools would then define which provider definition to use: vsphere or another-vsphere
|
# each pools would then define which provider definition to use: vsphere or another-vsphere
|
||||||
#
|
#
|
||||||
# if provider_class is not defined it will try to use the provider_name as the class, this is to be
|
# if provider_class is not defined it will try to use the provider_name as the class, this is to be
|
||||||
# backwards compatible for example when there is only one provider listed
|
# backwards compatible for example when there is only one provider listed
|
||||||
# :providers:
|
# :providers:
|
||||||
# :dummy:
|
# :dummy:
|
||||||
# filename: 'db.txs'
|
# filename: 'db.txs'
|
||||||
# the above example would create an object based on the class providers/dummy.rb
|
# the above example would create an object based on the class providers/dummy.rb
|
||||||
if $config[:providers].nil? || $config[:providers][provider_name.to_sym].nil? || $config[:providers][provider_name.to_sym]['provider_class'].nil?
|
if $config[:providers].nil? || $config[:providers][provider_name.to_sym].nil? || $config[:providers][provider_name.to_sym]['provider_class'].nil?
|
||||||
provider_class = provider_name
|
provider_class = provider_name
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ Gem::Specification.new do |s|
|
||||||
s.add_development_dependency 'pry'
|
s.add_development_dependency 'pry'
|
||||||
s.add_development_dependency 'rack-test', '>= 0.6'
|
s.add_development_dependency 'rack-test', '>= 0.6'
|
||||||
s.add_development_dependency 'rspec', '>= 3.2'
|
s.add_development_dependency 'rspec', '>= 3.2'
|
||||||
s.add_development_dependency 'rubocop', '~> 1.1.0'
|
s.add_development_dependency 'rubocop', '~> 1.28.2'
|
||||||
s.add_development_dependency 'simplecov', '>= 0.11.2'
|
s.add_development_dependency 'simplecov', '>= 0.11.2'
|
||||||
s.add_development_dependency 'thor', '~> 1.0', '>= 1.0.1'
|
s.add_development_dependency 'thor', '~> 1.0', '>= 1.0.1'
|
||||||
s.add_development_dependency 'yarjuf', '>= 2.0'
|
s.add_development_dependency 'yarjuf', '>= 2.0'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue