Skip to content

Commit

Permalink
Merge pull request #15142 from Ladas/leverage_builder_params_to_assin…
Browse files Browse the repository at this point in the history
…g_ems_id_to_inventory_objects

Leverage builder_params for assigning ems_id to each relevant object
  • Loading branch information
agrare authored May 23, 2017
2 parents f0094c9 + b179f0f commit 568ff20
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ def vms(extra_attributes = {})
:model_class => ::ManageIQ::Providers::CloudManager::Vm,
:association => :vms,
:delete_method => :disconnect_inv,
:attributes_blacklist => [:genealogy_parent]
:attributes_blacklist => [:genealogy_parent],
:unique_index_columns => [:ems_id, :ems_ref],
:builder_params => {
:ems_id => ->(persister) { persister.manager.id },
:name => "unknown",
:location => "unknown",
}
}

attributes.merge!(extra_attributes)
Expand All @@ -16,35 +22,52 @@ def miq_templates(extra_attributes = {})
:model_class => ::ManageIQ::Providers::CloudManager::Template,
:association => :miq_templates,
:delete_method => :disconnect_inv,
:attributes_blacklist => [:genealogy_parent]
:attributes_blacklist => [:genealogy_parent],
:unique_index_columns => [:ems_id, :ems_ref],
:builder_params => {
:ems_id => ->(persister) { persister.manager.id },
:name => "unknown",
:location => "unknown",
:template => true
}
}

attributes.merge!(extra_attributes)
end

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

attributes.merge!(extra_attributes)
end

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

attributes.merge!(extra_attributes)
end

def key_pairs(extra_attributes = {})
attributes = {
:model_class => ::ManageIQ::Providers::CloudManager::AuthKeyPair,
:manager_ref => [:name],
:association => :key_pairs
:model_class => ::ManageIQ::Providers::CloudManager::AuthKeyPair,
:manager_ref => [:name],
:association => :key_pairs,
:builder_params => {
:resource_id => ->(persister) { persister.manager.id },
:resource_type => ->(persister) { persister.manager.class.base_class },
}
}

attributes.merge!(extra_attributes)
Expand Down Expand Up @@ -108,7 +131,10 @@ def orchestration_stacks(extra_attributes = {})
attributes = {
:model_class => ::ManageIQ::Providers::CloudManager::OrchestrationStack,
:association => :orchestration_stacks,
:attributes_blacklist => [:parent]
:attributes_blacklist => [:parent],
:builder_params => {
:ems_id => ->(persister) { persister.manager.id },
}
}

attributes.merge!(extra_attributes)
Expand All @@ -126,7 +152,7 @@ def orchestration_stacks_resources(extra_attributes = {})
def orchestration_stacks_outputs(extra_attributes = {})
attributes = {
:model_class => ::OrchestrationStackOutput,
:association => :orchestration_stacks_outputs,
:association => :orchestration_stacks_outputs
}

attributes.merge!(extra_attributes)
Expand All @@ -135,7 +161,7 @@ def orchestration_stacks_outputs(extra_attributes = {})
def orchestration_stacks_parameters(extra_attributes = {})
attributes = {
:model_class => ::OrchestrationStackParameter,
:association => :orchestration_stacks_parameters,
:association => :orchestration_stacks_parameters
}

attributes.merge!(extra_attributes)
Expand Down Expand Up @@ -168,7 +194,7 @@ def orchestration_stack_ancestry(extra_attributes = {})
return if stacks_inventory_collection.blank?

stacks_parents = stacks_inventory_collection.data.each_with_object({}) do |x, obj|
parent_id = x.data[:parent].load.try(:id)
parent_id = x.data[:parent].try(:load).try(:id)
obj[x.id] = parent_id if parent_id
end

Expand All @@ -195,7 +221,7 @@ def orchestration_stack_ancestry(extra_attributes = {})

def vm_and_miq_template_ancestry(extra_attributes = {})
vm_and_miq_template_ancestry_save_block = lambda do |_ems, inventory_collection|
vms_inventory_collection = inventory_collection.dependency_attributes[:vms].try(:first)
vms_inventory_collection = inventory_collection.dependency_attributes[:vms].try(:first)
miq_templates_inventory_collection = inventory_collection.dependency_attributes[:miq_templates].try(:first)

return if vms_inventory_collection.blank? || miq_templates_inventory_collection.blank?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,67 @@ def cloud_subnet_network_ports(extra_attributes = {})
attributes = {
:model_class => ::CloudSubnetNetworkPort,
:manager_ref => [:address, :cloud_subnet, :network_port],
:association => :cloud_subnet_network_ports,
:association => :cloud_subnet_network_ports
}

attributes.merge!(extra_attributes)
end

def network_ports(extra_attributes = {})
attributes = {
:model_class => ::NetworkPort,
:association => :network_ports,
:model_class => ::NetworkPort,
:association => :network_ports,
:builder_params => {
:ems_id => ->(persister) { persister.manager.try(:network_manager).try(:id) || persister.manager.id },
}
}

attributes.merge!(extra_attributes)
end

