nm-cloud-setup: set preserve-external-ip flag during reapply
Externally added IP addresses/routes should be preserved by nm-cloud-setup. This allows other tools to also configure the interface and the Reapply() call from nm-cloud-setup would not interfere with those tools. https://bugzilla.redhat.com/show_bug.cgi?id=2132754
This commit is contained in:
@@ -450,6 +450,7 @@ _config_one(GCancellable *sigterm_cancellable,
|
|||||||
gboolean version_id_changed;
|
gboolean version_id_changed;
|
||||||
guint try_count;
|
guint try_count;
|
||||||
gboolean any_changes = FALSE;
|
gboolean any_changes = FALSE;
|
||||||
|
gboolean maybe_no_preserved_external_ip;
|
||||||
|
|
||||||
g_main_context_iteration(NULL, FALSE);
|
g_main_context_iteration(NULL, FALSE);
|
||||||
|
|
||||||
@@ -538,10 +539,17 @@ try_again:
|
|||||||
/* we are about to call Reapply(). Even if that fails, it counts as if we changed something. */
|
/* we are about to call Reapply(). Even if that fails, it counts as if we changed something. */
|
||||||
any_changes = TRUE;
|
any_changes = TRUE;
|
||||||
|
|
||||||
|
/* "preserve-external-ip" flag was only introduced in 1.41.6 (but maybe backported!).
|
||||||
|
* If we run 1.41.6+, we are sure that it's gonna work. Otherwise, we take into account
|
||||||
|
* that the call might fail due to the invalid flag and we retry. */
|
||||||
|
maybe_no_preserved_external_ip =
|
||||||
|
(nmc_client_has_version_info_v(nmc) < NM_ENCODE_VERSION(1, 41, 6));
|
||||||
|
|
||||||
if (!nmcs_device_reapply(device,
|
if (!nmcs_device_reapply(device,
|
||||||
sigterm_cancellable,
|
sigterm_cancellable,
|
||||||
applied_connection,
|
applied_connection,
|
||||||
applied_version_id,
|
applied_version_id,
|
||||||
|
maybe_no_preserved_external_ip,
|
||||||
&version_id_changed,
|
&version_id_changed,
|
||||||
&error)) {
|
&error)) {
|
||||||
if (version_id_changed && try_count < 5) {
|
if (version_id_changed && try_count < 5) {
|
||||||
|
@@ -822,6 +822,7 @@ nmcs_device_reapply(NMDevice *device,
|
|||||||
GCancellable *sigterm_cancellable,
|
GCancellable *sigterm_cancellable,
|
||||||
NMConnection *connection,
|
NMConnection *connection,
|
||||||
guint64 version_id,
|
guint64 version_id,
|
||||||
|
gboolean maybe_no_preserved_external_ip,
|
||||||
gboolean *out_version_id_changed,
|
gboolean *out_version_id_changed,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
@@ -829,11 +830,13 @@ nmcs_device_reapply(NMDevice *device,
|
|||||||
DeviceReapplyData data = {
|
DeviceReapplyData data = {
|
||||||
.main_loop = main_loop,
|
.main_loop = main_loop,
|
||||||
};
|
};
|
||||||
|
NMDeviceReapplyFlags reapply_flags = NM_DEVICE_REAPPLY_FLAGS_PRESERVE_EXTERNAL_IP;
|
||||||
|
|
||||||
|
again:
|
||||||
nm_device_reapply_async(device,
|
nm_device_reapply_async(device,
|
||||||
connection,
|
connection,
|
||||||
version_id,
|
version_id,
|
||||||
0,
|
reapply_flags,
|
||||||
sigterm_cancellable,
|
sigterm_cancellable,
|
||||||
_nmcs_device_reapply_cb,
|
_nmcs_device_reapply_cb,
|
||||||
&data);
|
&data);
|
||||||
@@ -841,6 +844,17 @@ nmcs_device_reapply(NMDevice *device,
|
|||||||
g_main_loop_run(main_loop);
|
g_main_loop_run(main_loop);
|
||||||
|
|
||||||
if (data.error) {
|
if (data.error) {
|
||||||
|
if (maybe_no_preserved_external_ip
|
||||||
|
&& reapply_flags == NM_DEVICE_REAPPLY_FLAGS_PRESERVE_EXTERNAL_IP
|
||||||
|
&& nm_g_error_matches(data.error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED)) {
|
||||||
|
/* Hm? Maybe we running against an older version of NetworkManager that
|
||||||
|
* doesn't support "preserve-external-ip" flags? Retry without the flag.
|
||||||
|
*
|
||||||
|
* Note that recent version would reject invalid flags with NM_DEVICE_ERROR_INVALID_ARGUMENT,
|
||||||
|
* but we want to detect old daemon versions here. */
|
||||||
|
reapply_flags = NM_DEVICE_REAPPLY_FLAGS_NONE;
|
||||||
|
goto again;
|
||||||
|
}
|
||||||
NM_SET_OUT(
|
NM_SET_OUT(
|
||||||
out_version_id_changed,
|
out_version_id_changed,
|
||||||
g_error_matches(data.error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_VERSION_ID_MISMATCH));
|
g_error_matches(data.error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_VERSION_ID_MISMATCH));
|
||||||
|
@@ -136,6 +136,7 @@ gboolean nmcs_device_reapply(NMDevice *device,
|
|||||||
GCancellable *sigterm_cancellable,
|
GCancellable *sigterm_cancellable,
|
||||||
NMConnection *connection,
|
NMConnection *connection,
|
||||||
guint64 version_id,
|
guint64 version_id,
|
||||||
|
gboolean maybe_no_preserved_external_ip,
|
||||||
gboolean *out_version_id_changed,
|
gboolean *out_version_id_changed,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user