summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2010-09-27 10:30:46 -0500
committerDan Williams <dcbw@redhat.com>2010-09-27 10:30:46 -0500
commit8b41f70dd54b0621bf4c096dcd9687531566b5dd (patch)
treebd766631d78f5d927afeb335436c66134159e4a3 /cli
parent6e287e41796add8acde11fbe8b4efc3282520969 (diff)
parent9c0a812d52e79dc8214e91c9fa003508485ea03e (diff)
downloadNetworkManager-8b41f70dd54b0621bf4c096dcd9687531566b5dd.tar.gz
Merge remote branch 'origin/master' into rm-userset
Diffstat (limited to 'cli')
-rw-r--r--cli/src/connections.c9
-rw-r--r--cli/src/devices.c12
-rw-r--r--cli/src/network-manager.c121
3 files changed, 117 insertions, 25 deletions
diff --git a/cli/src/connections.c b/cli/src/connections.c
index 20b681b559..606fddadee 100644
--- a/cli/src/connections.c
+++ b/cli/src/connections.c
@@ -60,9 +60,10 @@ static NmcOutputField nmc_fields_con_status[] = {
{"DEFAULT", N_("DEFAULT"), 8, NULL, 0}, /* 3 */
{"SPEC-OBJECT", N_("SPEC-OBJECT"), 10, NULL, 0}, /* 4 */
{"VPN", N_("VPN"), 5, NULL, 0}, /* 5 */
+ {"DBUS-PATH", N_("DBUS-PATH"), 51, NULL, 0}, /* 6 */
{NULL, NULL, 0, NULL, 0}
};
-#define NMC_FIELDS_CON_STATUS_ALL "NAME,UUID,DEVICES,DEFAULT,VPN,SPEC-OBJECT"
+#define NMC_FIELDS_CON_STATUS_ALL "NAME,UUID,DEVICES,DEFAULT,VPN,DBUS-PATH,SPEC-OBJECT"
#define NMC_FIELDS_CON_STATUS_COMMON "NAME,UUID,DEVICES,DEFAULT,VPN"
/* Available fields for 'con list' */
@@ -74,9 +75,10 @@ static NmcOutputField nmc_fields_con_list[] = {
{"TIMESTAMP-REAL", N_("TIMESTAMP-REAL"), 34, NULL, 0}, /* 4 */
{"AUTOCONNECT", N_("AUTOCONNECT"), 13, NULL, 0}, /* 5 */
{"READONLY", N_("READONLY"), 10, NULL, 0}, /* 6 */
+ {"DBUS-PATH", N_("DBUS-PATH"), 42, NULL, 0}, /* 7 */
{NULL, NULL, 0, NULL, 0}
};
-#define NMC_FIELDS_CON_LIST_ALL "NAME,UUID,TYPE,TIMESTAMP,TIMESTAMP-REAL,AUTOCONNECT,READONLY"
+#define NMC_FIELDS_CON_LIST_ALL "NAME,UUID,TYPE,TIMESTAMP,TIMESTAMP-REAL,AUTOCONNECT,READONLY,DBUS-PATH"
#define NMC_FIELDS_CON_LIST_COMMON "NAME,UUID,TYPE,TIMESTAMP-REAL"
@@ -370,6 +372,7 @@ show_connection (NMConnection *data, gpointer user_data)
timestamp = nm_setting_connection_get_timestamp (s_con);
timestamp_str = g_strdup_printf ("%" G_GUINT64_FORMAT, timestamp);
strftime (timestamp_real_str, sizeof (timestamp_real_str), "%c", localtime ((time_t *) &timestamp));
+
nmc->allowed_fields[0].value = nm_setting_connection_get_id (s_con);
nmc->allowed_fields[1].value = nm_setting_connection_get_uuid (s_con);
nmc->allowed_fields[2].value = nm_setting_connection_get_connection_type (s_con);
@@ -377,6 +380,7 @@ show_connection (NMConnection *data, gpointer user_data)
nmc->allowed_fields[4].value = timestamp ? timestamp_real_str : _("never");
nmc->allowed_fields[5].value = nm_setting_connection_get_autoconnect (s_con) ? _("yes") : _("no");
nmc->allowed_fields[6].value = nm_setting_connection_get_read_only (s_con) ? _("yes") : _("no");
+ nmc->allowed_fields[7].value = nm_connection_get_path (connection);
nmc->print_fields.flags &= ~NMC_PF_FLAG_MAIN_HEADER_ADD & ~NMC_PF_FLAG_MAIN_HEADER_ONLY & ~NMC_PF_FLAG_FIELD_NAMES; /* Clear header flags */
print_fields (nmc->print_fields, nmc->allowed_fields);
@@ -552,6 +556,7 @@ show_active_connection (gpointer data, gpointer user_data)
nmc->allowed_fields[3].value = nm_active_connection_get_default (active) ? _("yes") : _("no");
nmc->allowed_fields[4].value = nm_active_connection_get_specific_object (active);
nmc->allowed_fields[5].value = NM_IS_VPN_CONNECTION (active) ? _("yes") : _("no");
+ nmc->allowed_fields[6].value = nm_object_get_path (NM_OBJECT (active));
nmc->print_fields.flags &= ~NMC_PF_FLAG_MAIN_HEADER_ADD & ~NMC_PF_FLAG_MAIN_HEADER_ONLY & ~NMC_PF_FLAG_FIELD_NAMES; /* Clear header flags */
print_fields (nmc->print_fields, nmc->allowed_fields);
diff --git a/cli/src/devices.c b/cli/src/devices.c
index 7c9dcc5210..436b4b6eb8 100644
--- a/cli/src/devices.c
+++ b/cli/src/devices.c
@@ -58,12 +58,13 @@
/* Available fields for 'dev status' */
static NmcOutputField nmc_fields_dev_status[] = {
- {"DEVICE", N_("DEVICE"), 10, NULL, 0}, /* 0 */
- {"TYPE", N_("TYPE"), 17, NULL, 0}, /* 1 */
- {"STATE", N_("STATE"), 12, NULL, 0}, /* 2 */
- {NULL, NULL, 0, NULL, 0}
+ {"DEVICE", N_("DEVICE"), 10, NULL, 0}, /* 0 */
+ {"TYPE", N_("TYPE"), 17, NULL, 0}, /* 1 */
+ {"STATE", N_("STATE"), 13, NULL, 0}, /* 2 */
+ {"DBUS-PATH", N_("DBUS-PATH"), 43, NULL, 0}, /* 3 */
+ {NULL, NULL, 0, NULL, 0}
};
-#define NMC_FIELDS_DEV_STATUS_ALL "DEVICE,TYPE,STATE"
+#define NMC_FIELDS_DEV_STATUS_ALL "DEVICE,TYPE,STATE,DBUS-PATH"
#define NMC_FIELDS_DEV_STATUS_COMMON "DEVICE,TYPE,STATE"
@@ -763,6 +764,7 @@ show_device_status (NMDevice *device, NmCli *nmc)
nmc->allowed_fields[0].value = nm_device_get_iface (device);
nmc->allowed_fields[1].value = get_device_type (device);
nmc->allowed_fields[2].value = device_state_to_string (nm_device_get_state (device));
+ nmc->allowed_fields[3].value = nm_object_get_path (NM_OBJECT (device));
nmc->print_fields.flags &= ~NMC_PF_FLAG_MAIN_HEADER_ADD & ~NMC_PF_FLAG_MAIN_HEADER_ONLY & ~NMC_PF_FLAG_FIELD_NAMES; /* Clear header flags */
print_fields (nmc->print_fields, nmc->allowed_fields);
diff --git a/cli/src/network-manager.c b/cli/src/network-manager.c
index b65dfcd7bd..23a2ef11e7 100644
--- a/cli/src/network-manager.c
+++ b/cli/src/network-manager.c
@@ -34,14 +34,16 @@
static NmcOutputField nmc_fields_nm_status[] = {
{"RUNNING", N_("RUNNING"), 15, NULL, 0}, /* 0 */
{"STATE", N_("STATE"), 15, NULL, 0}, /* 1 */
- {"WIFI-HARDWARE", N_("WIFI-HARDWARE"), 15, NULL, 0}, /* 2 */
- {"WIFI", N_("WIFI"), 10, NULL, 0}, /* 3 */
- {"WWAN-HARDWARE", N_("WWAN-HARDWARE"), 15, NULL, 0}, /* 4 */
- {"WWAN", N_("WWAN"), 10, NULL, 0}, /* 5 */
+ {"NET-ENABLED", N_("NET-ENABLED"), 13, NULL, 0}, /* 2 */
+ {"WIFI-HARDWARE", N_("WIFI-HARDWARE"), 15, NULL, 0}, /* 3 */
+ {"WIFI", N_("WIFI"), 10, NULL, 0}, /* 4 */
+ {"WWAN-HARDWARE", N_("WWAN-HARDWARE"), 15, NULL, 0}, /* 5 */
+ {"WWAN", N_("WWAN"), 10, NULL, 0}, /* 6 */
{NULL, NULL, 0, NULL, 0}
};
-#define NMC_FIELDS_NM_STATUS_ALL "RUNNING,STATE,WIFI-HARDWARE,WIFI,WWAN-HARDWARE,WWAN"
+#define NMC_FIELDS_NM_STATUS_ALL "RUNNING,STATE,NET-ENABLED,WIFI-HARDWARE,WIFI,WWAN-HARDWARE,WWAN"
#define NMC_FIELDS_NM_STATUS_COMMON "RUNNING,STATE,WIFI-HARDWARE,WIFI,WWAN-HARDWARE,WWAN"
+#define NMC_FIELDS_NM_NET_ENABLED "NET-ENABLED"
#define NMC_FIELDS_NM_WIFI "WIFI"
#define NMC_FIELDS_NM_WWAN "WWAN"
@@ -60,10 +62,10 @@ usage (void)
{
fprintf (stderr,
_("Usage: nmcli nm { COMMAND | help }\n\n"
- " COMMAND := { status | sleep | wakeup | wifi | wwan }\n\n"
+ " COMMAND := { status | enable | sleep | wifi | wwan }\n\n"
" status\n"
- " sleep\n"
- " wakeup\n"
+ " enable [true|false]\n"
+ " sleep [true|false]\n"
" wifi [on|off]\n"
" wwan [on|off]\n\n"));
}
@@ -97,6 +99,7 @@ static NMCResultCode
show_nm_status (NmCli *nmc)
{
gboolean nm_running;
+ gboolean net_enabled;
NMState state;
const char *wireless_hw_enabled_str, *wireless_enabled_str;
const char *wwan_hw_enabled_str, *wwan_enabled_str;
@@ -136,6 +139,7 @@ show_nm_status (NmCli *nmc)
nm_running = nm_client_get_manager_running (nmc->client);
state = nm_client_get_state (nmc->client);
+ net_enabled = nm_client_networking_get_enabled (nmc->client);
if (nm_running) {
wireless_hw_enabled_str = nm_client_wireless_hardware_get_enabled (nmc->client) ? _("enabled") : _("disabled");
wireless_enabled_str = nm_client_wireless_get_enabled (nmc->client) ? _("enabled") : _("disabled");
@@ -147,10 +151,11 @@ show_nm_status (NmCli *nmc)
nmc->allowed_fields[0].value = nm_running ? _("running") : _("not running");
nmc->allowed_fields[1].value = nm_state_to_string (state);
- nmc->allowed_fields[2].value = wireless_hw_enabled_str;
- nmc->allowed_fields[3].value = wireless_enabled_str;
- nmc->allowed_fields[4].value = wwan_hw_enabled_str;
- nmc->allowed_fields[5].value = wwan_enabled_str;
+ nmc->allowed_fields[2].value = net_enabled ? _("enabled") : _("disabled");
+ nmc->allowed_fields[3].value = wireless_hw_enabled_str;
+ nmc->allowed_fields[4].value = wireless_enabled_str;
+ nmc->allowed_fields[5].value = wwan_hw_enabled_str;
+ nmc->allowed_fields[6].value = wwan_enabled_str;
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag;
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */
@@ -158,12 +163,49 @@ show_nm_status (NmCli *nmc)
return NMC_RESULT_SUCCESS;
}
+/* libnm-glib doesn't provide API fro Sleep method - implement D-Bus call ourselves */
+static void networking_set_sleep (NmCli *nmc, gboolean in_sleep)
+{
+ DBusGConnection *connection = NULL;
+ DBusGProxy *proxy = NULL;
+ GError *err = NULL;
+
+ connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err);
+ if (!connection) {
+ g_string_printf (nmc->return_text, _("Error: Couldn't connect to system bus: %s"), err->message);
+ nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
+ g_error_free (err);
+ goto gone;
+ }
+
+ proxy = dbus_g_proxy_new_for_name (connection,
+ "org.freedesktop.NetworkManager",
+ "/org/freedesktop/NetworkManager",
+ "org.freedesktop.NetworkManager");
+ if (!proxy) {
+ g_string_printf (nmc->return_text, _("Error: Couldn't create D-Bus object proxy."));
+ nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
+ goto gone;
+ }
+
+ if (!dbus_g_proxy_call (proxy, "Sleep", &err, G_TYPE_BOOLEAN, in_sleep, G_TYPE_INVALID, G_TYPE_INVALID)) {
+ g_string_printf (nmc->return_text, _("Error in sleep: %s"), err->message);
+ nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
+ g_error_free (err);
+ }
+
+gone:
+ if (connection) dbus_g_connection_unref (connection);
+ if (proxy) g_object_unref (proxy);
+}
/* entry point function for global network manager related commands 'nmcli nm' */
NMCResultCode
do_network_manager (NmCli *nmc, int argc, char **argv)
{
GError *error = NULL;
+ gboolean sleep_flag;
+ gboolean enable_net;
gboolean enable_wifi;
gboolean enable_wwan;
guint32 mode_flag = (nmc->print_output == NMC_PRINT_PRETTY) ? NMC_PF_FLAG_PRETTY : (nmc->print_output == NMC_PRINT_TERSE) ? NMC_PF_FLAG_TERSE : 0;
@@ -186,11 +228,54 @@ do_network_manager (NmCli *nmc, int argc, char **argv)
goto opt_error;
nmc->return_value = show_nm_status (nmc);
}
- else if (matches (*argv, "sleep") == 0) {
- nm_client_sleep (nmc->client, TRUE);
+ else if (matches (*argv, "enable") == 0) {
+ if (next_arg (&argc, &argv) != 0) {
+ /* no argument, show current state of networking */
+ if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
+ goto opt_error;
+ if (nmc->required_fields && strcasecmp (nmc->required_fields, "NET-ENABLED")) {
+ g_string_printf (nmc->return_text, _("Error: '--fields' value '%s' is not valid here; allowed fields: %s"),
+ nmc->required_fields, NMC_FIELDS_NM_NET_ENABLED);
+ nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
+ goto end;
+ }
+ nmc->allowed_fields = nmc_fields_nm_status;
+ nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_NM_NET_ENABLED, nmc->allowed_fields, NULL);
+ nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_MAIN_HEADER_ADD | NMC_PF_FLAG_FIELD_NAMES;
+ nmc->print_fields.header_name = _("Networking enabled");
+ print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
+ nmc->allowed_fields[2].value = nm_client_networking_get_enabled (nmc->client) ? _("enabled") : _("disabled");
+ nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag;
+ print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
+ } else {
+ if (!strcmp (*argv, "true"))
+ enable_net = TRUE;
+ else if (!strcmp (*argv, "false"))
+ enable_net = FALSE;
+ else {
+ g_string_printf (nmc->return_text, _("Error: invalid 'enable' parameter: '%s'; use 'true' or 'false'."), *argv);
+ nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
+ goto end;
+ }
+ nm_client_networking_set_enabled (nmc->client, enable_net);
+ }
}
- else if (matches (*argv, "wakeup") == 0) {
- nm_client_sleep (nmc->client, FALSE);
+ else if (matches (*argv, "sleep") == 0) {
+ if (next_arg (&argc, &argv) != 0) {
+ g_string_printf (nmc->return_text, _("Error: Sleeping status is not exported by NetworkManager."));
+ nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
+ } else {
+ if (!strcmp (*argv, "true"))
+ sleep_flag = TRUE;
+ else if (!strcmp (*argv, "false"))
+ sleep_flag = FALSE;
+ else {
+ g_string_printf (nmc->return_text, _("Error: invalid 'sleep' parameter: '%s'; use 'true' or 'false'."), *argv);
+ nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
+ goto end;
+ }
+ networking_set_sleep (nmc, sleep_flag);
+ }
}
else if (matches (*argv, "wifi") == 0) {
if (next_arg (&argc, &argv) != 0) {
@@ -208,7 +293,7 @@ do_network_manager (NmCli *nmc, int argc, char **argv)
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_MAIN_HEADER_ADD | NMC_PF_FLAG_FIELD_NAMES;
nmc->print_fields.header_name = _("WiFi enabled");
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
- nmc->allowed_fields[3].value = nm_client_wireless_get_enabled (nmc->client) ? _("enabled") : _("disabled");
+ nmc->allowed_fields[4].value = nm_client_wireless_get_enabled (nmc->client) ? _("enabled") : _("disabled");
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag;
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
} else {
@@ -240,7 +325,7 @@ do_network_manager (NmCli *nmc, int argc, char **argv)
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_MAIN_HEADER_ADD | NMC_PF_FLAG_FIELD_NAMES;
nmc->print_fields.header_name = _("WWAN enabled");
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
- nmc->allowed_fields[5].value = nm_client_wwan_get_enabled (nmc->client) ? _("enabled") : _("disabled");
+ nmc->allowed_fields[6].value = nm_client_wwan_get_enabled (nmc->client) ? _("enabled") : _("disabled");
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag;
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
} else {