From 893e6bfc44cd2dfdbf0aaa3b88d4a482ccb433f4 Mon Sep 17 00:00:00 2001 From: Moti Asayag Date: Mon, 18 Dec 2017 12:32:43 +0200 Subject: [PATCH] Introduce virtualization manager In order to support kubevirt as a secondary manager of the openshift/kubevirt provider, a new mixin is added to represent that capability. --- .../manageiq/providers/container_manager.rb | 16 ++++++++++ .../mixins/has_monitoring_manager_mixin.rb | 4 +-- .../has_virtualization_manager_mixin.rb | 29 +++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 app/models/mixins/has_virtualization_manager_mixin.rb diff --git a/app/models/manageiq/providers/container_manager.rb b/app/models/manageiq/providers/container_manager.rb index 5a7df3f20360..4486165e531f 100644 --- a/app/models/manageiq/providers/container_manager.rb +++ b/app/models/manageiq/providers/container_manager.rb @@ -5,6 +5,7 @@ class ContainerManager < BaseManager include AvailabilityMixin include HasMonitoringManagerMixin + include HasVirtualizationManagerMixin include SupportsFeatureMixin has_many :container_nodes, -> { active }, :foreign_key => :ems_id @@ -46,6 +47,11 @@ class ContainerManager < BaseManager has_many :all_container_images, :foreign_key => :ems_id, :dependent => :destroy, :class_name => "ContainerImage" has_many :all_container_nodes, :foreign_key => :ems_id, :dependent => :destroy, :class_name => "ContainerNode" + has_one :virtualization_manager, + :foreign_key => :parent_ems_id, + :class_name => "ManageIQ::Providers::Kubevirt::InfraManager", + :autosave => true, + :dependent => :destroy virtual_column :port_show, :type => :string @@ -92,5 +98,15 @@ def validate_authentication_status def port_show port.to_s end + + def endpoint_created(role) + monitoring_endpoint_created(role) if respond_to?(:monitoring_endpoint_created) + virtualization_endpoint_created(role) if respond_to?(:virtualization_endpoint_created) + end + + def endpoint_destroyed(role) + monitoring_endpoint_destroyed(role) if respond_to?(:monitoring_endpoint_destroyed) + virtualization_endpoint_destroyed(role) if respond_to?(:virtualization_endpoint_destroyed) + end end end diff --git a/app/models/mixins/has_monitoring_manager_mixin.rb b/app/models/mixins/has_monitoring_manager_mixin.rb index ef7aa0143d32..681186b00e9a 100644 --- a/app/models/mixins/has_monitoring_manager_mixin.rb +++ b/app/models/mixins/has_monitoring_manager_mixin.rb @@ -1,14 +1,14 @@ module HasMonitoringManagerMixin extend ActiveSupport::Concern - def endpoint_created(role) + def monitoring_endpoint_created(role) if role == "prometheus_alerts" && monitoring_manager.nil? monitoring_manager = ensure_monitoring_manager monitoring_manager.save end end - def endpoint_destroyed(role) + def monitoring_endpoint_destroyed(role) if role == "prometheus_alerts" && monitoring_manager.present? # TODO: if someone deletes the alerts endpoint and then quickly readds it they can end up without a manager. monitoring_manager.destroy_queue diff --git a/app/models/mixins/has_virtualization_manager_mixin.rb b/app/models/mixins/has_virtualization_manager_mixin.rb new file mode 100644 index 000000000000..dfba1c4093ca --- /dev/null +++ b/app/models/mixins/has_virtualization_manager_mixin.rb @@ -0,0 +1,29 @@ +module HasVirtualizationManagerMixin + extend ActiveSupport::Concern + + def virtualization_endpoint_created(role) + if role == "kubevirt" && virtualization_manager.nil? + virtualization_manager = ensure_virtualization_manager + virtualization_manager.save + end + end + + def virtualization_endpoint_destroyed(role) + if role == "kubevirt" && virtualization_manager.present? + virtualization_manager.destroy_queue + end + end + + private + + def ensure_virtualization_manager + if virtualization_manager.nil? + build_virtualization_manager(:parent_manager => self, + :name => "#{name} Virtualization Manager", + :zone_id => zone_id, + :provider_region => provider_region) + end + + virtualization_manager + end +end