lib/beaker/hypervisor/abs.rb in beaker-abs-0.5.0 vs lib/beaker/hypervisor/abs.rb in beaker-abs-0.6.0
- old
+ new
@@ -1,17 +1,26 @@
require 'beaker'
require 'json'
+require 'pry-byebug'
+require 'vmfloaty'
+require 'vmfloaty/conf'
+require 'vmfloaty/utils'
module Beaker
class Abs < Beaker::Hypervisor
def initialize(hosts, options)
@options = options
@logger = options[:logger]
@hosts = hosts
resource_hosts = ENV['ABS_RESOURCE_HOSTS'] || @options[:abs_resource_hosts]
- raise ArgumentError.new("ABS_RESOURCE_HOSTS must be specified when using the Beaker::Abs hypervisor") if resource_hosts.nil?
+
+ @abs_service_name = ENV['ABS_SERVICE_NAME'] || @options[:abs_service_name] || "abs"
+ @abs_service_priority = ENV['ABS_SERVICE_PRIORITY'] || @options[:abs_service_priority] || "1"
+
+ raise ArgumentError.new("ABS_RESOURCE_HOSTS must be specified when using the Beaker::Abs hypervisor when provisioning") if resource_hosts.nil? && !options[:provision]
+ resource_hosts = provision_vms(hosts).to_json if resource_hosts.nil?
@resource_hosts = JSON.parse(resource_hosts)
end
def connection_preference(host)
vmhostname = host[:vmhostname]
@@ -71,8 +80,81 @@
end
end
def cleanup
# nothing to do
+ end
+
+ def provision_vms(hosts)
+
+ verbose = false
+ config = Conf.read_config # get the vmfloaty config file in home dir
+
+ # TODO: the options object provided by the floaty cli is required in get_service_config()
+ # we should make it optional or accept nil
+ cli = Object.new
+ def cli.service() @abs_service_name end
+ def cli.priority() @abs_service_priority end # forces going ahead of queue
+ def cli.url() nil end
+ def cli.token() nil end
+ def cli.user() nil end
+
+ #the service object is the interfacte to all methods
+ abs_service = Service.new(cli, config)
+ supported_vm_list = abs_service.list(verbose)
+ supported_vm_list = supported_vm_list.reject { |e| e.empty? }
+ supported_vm_list = supported_vm_list.reject { |e| e.start_with?("*") }
+
+ vm_request = generate_floaty_request_strings(hosts, supported_vm_list)
+
+
+ vm_beaker_abs = []
+ # Will return a JSON Object like this:
+ # {"redhat-7-x86_64"=>["rich-apparition.delivery.puppetlabs.net", "despondent-side.delivery.puppetlabs.net"], "centos-7-x86_64"=>["firmer-vamp.delivery.puppetlabs.net"]}
+ os_types = Utils.generate_os_hash(vm_request.split)
+ vm_floaty_output = abs_service.retrieve(verbose, os_types)
+
+
+ raise ArgumentError.new("Timed out getting the ABS resources") if vm_floaty_output.nil?
+ vm_floaty_output_cleaned = Utils.standardize_hostnames(vm_floaty_output)
+ vm_floaty_output_cleaned.each do |os_platform, value|
+ # filter any extra key that does not have an Array value
+ if !value.is_a?(Array)
+ next
+ end
+ value.each do | hostname |
+ # I don't think the engine is being used by the beaker-abs process
+ vm_beaker_abs.push({"hostname": hostname, "type": os_platform, "engine":"beaker-abs"})
+ end
+ end
+
+ # to do need to figure out what the NSPooler requests are, and combine the output for that with vm_beaker_abs and return that object
+ # for now just returning vmpooler abs object
+ vm_beaker_abs
+ end
+
+ # Based upon the host file, this method counts the number of each template needed
+ # and generates the host=Xnum eg redhat-7-x86_64=2 expected by floaty
+ def generate_floaty_request_strings(hosts, supported_vm_list)
+ vm_list = {}
+
+ hosts.each do |host|
+ if supported_vm_list.include?(host[:template])
+ if vm_list.include?(host[:template])
+ vm_list[host[:template]] = vm_list[host[:template]] + 1
+ else
+ vm_list[host[:template]] = 1
+ end
+ else
+ raise ArgumentError.new("#{host.name} has a template #{host[:template]} that is not found in vmpooler or nspooler")
+ end
+ end
+
+ vm_request = ""
+ vm_list.each do |key, value|
+ vm_request.concat("#{key}=#{value} ")
+ end
+
+ vm_request
end
end
end