Commit 79ac1cf0 authored by Jiří Klimeš's avatar Jiří Klimeš

cli: add support for getting/setting hostname to nmcli (rh #1018510)

https://bugzilla.redhat.com/show_bug.cgi?id=1018510
parent d95da820
......@@ -93,8 +93,9 @@ usage_general (void)
{
fprintf (stderr,
_("Usage: nmcli general { COMMAND | help }\n\n"
" COMMAND := { status | permissions | logging }\n\n"
" COMMAND := { status | hostname | permissions | logging }\n\n"
" status\n\n"
" hostname [<hostname>]\n\n"
" permissions\n\n"
" logging [level <log level>] [domains <log domains>]\n\n"
));
......@@ -445,6 +446,19 @@ show_general_logging (NmCli *nmc)
return TRUE;
}
static void
save_hostname_cb (NMRemoteSettings *settings, GError *error, gpointer user_data)
{
NmCli *nmc = (NmCli *) user_data;
if (error) {
g_string_printf (nmc->return_text, _("Error: failed to set hostname: (%d) %s"),
error->code, error->message);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
}
quit ();
}
/*
* Entry point function for general operations 'nmcli general'
*/
......@@ -474,6 +488,35 @@ do_general (NmCli *nmc, int argc, char **argv)
}
show_nm_status (nmc, NULL, NULL);
}
else if (matches (*argv, "hostname") == 0) {
NMRemoteSettings *rem_settings;
/* get system settings */
if (!(rem_settings = nm_remote_settings_new (NULL))) {
g_string_printf (nmc->return_text, _("Error: Could not get system settings."));
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
goto finish;
}
if (next_arg (&argc, &argv) != 0) {
/* no arguments -> get hostname */
char *hostname = NULL;
g_object_get (rem_settings, NM_REMOTE_SETTINGS_HOSTNAME, &hostname, NULL);
if (hostname)
printf ("%s\n", hostname);
g_free (hostname);
} else {
/* hostname provided -> set it */
const char *hostname = *argv;
if (next_arg (&argc, &argv) == 0)
printf ("Warning: ignoring extra garbage after '%s' hostname\n", hostname);
nmc->should_wait = TRUE;
nm_remote_settings_save_hostname (rem_settings, hostname, save_hostname_cb, nmc);
}
}
else if (matches (*argv, "permissions") == 0) {
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error)) {
g_string_printf (nmc->return_text, _("Error: %s."), error->message);
......@@ -527,7 +570,6 @@ do_general (NmCli *nmc, int argc, char **argv)
finish:
if (error)
g_error_free (error);
quit ();
return nmc->return_value;
}
......
......@@ -21,7 +21,7 @@
.\"
.\" Copyright (C) 2010 - 2013 Red Hat, Inc.
.\"
.TH NMCLI "1" "31 October 2013"
.TH NMCLI "1" "7 November 2013"
.SH NAME
nmcli \- command\(hyline tool for controlling NetworkManager
......@@ -147,12 +147,12 @@ Show \fInmcli\fP version.
Print help information.
.SS \fIOBJECT\fP
.TP
.B general \- general NetworkManager status and operations
.B general \- general \fINetworkManager\fP status and operations
.br
Use this object to show NetworkManager status and permissions. You can also get
and change NetworkManager logging level and domains.
and change system hostname, as well as NetworkManager logging level and domains.
.TP
.SS \fICOMMAND\fP := { status | permissions | logging }
.SS \fICOMMAND\fP := { status | hostname | permissions | logging }
.sp
.RS
.TP
......@@ -161,6 +161,12 @@ and change NetworkManager logging level and domains.
Show overall status of NetworkManager. This is the default action, when no additional
command is provided for \fIgeneral\fP object.
.TP
.B hostname [<hostname>]
.br
Get and change system hostname. With no arguments, this prints currently configured hostname.
When you pass a hostname, it will be handed over to NetworkManager to be set as a new system
hostname.
.TP
.B permissions
.br
Show the permissions a caller has for various authenticated operations that
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment