Class: Actions::Katello::Host::HypervisorsUpdate
- Inherits:
-
EntryAction
- Object
- EntryAction
- Actions::Katello::Host::HypervisorsUpdate
- Defined in:
- app/lib/actions/katello/host/hypervisors_update.rb
Instance Method Summary collapse
- #finalize ⇒ Object
- #plan(environment, content_view, hypervisor_results) ⇒ Object
- #update_or_create_hypervisor(environment, content_view, hypervisor_json) ⇒ Object
Instance Method Details
#finalize ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/lib/actions/katello/host/hypervisors_update.rb', line 12 def finalize environment = ::Katello::KTEnvironment.find(input[:environment_id]) content_view = ::Katello::ContentView.find(input[:content_view_id]) hypervisor_results = input[:hypervisor_results] %w(created updated unchanged).each do |group| if hypervisor_results[group] hypervisor_results[group].each do |hypervisor| update_or_create_hypervisor(environment, content_view, hypervisor) end end end end |
#plan(environment, content_view, hypervisor_results) ⇒ Object
7 8 9 10 |
# File 'app/lib/actions/katello/host/hypervisors_update.rb', line 7 def plan(environment, content_view, hypervisor_results) plan_self(:environment_id => environment.id, :content_view_id => content_view.id, :hypervisor_results => hypervisor_results) end |
#update_or_create_hypervisor(environment, content_view, hypervisor_json) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/lib/actions/katello/host/hypervisors_update.rb', line 26 def update_or_create_hypervisor(environment, content_view, hypervisor_json) name = hypervisor_json[:name] # Since host names must be unique yet hypervisors may have unique subscription # facets in different orgs duplicate_name = "virt-who-#{name}-#{content_view.organization.id}" host = ::Host.find_by(:name => name) if host fail _("Host '%{name}' does not belong to an organization" % name) unless host.organization if host.organization.id != content_view.organization.id name = duplicate_name end elsif ::Host.find_by(:name => name) name = duplicate_name end host = ::Katello::Host::SubscriptionFacet.find_or_create_host_for_hypervisor(name, content_view.organization) host.subscription_facet ||= ::Katello::Host::SubscriptionFacet.new host.subscription_facet.update_from_consumer_attributes(hypervisor_json) host.subscription_facet.uuid = hypervisor_json[:uuid] host.subscription_facet.save! # TODO: Remove this legacy # http://projects.theforeman.org/issues/12556 unless ::Katello::Hypervisor.find_by(:name => name) hypervisor = ::Katello::Hypervisor.new(:environment_id => environment.id, :content_view_id => content_view.id) hypervisor.name = name hypervisor.cp_type = 'hypervisor' hypervisor.orchestration_for = :hypervisor hypervisor.load_from_cp(hypervisor_json) hypervisor.save! host.content_host = hypervisor end host.save! end |