cli: be more verbose when adding IP addresses in questionnaire (rh #1006450)

Now the session looks like this:
Do you want to add IP addresses? (yes/no) [yes]
Press <Enter> to finish adding addresses.
IPv4 address (IP[/plen] [gateway]) [none]: 10.0.0.22/24 10.0.0.1
  Address successfully added: 10.0.0.22/24 10.0.0.1
IPv4 address (IP[/plen] [gateway]) [none]: 10.0.0.22/24 10.0.0.1
  Warning: address already present: 10.0.0.22/24 10.0.0.1
IPv4 address (IP[/plen] [gateway]) [none]: 192.168.1.1 abc
Error: invalid gateway 'abc'
IPv4 address (IP[/plen] [gateway]) [none]:
IPv6 address (IP[/plen] [gateway]) [none]: abcd::1234 ::2 blabla
  Address successfully added: abcd::1234 ::2
  Warning: ignoring garbage at the end: 'blabla'
IPv6 address (IP[/plen] [gateway]) [none]:
This commit is contained in:
Jiří Klimeš
2013-09-19 13:14:37 +02:00
parent 469febc0d9
commit 5ba3e42b1e

View File

@@ -2221,6 +2221,7 @@ static gboolean
add_ip4_address_to_connection (NMIP4Address *ip4addr, NMConnection *connection)
{
NMSettingIP4Config *s_ip4;
gboolean ret;
if (!ip4addr)
return TRUE;
@@ -2233,16 +2234,17 @@ add_ip4_address_to_connection (NMIP4Address *ip4addr, NMConnection *connection)
NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
NULL);
}
nm_setting_ip4_config_add_address (s_ip4, ip4addr);
ret = nm_setting_ip4_config_add_address (s_ip4, ip4addr);
nm_ip4_address_unref (ip4addr);
return TRUE;
return ret;
}
static gboolean
add_ip6_address_to_connection (NMIP6Address *ip6addr, NMConnection *connection)
{
NMSettingIP6Config *s_ip6;
gboolean ret;
if (!ip6addr)
return TRUE;
@@ -2255,10 +2257,10 @@ add_ip6_address_to_connection (NMIP6Address *ip6addr, NMConnection *connection)
NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL,
NULL);
}
nm_setting_ip6_config_add_address (s_ip6, ip6addr);
ret = nm_setting_ip6_config_add_address (s_ip6, ip6addr);
nm_ip6_address_unref (ip6addr);
return TRUE;
return ret;
}
static char *
@@ -2869,12 +2871,14 @@ do_questionnaire_ip (NMConnection *connection)
NMIP4Address *ip4addr;
NMIP6Address *ip6addr;
char *str, *ip, *gw, *rest;
gboolean added;
/* Ask for IP addresses */
answer = nmc_get_user_input (_("Do you want to add IP addresses? (yes/no) [yes] "));
if (answer && (!nmc_string_to_bool (answer, &answer_bool, NULL) || !answer_bool))
return;
printf (_("Press <Enter> to finish adding addresses.\n"));
ip_loop = TRUE;
do {
str = nmc_get_user_input (_("IPv4 address (IP[/plen] [gateway]) [none]: "));
@@ -2882,9 +2886,14 @@ do_questionnaire_ip (NMConnection *connection)
if (ip) {
ip4addr = nmc_parse_and_build_ip4_address (ip, gw, &error);
if (ip4addr) {
add_ip4_address_to_connection (ip4addr, connection);
added = add_ip4_address_to_connection (ip4addr, connection);
gw = gw ? gw : "0.0.0.0";
if (added)
printf (_(" Address successfully added: %s %s\n"), ip, gw);
else
printf (_(" Warning: address already present: %s %s\n"), ip, gw);
if (rest)
printf (_("Warning: ignoring garbage at the end: '%s'\n"), rest);
printf (_(" Warning: ignoring garbage at the end: '%s'\n"), rest);
} else {
g_prefix_error (&error, _("Error: "));
printf ("%s\n", error->message);
@@ -2903,9 +2912,14 @@ do_questionnaire_ip (NMConnection *connection)
if (ip) {
ip6addr = nmc_parse_and_build_ip6_address (ip, gw, &error);
if (ip6addr) {
add_ip6_address_to_connection (ip6addr, connection);
added = add_ip6_address_to_connection (ip6addr, connection);
gw = gw ? gw : "::";
if (added)
printf (_(" Address successfully added: %s %s\n"), ip, gw);
else
printf (_(" Warning: address already present: %s %s\n"), ip, gw);
if (rest)
printf (_("Warning: ignoring garbage at the end: '%s'\n"), rest);
printf (_(" Warning: ignoring garbage at the end: '%s'\n"), rest);
} else {
g_prefix_error (&error, _("Error: "));
printf ("%s\n", error->message);