Module: Katello::HostsAndHostgroupsHelper
- Defined in:
- app/helpers/katello/hosts_and_hostgroups_helper.rb
Instance Method Summary collapse
- #blank_or_inherit_with_id(f, attr) ⇒ Object
- #content_view(host) ⇒ Object
- #content_views_for_host(host, options) ⇒ Object
- #envs_by_kt_org ⇒ Object
- #fetch_content_view(host, options = {}) ⇒ Object
- #fetch_lifecycle_environment(host, options = {}) ⇒ Object
- #host_hostgroup_kickstart_repository_id(host) ⇒ Object
- #kickstart_repository_id(host, options = {}) ⇒ Object
- #kickstart_repository_options(param_host, options = {}) ⇒ Object
- #kt_ak_label ⇒ Object
- #lifecycle_environment(host) ⇒ Object
- #lifecycle_environment_options(host, options = {}) ⇒ Object
- #os_updated_kickstart_options(host) ⇒ Object
- #use_install_media(host, options = {}) ⇒ Object
- #using_hostgroups_page? ⇒ Boolean
- #view_to_options(view_options, selected_val, include_blank = false) ⇒ Object
Instance Method Details
#blank_or_inherit_with_id(f, attr) ⇒ Object
11 12 13 14 15 |
# File 'app/helpers/katello/hosts_and_hostgroups_helper.rb', line 11 def blank_or_inherit_with_id(f, attr) return true unless f.object.respond_to?(:parent_id) && f.object.parent_id inherited_value = f.object.send(attr).try(:id) || '' %(<option data-id="#{inherited_value}" value="">#{blank_or_inherit_f(f, attr)}</option>) end |
#content_view(host) ⇒ Object
25 26 27 28 29 30 31 |
# File 'app/helpers/katello/hosts_and_hostgroups_helper.rb', line 25 def content_view(host) if host.is_a?(Hostgroup) host.content_view else host.content_facet.try(:content_view) end end |
#content_views_for_host(host, options) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'app/helpers/katello/hosts_and_hostgroups_helper.rb', line 122 def content_views_for_host(host, ) include_blank = .fetch(:include_blank, nil) if include_blank == true #check for true specifically include_blank = '<option></option>' end lifecycle_environment = fetch_lifecycle_environment(host, ) content_view = fetch_content_view(host, ) views = [] if lifecycle_environment views = Katello::ContentView.in_environment(lifecycle_environment) elsif content_view views = [content_view] end = views.map do |view| selected = content_view.try(:id) == view.id ? 'selected' : '' %(<option #{selected} value="#{view.id}">#{h(view.name)}</option>) end = .join .insert(0, include_blank) if include_blank .html_safe end |
#envs_by_kt_org ⇒ Object
17 18 19 20 21 22 23 |
# File 'app/helpers/katello/hosts_and_hostgroups_helper.rb', line 17 def envs_by_kt_org ::Environment.all.find_all(&:katello_id).group_by do |env| if env.katello_id env.katello_id.split('/').first end end end |
#fetch_content_view(host, options = {}) ⇒ Object
86 87 88 89 90 91 92 |
# File 'app/helpers/katello/hosts_and_hostgroups_helper.rb', line 86 def fetch_content_view(host, = {}) selected_host_group = .fetch(:selected_host_group, nil) return content_view(selected_host_group) if selected_host_group.present? selected_content_view = content_view(host) selected_content_view if selected_content_view.present? end |
#fetch_lifecycle_environment(host, options = {}) ⇒ Object
79 80 81 82 83 84 |
# File 'app/helpers/katello/hosts_and_hostgroups_helper.rb', line 79 def fetch_lifecycle_environment(host, = {}) selected_host_group = .fetch(:selected_host_group, nil) return lifecycle_environment(selected_host_group) if selected_host_group.present? selected_env = lifecycle_environment(host) return selected_env if selected_env.present? end |
#host_hostgroup_kickstart_repository_id(host) ⇒ Object
46 47 48 49 50 |
# File 'app/helpers/katello/hosts_and_hostgroups_helper.rb', line 46 def host_hostgroup_kickstart_repository_id(host) return if host.blank? return host.kickstart_repository_id if host.is_a?(Hostgroup) host.content_facet.kickstart_repository_id if host.try(:content_facet).present? end |
#kickstart_repository_id(host, options = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/helpers/katello/hosts_and_hostgroups_helper.rb', line 52 def kickstart_repository_id(host, = {}) return if host.try(:medium_id).present? host_ks_repo_id = host_hostgroup_kickstart_repository_id(host) = (host, ) # if the kickstart repo id is set in the selected_hostgroup use that selected_host_group = .fetch(:selected_host_group, nil) if selected_host_group.try(:kickstart_repository_id).present? ks_repo_ids = .map(&:id) if ks_repo_ids.include?(selected_host_group.kickstart_repository_id) return selected_host_group.kickstart_repository_id elsif host_ks_repo_id && ks_repo_ids.include?(host_ks_repo_id) return host_ks_repo_id else return .first.try(:id) end end # if the kickstart repo id is set in the host use that return host_ks_repo_id if host_ks_repo_id.present? if selected_host_group.try(:medium_id).blank? && host.try(:medium_id).blank? .first.try(:id) end end |
#kickstart_repository_options(param_host, options = {}) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'app/helpers/katello/hosts_and_hostgroups_helper.rb', line 158 def (param_host, = {}) # this method gets called in 2 places # 1) On initial page load or a host group selection. At that point the host object is already # => populated and we should just use that. # 2) Once you chose a diff os/content source/arch/lifecycle env/cv via the os_selected method. # In case 2 we want it to play by the rules of "one of these params" and # in case 1 we want it to behave as if everything is already set right and # We need to figure out the available KS repos in both cases. if param_host.present? # case 1 selected_host_group = .fetch(:selected_host_group, nil) host = selected_host_group.present? ? selected_host_group : param_host return [] unless host..is_a?(Redhat) new_host = ::Host.new # there is foreman bug right now that prevents # os and arch to get updated properly, # http://projects.theforeman.org/issues/14737 # so we are going to hard code it to use what # is in the param host for now. new_host. = param_host..present? ? param_host. : host. new_host.architecture = param_host.architecture.present? ? param_host.architecture : host.architecture if (host.is_a? Hostgroup) new_host.content_facet = Host::ContentFacet.new(:lifecycle_environment_id => host.lifecycle_environment_id, :content_view_id => host.content_view_id) elsif host.content_facet.present? new_host.content_facet = Host::ContentFacet.new(:lifecycle_environment_id => host.content_facet.lifecycle_environment_id, :content_view_id => host.content_facet.content_view_id) end new_host.content_source = host.content_source new_host..kickstart_repos(new_host).map { |repo| OpenStruct.new(repo) } else # case 2 (host) end end |
#kt_ak_label ⇒ Object
3 4 5 |
# File 'app/helpers/katello/hosts_and_hostgroups_helper.rb', line 3 def kt_ak_label "kt_activation_keys" end |
#lifecycle_environment(host) ⇒ Object
33 34 35 36 37 38 39 |
# File 'app/helpers/katello/hosts_and_hostgroups_helper.rb', line 33 def lifecycle_environment(host) if host.is_a?(Hostgroup) host.lifecycle_environment else host.content_facet.try(:lifecycle_environment) end end |
#lifecycle_environment_options(host, options = {}) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'app/helpers/katello/hosts_and_hostgroups_helper.rb', line 94 def (host, = {}) include_blank = .fetch(:include_blank, nil) if include_blank == true #check for true specifically include_blank = '<option></option>' end selected_id = fetch_lifecycle_environment(host, ).try(:id) orgs = Organization.current ? [Organization.current] : Organization.my_organizations = [] orgs.each do |org| = "" org.kt_environments.each do |env| selected = selected_id == env.id ? 'selected' : '' << %(<option value="#{env.id}" class="kt-env" #{selected}>#{h(env.name)}</option>) end if Organization.current << else << %(<optgroup label="#{org.name}">#{}</optgroup>) end end = .join .insert(0, include_blank) if include_blank .html_safe end |
#os_updated_kickstart_options(host) ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'app/helpers/katello/hosts_and_hostgroups_helper.rb', line 197 def (host) # this method gets called in 1 place Once you chose a diff os/content source/arch/lifecycle env/cv # via the os_selected method. # In this case we want it play by the rules of "one of these params" and # need to figure out the available KS repos for the given params. os_selection_params = ["operatingsystem_id", 'content_view_id', 'lifecycle_environment_id', 'content_source_id', 'architecture_id'] = [] if os_selection_params.all? { |key| params[key].present? } if host.nil? host = ::Host.new end host. = Operatingsystem.find(params[:operatingsystem_id]) host.architecture = Architecture.find(params[:architecture_id]) lifecycle_env = Katello::KTEnvironment.find(params[:lifecycle_environment_id]) content_view = Katello::ContentView.find(params[:content_view_id]) host.content_facet = Host::ContentFacet.new(:lifecycle_environment_id => lifecycle_env.id, :content_view_id => content_view.id) host.content_source = SmartProxy.find(params[:content_source_id]) if host..is_a?(Redhat) = host..kickstart_repos(host).map { |repo| OpenStruct.new(repo) } end end end |
#use_install_media(host, options = {}) ⇒ Object
41 42 43 44 |
# File 'app/helpers/katello/hosts_and_hostgroups_helper.rb', line 41 def use_install_media(host, = {}) return true if host && host.errors && host.errors.include?(:medium_id) kickstart_repository_id(host, ).blank? end |
#using_hostgroups_page? ⇒ Boolean
7 8 9 |
# File 'app/helpers/katello/hosts_and_hostgroups_helper.rb', line 7 def using_hostgroups_page? controller.controller_name == "hostgroups" end |
#view_to_options(view_options, selected_val, include_blank = false) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'app/helpers/katello/hosts_and_hostgroups_helper.rb', line 145 def (, selected_val, include_blank = false) if include_blank == true #check for true specifically include_blank = '<option></option>' end views = .map do |view| selected = selected_val == view.id ? 'selected' : '' %(<option #{selected} value="#{view.id}">#{h(view.name)}</option>) end views = views.join views.insert(0, include_blank) if include_blank views.html_safe end |