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

feat(vmware): Convert imc network config to Networking config Version 2 #5937

Conversation

PengpengSun
Copy link
Contributor

Proposed Commit Message

feat(vmware): Convert imc network config to Networking config Version 2

To support dhcp4-overrides and dhcp6-overrides, we need to convert network configuration read from imc configuration file to v2 instead of v1.
This PR also adds ipv6 routes support.

If you need to write multiple paragraphs, feel free.

Fixes LP: #1776452

Additional Context

Test Steps

Merge type

  • Squash merge using "Proposed Commit Message"
  • Rebase and merge unique commits. Requires commit messages per-commit each referencing the pull request number (#<PR_NUM>)

Copy link

github-actions bot commented Jan 7, 2025

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.)

@github-actions github-actions bot added the stale-pr Pull request is stale; will be auto-closed soon label Jan 7, 2025
@PengpengSun
Copy link
Contributor Author

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~

@TheRealFalcon TheRealFalcon removed the stale-pr Pull request is stale; will be auto-closed soon label Jan 7, 2025
@github-actions github-actions bot added the stale-pr Pull request is stale; will be auto-closed soon label Jan 22, 2025
@TheRealFalcon TheRealFalcon removed the stale-pr Pull request is stale; will be auto-closed soon label Jan 22, 2025
@canonical canonical deleted a comment from github-actions bot Jan 22, 2025
@TheRealFalcon TheRealFalcon self-assigned this Jan 23, 2025
@TheRealFalcon
Copy link
Member

@sshedi , is this something you could review too?

Copy link
Member

@TheRealFalcon TheRealFalcon left a 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]})
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

@TheRealFalcon TheRealFalcon Feb 5, 2025

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?

Copy link
Contributor Author

@PengpengSun PengpengSun Feb 6, 2025

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})
Copy link
Member

Choose a reason for hiding this comment

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

same default comment here

Copy link
Contributor Author

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:
Copy link
Member

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.

Copy link
Contributor

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)

Copy link
Contributor Author

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.

cloudinit/sources/helpers/vmware/imc/config_nic.py Outdated Show resolved Hide resolved
cloudinit/sources/helpers/vmware/imc/config_nic.py Outdated Show resolved Hide resolved

def gen_dhcp4(self, nic):
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, return {} now.

@PengpengSun
Copy link
Contributor Author

Overall the changes look good. I left a few inline comments.

Thanks @TheRealFalcon for the review, I'm traveling during spring festival here, probably won't be able to address any comments until Feb.5.

Copy link
Contributor

@sshedi sshedi left a 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):
Copy link
Contributor

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}

Copy link
Contributor Author

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:
Copy link
Contributor

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

Copy link
Contributor Author

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:
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

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:
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

this is also unused

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed it.

@PengpengSun
Copy link
Contributor Author

@PengpengSun I believe this change is opaque to user, right?

Right, it converts customization config to network v2 config supported by cloud-init, not written network configuration to Guest OS directly.

Need some changes, PTAL.

Thanks @sshedi for the review, I will address the comments.

Copy link
Contributor

@sshedi sshedi left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @PengpengSun

Copy link
Member

@TheRealFalcon TheRealFalcon left a comment

Choose a reason for hiding this comment

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

LGTM!

@TheRealFalcon TheRealFalcon merged commit b38ab5f into canonical:main Feb 7, 2025
22 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
Development

Successfully merging this pull request may close these issues.

3 participants