Skip to content

Commit

Permalink
Inventory FloatingIPs
Browse files Browse the repository at this point in the history
With this commit we inventory both FloatingIp and CloudNetwork where
the FloatingIp originates from. FloatingIps are directly related to
NetworkRouter while NetworkRouter has no direct relation to CloudNetwork
(but is connected via FloatingIps).

RFE BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1574922

Signed-off-by: Miha Pleško <miha.plesko@xlab.si>
  • Loading branch information
miha-plesko committed Jun 15, 2018
1 parent e126aed commit 963e139
Show file tree
Hide file tree
Showing 12 changed files with 313 additions and 7 deletions.
15 changes: 9 additions & 6 deletions app/models/manageiq/providers/nuage/inventory/collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ def initialize(_manager, _target)
end

def initialize_inventory_sources
@cloud_tenants = {}
@cloud_subnets = []
@l2_cloud_subnets = []
@security_groups = []
@zones = {}
@network_routers = {}
@cloud_tenants = {}
@cloud_subnets = []
@l2_cloud_subnets = []
@security_groups = []
@floating_ips = []
@zones = {}
@network_routers = {}
@shared_resources = []
@cloud_networks_floating = nil
end

def vsd_client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ def network_routers
_network_routers.values
end

def cloud_networks_floating
@cloud_networks_floating ||= _shared_resources.select { |res| res['type'] == 'FLOATING' }
end

def cloud_subnets
return @cloud_subnets if @cloud_subnets.any?
@cloud_subnets = vsd_client.get_subnets
Expand All @@ -22,6 +26,11 @@ def security_groups
@security_groups = vsd_client.get_policy_groups
end

def floating_ips
return @floating_ips if @floating_ips.any?
@floating_ips = vsd_client.get_floating_ips
end

def zones
_zones.values
end
Expand Down Expand Up @@ -59,6 +68,11 @@ def _network_routers
@network_routers = hash_by_id(vsd_client.get_domains)
end

def _shared_resources
return @shared_resources if @shared_resources.any?
@shared_resources = vsd_client.get_sharednetworkresources
end

def hash_by_id(list)
list.map { |el| [el['ID'], el] }.to_h
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def initialize(_manager, _target)
target.manager_refs_by_association_reset
end

def cloud_networks_floating
[] # TODO(miha-plesko): targeted refresh
end

def cloud_subnets
return [] if references(:cloud_subnets).blank?
references(:cloud_subnets).collect { |ems_ref| cloud_subnet(ems_ref) }
Expand Down Expand Up @@ -37,6 +41,10 @@ def network_routers
@network_routers_map.values.compact
end

def floating_ips
[] # TODO(miha-plesko): implement targeted refresh for floating ips
end

