Skip to content

Commit

Permalink
Better persister's IC definitions
Browse files Browse the repository at this point in the history
Optimizations
  • Loading branch information
slemrmartin committed Jun 21, 2018
1 parent 5cf7031 commit 46da4f3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 381 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
module ManageIQ::Providers::Azure::Inventory::Persister::Definitions::CloudCollections
extend ActiveSupport::Concern

# TODO: almost same as amazon
def initialize_cloud_inventory_collections
%i(vms
%i(availability_zones
disks
flavors
hardwares
operating_systems
networks
disks
availability_zones).each do |name|
operating_systems
vm_and_template_labels
vm_and_template_taggings
vms).each do |name|

add_collection(cloud, name)
end

add_miq_templates

add_flavors

add_key_pairs

add_resource_groups # not in amazon

add_vm_and_template_labels

add_vm_and_template_taggings
add_resource_groups

add_orchestration_stacks

Expand All @@ -38,111 +34,43 @@ def initialize_cloud_inventory_collections
end

# Custom processing of Ancestry
add_vm_and_miq_template_ancestry
%i(vm_and_miq_template_ancestry
orchestration_stack_ancestry).each do |name|

add_orchestration_stack_ancestry
add_collection(cloud, name)
end
end

# ------ IC provider specific definitions -------------------------

# TODO: Derive model class in core
# Different from amazon
def add_miq_templates
add_collection(cloud, :miq_templates) do |builder|
builder.add_properties(:model_class => ::ManageIQ::Providers::Azure::CloudManager::Template)

builder.add_builder_params(
builder.add_default_values(
:ems_id => manager.id,
:vendor => builder.vendor
)
end
end

# Missing in amazon
def add_resource_groups
add_collection(cloud, :resource_groups, {}, {:auto_inventory_attributes => false}) do |builder|
builder.add_properties(:model_class => ::ManageIQ::Providers::Azure::ResourceGroup)

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

# Targeted doesn't have special strategy like amazon
def add_flavors
add_collection(cloud, :flavors)
end

# TODO: almost same as amazon? (after targeted) - different model_class!
# TODO: Derive model class in core
def add_key_pairs(extra_properties = {})
add_collection(cloud, :key_pairs, extra_properties) do |builder|
builder.add_properties(:model_class => ::ManageIQ::Providers::Azure::CloudManager::AuthKeyPair)
builder.add_properties(:manager_uuids => name_references(:key_pairs)) if targeted?
end
end

# TODO: mslemr - parent model_class used anywhere? If not, should be deleted
def add_orchestration_stacks
add_collection(cloud, :orchestration_stacks) do |builder|
builder.add_properties(
:model_class => ::ManageIQ::Providers::Azure::CloudManager::OrchestrationStack,
:saver_strategy => 'default' # TODO(lsmola) can't batch unless we do smart batching
)
end
end

# TODO: mslemr - same as amazon!
def add_vm_and_template_labels
add_collection(cloud, :vm_and_template_labels) do |builder|
builder.add_targeted_arel(
lambda do |inventory_collection|
manager_uuids = inventory_collection.parent_inventory_collections.collect(&:manager_uuids).map(&:to_a).flatten
inventory_collection.parent.vm_and_template_labels.where(
'vms' => {:ems_ref => manager_uuids}
)
end
)
end
end

# TODO: mslemr - same as amazon!
def add_vm_and_template_taggings
add_collection(cloud, :vm_and_template_taggings) do |builder|
builder.add_properties(
:model_class => Tagging,
:manager_ref => %i(taggable tag),
:parent_inventory_collections => %i(vms miq_templates)
)

builder.add_targeted_arel(
lambda do |inventory_collection|
manager_uuids = inventory_collection.parent_inventory_collections.collect(&:manager_uuids).map(&:to_a).flatten
ems = inventory_collection.parent
ems.vm_and_template_taggings.where(
'taggable_id' => ems.vms_and_templates.where(:ems_ref => manager_uuids)
)
end
)
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 - same as amazon!
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]],
:orchestration_stacks_resources => [collections[:orchestration_stacks_resources]]
)
builder.add_properties(:saver_strategy => 'default') # TODO(lsmola) can't batch unless we do smart batching
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,35 @@ module ManageIQ::Providers::Azure::Inventory::Persister::Definitions::NetworkCol

def initialize_network_inventory_collections
%i(cloud_networks
security_groups
cloud_subnet_network_ports
floating_ips
network_ports
network_routers
load_balancers
load_balancer_pools
load_balancer_pool_members
load_balancer_pool_member_pools
load_balancer_listeners
load_balancer_listener_pools
load_balancer_health_checks
load_balancer_health_check_members).each do |name|
load_balancer_health_check_members
security_groups).each do |name|

add_collection(network, name)
end

add_cloud_subnet_network_ports

add_cloud_subnets # different in amazon
add_cloud_subnets

add_firewall_rules

add_floating_ips

add_network_ports

# Not in Amazon
%i(network_routers).each do |name|
add_collection(network, name)
end
end

# ------ IC provider specific definitions -------------------------

def add_cloud_subnet_network_ports
add_collection(network, :cloud_subnet_network_ports)
end

def add_network_ports
add_collection(network, :network_ports)
end

def add_floating_ips
add_collection(network, :floating_ips)
end

# TODO: Different from amazon
# TODO: Builder params
def add_cloud_subnets
add_collection(network, :cloud_subnets) do |builder|
add_collection(network, :cloud_subnets, :builder_params => nil) do |builder|
builder.add_properties(:parent_inventory_collections => %i(cloud_networks))
builder.add_properties(:builder_params => nil)

builder.add_targeted_arel(
lambda do |inventory_collection|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,5 @@ def initialize_cloud_inventory_collections
)
end
end

# TODO: Not in amazon
# add_orchestration_stacks(
# :parent => manager.parent_manager,
# :strategy => :local_db_cache_all
# )
end
end

This file was deleted.

Loading

0 comments on commit 46da4f3

Please sign in to comment.