From d1be3b3f84a652c9b53f1761f27ac47c1e55f07c Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 5 Jul 2017 08:57:47 -0400 Subject: [PATCH] Add VMware inventory collections --- .../vmware/infra_manager/inventory.rb | 3 ++ .../inventory/inventory_collections.rb | 45 +++++++++++++++++++ .../infra_manager/inventory/persister.rb | 42 +++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 app/models/manageiq/providers/vmware/infra_manager/inventory.rb create mode 100644 app/models/manageiq/providers/vmware/infra_manager/inventory/inventory_collections.rb create mode 100644 app/models/manageiq/providers/vmware/infra_manager/inventory/persister.rb diff --git a/app/models/manageiq/providers/vmware/infra_manager/inventory.rb b/app/models/manageiq/providers/vmware/infra_manager/inventory.rb new file mode 100644 index 000000000..a21dd4450 --- /dev/null +++ b/app/models/manageiq/providers/vmware/infra_manager/inventory.rb @@ -0,0 +1,3 @@ +class ManageIQ::Providers::Vmware::InfraManager::Inventory < ManagerRefresh::Inventory + require_nested :Persister +end diff --git a/app/models/manageiq/providers/vmware/infra_manager/inventory/inventory_collections.rb b/app/models/manageiq/providers/vmware/infra_manager/inventory/inventory_collections.rb new file mode 100644 index 000000000..050cf6068 --- /dev/null +++ b/app/models/manageiq/providers/vmware/infra_manager/inventory/inventory_collections.rb @@ -0,0 +1,45 @@ +class ManageIQ::Providers::Vmware::InfraManager::Inventory::InventoryCollections < ManagerRefresh::InventoryCollectionDefault::InfraManager + class << self + def customization_specs(extra_attributes = {}) + attributes = { + :model_class => ::CustomizationSpec, + :association => :customization_specs, + :manager_ref => [:name], + :builder_params => { + :ems_id => ->(persister) { persister.manager.id }, + }, + } + + attributes.merge!(extra_attributes) + end + + def vms_and_templates(extra_attributes = {}) + attributes = { + :model_class => ::VmOrTemplate, + :association => :vms_and_templates, + :builder_params => { + :ems_id => ->(persister) { persister.manager.id }, + }, + } + + attributes.merge!(extra_attributes) + end + + def storage_profiles(extra_attributes = {}) + attributes = { + :model_class => ::StorageProfile, + :association => :storage_profiles, + :builder_params => { + :ems_id => ->(persister) { persister.manager.id }, + }, + } + + attributes.merge!(extra_attributes) + end + + def hosts(extra_attributes = {}) + attributes = {:model_class => ManageIQ::Providers::Vmware::InfraManager::HostEsx} + super(attributes.merge(extra_attributes)) + end + end +end diff --git a/app/models/manageiq/providers/vmware/infra_manager/inventory/persister.rb b/app/models/manageiq/providers/vmware/infra_manager/inventory/persister.rb new file mode 100644 index 000000000..0260d1843 --- /dev/null +++ b/app/models/manageiq/providers/vmware/infra_manager/inventory/persister.rb @@ -0,0 +1,42 @@ +class ManageIQ::Providers::Vmware::InfraManager::Inventory::Persister < ManagerRefresh::Inventory::Persister + def initialize_inventory_collections + add_inventory_collections( + default_inventory_collections, inventory_collection_names, inventory_collection_options + ) + end + + def default_inventory_collections + ManageIQ::Providers::Vmware::InfraManager::Inventory::InventoryCollections + end + + def inventory_collection_names + %i( + custom_attributes + customization_specs + disks + ems_clusters + ems_folders + guest_devices + hardwares + hosts + host_hardwares + host_networks + host_storages + host_switches + host_operating_systems + lans + networks + operating_systems + resource_pools + snapshots + storages + storage_profiles + switches + vms_and_templates + ) + end + + def inventory_collection_options + {} + end +end