cloud-setup: configure disconnected wired devices on OCI

On OCI VMs (virtual machines, as opposed to BM -- bare metal), the VNICs
don't get their addresses via DHCP and need us to get the address from
the metadata and apply it.

https://issues.redhat.com/browse/NMT-1432
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2180
This commit is contained in:
Lubomir Rintel
2025-04-07 13:28:29 +02:00
parent 0540b3c9bc
commit 548e27ef5f
2 changed files with 59 additions and 14 deletions

View File

@@ -694,11 +694,10 @@ try_again:
static NMConnection *
_new_connection(void)
{
NMConnection *connection = NULL;
NMConnection *connection;
NMSetting *s_user;
connection = nm_simple_connection_new();
s_user = nm_setting_user_new();
nm_connection_add_setting(connection, s_user);
nm_setting_user_set_data(NM_SETTING_USER(s_user),
@@ -713,9 +712,13 @@ static gboolean
_config_ethernet(SigTermData *sigterm_data,
const NMCSProviderGetConfigIfaceData *config_data,
NMClient *nmc,
const NMCSProviderGetConfigResult *result)
const NMCSProviderGetConfigResult *result,
gboolean allow_new_connections)
{
gs_unref_object NMDevice *device = NULL;
gs_unref_object NMConnection *connection = NULL;
gs_unref_object NMActiveConnection *active_connection = NULL;
gs_free_error GError *error = NULL;
device = nm_g_object_ref(
_nmc_get_device_by_hwaddr(nmc, NM_TYPE_DEVICE_ETHERNET, config_data->hwaddr));
@@ -724,12 +727,52 @@ _config_ethernet(SigTermData *sigterm_data,
return FALSE;
}
if (allow_new_connections && nm_device_get_state(device) == NM_DEVICE_STATE_DISCONNECTED) {
connection = _new_connection();
nm_connection_add_setting(connection,
g_object_new(NM_TYPE_SETTING_CONNECTION,
NM_SETTING_CONNECTION_TYPE,
NM_SETTING_WIRED_SETTING_NAME,
NULL));
nm_connection_add_setting(connection,
g_object_new(NM_TYPE_SETTING_IP4_CONFIG,
NM_SETTING_IP_CONFIG_METHOD,
NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
NULL));
nm_connection_add_setting(connection,
g_object_new(NM_TYPE_SETTING_WIRED,
NM_SETTING_WIRED_MAC_ADDRESS,
config_data->hwaddr,
NULL));
_nmc_mangle_connection(device, connection, result, config_data, NULL, NULL);
active_connection = nmcs_add_and_activate(nmc, NULL, device, connection, &error);
if (!active_connection) {
if (!nm_utils_error_is_cancelled(error)) {
_LOGD("config device %s: failure to activate connection: %s",
nm_device_get_iface(NM_DEVICE(device)),
error->message);
}
return FALSE;
}
_LOGD("config device %s: connection \"%s\" (%s) created",
nm_device_get_iface(NM_DEVICE(device)),
nm_active_connection_get_id(active_connection),
nm_active_connection_get_uuid(active_connection));
return TRUE;
} else {
return _config_existing(sigterm_data,
config_data,
nmc,
result,
NM_SETTING_WIRED_SETTING_NAME,
device);
}
}
static gboolean
@@ -910,7 +953,8 @@ _config_one(SigTermData *sigterm_data,
_nm_utils_ascii_str_to_bool(g_getenv(NMCS_ENV_NM_CLOUD_SETUP_ALLOW_NEW_CONN),
NMCS_IS_PROVIDER_OCI(provider));
if (allow_new_connections && config_data->priv.oci.vlan_tag != 0) {
if (allow_new_connections && NMCS_IS_PROVIDER_OCI(provider)
&& config_data->priv.oci.vlan_tag != 0) {
if (config_data->priv.oci.parent_hwaddr == NULL) {
_LOGW("config device %s: has vlan id %d but no parent device",
config_data->hwaddr,
@@ -935,7 +979,8 @@ _config_one(SigTermData *sigterm_data,
config_data->hwaddr);
} else {
any_changes = _config_ethernet(sigterm_data, config_data, nmc, result);
any_changes =
_config_ethernet(sigterm_data, config_data, nmc, result, allow_new_connections);
}
return any_changes;

View File

@@ -649,7 +649,7 @@ nmcs_add_and_activate(NMClient *client,
nm_client_add_and_activate_connection_async(client,
connection,
NULL,
device,
NULL,
sigterm_cancellable,
_nmcs_add_and_activate_cb,