[docs]: apply_network_config: false config is not effect
Liuwenfan opened this issue · comments
Environment is such as:
Cloud-init: v23.1.1
platform: Azure
OS: Rocky9.2
I need to set apply_network_config to false in config file: /etc/cloud/cloud.cfg, to disable change the way of create network config file(ifcfg-ethx), because when more than one ip in machine metadata,cloud-init in init-local step set other ip to static ip.
I change config first, such as
cat /etc/cloud/cloud.cfg
# .....
datasource:
Azure:
apply_network_config: false
then reboot virtual machine, I find it is not effect, I can find message from log, this log is added by myself
DataSourceAzure.py[DEBUG]: debug ds_cfg :{'data_dir': '/var/lib/waagent', 'disk_aliases': {'ephemeral0': '/dev/disk/cloud/azure_resource'}, 'apply_network_config': True}
......
handlers.py[DEBUG]: finish: azure-ds/generate_network_config_from_instance_network_metadata: SUCCESS: generate_network_config_from_instance_network_metadata
but I alse can see the config is loaded by program,
2024-03-08 07:35:45,046 - stages.py[DEBUG]: debug _cfg: {'datasource_list': ['Azure', 'None'], 'datasource': {'Azure': {'apply_network_config': False}}......
I add some debug code in DataSourceAzure.py file
@azure_ds_telemetry_reporter
def _generate_network_config(self):
"""Generate network configuration according to configuration."""
# Use IMDS network metadata, if configured.
LOG.debug("debug _metadata_imds :%s",self._metadata_imds)
LOG.debug("debug ds_cfg :%s",self.ds_cfg)
if (
self._metadata_imds
and self._metadata_imds != sources.UNSET
and self.ds_cfg.get("apply_network_config")
):
try:
return generate_network_config_from_instance_network_metadata(
self._metadata_imds["network"]
)
except Exception as e:
LOG.error(
"Failed generating network config "
"from IMDS network metadata: %s",
str(e),
)
# Generate fallback configuration.
try:
return _generate_network_config_from_fallback_config()
except Exception as e:
LOG.error("Failed generating fallback network config: %s", str(e))
as you see, I want cloud-init generate network config content from _generate_network_config_from_fallback_config function, but the apply_network_config: false is not effect
I add some other test case, I change the config apply_network_config:false and sync the change to vm image.
the config in new machine that create from this image take effect.
@Liuwenfan Quick question, do you run sudo cloud-init clean --logs
after modifying the /etc/cloud/cloud.cfg
file and before rebooting the VM?
I have followed the following steps:
- Edit the
/etc/cloud/cloud.cfg
- Run
sudo cloud-init clean --logs
- Rebooted the VM
I get the following the logs:
2024-03-12 09:22:58,103 - handlers.py[DEBUG]: start: azure-ds/_generate_network_config: _generate_network_config
2024-03-12 09:22:58,103 - handlers.py[DEBUG]: start: azure-ds/_generate_network_config_from_fallback_config: _generate_network_config_from_fallback_config
2024-03-12 09:22:58,107 - handlers.py[DEBUG]: finish: azure-ds/_generate_network_config_from_fallback_config: SUCCESS: _generate_network_config_from_fallback_config
2024-03-12 09:22:58,107 - handlers.py[DEBUG]: finish: azure-ds/_generate_network_config: SUCCESS: _generate_network_config
2024-03-12 09:23:59,112 - handlers.py[DEBUG]: start: azure-ds/_generate_network_config: _generate_network_config
2024-03-12 09:23:59,112 - handlers.py[DEBUG]: start: azure-ds/_generate_network_config_from_fallback_config: _generate_network_config_from_fallback_config
2024-03-12 09:23:59,113 - handlers.py[DEBUG]: finish: azure-ds/_generate_network_config_from_fallback_config: SUCCESS: _generate_network_config_from_fallback_config
2024-03-12 09:23:59,113 - handlers.py[DEBUG]: finish: azure-ds/_generate_network_config: SUCCESS: _generate_network_config
I see it generates the network config from fallback config.
old config is apply_network_config:true? I have changed the config value to false in image;
I change the value to true in machine which default value of apply_network_config is false and effect, then run cloud-init clean command, command return status is zero.
after machine reboot, I get following logs:
2024-03-13 05:35:31,539+0000 - handlers.py[DEBUG]: finish: azure-ds/_generate_network_config_from_fallback_config: SUCCESS: _generate_network_config_from_fallback_config
the desired result is generate_network_config_from_instance_network_metadata, the current apply_network_config is true
Hey @Liuwenfan I have tried reproducing this
Rocky 9.3
Cloud-init v23.1.1
platform Azure
However I have not been successful.
- When the apply_network_config is True this is what I get
2024-03-13 09:16:12,045 - handlers.py[DEBUG]: start: azure-ds/_generate_network_config: _generate_network_config
2024-03-13 09:16:12,045 - handlers.py[DEBUG]: start: azure-ds/generate_network_config_from_instance_network_metadata: generate_network_config_from_instance_network_metadata
2024-03-13 09:16:12,048 - handlers.py[DEBUG]: finish: azure-ds/generate_network_config_from_instance_network_metadata: SUCCESS: generate_network_config_from_instance_network_metadata
2024-03-13 09:16:12,049 - handlers.py[DEBUG]: finish: azure-ds/_generate_network_config: SUCCESS: _generate_network_config
2024-03-13 09:17:12,952 - handlers.py[DEBUG]: start: azure-ds/_generate_network_config: _generate_network_config
2024-03-13 09:17:12,952 - handlers.py[DEBUG]: start: azure-ds/generate_network_config_from_instance_network_metadata: generate_network_config_from_instance_network_metadata
2024-03-13 09:17:12,954 - handlers.py[DEBUG]: finish: azure-ds/generate_network_config_from_instance_network_metadata: SUCCESS: generate_network_config_from_instance_network_metadata
2024-03-13 09:17:12,954 - handlers.py[DEBUG]: finish: azure-ds/_generate_network_config: SUCCESS: _generate_network_config
- I change the value to false
- Run
sudo cloud-init clean --logs
- Reboot vm
- Checking the logs later I get
2024-03-15 13:15:01,608 - handlers.py[DEBUG]: start: azure-ds/_generate_network_config: _generate_network_config
2024-03-15 13:15:01,608 - handlers.py[DEBUG]: start: azure-ds/_generate_network_config_from_fallback_config: _generate_network_config_from_fallback_config
2024-03-15 13:15:01,609 - handlers.py[DEBUG]: finish: azure-ds/_generate_network_config_from_fallback_config: SUCCESS: _generate_network_config_from_fallback_config
2024-03-15 13:15:01,609 - handlers.py[DEBUG]: finish: azure-ds/_generate_network_config: SUCCESS: _generate_network_config
2024-03-15 13:16:02,540 - handlers.py[DEBUG]: start: azure-ds/_generate_network_config: _generate_network_config
2024-03-15 13:16:02,541 - handlers.py[DEBUG]: start: azure-ds/_generate_network_config_from_fallback_config: _generate_network_config_from_fallback_config
2024-03-15 13:16:02,542 - handlers.py[DEBUG]: finish: azure-ds/_generate_network_config_from_fallback_config: SUCCESS: _generate_network_config_from_fallback_config
2024-03-15 13:16:02,542 - handlers.py[DEBUG]: finish: azure-ds/_generate_network_config: SUCCESS: _generate_network_config
Thanks, @Liuwenfan, for reporting this.
I am unable to reproduce your issue. In my end, if apply_network_config
is set to true
, then generate_network_config_from_instance_network_metadata
is executed and if set to false
, then _generate_network_config_from_fallback_config
and that is the expected behavior.
Could you please attach the [logs](sudo cloud-init collect-logs) of one of your instances, without any modification of cloud-init source code, and explain what is the behavior you expect?