Skip to content

Commit

Permalink
Merge pull request ManageIQ#15441 from pkliczewski/master
Browse files Browse the repository at this point in the history
InfraManager Inventory Collections for Full Refresh
  • Loading branch information
agrare committed Jul 5, 2017
2 parents 9c808a7 + 6eeec01 commit e1fbd92
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 40 deletions.
1 change: 1 addition & 0 deletions app/models/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Host < ApplicationRecord
has_many :host_switches, :dependent => :destroy
has_many :switches, :through => :host_switches
has_many :lans, :through => :switches
has_many :networks, :through => :hardware
has_many :patches, :dependent => :destroy
has_many :system_services, :dependent => :destroy
has_many :host_services, :class_name => "SystemService", :foreign_key => "host_id", :inverse_of => :host
Expand Down
12 changes: 12 additions & 0 deletions app/models/manageiq/providers/infra_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ class InfraManager < BaseManager

include AvailabilityMixin

has_many :host_hardwares, :through => :hosts, :source => :hardware
has_many :host_operating_systems, :through => :hosts, :source => :operating_system
has_many :host_storages, :through => :hosts
has_many :host_switches, :through => :hosts
has_many :host_networks, :through => :hosts, :source => :networks
has_many :snapshots, :through => :vms_and_templates
has_many :operating_systems, :through => :vms_and_templates
has_many :switches, :through => :hosts
has_many :lans, :through => :hosts
has_many :networks, :through => :hardwares
has_many :guest_devices, :through => :hardwares

class << model_name
define_method(:route_key) { "ems_infras" }
define_method(:singular_route_key) { "ems_infra" }
Expand Down
152 changes: 112 additions & 40 deletions app/models/manager_refresh/inventory_collection_default/infra_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ class ManagerRefresh::InventoryCollectionDefault::InfraManager < ManagerRefresh:
class << self
def vms(extra_attributes = {})
attributes = {
:model_class => ::ManageIQ::Providers::InfraManager::Vm,
:association => :vms,
:model_class => ::ManageIQ::Providers::InfraManager::Vm,
:association => :vms,
:builder_params => {
:ems_id => ->(persister) { persister.manager.id },
},
}

attributes.merge!(extra_attributes)
end

def miq_templates(extra_attributes = {})
attributes = {
:model_class => ::ManageIQ::Providers::InfraManager::Template,
:association => :miq_templates,
:model_class => ::ManageIQ::Providers::InfraManager::Template,
:association => :miq_templates,
:builder_params => {
:ems_id => ->(persister) { persister.manager.id },
},
}

attributes.merge!(extra_attributes)
Expand All @@ -22,17 +28,27 @@ def disks(extra_attributes = {})
attributes = {
:model_class => ::Disk,
:manager_ref => [:hardware, :device_name],
:association => :disks
:association => :disks,
}

attributes.merge!(extra_attributes)
end

def nics(extra_attributes = {})
def networks(extra_attributes = {})
attributes = {
:model_class => ::Network,
:manager_ref => [:hardware, :ipaddress],
:association => :nics
:model_class => ::Network,
:manager_ref => [:hardware, :ipaddress],
:association => :networks,
}

attributes.merge!(extra_attributes)
end

def host_networks(extra_attributes = {})
attributes = {
:model_class => ::Network,
:manager_ref => [:hardware, :ipaddress],
:association => :host_networks,
}

attributes.merge!(extra_attributes)
Expand All @@ -42,7 +58,7 @@ def guest_devices(extra_attributes = {})
attributes = {
:model_class => ::GuestDevice,
:manager_ref => [:hardware, :uid_ems],
:association => :guest_devices
:association => :guest_devices,
}

attributes.merge!(extra_attributes)
Expand All @@ -52,7 +68,17 @@ def hardwares(extra_attributes = {})
attributes = {
:model_class => ::Hardware,
:manager_ref => [:vm_or_template],
:association => :hardwares
:association => :hardwares,
}

attributes.merge!(extra_attributes)
end

def host_hardwares(extra_attributes = {})
attributes = {
:model_class => ::Hardware,
:manager_ref => [:host],
:association => :host_hardwares,
}

attributes.merge!(extra_attributes)
Expand All @@ -62,7 +88,7 @@ def snapshots(extra_attributes = {})
attributes = {
:model_class => ::Snapshot,
:manager_ref => [:uid],
:association => :snapshots
:association => :snapshots,
}

attributes.merge!(extra_attributes)
Expand All @@ -72,7 +98,17 @@ def operating_systems(extra_attributes = {})
attributes = {
:model_class => ::OperatingSystem,
:manager_ref => [:vm_or_template],
:association => :operating_systems
:association => :operating_systems,
}

attributes.merge!(extra_attributes)
end

def host_operating_systems(extra_attributes = {})
attributes = {
:model_class => ::OperatingSystem,
:manager_ref => [:host],
:association => :host_operating_systems,
}

