Module: Katello::Concerns::SubscriptionFacetHostExtensions::ClassMethods
- Defined in:
- app/models/katello/concerns/subscription_facet_host_extensions.rb
Instance Method Summary collapse
- #find_by_activation_key(_key, operator, value) ⇒ Object
- #find_by_activation_key_id(_key, operator, value) ⇒ Object
- #find_by_hypervisor_host(_key, operator, value) ⇒ Object
- #find_by_purpose_addon(_key, operator, value) ⇒ Object
- #find_by_subscription_id(_key, operator, value) ⇒ Object
- #find_by_subscription_name(_key, operator, value) ⇒ Object
- #purpose_status_map ⇒ Object
- #return_hosts(hosts) ⇒ Object
- #return_hosts_by_id(host_ids) ⇒ Object
Instance Method Details
#find_by_activation_key(_key, operator, value) ⇒ Object
109 110 111 112 113 |
# File 'app/models/katello/concerns/subscription_facet_host_extensions.rb', line 109 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
115 116 117 118 119 |
# File 'app/models/katello/concerns/subscription_facet_host_extensions.rb', line 115 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
121 122 123 124 125 126 |
# File 'app/models/katello/concerns/subscription_facet_host_extensions.rb', line 121 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_purpose_addon(_key, operator, value) ⇒ Object
103 104 105 106 107 |
# File 'app/models/katello/concerns/subscription_facet_host_extensions.rb', line 103 def find_by_purpose_addon(_key, operator, value) conditions = sanitize_sql_for_conditions(["#{Katello::PurposeAddon.table_name}.name #{operator} ?", value_to_sql(operator, value)]) hosts = ::Host::Managed.joins(:purpose_addons).where(conditions) return_hosts(hosts) end |
#find_by_subscription_id(_key, operator, value) ⇒ Object
135 136 137 138 139 140 |
# File 'app/models/katello/concerns/subscription_facet_host_extensions.rb', line 135 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
128 129 130 131 132 133 |
# File 'app/models/katello/concerns/subscription_facet_host_extensions.rb', line 128 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 |
#purpose_status_map ⇒ Object
99 100 101 |
# File 'app/models/katello/concerns/subscription_facet_host_extensions.rb', line 99 def purpose_status_map ::Katello::PurposeStatus.status_map end |
#return_hosts(hosts) ⇒ Object
150 151 152 153 154 155 156 |
# File 'app/models/katello/concerns/subscription_facet_host_extensions.rb', line 150 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
142 143 144 145 146 147 148 |
# File 'app/models/katello/concerns/subscription_facet_host_extensions.rb', line 142 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 |