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

libnetplan: expose the routes list in the netdef #397

Merged
merged 1 commit into from Aug 17, 2023

Conversation

daniloegea
Copy link
Collaborator

@daniloegea daniloegea commented Aug 16, 2023

Description

I created the NetplanRoute class as a dataclass but I'm not convinced it's a good idea... I feel like it's better to assign each property separately without an __init__ method...

Checklist

  • Runs make check successfully.
  • Retains 100% code coverage (make check-coverage).
  • New/changed keys in YAML format are documented.
  • (Optional) Adds example YAML for new feature.
  • (Optional) Closes an open bug in Launchpad.

@daniloegea daniloegea requested a review from slyon August 16, 2023 17:11
Copy link
Collaborator

@slyon slyon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, lgtm. I left one non-blocking inline comment.

What's your reasoning against the @dataclass, I think it's looking good.

from: 192.168.0.0/24''')

netdef = next(netplan.netdef.NetDefinitionIterator(state, "ethernets"))
routes = [route for route in netdef.routes]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
routes = [route for route in netdef.routes]
routes = list(netdef.routes)

suggestion (non-blocking): I guess this way it would be easier to read and according to https://www.curs-ml.com/post/fastest-way-to-convert-an-iterator-to-a-list it would even be faster. But OTOH this is a test case, so we can keep it as-is if you want to. The same applies to ip in netdef.routes (and others) above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, yeah I think at some point I was calling str() on route and ended up leaving the list comprehension there.

@daniloegea
Copy link
Collaborator Author

So, I think the only thing I didn't like is passing all those objects of the same type to the constructor. One can easily get confused and put them in the wrong place. It's harder to do that using the pattern route.to = to, route.via = via...

But I think the dataclass will be beneficial in other ways, such as comparing the objects for example... let's see I guess

@slyon
Copy link
Collaborator

slyon commented Aug 17, 2023

But I think the dataclass will be beneficial in other ways, such as comparing the objects for example... let's see I guess

We could consider calling it class _NetplanRoute for now, so it's easier for us to change the structure in the future. We're our only consumer of that class currently anyway.

@daniloegea daniloegea merged commit f96a184 into canonical:main Aug 17, 2023
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants