Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Lighter unique Host#domain lookup for in MiqProvisionVirtWorkflow #17403

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/models/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,17 @@ def self.failover
where(:failover => true)
end

def self.all_unique_downcased_domains(includes = nil)
select_rows = select("lower(regexp_replace(split_part(hostname, ',', 1), '[^\.]*\.', '')) as domain")
.select(:id).to_sql
.sub!("SELECT", "DISTINCT ON (domain)")
.sub!(/ FROM.*$/, '')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed the other day while browsing the arel codebase (like you do), there is a distinct_on method I might be able to leverage here. Will look into doing that at some point.


query = select(select_rows).where.not(:hostname => nil)
query = query.includes(includes) if includes
query
end

def authentication_check_role
'smartstate'
end
Expand Down
14 changes: 8 additions & 6 deletions app/models/miq_provision_virt_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -542,13 +542,15 @@ def allowed_domains(options = {})
@domains ||= begin
domains = {}
if @values[:forced_sysprep_domain_name].blank?
Host.all.each do |host|
domain = host.domain.to_s.downcase
next if domain.blank? || domains.key?(domain)
# Filter by host platform or is proxy is active
includes = [:operating_system, :hardware] if options[:platform]
Host.all_unique_downcased_domains(includes).each do |host|
# Filter by host platform
# FIXME: Does this even make sense? The domain could be applied to
# hosts with multiple different opperating systems, right? And only
# the first one pulled in will be what is filtered?
next unless options[:platform].nil? || options[:platform].include?(host.platform)
next unless options[:active_proxy].nil? || host.is_proxy_active? == options[:active_proxy]
domains[domain] = domain

domains[host.attributes["domain"]] = host.attributes["domain"]
end
else
@values[:forced_sysprep_domain_name].to_miq_a.each { |d| domains[d] = d }
Expand Down