attributes.merge!(extra_attributes)
Expand All @@ -82,17 +118,21 @@ def custom_attributes(extra_attributes = {})
attributes = {
:model_class => ::CustomAttribute,
:manager_ref => [:name],
:association => :custom_attributes
:association => :custom_attributes,
}

attributes.merge!(extra_attributes)
end

def datacenters(extra_attributes = {})
def ems_folders(extra_attributes = {})
attributes = {
:model_class => ::Datacenter,
:association => :datacenters,
:attributes_blacklist => [:ems_children]
:model_class => ::EmsFolder,
:association => :ems_folders,
:manager_ref => [:uid_ems],
:attributes_blacklist => [:ems_children],
:builder_params => {
:ems_id => ->(persister) { persister.manager.id },
},
}

attributes.merge!(extra_attributes)
Expand All @@ -103,7 +143,10 @@ def resource_pools(extra_attributes = {})
:model_class => ::ResourcePool,
:association => :resource_pools,
:manager_ref => [:uid_ems],
:attributes_blacklist => [:ems_children]
:attributes_blacklist => [:ems_children],
:builder_params => {
:ems_id => ->(persister) { persister.manager.id },
},
}

attributes.merge!(extra_attributes)
Expand All @@ -113,7 +156,10 @@ def ems_clusters(extra_attributes = {})
attributes = {
:model_class => ::EmsCluster,
:association => :ems_clusters,
:attributes_blacklist => [:ems_children, :datacenter_id]
:attributes_blacklist => [:ems_children, :datacenter_id],
:builder_params => {
:ems_id => ->(persister) { persister.manager.id },
},
}

attributes.merge!(extra_attributes)
Expand All @@ -122,55 +168,81 @@ def ems_clusters(extra_attributes = {})
def storages(extra_attributes = {})
attributes = {
:model_class => ::Storage,
:association => :storages,
# TODO: change :manager_ref => [:location],
:association => :storages
}

attributes.merge!(extra_attributes)
end

def hosts(extra_attributes = {})
attributes = {
:model_class => ::Host,
:association => :hosts,
:model_class => ::Host,
:association => :hosts,
:builder_params => {
:ems_id => ->(persister) { persister.manager.id },
},
}

attributes.merge!(extra_attributes)
end

def datacenter_children(extra_attributes = {})
datacenter_children_save_block = lambda do |_ems, inventory_collection|
# TODO
end
def host_storages(extra_attributes = {})
attributes = {
:model_class => ::HostStorage,
:manager_ref => [:host, :storage],
:association => :host_storages,
}

attributes.merge!(extra_attributes)
end

def host_switches(extra_attributes = {})
attributes = {
:association => :datacenter_children,
:custom_save_block => datacenter_children_save_block,
:model_class => ::HostSwitch,
:manager_ref => [:host, :switch],
:association => :host_switches
}

attributes.merge!(extra_attributes)
end

def resource_pool_children(extra_attributes = {})
resource_pool_children_save_block = lambda do |_ems, inventory_collection|
# TODO
end
def switches(extra_attributes = {})
attributes = {
:model_class => ::Switch,
:manager_ref => [:uid_ems],
:association => :switches,
}

attributes.merge!(extra_attributes)
end

def lans(extra_attributes = {})
attributes = {
:association => :resource_pool_children,
:custom_save_block => resource_pool_children_save_block,
:model_class => ::Lan,
:manager_ref => [:uid_ems],
:association => :lans,
}

attributes.merge!(extra_attributes)
end

def ems_clusters_children(extra_attributes = {})
ems_cluster_children_save_block = lambda do |_ems, inventory_collection|
# TODO
def snapshot_parent(extra_attributes = {})
snapshot_parent_save_block = lambda do |_ems, inventory_collection|
snapshot_collection = inventory_collection.dependency_attributes[:snapshots].try(:first)

snapshot_collection.each do |snapshot|
ActiveRecord::Base.transaction do
child = Snapshot.find(snapshot.id)
parent = Snapshot.find_by(:uid_ems => snapshot.parent_uid)
child.update_attribute(:parent_id, parent.try(:id))
end
end
end

attributes = {
:association => :ems_cluster_children,
:custom_save_block => ems_cluster_children_save_block,
:association => :snapshot_patent,
:custom_save_block => snapshot_parent_save_block,
}

attributes.merge!(extra_attributes)
Expand Down
1 change: 1 addition & 0 deletions app/models/operating_system.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'miq-encode'

class OperatingSystem < ApplicationRecord
belongs_to :host
belongs_to :vm_or_template
belongs_to :vm, :foreign_key => :vm_or_template_id
belongs_to :miq_template, :foreign_key => :vm_or_template_id
Expand Down

0 comments on commit e1fbd92

Please sign in to comment.