def cloud_subnet(ems_ref)
return @cloud_subnets_map[ems_ref] if @cloud_subnets_map.key?(ems_ref)
@cloud_subnets_map[ems_ref] = safe_call { vsd_client.get_subnet(ems_ref) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
class ManageIQ::Providers::Nuage::Inventory::Parser::NetworkManager < ManageIQ::Providers::Nuage::Inventory::Parser
def parse
cloud_tenants
cloud_networks_floating
network_routers
cloud_subnets
l2_cloud_subnets
security_groups
floating_ips
end

private
Expand All @@ -18,6 +20,16 @@ def cloud_tenants
end
end

def cloud_networks_floating
collector.cloud_networks_floating.each do |network|
persister.cloud_networks.find_or_build(network['ID']).assign_attributes(
:type => collector.manager.class.floating_cloud_network_type,
:name => network['name'],
:cidr => to_cidr(network['address'], network['netmask'])
)
end
end

def network_routers
collector.network_routers.each do |router|
persister.network_routers.find_or_build(router['ID']).assign_attributes(
Expand Down Expand Up @@ -65,6 +77,18 @@ def security_groups
end
end

def floating_ips
collector.floating_ips.each do |ip|
persister.floating_ips.find_or_build(ip['ID']).assign_attributes(
:address => ip['address'],
:cloud_network => persister.cloud_networks.lazy_find(ip['associatedSharedNetworkResourceID']),
# TODO(miha-plesko): uncomment when https://github.com/ManageIQ/manageiq-schema/pull/217 is merged
# :network_router => persister.network_routers.lazy_find(ip['parentID']),
:cloud_tenant => persister.network_routers.lazy_find(ip['parentID'], :key => :cloud_tenant)
)
end
end

def map_extra_attributes(zone_id)
if (zone = collector.zone(zone_id))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ def initialize_network_inventory_collections
%i(cloud_tenants
cloud_subnets
security_groups
cloud_networks
floating_ips
network_routers).each do |name|

add_collection(network, name) do |builder|
Expand Down
6 changes: 6 additions & 0 deletions app/models/manageiq/providers/nuage/network_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ class ManageIQ::Providers::Nuage::NetworkManager < ManageIQ::Providers::NetworkM
require_nested :VsdClient
require_nested :CloudTenant
require_nested :NetworkRouter
require_nested :CloudNetwork
require_nested :CloudSubnet
require_nested :CloudSubnetL3
require_nested :CloudSubnetL2
require_nested :SecurityGroup
require_nested :FloatingIp

supports :ems_network_new

Expand Down Expand Up @@ -51,6 +53,10 @@ def self.l3_cloud_subnet_type
'ManageIQ::Providers::Nuage::NetworkManager::CloudSubnetL3'
end

def self.floating_cloud_network_type
'ManageIQ::Providers::Nuage::NetworkManager::CloudNetwork::Floating'
end

def name
self[:name]
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ManageIQ::Providers::Nuage::NetworkManager::CloudNetwork < ::CloudNetwork
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ManageIQ::Providers::Nuage::NetworkManager::CloudNetwork::Floating < ManageIQ::Providers::Nuage::NetworkManager::CloudNetwork
end
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
class ManageIQ::Providers::Nuage::NetworkManager::NetworkRouter < ::NetworkRouter
has_many :floating_ips, :dependent => :destroy
end
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ def get_l2_domains
get_list('l2domains')
end

def get_floating_ips
get_list('floatingips')
end

def get_sharednetworkresources
get_list('sharednetworkresources')
end

private

# TODO(miha-plesko): Is this filter really supposed to be used here in client? Looks like debugging leftover,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
let(:l2_subnet_ref1) { "3b733a41-774d-4aaa-8e64-588d5533a5c0" }
let(:l2_subnet_ref2) { "8efc78b0-df2a-4c6f-964b-463a9d106bed" }
let(:router_ref) { "75ad8ee8-726c-4950-94bc-6a5aab64631d" }
let(:floating_ip_ref) { "3a00891b-29ba-4f60-8f35-033d84aa1083" }
let(:network_ref) { "17b305a7-eec9-4492-acb9-20a1d63a8ba1" }

ALL_REFRESH_SETTINGS.each do |settings|
context "with settings #{settings}" do
Expand Down Expand Up @@ -86,6 +88,8 @@
assert_security_groups
assert_cloud_subnets
assert_l2_cloud_subnets
assert_floating_ips
assert_cloud_networks
end
end
end
Expand All @@ -95,9 +99,10 @@
def assert_table_counts
expect(ExtManagementSystem.count).to eq(1)
expect(CloudTenant.count).to eq(2)
expect(CloudNetwork.count).to eq(1)
expect(SecurityGroup.count).to eq(1)
expect(CloudSubnet.count).to eq(6)
expect(FloatingIp.count).to eq(0)
expect(FloatingIp.count).to eq(3)
expect(NetworkPort.count).to eq(0)
expect(NetworkRouter.count).to eq(1)
end
Expand Down Expand Up @@ -244,4 +249,25 @@ def assert_l2_cloud_subnets
:network_router_id => nil
)
end

def assert_floating_ips
ip = FloatingIp.find_by(:ems_ref => floating_ip_ref)
expect(ip).to have_attributes(
:address => '10.85.92.109',
:cloud_tenant_id => CloudTenant.find_by(:ems_ref => tenant_ref2).id,
:type => 'ManageIQ::Providers::Nuage::NetworkManager::FloatingIp'
)
# TODO(miha-plesko): uncomment when https://github.com/ManageIQ/manageiq-schema/pull/217 is merged
# expect(NetworkRouter.find_by(:ems_ref => router_ref).floating_ips).to include(ip)
end

def assert_cloud_networks
net = CloudNetwork.find_by(:ems_ref => network_ref)
expect(net).to have_attributes(
:name => 'Subnet 0',
:cidr => '10.85.92.0/24',
:type => 'ManageIQ::Providers::Nuage::NetworkManager::CloudNetwork::Floating'
)
expect(net.floating_ips).to include(FloatingIp.find_by(:ems_ref => floating_ip_ref))
end
end
Loading

0 comments on commit 963e139

Please sign in to comment.