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

Filter out duplicates during inventory collection #212

Merged
merged 3 commits into from
Jan 31, 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 @@ -86,11 +86,11 @@ def child_manager_fetch_path(collection, ems_ref)
end

def servers
@servers ||= @connection.handled_list(:servers, {}, openstack_admin?)
@servers ||= uniques(@connection.handled_list(:servers, {}, openstack_admin?))
end

def vnfs
@vnfs ||= @nfv_service.handled_list(:vnfs, {}, openstack_admin?)
@vnfs ||= uniques(@nfv_service.handled_list(:vnfs, {}, openstack_admin?))
end

def availability_zones_compute
Expand All @@ -108,7 +108,7 @@ def availability_zones
def volumes
# TODO: support volumes through :nova as well?
return [] unless @volume_service.name == :cinder
@volumes ||= @volume_service.handled_list(:volumes)
@volumes ||= uniques(@volume_service.handled_list(:volumes))
end

def get_availability_zones
Expand Down Expand Up @@ -137,7 +137,7 @@ def get_quotas
end

def get_key_pairs
kps = @connection.handled_list(:key_pairs, {}, openstack_admin?)
kps = uniques(@connection.handled_list(:key_pairs, {}, openstack_admin?))
process_collection(kps, :key_pairs) { |kp| parse_key_pair(kp) }
end

Expand All @@ -149,7 +149,8 @@ def get_servers
def get_vnfds
return unless @nfv_service

process_collection(@nfv_service.handled_list(:vnfds, {}, openstack_admin?), :orchestration_templates_catalog) { |vnfd| parse_vnfd(vnfd) }
unique_vnfds = uniques(@nfv_service.handled_list(:vnfds, {}, openstack_admin?))
process_collection(unique_vnfds, :orchestration_templates_catalog) { |vnfd| parse_vnfd(vnfd) }
end

def get_vnfs
Expand Down Expand Up @@ -432,7 +433,7 @@ def add_instance_disk(disks, size, location, name)
def get_cloud_services
# TODO(pblaho): repeat for each posible service (compute, identity, ...)
source = 'compute'
services = @compute_service.handled_list(:services, {}, openstack_admin?)
services = uniques(@compute_service.handled_list(:services, {}, openstack_admin?))
process_collection(services, :cloud_services) { |service| parse_cloud_service(service, source) }
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ def stack_server_resources
end

def servers
@servers ||= @connection.handled_list(:servers)
@servers ||= uniques(@connection.handled_list(:servers))
end

def hosts
@hosts ||= @baremetal_service.handled_list(:nodes)
@hosts ||= uniques(@baremetal_service.handled_list(:nodes))
end

def clouds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,23 @@ def parent_manager_find_device_connected_to_network_port(ems_ref)
end

def security_groups
@security_groups ||= @network_service.handled_list(:security_groups, {}, openstack_network_admin?)
@security_groups ||= uniques(@network_service.handled_list(:security_groups, {}, openstack_network_admin?))
end

def networks
@networks ||= @network_service.handled_list(:networks, {}, openstack_network_admin?)
@networks ||= uniques(@network_service.handled_list(:networks, {}, openstack_network_admin?))
end

def network_ports
@network_ports ||= @network_service.handled_list(:ports, {}, openstack_network_admin?)
@network_ports ||= uniques(@network_service.handled_list(:ports, {}, openstack_network_admin?))
end

def network_routers
@network_routers ||= @network_service.handled_list(:routers, {}, openstack_network_admin?)
@network_routers ||= uniques(@network_service.handled_list(:routers, {}, openstack_network_admin?))
end

def floating_ips
@floating_ips ||= @network_service.handled_list(:floating_ips, {}, openstack_network_admin?)
@floating_ips ||= uniques(@network_service.handled_list(:floating_ips, {}, openstack_network_admin?))
end

def get_networks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def get_flavors
else
@connection.handled_list(:flavors)
end
flavors = uniques(flavors)
process_collection(flavors, :flavors) { |flavor| parse_flavor(flavor) }
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ module ManageIQ::Providers
module Openstack
module RefreshParserCommon
module HelperMethods
def uniques(collection)
unique_objs = []
# caling uniq on a fog collection makes it lose
# properties from fog that it will attempt to use
# during iteration, resulting in an exeption.
# to avoid that, turn it into an array first.
unique_objs.concat(collection)
# uniquify via identity if these are fog objects
unique_objs.uniq!(&:identity) if (unique_objs.size > 0 && unique_objs[0].respond_to?(:identity))
unique_objs
end

def openstack_admin?
::Settings.ems_refresh.openstack.try(:is_admin)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def get_images
else
@image_service.handled_list(:images)
end
images = uniques(images)
process_collection(images, :vms) { |image| parse_image(image) }
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ def load_orchestration_stacks
private

def stacks
@stacks ||= detailed_stacks
@stacks ||= uniques(detailed_stacks)
end

def root_stacks
@root_stacks ||= detailed_stacks(false)
@root_stacks ||= uniques(detailed_stacks(false))
end

def detailed_stacks(show_nested = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ def list
all_objects = objects_on_page = call_list_method(@collection_type, @options, @method)

while more_pages?(objects_on_page)
last_page_count = objects_on_page.length
objects_on_page = call_list_method(@collection_type,
@options,
@method,
:marker => marker(objects_on_page),
:limit => @service.default_pagination_limit)
break if pagination_break?(all_objects, objects_on_page)
all_objects.concat(objects_on_page)
# Break after adding this page if it contained less elements than the previous page.
# having less elements should indicate that this is the last page in the set.
# This is a sanity test to prevent timing-related looping or repetition
break if objects_on_page.length < last_page_count
end

all_objects
Expand Down
Loading