Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,60 @@ def partial_refresh_parser_class
def persister_class
ManageIQ::Providers::Openshift::Inventory::Persister::InfraManager
end

#
# Performs a full refresh.
#
def full_refresh
# Create and populate the collector, persister and parser
# and parse inventories
inventory = provider_class::Inventory.build(manager, nil)
collector = inventory.collector
persister = inventory.parse

# execute persist:
persister&.persist!

# Update the memory:
memory.add_list_version(:nodes, collector.nodes.resourceVersion)
memory.add_list_version(:vms, collector.vms.resourceVersion)
memory.add_list_version(:vm_instances, collector.vm_instances.resourceVersion)
memory.add_list_version(:templates, collector.templates.resourceVersion)
memory.add_list_version(:instance_types, collector.instance_types.resourceVersion)

manager.update(:last_refresh_error => nil, :last_refresh_date => Time.now.utc)
rescue StandardError => error
_log.error('Full refresh failed.')
_log.log_backtrace(error)
manager.update(:last_refresh_error => error.to_s, :last_refresh_date => Time.now.utc)
end

#
# Start watches
#
def start_watches
# This flag will be used to tell the threads to get out of their loops:
@finish = Concurrent::AtomicBoolean.new(false)

# Create the watches:
@watches = []
@watches << @manager.kubeclient.watch_nodes(:resource_version => memory.get_list_version(:nodes))
@watches << @manager.kubeclient("kubevirt.io/v1").watch_virtual_machines(:resource_version => memory.get_list_version(:vms))
@watches << @manager.kubeclient("kubevirt.io/v1").watch_virtual_machine_instances(:resource_version => memory.get_list_version(:vm_instances))
@watches << @manager.kubeclient("template.openshift.io/v1").watch_templates(:resource_version => memory.get_list_version(:templates))
@watches << @manager.kubeclient("instancetype.kubevirt.io/v1beta1").watch_virtual_machine_cluster_instancetypes(:resource_version => memory.get_list_version(:instance_types))

# Create the threads that run the watches and put the notices in the queue:
@watchers = []
@watches.each do |watch|
thread = Thread.new do
until @finish.value
watch.each do |notice|
@queue.push(notice)
end
end
end
@watchers << thread
end
end
Comment on lines +21 to +76
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO if we move the list of watches out into a method that could be overridden we don't have to override these entire methods

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module ManageIQ::Providers::Openshift::Inventory::Collector::InfraManager::CollectorMixin
extend ActiveSupport::Concern

attr_reader :templates
end
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
class ManageIQ::Providers::Openshift::Inventory::Collector::InfraManager::FullRefresh < ManageIQ::Providers::Kubevirt::Inventory::Collector::FullRefresh
include ManageIQ::Providers::Openshift::Inventory::Collector::InfraManager::CollectorMixin

def initialize(manager, refresh_target)
super

@templates = @manager.kubeclient("template.openshift.io/v1").get_templates
end
end
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
class ManageIQ::Providers::Openshift::Inventory::Collector::InfraManager::PartialRefresh < ManageIQ::Providers::Kubevirt::Inventory::Collector::PartialRefresh
include ManageIQ::Providers::Openshift::Inventory::Collector::InfraManager::CollectorMixin

def initialize(manager, notices)
super

@templates = notices_of_kind(notices, 'VirtualMachineTemplate')
end
end
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
class ManageIQ::Providers::Openshift::Inventory::Parser::InfraManager::FullRefresh < ManageIQ::Providers::Kubevirt::Inventory::Parser::FullRefresh
include ManageIQ::Providers::Openshift::Inventory::Parser::InfraManager::ParserMixin

def parse
super

templates = collector.templates
@template_collection = persister.template_collection
process_templates(templates)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module ManageIQ::Providers::Openshift::Inventory::Parser::InfraManager::ParserMixin
extend ActiveSupport::Concern

attr_reader :template_collection

def process_templates(objects)
objects.each do |object|
process_template(object)
end
end

def process_template(object)
# Get the basic information:
uid = object.metadata.uid
vm = vm_from_objects(object.objects)
return if vm.nil?

# Add the inventory object for the template:
template_object = template_collection.find_or_build(uid)
template_object.connection_state = 'connected'
template_object.ems_ref = uid
template_object.name = object.metadata.name
template_object.raw_power_state = 'never'
template_object.template = true
template_object.uid_ems = uid
template_object.location = object.metadata.namespace

# Add the inventory object for the hardware:
process_hardware(template_object, object.parameters, object.metadata.labels, vm.dig(:spec, :template, :spec, :domain))

# Add the inventory object for the OperatingSystem
process_os(template_object, object.metadata.labels, object.metadata.annotations)
end
end
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
class ManageIQ::Providers::Openshift::Inventory::Parser::InfraManager::PartialRefresh < ManageIQ::Providers::Kubevirt::Inventory::Parser::PartialRefresh
include ManageIQ::Providers::Openshift::Inventory::Parser::InfraManager::ParserMixin

def parse
templates = collector.templates
template_ids = get_object_ids(templates.map(&:object))
discard_deleted_notices(templates)
@template_collection = persister.template_collection(:targeted => true, :ids => template_ids)
process_templates(templates.map(&:object))
end
end
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
class ManageIQ::Providers::Openshift::Inventory::Persister::InfraManager < ManageIQ::Providers::Kubevirt::Inventory::Persister
def template_collection(targeted: false, ids: [])
add_collection(infra, :miq_templates) do |builder|
builder.add_properties(
:targeted => targeted,
:manager_uuids => ids,
:parent_inventory_collections => %i(vms)
)

builder.add_default_values(
:type => "#{manager.class}::Template",
:vendor => manager.class.vendor
)
end
end
end
Loading