-
Notifications
You must be signed in to change notification settings - Fork 20
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
Extend NetworkManager inventory #9
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't believe the amazing quality level of your first PR on MIQ @mancabizjak , it totally feels like you're developing MIQ for months already and not just 5 days. Kudos 👍 Few small comments anyway
) | ||
if network.subnets | ||
cloud_subnets(network) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could capture the just-built network and pass it to the cloud_subnets
function so that we don't lazy_find it over and over again:
network_obj = persister.cloud_networks.build(...)
cloud_subnets(network_obj, network.subnets) if network.subnets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, missed that. Thanks, done 👍
:ems_ref => port.id.downcase, | ||
:mac_address => port.mac_address, | ||
:device => port.virtual_machine ? persister.vms.lazy_find(port.virtual_machine.id.downcase) : nil, | ||
:security_groups => build_security_groups(port) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we need utility function here because we're just filling in a simple relation. I'd go with a simple IF statement at the top instead:
security_groups = []
if (security_group_id = port.network_security_group&.id&.downcase)
security_groups = [persister.security_groups.lazy_find(security_group_id)]
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is exactly how I used to have it initially, when I hooked security_groups
to network ports only. But then I needed the same logic for subnets and I thought it made sense to extract it to a helper function (note that this is also mirrored by the assert_security_groups_binding
which is used in both assert_specific_subnet
and assert_specific_network_port
).
I did modify the helper itself to make use of &.
when accessing entity's security group though 👍
:name => port.name, | ||
:ems_ref => port.id.downcase, | ||
:mac_address => port.mac_address, | ||
:device => port.virtual_machine ? persister.vms.lazy_find(port.virtual_machine.id.downcase) : nil, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:device => port.virtual_machine ? persister.vms.lazy_find(port.virtual_machine.id.downcase) : nil, | |
:device => persister.vms.lazy_find(port.virtual_machine&.id&.downcase), |
"addressPrefix": "[variables('subnetPrefix')]", | ||
"networkSecurityGroup": { | ||
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome 👍
expect(subnet).not_to be_nil | ||
expect(ems_ref_suffix(subnet.ems_ref)).to match(%r{^/providers/microsoft.network/virtualnetworks/[^/]+/subnets/[^/]+$}) | ||
|
||
expect(subnet.cloud_network).not_to be_nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assertion is actually redundant because we assert the exact value in the next line anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I removed a similar redundant case from assert_specific_network_port
as well.
assert_security_groups_binding(network_port) | ||
end | ||
|
||
def assert_security_groups_binding(entity) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this DRY approach you took here 👍
persister.cloud_subnets.build( | ||
:name => subnet.name, | ||
:ems_ref => subnet.id.downcase, | ||
:cloud_network => persister.cloud_networks.lazy_find(network.id.downcase), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is called right after building the network you can save the lazy_find and pass in the persisted network object directly if you want.
Example:
persister_network = persister.cloud_networks.build()
cloud_subnets(persister_network, network.subnets) if network.subnets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah @miha-plesko beat me to it #9 (comment)
security_groups].each do |name| | ||
add_collection(network, name) | ||
|
||
add_collection(cloud, :vms) do |builder| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this inside the loop above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, fixed.
I completely agree. This is a great PR for anyone, for your first this is amazing great work. |
So far the provider's NetworkManager inventory supported security groups. With this commit we extend NetworkManager inventory with cloud networks, cloud subnets and network ports. Cloud subnets and network ports are connected to security groups, while network ports are in addition connected to VMs. Signed-off-by: Manca Bizjak <[email protected]>
bc827ac
to
2bfe503
Compare
Checked commit xlab-si@2bfe503 with ruby 2.4.6, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your reviews and encouraging words @miha-plesko @agrare! Please see the changes I made according to your comments.
) | ||
if network.subnets | ||
cloud_subnets(network) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, missed that. Thanks, done 👍
:ems_ref => port.id.downcase, | ||
:mac_address => port.mac_address, | ||
:device => port.virtual_machine ? persister.vms.lazy_find(port.virtual_machine.id.downcase) : nil, | ||
:security_groups => build_security_groups(port) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is exactly how I used to have it initially, when I hooked security_groups
to network ports only. But then I needed the same logic for subnets and I thought it made sense to extract it to a helper function (note that this is also mirrored by the assert_security_groups_binding
which is used in both assert_specific_subnet
and assert_specific_network_port
).
I did modify the helper itself to make use of &.
when accessing entity's security group though 👍
security_groups].each do |name| | ||
add_collection(network, name) | ||
|
||
add_collection(cloud, :vms) do |builder| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, fixed.
expect(subnet).not_to be_nil | ||
expect(ems_ref_suffix(subnet.ems_ref)).to match(%r{^/providers/microsoft.network/virtualnetworks/[^/]+/subnets/[^/]+$}) | ||
|
||
expect(subnet.cloud_network).not_to be_nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I removed a similar redundant case from assert_specific_network_port
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 LGTM
Extend NetworkManager inventory
So far the provider's
NetworkManager
inventory supported only security groups.With this commit we extend the
NetworkManager
inventory with cloud networks, cloud subnets and network ports. Cloud subnets and network ports are connected to security groups, while networkports are in addition connected to VMs.