-
Notifications
You must be signed in to change notification settings - Fork 896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhanced inventory collector target and parser classes #13907
Changes from 6 commits
28a74aa
e2d8125
0f57da2
9435aca
4fc9ecf
6ec3730
42ab658
bcf3d5d
b58126d
8981373
c333f2d
4214aa2
85ad5bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
class ManagerRefresh::Inventory::Collector | ||
attr_accessor :manager | ||
attr_accessor :target | ||
attr_accessor :manager, :target | ||
|
||
# @param manager [ManageIQ::Providers::BaseManager] A manager object | ||
# @param target [ActiveRecord|Hash] A refresh Target object | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why could this be a Hash? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Object |
||
def initialize(manager, target) | ||
@manager = manager | ||
@target = target | ||
end | ||
|
||
def options | ||
@options ||= Settings.ems_refresh[manager.class.ems_type] | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,70 @@ | ||
class ManagerRefresh::Inventory::Target | ||
# @param [ApplicationRecord] root | ||
def initialize(root) | ||
@root = root | ||
end | ||
attr_reader :collector, :collections | ||
|
||
delegate :manager, :target, :to => :collector | ||
|
||
def collections | ||
@collections ||= {} | ||
# @param collector [ManagerRefresh::Inventory::Collector] A collector object | ||
def initialize(collector) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if I like the collector being tied to this class. |
||
@collector = collector | ||
@collections = {} | ||
initialize_inventory_collections | ||
end | ||
|
||
def inventory_collections | ||
@collections.values | ||
collections.values | ||
end | ||
|
||
def inventory_collections_names | ||
collections.keys | ||
end | ||
|
||
protected | ||
|
||
def initialize_inventory_collections | ||
raise NotImplementedError, _("must be implemented in a subclass") | ||
end | ||
|
||
# Adds 1 ManagerRefresh::InventoryCollection under a target.collections using :association key as index | ||
# | ||
# @param inventory_collection_data [Hash] Hash used for ManagerRefresh::InventoryCollection initialize | ||
def add_inventory_collection(inventory_collection_data) | ||
data = inventory_collection_data | ||
data[:parent] ||= manager | ||
|
||
if !data.key?(:delete_method) && data[:model_class] | ||
# Automatically infer what the delete method should be, unless the delete methods was given | ||
data[:delete_method] = data[:model_class].new.respond_to?(:disconnect_inv) ? :disconnect_inv : nil | ||
end | ||
|
||
collections[data[:association]] = ::ManagerRefresh::InventoryCollection.new(data) | ||
end | ||
|
||
# Adds multiple inventory collections with the same data | ||
# | ||
# @param default [ManagerRefresh::InventoryCollectionDefault] Default | ||
# @param inventory_collections [Array] Array of method names for passed default parameter | ||
# @param inventory_collections_data [Hash] Hash used for ManagerRefresh::InventoryCollection initialize | ||
def add_inventory_collections(default, inventory_collections, inventory_collections_data = {}) | ||
inventory_collections.each do |inventory_collection| | ||
add_inventory_collection(default.send(inventory_collection, inventory_collections_data)) | ||
end | ||
end | ||
|
||
# Adds remaining inventory collections with the same data | ||
# | ||
# @param defaults [Array] Array of ManagerRefresh::InventoryCollectionDefault | ||
# @param inventory_collections_data [Hash] Hash used for ManagerRefresh::InventoryCollection initialize | ||
def add_remaining_inventory_collections(defaults, inventory_collections_data = {}) | ||
defaults.each do |default| | ||
# Get names of all inventory collections defined in passed classes with Defaults | ||
all_inventory_collections = default.methods - ::ManagerRefresh::InventoryCollectionDefault.methods | ||
# Get names of all defined inventory_collections | ||
defined_inventory_collections = inventory_collections_names | ||
|
||
# Add all missing inventory_collections with defined init_data | ||
add_inventory_collections(default, | ||
all_inventory_collections - defined_inventory_collections, | ||
inventory_collections_data) | ||
end | ||
end | ||
end |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really like how
@root
(single refresh specific variable) was removed from the collection definition.Would be nice if
Persister
definition was reusable. (future thought)