Skip to content

Commit

Permalink
Merge 103a1cf into c2f58c6
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderZagaynov committed Feb 20, 2018
2 parents c2f58c6 + 103a1cf commit a351545
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions app/models/manager_refresh/inventory_collection_default.rb
@@ -1,4 +1,30 @@
class ManagerRefresh::InventoryCollectionDefault
INVENTORY_RECONNECT_BLOCK = lambda do |inventory_collection, inventory_objects_index, attributes_index|
relation = inventory_collection.model_class.where(:ems_id => nil)

return if relation.count <= 0

inventory_objects_index.each_slice(100) do |batch|
batch_refs = batch.map(&:first)
relation.where(inventory_collection.manager_ref.first => batch_refs).each do |record|
index = inventory_collection.object_index_with_keys(inventory_collection.manager_ref_to_cols, record)

# We need to delete the record from the inventory_objects_index
# and attributes_index, otherwise it would be sent for create.
inventory_object = inventory_objects_index.delete(index)
hash = attributes_index.delete(index)

record.assign_attributes(hash.except(:id, :type))
if !inventory_collection.check_changed? || record.changed?
record.save!
inventory_collection.store_updated_records(record)
end

inventory_object.id = record.id
end
end
end.freeze

class << self
def vms(extra_attributes = {})
attributes = {
Expand Down Expand Up @@ -42,7 +68,8 @@ def vms(extra_attributes = {})
:ems_id => ->(persister) { persister.manager.id },
:name => "unknown",
:location => "unknown",
}
},
:custom_reconnect_block => INVENTORY_RECONNECT_BLOCK,
}

attributes.merge!(extra_attributes)
Expand Down Expand Up @@ -82,7 +109,8 @@ def miq_templates(extra_attributes = {})
:name => "unknown",
:location => "unknown",
:template => true
}
},
:custom_reconnect_block => INVENTORY_RECONNECT_BLOCK,
}

attributes.merge!(extra_attributes)
Expand Down

0 comments on commit a351545

Please sign in to comment.