Skip to content

Commit

Permalink
Move duplicated collector code into helper module
Browse files Browse the repository at this point in the history
  • Loading branch information
mansam committed Aug 17, 2017
1 parent 2087eec commit 670c192
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class ManageIQ::Providers::Openstack::Inventory::Collector::CloudManager < ManageIQ::Providers::Openstack::Inventory::Collector
include ManageIQ::Providers::Openstack::Inventory::Collector::HelperMethods

def availability_zones_compute
@availability_zones_compute ||= safe_list { compute_service.availability_zones.summary }
end
Expand Down Expand Up @@ -43,16 +45,6 @@ def private_flavor(flavor_id)
end
end

def tenant_ids_with_flavor_access(flavor_id)
unparsed_tenants = safe_get { connection.list_tenants_with_flavor_access(flavor_id) }
flavor_access = unparsed_tenants.try(:data).try(:[], :body).try(:[], "flavor_access") || []
flavor_access.map! { |t| t['tenant_id'] }
rescue
[]
else
flavor_access
end

def flavors_by_id
@flavors_by_id ||= Hash[flavors.collect { |f| [f.id, f] }]
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module ManageIQ::Providers::Openstack::Inventory::Collector::HelperMethods
def orchestration_stack_by_resource_id(resource_id)
@resources ||= {}
if @resources.empty?
orchestration_stacks.each do |stack|
resources = orchestration_resources(stack)
resources.each do |r|
@resources[r.physical_resource_id] = r
end
end
end
@resources[resource_id]
end

def tenant_ids_with_flavor_access(flavor_id)
unparsed_tenants = safe_get { connection.list_tenants_with_flavor_access(flavor_id) }
flavor_access = unparsed_tenants.try(:data).try(:[], :body).try(:[], "flavor_access") || []
flavor_access.map! { |t| t['tenant_id'] }
rescue
[]
else
flavor_access
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class ManageIQ::Providers::Openstack::Inventory::Collector::NetworkManager < ManageIQ::Providers::Openstack::Inventory::Collector
include ManageIQ::Providers::Openstack::Inventory::Collector::HelperMethods

def floating_ips
return @floating_ips if @floating_ips.any?
@floating_ips = network_service.handled_list(:floating_ips, {}, ::Settings.ems.ems_openstack.refresh.is_admin)
Expand Down Expand Up @@ -49,17 +51,4 @@ def orchestration_resources(stack)
@os_handle ||= manager.openstack_handle
safe_list { stack.resources }
end

def orchestration_stack_by_resource_id(resource_id)
@resources ||= {}
if @resources.empty?
orchestration_stacks.each do |stack|
resources = orchestration_resources(stack)
resources.each do |r|
@resources[r.physical_resource_id] = r
end
end
end
@resources[resource_id]
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class ManageIQ::Providers::Openstack::Inventory::Collector::TargetCollection < ManageIQ::Providers::Openstack::Inventory::Collector
include ManageIQ::Providers::Openstack::Inventory::Collector::HelperMethods

def initialize(_manager, _target)
super
parse_targets!
Expand Down Expand Up @@ -94,16 +96,6 @@ def tenants
end.compact
end

def tenant_ids_with_flavor_access(flavor_id)
unparsed_tenants = safe_get { connection.list_tenants_with_flavor_access(flavor_id) }
flavor_access = unparsed_tenants.try(:data).try(:[], :body).try(:[], "flavor_access") || []
flavor_access.map! { |t| t['tenant_id'] }
rescue
[]
else
flavor_access
end

def key_pairs
return [] if references(:key_pairs).blank?
@key_pairs = references(:key_pairs).collect do |key_pair_id|
Expand Down Expand Up @@ -137,19 +129,6 @@ def orchestration_resources(stack)
safe_list { stack.resources }
end

def orchestration_stack_by_resource_id(resource_id)
@resources ||= {}
if @resources.empty?
orchestration_stacks.each do |stack|
resources = orchestration_resources(stack)
resources.each do |r|
@resources[r.physical_resource_id] = r
end
end
end
@resources[resource_id]
end

private

def parse_targets!
Expand Down

0 comments on commit 670c192

Please sign in to comment.