cli: add nmcli monitor
https://bugzilla.redhat.com/show_bug.cgi?id=1034158
This commit is contained in:
@@ -10265,3 +10265,9 @@ opt_error:
|
|||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
return nmc->return_value;
|
return nmc->return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
monitor_connections (NmCli *nmc)
|
||||||
|
{
|
||||||
|
do_connection_monitor (nmc, 0, NULL);
|
||||||
|
}
|
||||||
|
@@ -24,4 +24,6 @@
|
|||||||
|
|
||||||
NMCResultCode do_connections (NmCli *nmc, int argc, char **argv);
|
NMCResultCode do_connections (NmCli *nmc, int argc, char **argv);
|
||||||
|
|
||||||
|
void monitor_connections (NmCli *nmc);
|
||||||
|
|
||||||
#endif /* NMC_CONNECTIONS_H */
|
#endif /* NMC_CONNECTIONS_H */
|
||||||
|
@@ -3657,3 +3657,9 @@ opt_error:
|
|||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
return nmc->return_value;
|
return nmc->return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
monitor_devices (NmCli *nmc)
|
||||||
|
{
|
||||||
|
do_device_monitor (nmc, 0, NULL);
|
||||||
|
}
|
||||||
|
@@ -24,4 +24,6 @@
|
|||||||
|
|
||||||
NMCResultCode do_devices (NmCli *nmc, int argc, char **argv);
|
NMCResultCode do_devices (NmCli *nmc, int argc, char **argv);
|
||||||
|
|
||||||
|
void monitor_devices (NmCli *nmc);
|
||||||
|
|
||||||
#endif /* NMC_DEVICES_H */
|
#endif /* NMC_DEVICES_H */
|
||||||
|
@@ -27,6 +27,9 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "general.h"
|
#include "general.h"
|
||||||
|
|
||||||
|
#include "devices.h"
|
||||||
|
#include "connections.h"
|
||||||
|
|
||||||
/* Available fields for 'general status' */
|
/* Available fields for 'general status' */
|
||||||
static NmcOutputField nmc_fields_nm_status[] = {
|
static NmcOutputField nmc_fields_nm_status[] = {
|
||||||
{"RUNNING", N_("RUNNING")}, /* 0 */
|
{"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"));
|
"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 */
|
/* quit main loop */
|
||||||
static void
|
static void
|
||||||
quit (void)
|
quit (void)
|
||||||
@@ -889,3 +901,88 @@ finish:
|
|||||||
return nmc->return_value;
|
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;
|
||||||
|
}
|
||||||
|
@@ -25,5 +25,6 @@
|
|||||||
NMCResultCode do_general (NmCli *nmc, int argc, char **argv);
|
NMCResultCode do_general (NmCli *nmc, int argc, char **argv);
|
||||||
NMCResultCode do_networking (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_radio (NmCli *nmc, int argc, char **argv);
|
||||||
|
NMCResultCode do_monitor (NmCli *nmc, int argc, char **argv);
|
||||||
|
|
||||||
#endif /* NMC_GENERAL_H */
|
#endif /* NMC_GENERAL_H */
|
||||||
|
@@ -103,6 +103,7 @@ usage (const char *prog_name)
|
|||||||
" c[onnection] NetworkManager's connections\n"
|
" c[onnection] NetworkManager's connections\n"
|
||||||
" d[evice] devices managed by NetworkManager\n"
|
" d[evice] devices managed by NetworkManager\n"
|
||||||
" a[gent] NetworkManager secret agent or polkit agent\n"
|
" a[gent] NetworkManager secret agent or polkit agent\n"
|
||||||
|
" m[monitor] monitor NetworkManager changes\n"
|
||||||
"\n"),
|
"\n"),
|
||||||
prog_name);
|
prog_name);
|
||||||
}
|
}
|
||||||
@@ -119,6 +120,7 @@ static const struct cmd {
|
|||||||
NMCResultCode (*func) (NmCli *nmc, int argc, char **argv);
|
NMCResultCode (*func) (NmCli *nmc, int argc, char **argv);
|
||||||
} nmcli_cmds[] = {
|
} nmcli_cmds[] = {
|
||||||
{ "general", do_general },
|
{ "general", do_general },
|
||||||
|
{ "monitor", do_monitor },
|
||||||
{ "networking", do_networking },
|
{ "networking", do_networking },
|
||||||
{ "radio", do_radio },
|
{ "radio", do_radio },
|
||||||
{ "connection", do_connections },
|
{ "connection", do_connections },
|
||||||
|
@@ -33,7 +33,7 @@ nmcli \- command\(hyline tool for controlling NetworkManager
|
|||||||
.sp
|
.sp
|
||||||
|
|
||||||
.IR OBJECT " := { "
|
.IR OBJECT " := { "
|
||||||
.BR general " | " networking " | " radio " | " connection " | " device " | " agent
|
.BR general " | " networking " | " radio " | " connection " | " device " | " agent " | " monitor
|
||||||
.RI " }"
|
.RI " }"
|
||||||
.sp
|
.sp
|
||||||
|
|
||||||
@@ -259,6 +259,16 @@ are supplied, mobile broadband status is printed; \fIon\fP enables mobile broadb
|
|||||||
Show or set all previously mentioned radio switches at the same time.
|
Show or set all previously mentioned radio switches at the same time.
|
||||||
.RE
|
.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
|
.TP
|
||||||
.B connection \- start, stop, and manage network connections
|
.B connection \- start, stop, and manage network connections
|
||||||
.sp
|
.sp
|
||||||
@@ -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.
|
See \fBconnection show\fP above for the description of the <ID>-specifying keywords.
|
||||||
.br
|
.br
|
||||||
Monitors all connection profiles in case none is specified. The command terminates
|
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
|
.TP
|
||||||
.B reload
|
.B reload
|
||||||
.br
|
.br
|
||||||
@@ -861,7 +872,8 @@ Monitor device activity. This command prints a line whenever the specified devic
|
|||||||
change state.
|
change state.
|
||||||
.br
|
.br
|
||||||
Monitors all devices in case no interface is specified. The monitor terminates when
|
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
|
.TP
|
||||||
.B wifi [list [ifname <ifname>] [bssid <BSSID>]]
|
.B wifi [list [ifname <ifname>] [bssid <BSSID>]]
|
||||||
.br
|
.br
|
||||||
|
Reference in New Issue
Block a user