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:
@@ -694,11 +694,10 @@ try_again:
|
|||||||
static NMConnection *
|
static NMConnection *
|
||||||
_new_connection(void)
|
_new_connection(void)
|
||||||
{
|
{
|
||||||
NMConnection *connection = NULL;
|
NMConnection *connection;
|
||||||
NMSetting *s_user;
|
NMSetting *s_user;
|
||||||
|
|
||||||
connection = nm_simple_connection_new();
|
connection = nm_simple_connection_new();
|
||||||
|
|
||||||
s_user = nm_setting_user_new();
|
s_user = nm_setting_user_new();
|
||||||
nm_connection_add_setting(connection, s_user);
|
nm_connection_add_setting(connection, s_user);
|
||||||
nm_setting_user_set_data(NM_SETTING_USER(s_user),
|
nm_setting_user_set_data(NM_SETTING_USER(s_user),
|
||||||
@@ -713,9 +712,13 @@ static gboolean
|
|||||||
_config_ethernet(SigTermData *sigterm_data,
|
_config_ethernet(SigTermData *sigterm_data,
|
||||||
const NMCSProviderGetConfigIfaceData *config_data,
|
const NMCSProviderGetConfigIfaceData *config_data,
|
||||||
NMClient *nmc,
|
NMClient *nmc,
|
||||||
const NMCSProviderGetConfigResult *result)
|
const NMCSProviderGetConfigResult *result,
|
||||||
|
gboolean allow_new_connections)
|
||||||
{
|
{
|
||||||
gs_unref_object NMDevice *device = NULL;
|
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(
|
device = nm_g_object_ref(
|
||||||
_nmc_get_device_by_hwaddr(nmc, NM_TYPE_DEVICE_ETHERNET, config_data->hwaddr));
|
_nmc_get_device_by_hwaddr(nmc, NM_TYPE_DEVICE_ETHERNET, config_data->hwaddr));
|
||||||
@@ -724,6 +727,45 @@ _config_ethernet(SigTermData *sigterm_data,
|
|||||||
return FALSE;
|
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,
|
return _config_existing(sigterm_data,
|
||||||
config_data,
|
config_data,
|
||||||
nmc,
|
nmc,
|
||||||
@@ -731,6 +773,7 @@ _config_ethernet(SigTermData *sigterm_data,
|
|||||||
NM_SETTING_WIRED_SETTING_NAME,
|
NM_SETTING_WIRED_SETTING_NAME,
|
||||||
device);
|
device);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
_oci_new_vlan_dev(SigTermData *sigterm_data,
|
_oci_new_vlan_dev(SigTermData *sigterm_data,
|
||||||
@@ -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),
|
_nm_utils_ascii_str_to_bool(g_getenv(NMCS_ENV_NM_CLOUD_SETUP_ALLOW_NEW_CONN),
|
||||||
NMCS_IS_PROVIDER_OCI(provider));
|
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) {
|
if (config_data->priv.oci.parent_hwaddr == NULL) {
|
||||||
_LOGW("config device %s: has vlan id %d but no parent device",
|
_LOGW("config device %s: has vlan id %d but no parent device",
|
||||||
config_data->hwaddr,
|
config_data->hwaddr,
|
||||||
@@ -935,7 +979,8 @@ _config_one(SigTermData *sigterm_data,
|
|||||||
config_data->hwaddr);
|
config_data->hwaddr);
|
||||||
|
|
||||||
} else {
|
} 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;
|
return any_changes;
|
||||||
|
@@ -649,7 +649,7 @@ nmcs_add_and_activate(NMClient *client,
|
|||||||
|
|
||||||
nm_client_add_and_activate_connection_async(client,
|
nm_client_add_and_activate_connection_async(client,
|
||||||
connection,
|
connection,
|
||||||
NULL,
|
device,
|
||||||
NULL,
|
NULL,
|
||||||
sigterm_cancellable,
|
sigterm_cancellable,
|
||||||
_nmcs_add_and_activate_cb,
|
_nmcs_add_and_activate_cb,
|
||||||
|
Reference in New Issue
Block a user