mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Update domain in V2 api
This commit is contained in:
parent
aeabb7e134
commit
35dc7cb26f
5 changed files with 14 additions and 42 deletions
|
|
@ -76,7 +76,6 @@ module Vmpooler
|
||||||
parsed_config[:config]['prefix'] = ENV['PREFIX'] || parsed_config[:config]['prefix'] || ''
|
parsed_config[:config]['prefix'] = ENV['PREFIX'] || parsed_config[:config]['prefix'] || ''
|
||||||
parsed_config[:config]['logfile'] = ENV['LOGFILE'] if ENV['LOGFILE']
|
parsed_config[:config]['logfile'] = ENV['LOGFILE'] if ENV['LOGFILE']
|
||||||
parsed_config[:config]['site_name'] = ENV['SITE_NAME'] if ENV['SITE_NAME']
|
parsed_config[:config]['site_name'] = ENV['SITE_NAME'] if ENV['SITE_NAME']
|
||||||
parsed_config[:config]['domain'] = ENV['DOMAIN'] if ENV['DOMAIN']
|
|
||||||
parsed_config[:config]['clone_target'] = ENV['CLONE_TARGET'] if ENV['CLONE_TARGET']
|
parsed_config[:config]['clone_target'] = ENV['CLONE_TARGET'] if ENV['CLONE_TARGET']
|
||||||
parsed_config[:config]['timeout'] = string_to_int(ENV['TIMEOUT']) if ENV['TIMEOUT']
|
parsed_config[:config]['timeout'] = string_to_int(ENV['TIMEOUT']) if ENV['TIMEOUT']
|
||||||
parsed_config[:config]['vm_lifetime_auth'] = string_to_int(ENV['VM_LIFETIME_AUTH']) if ENV['VM_LIFETIME_AUTH']
|
parsed_config[:config]['vm_lifetime_auth'] = string_to_int(ENV['VM_LIFETIME_AUTH']) if ENV['VM_LIFETIME_AUTH']
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
module Vmpooler
|
module Vmpooler
|
||||||
class API < Sinatra::Base
|
class API < Sinatra::Base
|
||||||
# Load API components
|
# Load API components
|
||||||
%w[helpers dashboard reroute v1 v2 request_logger healthcheck].each do |lib|
|
%w[helpers dashboard reroute v2 request_logger healthcheck].each do |lib|
|
||||||
require "vmpooler/api/#{lib}"
|
require "vmpooler/api/#{lib}"
|
||||||
end
|
end
|
||||||
# Load dashboard components
|
# Load dashboard components
|
||||||
|
|
@ -53,7 +53,6 @@ module Vmpooler
|
||||||
use Vmpooler::Dashboard
|
use Vmpooler::Dashboard
|
||||||
use Vmpooler::API::Dashboard
|
use Vmpooler::API::Dashboard
|
||||||
use Vmpooler::API::Reroute
|
use Vmpooler::API::Reroute
|
||||||
use Vmpooler::API::V1
|
|
||||||
use Vmpooler::API::V2
|
use Vmpooler::API::V2
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'vmpooler/api/v1'
|
require 'vmpooler/util/parsing'
|
||||||
|
require 'vmpooler/dns'
|
||||||
|
|
||||||
module Vmpooler
|
module Vmpooler
|
||||||
class API
|
class API
|
||||||
|
|
@ -87,9 +88,7 @@ module Vmpooler
|
||||||
# last vm added. The part of the response is only being retained for
|
# last vm added. The part of the response is only being retained for
|
||||||
# backwards compatibility as the hostnames are now fqdn's instead of bare
|
# backwards compatibility as the hostnames are now fqdn's instead of bare
|
||||||
# hostnames. This change is a result of now being able to specify a domain
|
# hostnames. This change is a result of now being able to specify a domain
|
||||||
# per pool. If no vm's in the result had a domain sepcified then the
|
# per pool.
|
||||||
# domain key will be omitted similar to how it was previously omitted if
|
|
||||||
# the global option domain wasn't specified.
|
|
||||||
def atomically_allocate_vms(payload)
|
def atomically_allocate_vms(payload)
|
||||||
tracer.in_span("Vmpooler::API::V2.#{__method__}") do |span|
|
tracer.in_span("Vmpooler::API::V2.#{__method__}") do |span|
|
||||||
result = { 'ok' => false }
|
result = { 'ok' => false }
|
||||||
|
|
@ -126,15 +125,10 @@ module Vmpooler
|
||||||
else
|
else
|
||||||
vm_names = []
|
vm_names = []
|
||||||
vms.each do |(vmpool, vmname, vmtemplate)|
|
vms.each do |(vmpool, vmname, vmtemplate)|
|
||||||
vmdomain = Parsing.get_domain_for_pool(full_config, vmpool)
|
vmdomain = Dns.get_domain_for_pool(full_config, vmpool)
|
||||||
if vmdomain
|
|
||||||
vmfqdn = "#{vmname}.#{vmdomain}"
|
vmfqdn = "#{vmname}.#{vmdomain}"
|
||||||
update_result_hosts(result, vmtemplate, vmfqdn)
|
update_result_hosts(result, vmtemplate, vmfqdn)
|
||||||
vm_names.append(vmfqdn)
|
vm_names.append(vmfqdn)
|
||||||
else
|
|
||||||
update_result_hosts(result, vmtemplate, vmname)
|
|
||||||
vm_names.append(vmname)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
span.set_attribute('vmpooler.vm_names', vm_names.join(',')) unless vm_names.empty?
|
span.set_attribute('vmpooler.vm_names', vm_names.join(',')) unless vm_names.empty?
|
||||||
|
|
@ -320,7 +314,7 @@ module Vmpooler
|
||||||
result[params[:hostname]]['ip'] = ipAddress
|
result[params[:hostname]]['ip'] = ipAddress
|
||||||
|
|
||||||
if rdata['pool']
|
if rdata['pool']
|
||||||
vmdomain = Parsing.get_domain_for_pool(full_config, rdata['pool'])
|
vmdomain = Dns.get_domain_for_pool(full_config, rdata['pool'])
|
||||||
if vmdomain
|
if vmdomain
|
||||||
result[params[:hostname]]['fqdn'] = "#{params[:hostname]}.#{vmdomain}"
|
result[params[:hostname]]['fqdn'] = "#{params[:hostname]}.#{vmdomain}"
|
||||||
end
|
end
|
||||||
|
|
@ -436,8 +430,8 @@ module Vmpooler
|
||||||
result['ready'] = true
|
result['ready'] = true
|
||||||
Parsing.get_platform_pool_count(request_hash['requested']) do |platform_alias, pool, _count|
|
Parsing.get_platform_pool_count(request_hash['requested']) do |platform_alias, pool, _count|
|
||||||
instances = backend.smembers("vmpooler__#{request_id}__#{platform_alias}__#{pool}")
|
instances = backend.smembers("vmpooler__#{request_id}__#{platform_alias}__#{pool}")
|
||||||
domain = Parsing.get_domain_for_pool(full_config, pool)
|
domain = Dns.get_domain_for_pool(full_config, pool)
|
||||||
instances.map! { |instance| instance.concat(".#{domain}") } if domain
|
instances.map! { |instance| instance.concat(".#{domain}") }
|
||||||
|
|
||||||
if result.key?(platform_alias)
|
if result.key?(platform_alias)
|
||||||
result[platform_alias][:hostname] = result[platform_alias][:hostname] + instances
|
result[platform_alias][:hostname] = result[platform_alias][:hostname] + instances
|
||||||
|
|
|
||||||
|
|
@ -29,10 +29,10 @@ Date.prototype.yyyymmdd = function() {
|
||||||
|
|
||||||
var data_url = {
|
var data_url = {
|
||||||
'capacity': '/dashboard/stats/vmpooler/pool',
|
'capacity': '/dashboard/stats/vmpooler/pool',
|
||||||
'pools' : '/api/v1/vm',
|
'pools' : '/api/v2/vm',
|
||||||
'running' : '/dashboard/stats/vmpooler/running',
|
'running' : '/dashboard/stats/vmpooler/running',
|
||||||
'status' : '/api/v1/status',
|
'status' : '/api/v2/status',
|
||||||
'summary' : '/api/v1/summary'
|
'summary' : '/api/v2/summary'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,25 +12,5 @@ module Vmpooler
|
||||||
yield platform_alias, pool, count
|
yield platform_alias, pool, count
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# @param config [String] - the full config structure
|
|
||||||
# @param pool_name [String] - the name of the pool
|
|
||||||
# @return [String] - domain name for pool, if set in the provider for the pool or in the config block
|
|
||||||
def self.get_domain_for_pool(config, pool_name)
|
|
||||||
pool = config[:pools].find { |p| p['name'] == pool_name }
|
|
||||||
return nil unless pool
|
|
||||||
|
|
||||||
provider_name = pool.fetch('provider', 'vsphere') # see vmpooler.yaml.example where it states defaulting to vsphere
|
|
||||||
|
|
||||||
if config[:providers] && config[:providers][provider_name.to_sym] && config[:providers][provider_name.to_sym]['domain']
|
|
||||||
domain = config[:providers][provider_name.to_sym]['domain']
|
|
||||||
elsif config[:config] && config[:config]['domain']
|
|
||||||
domain = config[:config]['domain']
|
|
||||||
else
|
|
||||||
domain = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
domain
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue