Module: Katello::Concerns::SubscriptionFacetHostExtensions::ClassMethods

Defined in:
app/models/katello/concerns/subscription_facet_host_extensions.rb

Instance Method Summary collapse

Instance Method Details

#find_by_activation_key(_key, operator, value) ⇒ Object



82
83
84
85
86
# File 'app/models/katello/concerns/subscription_facet_host_extensions.rb', line 82

def find_by_activation_key(_key, operator, value)
  conditions = sanitize_sql_for_conditions(["#{Katello::ActivationKey.table_name}.name #{operator} ?", value_to_sql(operator, value)])
  hosts = ::Host::Managed.joins(:activation_keys).where(conditions)
  return_hosts(hosts)
end

#find_by_activation_key_id(_key, operator, value) ⇒ Object



88
89
90
91
92
# File 'app/models/katello/concerns/subscription_facet_host_extensions.rb', line 88

def find_by_activation_key_id(_key, operator, value)
  conditions = sanitize_sql_for_conditions(["#{Katello::ActivationKey.table_name}.id #{operator} ?", value_to_sql(operator, value)])
  hosts = ::Host::Managed.joins(:activation_keys).where(conditions)
  return_hosts(hosts)
end

#find_by_hypervisor_host(_key, operator, value) ⇒ Object



94
95
96
97
98
99
# File 'app/models/katello/concerns/subscription_facet_host_extensions.rb', line 94

def find_by_hypervisor_host(_key, operator, value)
  conditions = sanitize_sql_for_conditions(["#{::Host.table_name}.name #{operator} ?", value_to_sql(operator, value)])
  hosts = ::Host.where(conditions)
  hosts = ::Host.joins(:subscription_facet).where("#{Katello::Host::SubscriptionFacet.table_name}.hypervisor_host_id" => hosts)
  return_hosts(hosts)
end

#find_by_subscription_id(_key, operator, value) ⇒ Object



108
109
110
111
112
113
# File 'app/models/katello/concerns/subscription_facet_host_extensions.rb', line 108

def find_by_subscription_id(_key, operator, value)
  conditions = sanitize_sql_for_conditions(["#{Katello::Pool.table_name}.id #{operator} ?", value_to_sql(operator, value)])
  sub_facets = ::Katello::Host::SubscriptionFacet.joins(:pools).where(conditions)
  host_ids = sub_facets.select(:host_id)
  return_hosts_by_id(host_ids)
end

#find_by_subscription_name(_key, operator, value) ⇒ Object



101
102
103
104
105
106
# File 'app/models/katello/concerns/subscription_facet_host_extensions.rb', line 101

def find_by_subscription_name(_key, operator, value)
  conditions = sanitize_sql_for_conditions(["#{Katello::Subscription.table_name}.name #{operator} ?", value_to_sql(operator, value)])
  sub_facets = ::Katello::Host::SubscriptionFacet.joins(pools: :subscription).where(conditions)
  host_ids = sub_facets.select(:host_id)
  return_hosts_by_id(host_ids)
end

#return_hosts(hosts) ⇒ Object



123
124
125
126
127
128
129
# File 'app/models/katello/concerns/subscription_facet_host_extensions.rb', line 123

def return_hosts(hosts)
  if hosts.empty?
    {:conditions => "1=0"}
  else
    {:conditions => "#{::Host::Managed.table_name}.id IN (#{hosts.pluck(:id).join(',')})"}
  end
end

#return_hosts_by_id(host_ids) ⇒ Object



115
116
117
118
119
120
121
# File 'app/models/katello/concerns/subscription_facet_host_extensions.rb', line 115

def return_hosts_by_id(host_ids)
  if host_ids.empty?
    {:conditions => "1=0"}
  else
    {:conditions => "#{::Host::Managed.table_name}.id IN (#{host_ids.to_sql})"}
  end
end

#rhel_lifecycle_status_mapObject



78
79
80
# File 'app/models/katello/concerns/subscription_facet_host_extensions.rb', line 78

def rhel_lifecycle_status_map
  ::Katello::RhelLifecycleStatus.status_map
end