def floating_ips(extra_attributes = {})
attributes = {
:model_class => ::FloatingIp,
:association => :floating_ips,
:model_class => ::FloatingIp,
:association => :floating_ips,
:builder_params => {
:ems_id => ->(persister) { persister.manager.try(:network_manager).try(:id) || persister.manager.id },
}
}

attributes.merge!(extra_attributes)
end

def cloud_subnets(extra_attributes = {})
attributes = {
:model_class => ::CloudSubnet,
:association => :cloud_subnets,
:model_class => ::CloudSubnet,
:association => :cloud_subnets,
:builder_params => {
:ems_id => ->(persister) { persister.manager.try(:network_manager).try(:id) || persister.manager.id },
}
}

attributes.merge!(extra_attributes)
end

def cloud_networks(extra_attributes = {})
attributes = {
:model_class => ::CloudNetwork,
:association => :cloud_networks,
:model_class => ::CloudNetwork,
:association => :cloud_networks,
:builder_params => {
:ems_id => ->(persister) { persister.manager.try(:network_manager).try(:id) || persister.manager.id },
}
}

attributes.merge!(extra_attributes)
end

def security_groups(extra_attributes = {})
attributes = {
:model_class => ::SecurityGroup,
:association => :security_groups,
:model_class => ::SecurityGroup,
:association => :security_groups,
:builder_params => {
:ems_id => ->(persister) { persister.manager.try(:network_manager).try(:id) || persister.manager.id },
}
}

attributes.merge!(extra_attributes)
Expand All @@ -59,34 +74,43 @@ def firewall_rules(extra_attributes = {})
attributes = {
:model_class => ::FirewallRule,
:manager_ref => [:resource, :source_security_group, :direction, :host_protocol, :port, :end_port, :source_ip_range],
:association => :firewall_rules,
:association => :firewall_rules
}

attributes.merge!(extra_attributes)
end

def load_balancers(extra_attributes = {})
attributes = {
:model_class => ::LoadBalancer,
:association => :load_balancers,
:model_class => ::LoadBalancer,
:association => :load_balancers,
:builder_params => {
:ems_id => ->(persister) { persister.manager.try(:network_manager).try(:id) || persister.manager.id },
}
}

attributes.merge!(extra_attributes)
end

def load_balancer_pools(extra_attributes = {})
attributes = {
:model_class => ::LoadBalancerPool,
:association => :load_balancer_pools,
:model_class => ::LoadBalancerPool,
:association => :load_balancer_pools,
:builder_params => {
:ems_id => ->(persister) { persister.manager.try(:network_manager).try(:id) || persister.manager.id },
}
}

attributes.merge!(extra_attributes)
end

def load_balancer_pool_members(extra_attributes = {})
attributes = {
:model_class => ::LoadBalancerPoolMember,
:association => :load_balancer_pool_members,
:model_class => ::LoadBalancerPoolMember,
:association => :load_balancer_pool_members,
:builder_params => {
:ems_id => ->(persister) { persister.manager.try(:network_manager).try(:id) || persister.manager.id },
}
}

attributes.merge!(extra_attributes)
Expand All @@ -96,16 +120,19 @@ def load_balancer_pool_member_pools(extra_attributes = {})
attributes = {
:model_class => ::LoadBalancerPoolMemberPool,
:manager_ref => [:load_balancer_pool, :load_balancer_pool_member],
:association => :load_balancer_pool_member_pools,
:association => :load_balancer_pool_member_pools
}

attributes.merge!(extra_attributes)
end

def load_balancer_listeners(extra_attributes = {})
attributes = {
:model_class => ::LoadBalancerListener,
:association => :load_balancer_listeners,
:model_class => ::LoadBalancerListener,
:association => :load_balancer_listeners,
:builder_params => {
:ems_id => ->(persister) { persister.manager.try(:network_manager).try(:id) || persister.manager.id },
}
}

attributes.merge!(extra_attributes)
Expand All @@ -115,16 +142,19 @@ def load_balancer_listener_pools(extra_attributes = {})
attributes = {
:model_class => ::LoadBalancerListenerPool,
:manager_ref => [:load_balancer_listener, :load_balancer_pool],
:association => :load_balancer_listener_pools,
:association => :load_balancer_listener_pools
}

attributes.merge!(extra_attributes)
end

def load_balancer_health_checks(extra_attributes = {})
attributes = {
:model_class => ::LoadBalancerHealthCheck,
:association => :load_balancer_health_checks,
:model_class => ::LoadBalancerHealthCheck,
:association => :load_balancer_health_checks,
:builder_params => {
:ems_id => ->(persister) { persister.manager.try(:network_manager).try(:id) || persister.manager.id },
}
}

attributes.merge!(extra_attributes)
Expand All @@ -134,7 +164,7 @@ def load_balancer_health_check_members(extra_attributes = {})
attributes = {
:model_class => ::LoadBalancerHealthCheckMember,
:manager_ref => [:load_balancer_health_check, :load_balancer_pool_member],
:association => :load_balancer_health_check_members,
:association => :load_balancer_health_check_members
}

attributes.merge!(extra_attributes)
Expand Down

0 comments on commit 568ff20

Please sign in to comment.