-
Notifications
You must be signed in to change notification settings - Fork 908
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
feat(vmware): Convert imc network config to Networking config Version 2 #5937
feat(vmware): Convert imc network config to Networking config Version 2 #5937
Conversation
Hello! Thank you for this proposed change to cloud-init. This pull request is now marked as stale as it has not seen any activity in 14 days. If no activity occurs within the next 7 days, this pull request will automatically close. If you are waiting for code review and you are seeing this message, apologies! Please reply, tagging TheRealFalcon, and he will ensure that someone takes a look soon. (If the pull request is closed and you would like to continue working on it, please do tag TheRealFalcon to reopen it.) |
tag @TheRealFalcon to reopen it, thanks~ |
@sshedi , is this something you could review too? |
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.
Overall the changes look good. I left a few inline comments.
v4 = v4_addrs[0] | ||
# Add the ipv4 default route | ||
if nic.primary and v4.gateways: | ||
route_list.append({"to": "default", "via": v4.gateways[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.
default
works on netplan, but isn't a standard v2 option. This won't work on OSes that don't use netplan.
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.
Hi @TheRealFalcon , this converting code is to convert our customization config to network v2 config supported by cloud-init, so it will be a part of metadata but written to OS directly.
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.
@PengpengSun , sorry if I'm not understanding something, but network v2 config does not support specifying to: "default"
. You could use something like 0.0.0.0/0
, but to: "default"
will result in an error on systems that don't use netplan. Is there something I'm missing about where this gets rendered to?
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 @TheRealFalcon , I get it now. Using 0.0.0.0/0
here.
And I need to test this on real guest os other than Ubuntu, maybe RHEL.
v6_cidr = ipv6_mask_to_net_prefix(v6.netmask) | ||
# Add the ipv6 default route | ||
if nic.primary and v6.gateway: | ||
route_list.append({"to": "default", "via": v6.gateway}) |
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.
same default
comment here
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.
Using ::/0
here
nic_config_dict = {} | ||
# match | ||
match = self.gen_match(mac) | ||
if match: |
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.
match
will always be non-None so this check isn't necessary.
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 think we can condense this function.
nic_config_dict = {}
generators = [
self.gen_match(mac),
self.gen_set_name(name),
self.gen_wakeonlan(nic),
self.gen_dhcp4(nic),
self.gen_dhcp6(nic),
self.gen_addresses(nic),
self.gen_routes(nic),
self.gen_nameservers()
]
for value in generators:
if value:
nic_config_dict.update(value)
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.
Updated this part as @sshedi suggested, thanks.
|
||
def gen_dhcp4(self, nic): |
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.
Nit: for the rest of these methods, do you think it makes more sense to return {}
rather than None
? The typing becomes more consistent and doesn't require None
checks then.
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.
Yes, return {}
now.
Thanks @TheRealFalcon for the review, I'm traveling during spring festival here, probably won't be able to address any comments until Feb.5. |
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.
@PengpengSun I believe this change is opaque to user, right?
Need some changes, PTAL.
def gen_set_name(self, name): | ||
return {"set-name": name} | ||
|
||
def gen_wakeonlan(self, nic): |
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.
def gen_wakeonlan(self, nic):
return {"wakeonlan": nic.onboot}
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.
Updated, thanks.
|
||
return route_list | ||
dhcp4.update({"dhcp4": False}) | ||
if dhcp4: |
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.
If you are okay with returning {}
instead of None
, you can just do return dhcp4
here
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.
Yes, just return dhcp4
now.
nic_config_dict = {} | ||
# match | ||
match = self.gen_match(mac) | ||
if match: |
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 think we can condense this function.
nic_config_dict = {}
generators = [
self.gen_match(mac),
self.gen_set_name(name),
self.gen_wakeonlan(nic),
self.gen_dhcp4(nic),
self.gen_dhcp6(nic),
self.gen_addresses(nic),
self.gen_routes(nic),
self.gen_nameservers()
]
for value in generators:
if value:
nic_config_dict.update(value)
def gen_addresses(self, nic): | ||
address_list = [] | ||
v4_cidr = 32 | ||
v6_cidr = 128 |
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 value 128
never gets used.
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.
Removed it.
v4_addrs = nic.staticIpv4 | ||
if v4_addrs: | ||
v4 = v4_addrs[0] | ||
if v4.netmask: |
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 specifying netmask is optional during static ip setting? please correct me if I'm wrong here.
If there is no netmask given this will result in <ip>/32
as netmask, is that fine?
I think netmask should be a mandatory field during static ip setting, also please add a test for the same.
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.
Per our API definition, netmask is optional for ipv4, if no netmask given, <ip>/32
is the expected result.
see subnetMask in https://dp-downloads.broadcom.com/api-content/apis/API_VWSA_001/8.0U3/html/ReferenceGuides/vim.vm.customization.IPSettings.html
but it's mandatory if static ipv6 address included.
see subnetMask in https://dp-downloads.broadcom.com/api-content/apis/API_VWSA_001/8.0U3/html/ReferenceGuides/vim.vm.customization.FixedIpV6.html
I added 2 tests for both ipv4 and ipv6 cases.
# if not self._primaryNic: | ||
# route_list.extend(self._genIpv6Route(name, nic, addrs)) | ||
v4_cidr = 32 | ||
v6_cidr = 128 |
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 also unused
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.
removed it.
Right, it converts customization config to network v2 config supported by cloud-init, not written network configuration to Guest OS directly.
Thanks @sshedi for the review, I will address the comments. |
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. Thanks @PengpengSun
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!
Proposed Commit Message
Additional Context
Test Steps
Merge type