Skip to content
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

Persister: optimized InventoryCollection definitions #307

Merged
merged 2 commits into from
Jul 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def initialize_cloud_inventory_collections

add_orchestration_templates

add_vm_and_miq_template_ancestry
# Custom processing of Ancestry
add_collection(cloud, :vm_and_miq_template_ancestry)

add_orchestration_stack_ancestry
end
Expand All @@ -58,7 +59,7 @@ def add_miq_templates
add_collection(cloud, :miq_templates) do |builder|
builder.add_properties(:model_class => ::MiqTemplate)

builder.add_builder_params(:ext_management_system => manager)
builder.add_default_values(:ems_id => manager.id)

# Extra added to automatic attributes
builder.add_inventory_attributes(%i(cloud_tenant cloud_tenants))
Expand Down Expand Up @@ -118,40 +119,19 @@ def add_orchestration_templates
end
end

# TODO: mslemr - parent model class used anywhere?
def add_key_pairs(extra_properties = {})
add_collection(cloud, :key_pairs, extra_properties) do |builder|
builder.add_properties(
:model_class => ManageIQ::Providers::Openstack::CloudManager::AuthKeyPair,
)

builder.add_builder_params(:resource => manager) unless targeted?
builder.add_default_values(:resource => manager) unless targeted?
end
end

# TODO: mslemr - same as amazon!
def add_vm_and_miq_template_ancestry
add_collection(cloud, :vm_and_miq_template_ancestry, {}, {:auto_inventory_attributes => false, :auto_model_class => false, :without_model_class => true}) do |builder|
builder.add_dependency_attributes(
:vms => [collections[:vms]],
:miq_templates => [collections[:miq_templates]]
)
end
end

# TODO: mslemr - almost same as amazon!
# Needed remove_dependency_attributes for core basic definition
def add_orchestration_stack_ancestry
add_collection(cloud, :orchestration_stack_ancestry, {}, {:auto_inventory_attributes => false, :auto_model_class => false, :without_model_class => true}) do |builder|
builder.add_dependency_attributes(
:orchestration_stacks => [collections[:orchestration_stacks]]
)

if targeted?
builder.add_dependency_attributes(
:orchestration_stacks_resources => [collections[:orchestration_stacks_resources]]
)
end
add_collection(cloud, :orchestration_stack_ancestry) do |builder|
builder.remove_dependency_attributes(:orchestration_stacks_resources) unless targeted?
end
end

Expand All @@ -160,7 +140,7 @@ def add_orchestration_stack_ancestry
# Shortcut for better code readability
def add_orchestration_stacks_with_ems_param
add_orchestration_stacks do |builder|
builder.add_builder_params(:ext_management_system => manager)
builder.add_default_values(:ems_id => manager.id)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def add_cloud_networks
add_collection(network, :cloud_networks) do |builder|
builder.add_properties(:model_class => ManageIQ::Providers::Openstack::NetworkManager::CloudNetwork)

ems_network_builder_param(builder)
network_ems_default_value(builder)
end
end

Expand All @@ -37,7 +37,7 @@ def add_cloud_subnets
add_collection(network, :cloud_subnets) do |builder|
builder.add_properties(:model_class => ManageIQ::Providers::Openstack::NetworkManager::CloudSubnet)

ems_network_builder_param(builder)
network_ems_default_value(builder)
end
end

Expand All @@ -62,7 +62,7 @@ def add_floating_ips
add_collection(network, :floating_ips) do |builder|
builder.add_properties(:model_class => ManageIQ::Providers::Openstack::NetworkManager::FloatingIp)

ems_network_builder_param(builder)
network_ems_default_value(builder)
end
end

Expand All @@ -71,7 +71,7 @@ def add_network_ports
builder.add_properties(:model_class => ManageIQ::Providers::Openstack::NetworkManager::NetworkPort)
builder.add_properties(:delete_method => :disconnect_port)

ems_network_builder_param(builder)
network_ems_default_value(builder)
end
end

Expand All @@ -80,7 +80,7 @@ def add_network_routers
add_collection(network, :network_routers) do |builder|
builder.add_properties(:model_class => ManageIQ::Providers::Openstack::NetworkManager::NetworkRouter)

ems_network_builder_param(builder)
network_ems_default_value(builder)
end
end

Expand All @@ -89,7 +89,7 @@ def add_security_groups
add_collection(network, :security_groups) do |builder|
builder.add_properties(:model_class => ManageIQ::Providers::Openstack::NetworkManager::SecurityGroup)

ems_network_builder_param(builder)
network_ems_default_value(builder)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ def initialize_storage_inventory_collections
add_collection(cloud, name) do |builder|
if targeted?
builder.add_properties(:parent => manager.cinder_manager)
builder.add_builder_params(:ext_management_system => manager.cinder_manager)
builder.add_default_values(:ems_id => manager.cinder_manager.try(:id))
else
builder.add_builder_params(:ext_management_system => manager)
builder.add_default_values(:ems_id => manager.id)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ module ManageIQ::Providers::Openstack::Inventory::Persister::Definitions::Utils
# Shortcut for better code readability
def add_collection_with_ems_param(builder_class, collection_name, extra_properties = {}, settings = {})
add_collection(builder_class, collection_name, extra_properties, settings) do |builder|
ems_builder_param(builder)
ems_default_value(builder)

yield builder if block_given?
end
end

def ems_builder_param(builder)
builder.add_builder_params(:ext_management_system => manager)
def ems_default_value(builder)
builder.add_default_values(:ems_id => manager.id)
end

def ems_network_builder_param(builder)
def network_ems_default_value(builder)
ems = targeted? ? manager.network_manager : manager
builder.add_builder_params(:ext_management_system => ems)
builder.add_default_values(:ems_id => ems.id)
end
end