summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubomir Rintel <lkundrak@v3.sk>2015-03-27 13:07:43 +0100
committerLubomir Rintel <lkundrak@v3.sk>2015-12-05 12:16:23 +0100
commitd03f347b9dbdadb10952fb2704436b4405d38ac3 (patch)
tree28345a5b570dfb2a0f3f9c68f455a9a8e5598304
parente92e06bdc740acae4ca9bc03368208cfb6daf286 (diff)
downloadNetworkManager-lr/nmcli-monitor-rh1034158.tar.gz
cli: add nmcli monitorlr/nmcli-monitor-rh1034158
https://bugzilla.redhat.com/show_bug.cgi?id=1034158
-rw-r--r--clients/cli/connections.c6
-rw-r--r--clients/cli/connections.h2
-rw-r--r--clients/cli/devices.c6
-rw-r--r--clients/cli/devices.h2
-rw-r--r--clients/cli/general.c97
-rw-r--r--clients/cli/general.h1
-rw-r--r--clients/cli/nmcli.c2
-rw-r--r--man/nmcli.1.in18
8 files changed, 131 insertions, 3 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c
index e35e7dae1e..100d0a1a02 100644
--- a/clients/cli/connections.c
+++ b/clients/cli/connections.c
@@ -10265,3 +10265,9 @@ opt_error:
g_error_free (error);
return nmc->return_value;
}
+
+void
+monitor_connections (NmCli *nmc)
+{
+ do_connection_monitor (nmc, 0, NULL);
+}
diff --git a/clients/cli/connections.h b/clients/cli/connections.h
index c736859799..c158b63488 100644
--- a/clients/cli/connections.h
+++ b/clients/cli/connections.h
@@ -24,4 +24,6 @@
NMCResultCode do_connections (NmCli *nmc, int argc, char **argv);
+void monitor_connections (NmCli *nmc);
+
#endif /* NMC_CONNECTIONS_H */
diff --git a/clients/cli/devices.c b/clients/cli/devices.c
index 4cfa35ca0b..3ca3a6b900 100644
--- a/clients/cli/devices.c
+++ b/clients/cli/devices.c
@@ -3657,3 +3657,9 @@ opt_error:
g_error_free (error);
return nmc->return_value;
}
+
+void
+monitor_devices (NmCli *nmc)
+{
+ do_device_monitor (nmc, 0, NULL);
+}
diff --git a/clients/cli/devices.h b/clients/cli/devices.h
index 152dd20776..56fc9c2f49 100644
--- a/clients/cli/devices.h
+++ b/clients/cli/devices.h
@@ -24,4 +24,6 @@
NMCResultCode do_devices (NmCli *nmc, int argc, char **argv);
+void monitor_devices (NmCli *nmc);
+
#endif /* NMC_DEVICES_H */
diff --git a/clients/cli/general.c b/clients/cli/general.c
index abf71f67a1..b49b242d9a 100644
--- a/clients/cli/general.c
+++ b/clients/cli/general.c
@@ -27,6 +27,9 @@
#include "utils.h"
#include "general.h"
+#include "devices.h"
+#include "connections.h"
+
/* Available fields for 'general status' */
static NmcOutputField nmc_fields_nm_status[] = {
{"RUNNING", N_("RUNNING")}, /* 0 */
@@ -207,6 +210,15 @@ usage_radio_wwan (void)
"Get status of mobile broadband radio switch, or turn it on/off.\n\n"));
}
+static void
+usage_monitor (void)
+{
+ g_printerr (_("Usage: nmcli monitor\n"
+ "\n"
+ "Monitor NetworkManager changes.\n"
+ "Prints a line whenever a change occurs in NetworkManager\n\n"));
+}
+
/* quit main loop */
static void
quit (void)
@@ -889,3 +901,88 @@ finish:
return nmc->return_value;
}
+static void
+client_hostname (NMClient *client, GParamSpec *param, NmCli *nmc)
+{
+ const char *hostname;
+
+ g_object_get (client, NM_CLIENT_HOSTNAME, &hostname, NULL);
+ g_print (_("Hostname set to '%s'\n"), hostname);
+}
+
+static void
+client_primary_connection (NMClient *client, GParamSpec *param, NmCli *nmc)
+{
+ NMConnection *primary;
+ const char *id;
+
+ g_object_get (client, NM_CLIENT_PRIMARY_CONNECTION, &primary, NULL);
+ if (primary) {
+ id = nm_connection_get_id (primary);
+ if (!id)
+ id = nm_connection_get_uuid (primary);
+
+ g_print (_("'%s' is now the primary connection\n"), id);
+ } else {
+ g_print (_("There's no primary connection\n"));
+ }
+}
+
+static void
+client_connectivity (NMClient *client, GParamSpec *param, NmCli *nmc)
+{
+ NMConnectivityState connectivity;
+ char *str;
+
+ g_object_get (client, NM_CLIENT_CONNECTIVITY, &connectivity, NULL);
+ str = nmc_colorize (nmc, connectivity_to_color (connectivity), NMC_TERM_FORMAT_NORMAL,
+ _("Connectivity is now '%s'\n"), nm_connectivity_to_string (connectivity));
+ g_print ("%s", str);
+ g_free (str);
+}
+
+static void
+client_state (NMClient *client, GParamSpec *param, NmCli *nmc)
+{
+ NMState state;
+ char *str;
+
+ g_object_get (client, NM_CLIENT_STATE, &state, NULL);
+ str = nmc_colorize (nmc, state_to_color (state), NMC_TERM_FORMAT_NORMAL,
+ _("Networkmanager is now in the '%s' state\n"),
+ nm_state_to_string (state));
+ g_print ("%s", str);
+ g_free (str);
+}
+
+NMCResultCode
+do_monitor (NmCli *nmc, int argc, char **argv)
+{
+ if (argc > 0) {
+ if (!nmc_arg_is_help (*argv)) {
+ g_string_printf (nmc->return_text, _("Error: 'monitor' command '%s' is not valid."), *argv);
+ nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
+ }
+
+ usage_monitor ();
+ return nmc->return_value;
+ }
+
+ nmc->get_client (nmc); /* create NMClient */
+
+ g_signal_connect (nmc->client, "notify::" NM_CLIENT_HOSTNAME,
+ G_CALLBACK (client_hostname), nmc);
+ g_signal_connect (nmc->client, "notify::" NM_CLIENT_PRIMARY_CONNECTION,
+ G_CALLBACK (client_primary_connection), nmc);
+ g_signal_connect (nmc->client, "notify::" NM_CLIENT_CONNECTIVITY,
+ G_CALLBACK (client_connectivity), nmc);
+ g_signal_connect (nmc->client, "notify::" NM_CLIENT_STATE,
+ G_CALLBACK (client_state), nmc);
+
+ nmc->should_wait++;
+
+ monitor_devices (nmc);
+ monitor_connections (nmc);
+
+ return NMC_RESULT_SUCCESS;
+}
diff --git a/clients/cli/general.h b/clients/cli/general.h
index 7e8c21f9bc..40dddb20d9 100644
--- a/clients/cli/general.h
+++ b/clients/cli/general.h
@@ -25,5 +25,6 @@
NMCResultCode do_general (NmCli *nmc, int argc, char **argv);
NMCResultCode do_networking (NmCli *nmc, int argc, char **argv);
NMCResultCode do_radio (NmCli *nmc, int argc, char **argv);
+NMCResultCode do_monitor (NmCli *nmc, int argc, char **argv);
#endif /* NMC_GENERAL_H */
diff --git a/clients/cli/nmcli.c b/clients/cli/nmcli.c
index 9242dd4f41..ac72607d0b 100644
--- a/clients/cli/nmcli.c
+++ b/clients/cli/nmcli.c
@@ -103,6 +103,7 @@ usage (const char *prog_name)
" c[onnection] NetworkManager's connections\n"
" d[evice] devices managed by NetworkManager\n"
" a[gent] NetworkManager secret agent or polkit agent\n"
+ " m[monitor] monitor NetworkManager changes\n"
"\n"),
prog_name);
}
@@ -119,6 +120,7 @@ static const struct cmd {
NMCResultCode (*func) (NmCli *nmc, int argc, char **argv);
} nmcli_cmds[] = {
{ "general", do_general },
+ { "monitor", do_monitor },
{ "networking", do_networking },
{ "radio", do_radio },
{ "connection", do_connections },
diff --git a/man/nmcli.1.in b/man/nmcli.1.in
index d24a1cb159..6e8881b142 100644
--- a/man/nmcli.1.in
+++ b/man/nmcli.1.in
@@ -33,7 +33,7 @@ nmcli \- command\(hyline tool for controlling NetworkManager
.sp
.IR OBJECT " := { "
-.BR general " | " networking " | " radio " | " connection " | " device " | " agent
+.BR general " | " networking " | " radio " | " connection " | " device " | " agent " | " monitor
.RI " }"
.sp
@@ -260,6 +260,16 @@ Show or set all previously mentioned radio switches at the same time.
.RE
.TP
+.B monitor \- monitor NetworkManager
+.br
+Use this object to observe NetworkManager activity. Watches for changes
+in connectivity state, devices or connection profiles.
+.br
+See also \fImonitor\fP command of \fIconnection\fP or \fIdevice\fP object
+to watch for changes in certain objects or object classes.
+.RE
+
+.TP
.B connection \- start, stop, and manage network connections
.sp
NetworkManager stores all network configuration as \fIconnections\fP, which are
@@ -789,7 +799,8 @@ its name, UUID or D-Bus path. If <ID> is ambiguous, a keyword \fIid\fP,
See \fBconnection show\fP above for the description of the <ID>-specifying keywords.
.br
Monitors all connection profiles in case none is specified. The command terminates
-when all monitored connections disappear.
+when all monitored connections disappear. If you want to monitor connection creation
+consider using the global monitor with \fInmcli monitor\fP command.
.TP
.B reload
.br
@@ -861,7 +872,8 @@ Monitor device activity. This command prints a line whenever the specified devic
change state.
.br
Monitors all devices in case no interface is specified. The monitor terminates when
-all specified devices disappear.
+all specified devices disappear. If you want to monitor device addition consider
+using the global monitor with \fInmcli monitor\fP command.
.TP
.B wifi [list [ifname <ifname>] [bssid <BSSID>]]
.br