Skip to content

Commit

Permalink
Merge pull request ManageIQ#12 from xlab-si/parser-sets-resource-group
Browse files Browse the repository at this point in the history
NetworkManager parser sets resource group for networks, network ports and security groups
  • Loading branch information
agrare authored Oct 2, 2019
2 parents d7e4503 + 95fa89c commit aaad798
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ def parse
def cloud_networks
collector.networks.each do |network|
cloud_network = persister.cloud_networks.build(
:name => network.name,
:ems_ref => network.id.downcase
:name => network.name,
:ems_ref => network.id.downcase,
:resource_group => persister.resource_groups.lazy_find(collector.resource_group_id(network.id))
)

cloud_subnets(network, cloud_network) if network.subnets
Expand All @@ -37,6 +38,7 @@ def network_ports
persister.network_ports.build(
:name => port.name,
:ems_ref => port.id.downcase,
:resource_group => persister.resource_groups.lazy_find(collector.resource_group_id(port.id)),
:mac_address => port.mac_address,
:device => persister.vms.lazy_find(port.virtual_machine&.id&.downcase),
:security_groups => build_security_groups(port)
Expand All @@ -59,8 +61,9 @@ def build_security_groups(entity)
def security_groups
collector.security_groups.each do |security_group|
persister.security_groups.build(
:name => security_group.name,
:ems_ref => security_group.id.downcase
:name => security_group.name,
:ems_ref => security_group.id.downcase,
:resource_group => persister.resource_groups.lazy_find(collector.resource_group_id(security_group.id))
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ def initialize_network_inventory_collections
add_collection(network, name)
end

add_collection(cloud, :vms) do |builder|
builder.add_properties(
:parent => manager.parent_manager,
:strategy => :local_db_find_references
)
add_related_cloud_collections
end

def add_related_cloud_collections
%i[resource_groups
vms].each do |name|
add_collection(cloud, name) do |builder|
builder.add_properties(
:parent => manager.parent_manager,
:strategy => :local_db_find_references
)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def assert_specific_orchestration_stack
def assert_specific_network
expect(network).not_to be_nil
expect(ems_ref_suffix(network.ems_ref)).to match(%r{^/providers/microsoft.network/virtualnetworks/[^/]+$})
expect(network.resource_group).to eq(resource_group)

expect(network.cloud_subnets).not_to be_nil
expect(network.cloud_subnets.size).to eq(1)
Expand All @@ -173,9 +174,11 @@ def assert_specific_subnet
def assert_specific_network_port
expect(network_port).not_to be_nil
expect(ems_ref_suffix(network_port.ems_ref)).to match(%r{^/providers/microsoft.network/networkinterfaces/[^/]+$})
expect(network_port.mac_address).to eq('001DD8B70047')

expect(network_port.device).to eq(vm)
expect(network_port).to have_attributes(
:resource_group => resource_group,
:mac_address => '001DD8B70047',
:device => vm
)

assert_security_groups_binding(network_port)
end
Expand All @@ -189,5 +192,6 @@ def assert_security_groups_binding(entity)
def assert_security_group
expect(security_group).not_to be_nil
expect(ems_ref_suffix(security_group.ems_ref)).to match(%r{^/providers/microsoft.network/networksecuritygroups/[^/]+$})
expect(security_group.resource_group).to eq(resource_group)
end
end

0 comments on commit aaad798

Please sign in to comment.