summaryrefslogtreecommitdiff
path: root/libnm/nm-client.c
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-03-28 08:09:56 +0200
committerThomas Haller <thaller@redhat.com>2018-04-04 14:02:13 +0200
commitf67303221bdc8098cb3b6203ec777b294e412971 (patch)
treec084b9d71667d8bdb8617e36cc965ee437ee751f /libnm/nm-client.c
parentab8312a18e8b281a62f39ce59a077fda77943187 (diff)
downloadNetworkManager-f67303221bdc8098cb3b6203ec777b294e412971.tar.gz
checkpoint: allow resetting the rollback timeout via D-Bus
This allows to adjust the timeout of an existing checkpoint. The main usecase of checkpoints, is to have a fail-safe when configuring the network remotely. By allowing to reset the timeout, the user can perform a series of actions, and keep bumping the timeout. That way, the entire series is still guarded by the same checkpoint, but the user can start with short timeout, and re-adjust the timeout as he goes along. The libnm API only implements the async form (at least for now). Sync methods are fundamentally wrong with D-Bus, and it's probably not needed. Also, follow glib convenction, where the async form doesn't have the _async name suffix. Also, accept a D-Bus path as argument, not a NMCheckpoint instance. The libnm API should not be more restricted than the underlying D-Bus API. It would be cumbersome to require the user to lookup the NMCheckpoint instance first, especially since libnm doesn't provide an efficient or convenient lookup-by-path method. On the other hand, retrieving the path from a NMCheckpoint instance is always possible.
Diffstat (limited to 'libnm/nm-client.c')
-rw-r--r--libnm/nm-client.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/libnm/nm-client.c b/libnm/nm-client.c
index da0c100804..9cc36d11e7 100644
--- a/libnm/nm-client.c
+++ b/libnm/nm-client.c
@@ -2372,6 +2372,88 @@ nm_client_checkpoint_rollback_finish (NMClient *client,
}
}
+static void
+checkpoint_adjust_rollback_timeout_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ gs_unref_object GSimpleAsyncResult *simple = user_data;
+ GError *error = NULL;
+
+ if (nm_manager_checkpoint_adjust_rollback_timeout_finish (NM_MANAGER (object), result, &error))
+ g_simple_async_result_set_op_res_gboolean (simple, TRUE);
+ else
+ g_simple_async_result_take_error (simple, error);
+
+ g_simple_async_result_complete (simple);
+}
+
+/**
+ * nm_client_checkpoint_adjust_rollback_timeout:
+ * @client: the %NMClient
+ * @checkpoint_path: a D-Bus path to a checkpoint
+ * @add_timeout: the timeout in seconds counting from now.
+ * Set to zero, to disable the timeout.
+ * @cancellable: a #GCancellable, or %NULL
+ * @callback: (scope async): callback to be called when the add operation completes
+ * @user_data: (closure): caller-specific data passed to @callback
+ *
+ * Resets the timeout for the checkpoint with path @checkpoint_path
+ * to @timeout_add.
+ *
+ * Since: 1.12
+ **/
+void
+nm_client_checkpoint_adjust_rollback_timeout (NMClient *client,
+ const char *checkpoint_path,
+ guint32 add_timeout,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *simple;
+ GError *error = NULL;
+
+ g_return_if_fail (NM_IS_CLIENT (client));
+
+ if (!_nm_client_check_nm_running (client, &error)) {
+ g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error);
+ return;
+ }
+
+ simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data,
+ nm_client_checkpoint_rollback_async);
+ if (cancellable)
+ g_simple_async_result_set_check_cancellable (simple, cancellable);
+ nm_manager_checkpoint_adjust_rollback_timeout (NM_CLIENT_GET_PRIVATE (client)->manager,
+ checkpoint_path, add_timeout,
+ cancellable, checkpoint_adjust_rollback_timeout_cb, simple);
+}
+
+/**
+ * nm_client_checkpoint_adjust_rollback_timeout_finish:
+ * @client: an #NMClient
+ * @result: the result passed to the #GAsyncReadyCallback
+ * @error: location for a #GError, or %NULL
+ *
+ * Gets the result of a call to nm_client_checkpoint_adjust_rollback_timeout().
+ *
+ * Returns: %TRUE on success or %FALSE on failure.
+ *
+ * Since: 1.12
+ **/
+gboolean
+nm_client_checkpoint_adjust_rollback_timeout_finish (NMClient *client,
+ GAsyncResult *result,
+ GError **error)
+{
+ g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
+ g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE);
+
+ return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
+ error);
+}
+
/****************************************************************/
/* Object Initialization */
/****************************************************************/