Merge pull request #98 from puppetlabs/better-abs-config

(maint) Support any vmpooler for ABS via vmpooler_fallback
This commit is contained in:
mattkirby 2020-09-17 10:08:05 -07:00 committed by GitHub
commit f3cd540455
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 13 deletions

View file

@ -210,7 +210,7 @@ class ABS
end
# Retrieve an OS from ABS.
def self.retrieve(verbose, os_types, token, url, user, options, _ondemand = nil)
def self.retrieve(verbose, os_types, token, url, user, config, _ondemand = nil)
#
# Contents of post must be like:
#
@ -231,7 +231,7 @@ class ABS
conn.headers['X-AUTH-TOKEN'] = token if token
saved_job_id = DateTime.now.strftime('%Q')
vmpooler_config = Utils.get_vmpooler_service_config
vmpooler_config = Utils.get_vmpooler_service_config(config['vmpooler_fallback'])
req_obj = {
:resources => os_types,
:job => {
@ -243,15 +243,15 @@ class ABS
:vm_token => vmpooler_config['token'] # request with this token, on behalf of this user
}
if options['priority']
req_obj[:priority] = if options['priority'] == 'high'
if config['priority']
req_obj[:priority] = if config['priority'] == 'high'
1
elsif options['priority'] == 'medium'
elsif config['priority'] == 'medium'
2
elsif options['priority'] == 'low'
elsif config['priority'] == 'low'
3
else
options['priority'].to_i
config['priority'].to_i
end
end

View file

@ -141,11 +141,11 @@ class Service
def maybe_use_vmpooler
if @service_object.is_a?(ABS.class)
if !self.silent
FloatyLogger.info "The service in use is ABS, but the requested method should run against vmpooler directly, using vmpooler config from ~/.vmfloaty.yml"
FloatyLogger.info "The service in use is ABS, but the requested method should run against vmpooler directly, using fallback_vmpooler config from ~/.vmfloaty.yml"
self.silent = true
end
@config = Utils.get_vmpooler_service_config
@config = Utils.get_vmpooler_service_config(@config['vmpooler_fallback'])
@service_object = Pooler
end
end

View file

@ -259,7 +259,7 @@ class Utils
end
# This method gets the vmpooler service configured in ~/.vmfloaty
def self.get_vmpooler_service_config
def self.get_vmpooler_service_config(vmpooler_fallback)
config = Conf.read_config
# The top-level url, user, and token values in the config file are treated as defaults
service_config = {
@ -270,11 +270,15 @@ class Utils
}
# at a minimum, the url needs to be configured
if config['services'] && config['services']['vmpooler'] && config['services']['vmpooler']['url']
if config['services'] && config['services'][vmpooler_fallback] && config['services'][vmpooler_fallback]['url']
# If the service is configured but some values are missing, use the top-level defaults to fill them in
service_config.merge! config['services']['vmpooler']
service_config.merge! config['services'][vmpooler_fallback]
else
raise ArgumentError, "Could not find a configured service named 'vmpooler' in ~/.vmfloaty.yml use this format:\nservices:\n vmpooler:\n url: 'http://vmpooler.com'\n user: 'superman'\n token: 'kryptonite'"
if vmpooler_fallback.nil?
raise ArgumentError, "The abs service should have a key named 'vmpooler_fallback' in ~/.vmfloaty.yml with a value that points to a vmpooler service name use this format:\nservices:\n myabs:\n url: 'http://abs.com'\n user: 'superman'\n token: 'kryptonite'\n vmpooler_fallback: 'myvmpooler'\n myvmpooler:\n url: 'http://vmpooler.com'\n user: 'superman'\n token: 'kryptonite'"
else
raise ArgumentError, "Could not find a configured service named '#{vmpooler_fallback}' in ~/.vmfloaty.yml use this format:\nservices:\n #{vmpooler_fallback}:\n url: 'http://vmpooler.com'\n user: 'superman'\n token: 'kryptonite'"
end
end
service_config