canonical / cloud-init

Official upstream for the cloud-init: cloud instance initialization
https://cloud-init.io/
Other
2.87k stars 856 forks source link

[enhancement]: Support V1/V2 network-config via nocloud-net with custom webserver #4303

Open codefritzel opened 1 year ago

codefritzel commented 1 year ago

Enhancement

When nocloud-net is reading the seed data, it doesn't read the network-config file as specified at the bottom of the NoCloud docs. Even though supporting this would involve reconfiguring the network after it has already come up, there is no reason why this couldn't be done.

Original Description

Why can't I specify the network-config using this method? If a drive is mounted with the network-config file, this works.

Is there any reason why the custom webserver method (nocloud-net) does not support this?

See https://cloudinit.readthedocs.io/en/latest/reference/datasources/nocloud.html

dermotbradley commented 1 year ago

Why can't I specify the network-config using this method?

You can.

Yes nocloud-net does not request a "network-config" url. I do not know the reasons for this.

However, as indicated in the document you linked to, you can embed network configuration in the meta-data.

To quote from that document:

Also, you can inject an /etc/network/interfaces file by providing the content for that file in the network-interfaces field of meta-data.

and immediately after this quote the document provides an example of doing so.

TheRealFalcon commented 1 year ago

@codefritzel Does embedding network into meta data work for your use cases? Was there a reason you wanted a separate request for network-config, or just not aware that it could be done this way?

codefritzel commented 1 year ago

Thanks for the hint with the network-interfaces field but it does not work for my case.

My web server provides the following meta_data:

instance-id: instance1
local-hostname: instance1
network-interfaces:
  network:
    ethernets:
      interface0:
        addresses:
        - 40.156.170.15/24
        gateway4: 40.156.170.1
        match:
          macaddress: '52:54:00:12:34:56'
        set-name: interface0
    version: 2

The hostname is applied, but the network configuration is not.

If I add the network section to /etc/cloud.cfg.d/ is works.

dermotbradley commented 1 year ago

Thanks for the hint with the network-interfaces field but it does not work for my case.

The documentation I referenced states:

Also, you can inject an /etc/network/interfaces file by providing the content for that file in the network-interfaces field of meta-data.

You embedded a network config v2 style configuration in the meta-data file, rather than a /etc/network/interfaces style configuration and that is why it did not work.

The referenced page shows an example of how to use network-interfaces:.

codefritzel commented 1 year ago

Why is v2 not supported? For my case I need the matching of the MAC address to set a static ip.

Is there a reason why the network config is so different between nocloud and nocloud-net?

TheRealFalcon commented 1 year ago

@codefritzel , I understand your problem now.

Is there a reason why the network config is so different between nocloud and nocloud-net?

Cloud-init runs in multiple stages. The nocloud datasource is configured at an earlier stage, before network has been setup, so it is easier for cloud-init to fetch the network configuration and apply it during that time. nocloud-net is configured after network has already come up (because of the need to contact a web server). This means cloud-init would need to apply and potentially change the configuration of the already-up network. This is certainly do-able, but just involves a slightly more complicated code path.

Regardless, This would be a worthwhile feature. I don't see a reason why this can't be added.