diff --git a/app/models/manageiq/providers/vmware/cloud_manager/refresh_parser.rb b/app/models/manageiq/providers/vmware/cloud_manager/refresh_parser.rb index 29f7273b6..9343a7e19 100644 --- a/app/models/manageiq/providers/vmware/cloud_manager/refresh_parser.rb +++ b/app/models/manageiq/providers/vmware/cloud_manager/refresh_parser.rb @@ -141,6 +141,7 @@ def parse_vm(vm) :ems_ref => uid, :name => name, :hostname => hostname, + :location => uid, :vendor => "vmware", :raw_power_state => status, :snapshots => [parse_snapshot(vm)].compact, @@ -193,6 +194,7 @@ def parse_image(image, is_public) :uid_ems => uid, :ems_ref => uid, :name => name, + :location => uid, :vendor => "vmware", :raw_power_state => "never", :publicly_available => is_public diff --git a/app/models/manageiq/providers/vmware/inventory/parser/cloud_manager.rb b/app/models/manageiq/providers/vmware/inventory/parser/cloud_manager.rb index 226fdc368..bf9b0cbc8 100644 --- a/app/models/manageiq/providers/vmware/inventory/parser/cloud_manager.rb +++ b/app/models/manageiq/providers/vmware/inventory/parser/cloud_manager.rb @@ -33,6 +33,7 @@ def vms :uid_ems => vm[:vm].id, :name => vm[:vm].name, :hostname => vm[:hostname], + :location => vm[:vm].id, :vendor => 'vmware', :raw_power_state => vm[:vm].status, :orchestration_stack => persister.orchestration_stacks.lazy_find(vm[:vm].vapp_id), @@ -98,6 +99,7 @@ def images persister.miq_templates.find_or_build(image[:image].id).assign_attributes( :uid_ems => image[:image].id, :name => image[:image].name, + :location => image[:image].id, :vendor => 'vmware', :raw_power_state => 'never', :publicly_available => image[:is_published] diff --git a/app/models/manageiq/providers/vmware/inventory/persister.rb b/app/models/manageiq/providers/vmware/inventory/persister.rb index 93452bcc2..07b4b421d 100644 --- a/app/models/manageiq/providers/vmware/inventory/persister.rb +++ b/app/models/manageiq/providers/vmware/inventory/persister.rb @@ -7,7 +7,7 @@ def cloud ManageIQ::Providers::Vmware::InventoryCollectionDefault::CloudManager end - def targeted + def targeted? false end @@ -20,7 +20,7 @@ def shared_options settings_options.merge( :strategy => strategy, - :targeted => targeted, + :targeted => targeted?, ) end end diff --git a/app/models/manageiq/providers/vmware/inventory/persister/cloud_manager.rb b/app/models/manageiq/providers/vmware/inventory/persister/cloud_manager.rb index 36376fd73..649041f24 100644 --- a/app/models/manageiq/providers/vmware/inventory/persister/cloud_manager.rb +++ b/app/models/manageiq/providers/vmware/inventory/persister/cloud_manager.rb @@ -1,18 +1,15 @@ class ManageIQ::Providers::Vmware::Inventory::Persister::CloudManager < ManageIQ::Providers::Vmware::Inventory::Persister + include ::ManageIQ::Providers::Vmware::Inventory::Persister::Definitions::CloudCollections + def initialize_inventory_collections - add_inventory_collections( - cloud, - %i( - availability_zones - orchestration_stacks - vms - snapshots - hardwares - disks - operating_systems - orchestration_templates - miq_templates - ) - ) + initialize_cloud_inventory_collections + end + + def shared_options + { + :strategy => strategy, + :targeted => targeted?, + :parent => manager.presence + } end end diff --git a/app/models/manageiq/providers/vmware/inventory/persister/definitions/cloud_collections.rb b/app/models/manageiq/providers/vmware/inventory/persister/definitions/cloud_collections.rb new file mode 100644 index 000000000..52f8525fa --- /dev/null +++ b/app/models/manageiq/providers/vmware/inventory/persister/definitions/cloud_collections.rb @@ -0,0 +1,46 @@ +module ManageIQ::Providers::Vmware::Inventory::Persister::Definitions::CloudCollections + extend ActiveSupport::Concern + + def cloud + ::ManagerRefresh::InventoryCollection::Builder::CloudManager + end + + def initialize_cloud_inventory_collections + %i(vms + availability_zones + disks + hardwares + operating_systems + snapshots).each do |name| + + add_collection(cloud, name) + end + + add_orchestration_templates + + add_orchestration_stacks + + add_miq_templates + end + + # ------ IC provider specific definitions ------------------------- + + def add_miq_templates + add_collection(cloud, :miq_templates) do |builder| + builder.add_properties(:model_class => ::ManageIQ::Providers::Vmware::CloudManager::Template) + end + end + + # TODO: mslemr - parent model_class used anywhere? If not, should be deleted from core + def add_orchestration_stacks + add_collection(cloud, :orchestration_stacks) do |builder| + builder.add_properties(:model_class => ::ManageIQ::Providers::Vmware::CloudManager::OrchestrationStack) + end + end + + def add_orchestration_templates + add_collection(cloud, :orchestration_templates) do |builder| + builder.add_builder_params(:ems_id => manager.id) + end + end +end diff --git a/app/models/manageiq/providers/vmware/inventory_collection_default/cloud_manager.rb b/app/models/manageiq/providers/vmware/inventory_collection_default/cloud_manager.rb deleted file mode 100644 index d71496b90..000000000 --- a/app/models/manageiq/providers/vmware/inventory_collection_default/cloud_manager.rb +++ /dev/null @@ -1,153 +0,0 @@ -class ManageIQ::Providers::Vmware::InventoryCollectionDefault::CloudManager < ManagerRefresh::InventoryCollectionDefault::CloudManager - class << self - def availability_zones(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Vmware::CloudManager::AvailabilityZone, - :inventory_object_attributes => %i( - type - ems_id - ems_ref - name - ) - } - - super(attributes.merge!(extra_attributes)) - end - - def orchestration_stacks(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Vmware::CloudManager::OrchestrationStack, - :inventory_object_attributes => %i( - type - ems_id - ems_ref - name - description - status - ) - } - - super(attributes.merge!(extra_attributes)) - end - - def vms(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Vmware::CloudManager::Vm, - :inventory_object_attributes => %i( - type - uid_ems - ems_ref - name - hostname - vendor - raw_power_state - snapshots - hardware - operating_system - orchestration_stack - cpu_hot_add_enabled - memory_hot_add_enabled - ) - } - - super(attributes.merge!(extra_attributes)) - end - - def snapshots(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Vmware::CloudManager::Snapshot, - :inventory_object_attributes => %i( - type - name - uid - ems_ref - parent_uid - create_time - total_size - ), - } - - super(attributes.merge!(extra_attributes)) - end - - def hardwares(extra_attributes = {}) - attributes = { - :inventory_object_attributes => %i( - guest_os - guest_os_full_name - bitness - cpu_sockets - cpu_cores_per_socket - cpu_total_cores - memory_mb - disk_capacity - disks - ) - } - - super(attributes.merge!(extra_attributes)) - end - - def disks(extra_attributes = {}) - attributes = { - :inventory_object_attributes => %i( - device_name - device_type - disk_type - controller_type - size - location - filename - ) - } - - super(attributes.merge!(extra_attributes)) - end - - def operating_systems(extra_attributes = {}) - attributes = { - :inventory_object_attributes => %i( - product_name - ) - } - - super(attributes.merge!(extra_attributes)) - end - - def orchestration_templates(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Vmware::CloudManager::OrchestrationTemplate, - :inventory_object_attributes => %i( - type - ems_ref - name - description - orderable - content - ems_id - ), - :builder_params => { - :ems_id => ->(persister) { persister.manager.id }, - } - } - - super(attributes.merge!(extra_attributes)) - end - - def miq_templates(extra_attributes = {}) - attributes = { - :model_class => ::ManageIQ::Providers::Vmware::CloudManager::Template, - :inventory_object_attributes => %i( - uid_ems - ems_ref - name - vendor - raw_power_state - publicly_available - ) - } - - super(attributes.merge!(extra_attributes)) - end - end -end diff --git a/spec/models/manageiq/providers/vmware/cloud_manager/refresher_spec.rb b/spec/models/manageiq/providers/vmware/cloud_manager/refresher_spec.rb index 1dd72d874..5f960abf0 100644 --- a/spec/models/manageiq/providers/vmware/cloud_manager/refresher_spec.rb +++ b/spec/models/manageiq/providers/vmware/cloud_manager/refresher_spec.rb @@ -172,7 +172,7 @@ def assert_specific_template :vendor => 'vmware', :power_state => 'never', :publicly_available => false, - :location => 'unknown', + :location => 'vm-ac90bd58-3bc4-47a5-bc8c-f1c8f5c468b6', :tools_status => nil, :boot_time => nil, :standby_action => nil, @@ -205,7 +205,7 @@ def assert_specific_vm_powered_on :uid_ems => 'vm-84faa107-c0b9-4a21-adc5-b17e0c5355a2', :vendor => 'vmware', :power_state => 'on', - :location => 'unknown', + :location => 'vm-84faa107-c0b9-4a21-adc5-b17e0c5355a2', :tools_status => nil, :boot_time => nil, :standby_action => nil, @@ -295,7 +295,7 @@ def assert_specific_vm_powered_off :uid_ems => 'vm-aaf94123-cbf9-4de9-841c-41dd41ac310e', :vendor => 'vmware', :power_state => 'off', - :location => 'unknown', + :location => 'vm-aaf94123-cbf9-4de9-841c-41dd41ac310e', :tools_status => nil, :boot_time => nil, :standby_action => nil,