summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-06-10 15:27:59 +0200
committerThomas Haller <thaller@redhat.com>2020-06-10 15:30:38 +0200
commit9959bc58de5c331e2ef29034d03c3c81bda12a52 (patch)
tree15004dd4a2bcaf9111c7aa1d6e290f49d625a762
parent1573ca755b248b6f50b0882f27ca2d1c88a39443 (diff)
downloadNetworkManager-th/mark-external-connection.tar.gz
cli: show differnt text for state of externally connected devicesth/mark-external-connection
-rw-r--r--clients/cli/connections.c4
-rw-r--r--clients/cli/devices.c16
-rw-r--r--clients/cli/general.c6
-rw-r--r--clients/common/nm-client-utils.c32
-rw-r--r--clients/common/nm-client-utils.h2
5 files changed, 44 insertions, 16 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c
index 5a4a8ecc3f..44e34d56a6 100644
--- a/clients/cli/connections.c
+++ b/clients/cli/connections.c
@@ -2613,7 +2613,7 @@ progress_active_connection_cb (gpointer user_data)
}
str = device
- ? gettext (nmc_device_state_to_string (nm_device_get_state (device)))
+ ? gettext (nmc_device_state_to_string_with_external (device))
: active_connection_state_to_string (ac_state);
nmc_terminal_show_progress (str);
@@ -6820,7 +6820,7 @@ progress_activation_editor_cb (gpointer user_data)
ac_state = nm_active_connection_get_state (ac);
dev_state = nm_device_get_state (device);
- nmc_terminal_show_progress (gettext (nmc_device_state_to_string (dev_state)));
+ nmc_terminal_show_progress (gettext (nmc_device_state_to_string_with_external (device)));
if ( ac_state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED
|| dev_state == NM_DEVICE_STATE_ACTIVATED) {
diff --git a/clients/cli/devices.c b/clients/cli/devices.c
index 031017283d..eaa9f0c3d1 100644
--- a/clients/cli/devices.c
+++ b/clients/cli/devices.c
@@ -100,7 +100,7 @@ _metagen_device_status_get_fcn (NMC_META_GENERIC_INFO_GET_FCN_ARGS)
case NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_TYPE:
return nm_device_get_type_description (d);
case NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_STATE:
- return nmc_meta_generic_get_str_i18n (nmc_device_state_to_string (nm_device_get_state (d)),
+ return nmc_meta_generic_get_str_i18n (nmc_device_state_to_string_with_external (d),
get_type);
case NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_IP4_CONNECTIVITY:
return nmc_meta_generic_get_str_i18n (nm_connectivity_to_string (nm_device_get_connectivity (d, AF_INET)),
@@ -147,7 +147,6 @@ _metagen_device_detail_general_get_fcn (NMC_META_GENERIC_INFO_GET_FCN_ARGS)
{
NMDevice *d = target;
NMActiveConnection *ac;
- NMDeviceState state;
NMDeviceStateReason state_reason;
NMConnectivityState connectivity;
const char *s;
@@ -180,10 +179,9 @@ _metagen_device_detail_general_get_fcn (NMC_META_GENERIC_INFO_GET_FCN_ARGS)
case NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_MTU:
return (*out_to_free = g_strdup_printf ("%u", (guint) nm_device_get_mtu (d)));
case NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_STATE:
- state = nm_device_get_state (d);
return (*out_to_free = nmc_meta_generic_get_enum_with_detail (NMC_META_GENERIC_GET_ENUM_TYPE_PARENTHESES,
- state,
- nmc_device_state_to_string (state),
+ nm_device_get_state (d),
+ nmc_device_state_to_string_with_external (d),
get_type));
case NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_REASON:
state_reason = nm_device_get_state_reason (d);
@@ -1849,7 +1847,7 @@ progress_cb (gpointer user_data)
{
NMDevice *device = (NMDevice *) user_data;
- nmc_terminal_show_progress (device ? gettext (nmc_device_state_to_string (nm_device_get_state (device))) : "");
+ nmc_terminal_show_progress (device ? gettext (nmc_device_state_to_string_with_external (device)) : "");
return TRUE;
}
@@ -2620,17 +2618,15 @@ do_device_set (const NMCCommand *cmd, NmCli *nmc, int argc, const char *const*ar
static void
device_state (NMDevice *device, GParamSpec *pspec, NmCli *nmc)
{
- NMDeviceState state = nm_device_get_state (device);
+ gs_free char *str = NULL;
NMMetaColor color;
- char *str;
color = nmc_device_state_to_color (device);
str = nmc_colorize (&nmc->nmc_config, color, "%s: %s\n",
nm_device_get_iface (device),
- gettext (nmc_device_state_to_string (state)));
+ gettext (nmc_device_state_to_string_with_external (device)));
g_print ("%s", str);
- g_free (str);
}
static void
diff --git a/clients/cli/general.c b/clients/cli/general.c
index 550ccb14d0..a771e1d58f 100644
--- a/clients/cli/general.c
+++ b/clients/cli/general.c
@@ -1426,25 +1426,23 @@ nmc_command_func_overview (const NMCCommand *cmd, NmCli *nmc, int argc, const ch
devices = nmc_get_devices_sorted (nmc->client);
for (i = 0; devices[i]; i++) {
NMDevice *device = devices[i];
- NMDeviceState state;
ac = nm_device_get_active_connection (device);
- state = nm_device_get_state (device);
color = nmc_device_state_to_color (device);
if (ac) {
/* TRANSLATORS: prints header line for activated device in plain `nmcli` overview output as
* "<interface-name>: <device-state> to <connection-id>" */
tmp = nmc_colorize (&nmc->nmc_config, color, C_("nmcli-overview", "%s: %s to %s"),
nm_device_get_iface (device),
- gettext (nmc_device_state_to_string (state)),
+ gettext (nmc_device_state_to_string_with_external (device)),
nm_active_connection_get_id (ac));
} else {
/* TRANSLATORS: prints header line for not active device in plain `nmcli` overview output as
* "<interface-name>: <device-state>" */
tmp = nmc_colorize (&nmc->nmc_config, color, C_("nmcli-overview", "%s: %s"),
nm_device_get_iface (device),
- gettext (nmc_device_state_to_string (state)));
+ gettext (nmc_device_state_to_string_with_external (device)));
}
g_print ("%s\n", tmp);
g_free (tmp);
diff --git a/clients/common/nm-client-utils.c b/clients/common/nm-client-utils.c
index 97885291d6..d3a02161ce 100644
--- a/clients/common/nm-client-utils.c
+++ b/clients/common/nm-client-utils.c
@@ -265,6 +265,38 @@ NM_UTILS_LOOKUP_STR_DEFINE (nmc_device_state_to_string, NMDeviceState,
NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_UNKNOWN, N_("unknown")),
)
+static
+NM_UTILS_LOOKUP_STR_DEFINE (_device_state_to_string, NMDeviceState,
+ NM_UTILS_LOOKUP_DEFAULT (NULL),
+ NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_PREPARE, N_("connecting (externally)")),
+ NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_CONFIG, N_("connecting (externally)")),
+ NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_NEED_AUTH, N_("connecting (externally)")),
+ NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_IP_CONFIG, N_("connecting (externally)")),
+ NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_IP_CHECK, N_("connecting (externally)")),
+ NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_SECONDARIES, N_("connecting (externally)")),
+ NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_ACTIVATED, N_("connected (externally)")),
+ NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_DEACTIVATING, N_("deactivating (externally)")),
+ NM_UTILS_LOOKUP_ITEM (NM_DEVICE_STATE_FAILED, N_("deactivating (externally)")),
+ NM_UTILS_LOOKUP_ITEM_IGNORE_OTHER (),
+)
+
+const char *
+nmc_device_state_to_string_with_external (NMDevice *device)
+{
+ NMActiveConnection *ac;
+ NMDeviceState state;
+ const char *s;
+
+ state = nm_device_get_state (device);
+
+ if ( (ac = nm_device_get_active_connection (device))
+ && NM_FLAGS_HAS (nm_active_connection_get_state_flags (ac), NM_ACTIVATION_STATE_FLAG_EXTERNAL)
+ && (s = _device_state_to_string (state)))
+ return s;
+
+ return nmc_device_state_to_string (state);
+}
+
NM_UTILS_LOOKUP_STR_DEFINE (nmc_device_metered_to_string, NMMetered,
NM_UTILS_LOOKUP_DEFAULT (N_("unknown")),
NM_UTILS_LOOKUP_ITEM (NM_METERED_YES, N_("yes")),
diff --git a/clients/common/nm-client-utils.h b/clients/common/nm-client-utils.h
index 8983e6c89b..28eac4573f 100644
--- a/clients/common/nm-client-utils.h
+++ b/clients/common/nm-client-utils.h
@@ -28,6 +28,8 @@ gboolean matches (const char *cmd, const char *pattern);
/* FIXME: don't expose this function on its own, at least not from this file. */
const char *nmc_bond_validate_mode (const char *mode, GError **error);
+const char *nmc_device_state_to_string_with_external (NMDevice *device);
+
const char *nm_active_connection_state_reason_to_string (NMActiveConnectionStateReason reason);
const char *nmc_device_state_to_string (NMDeviceState state);
const char *nmc_device_reason_to_string (NMDeviceStateReason reason);