Skip to content

Commit

Permalink
Merge pull request #44 from mchf/master
Browse files Browse the repository at this point in the history
DNS CLI supports editing nameservers.
https://fate.suse.com/312733
  • Loading branch information
mvidner committed Jan 23, 2013
2 parents bafcfc6 + 4446a76 commit a9540ba
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 11 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
2.24.12
2.24.13
7 changes: 7 additions & 0 deletions package/yast2-network.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Mon Jan 21 20:09:15 UTC 2013 - mfilka@suse.com

- fate#312733
- nameservers editing supported via CLI
- 2.24.13

-------------------------------------------------------------------
Thu Jan 17 16:12:32 CET 2013 - locilka@suse.com

Expand Down
102 changes: 92 additions & 10 deletions src/clients/dns.ycp
Expand Up @@ -58,6 +58,11 @@ define boolean Modified() {
include "network/runtime.ycp";
include "network/services/dns.ycp";

const string HOSTNAME = "hostname";
const string NAMESERVER_1 = "nameserver1";
const string NAMESERVER_2 = "nameserver2";
const string NAMESERVER_3 = "nameserver3";

/**
* Main DNS GUI
*/
Expand Down Expand Up @@ -107,19 +112,76 @@ define boolean ListHandler(map<string, string> options) {
*/
define boolean EditHandler(map<string, string> options)
{
string new_hostname = options[ "hostname"]:"";

y2milestone( "Edit handler, options: %1", options);

if( ! Hostname::Check( new_hostname))
// validator: a reference to boolean( string) is expected
// setter: a reference to void( any) is expected
// fail message: a string is expected
map< string, map< string, any> > option_handlers = $[
HOSTNAME: $[
"validator": Hostname::Check,
"setter": SetHostname,
"fail_message": _( "InvalidHostname. ") + Hostname::ValidHost(),
],
NAMESERVER_1: $[
"validator": IP::Check,
"setter": SetNameserver1,
"fail_message": _( "Invalid IP. ") + IP::Valid4() + "\n" + IP::Valid6(),
],
NAMESERVER_2: $[
"validator": IP::Check,
"setter": SetNameserver2,
"fail_message": _( "Invalid IP. ") + IP::Valid4() + "\n" + IP::Valid6(),
],
NAMESERVER_3: $[
"validator": IP::Check,
"setter": SetNameserver3,
"fail_message": _( "Invalid IP. ") + IP::Valid4() + "\n" + IP::Valid6(),
],
];

const list< string> unmanaged_only_options = [
NAMESERVER_1,
NAMESERVER_2,
NAMESERVER_3,
];

boolean ret = true;

foreach( string option, string value, options,
{
CommandLine::Print( _( "Invalid hostname. ") + Hostname::ValidHost() );
return false;
}
if( contains( unmanaged_only_options, option) && NetworkService::IsManaged() )
{
CommandLine::Print( _("Cannot set ") + option + _(". Network is managed by NetworkManager."));

ret = false;
}

SetHostname( new_hostname);
boolean( string) option_validator = ( boolean( string)) option_handlers[ option, "validator"]:nil;
void( any) option_setter = ( void( any)) option_handlers[ option, "setter"]:nil;
string fail_message = ( string) option_handlers[ option, "fail_message"]:_( "Invalid option value.");

return true;
if( ( option_validator == nil) || ( option_setter == nil))
{
y2internal( "Edit handler: unknown option (%1=%2) or unknown option handlers", option, value);

CommandLine::Print( _("Internal error") );

ret = false;
}

if( option_validator( value))
{
option_setter( value);
}
else
{
CommandLine::Print( fail_message);
ret = false;
}
});

return ret;
}

/**
Expand Down Expand Up @@ -169,14 +231,34 @@ map cmdline = $[
],
],
"options" : $[
"hostname" : $[
HOSTNAME : $[
"help" : _( "Used machine hostname"),
"type" : "string",
"example" : "dns edit hostname=SUSE-host",
],
NAMESERVER_1 : $[
"help" : _( "IP address of first nameserver."),
"type" : "string",
"example" : "dns edit nameserver1=192.168.0.1",
],
NAMESERVER_2 : $[
"help" : _( "IP address of second nameserver."),
"type" : "string",
"example" : "dns edit nameserver2=192.168.0.1",
],
NAMESERVER_3 : $[
"help" : _( "IP address of third nameserver."),
"type" : "string",
"example" : "dns edit nameserver3=192.168.0.1",
],
],
"mappings" : $[
"edit" : [ "hostname" ],
"edit" : [
HOSTNAME,
NAMESERVER_1,
NAMESERVER_2,
NAMESERVER_3,
],
],
];

Expand Down
24 changes: 24 additions & 0 deletions src/services/dns.ycp
Expand Up @@ -179,6 +179,30 @@ define void SetHostname( any value)
SetHnItem( "HOSTNAME", value);
}

/**
* Function for updating ip address of first nameserver.
*/
define void SetNameserver1( any value)
{
SetHnItem( "NAMESERVER_1", value);
}

/**
* Function for updating ip address of second nameserver.
*/
define void SetNameserver2( any value)
{
SetHnItem( "NAMESERVER_2", value);
}

/**
* Function for updating ip address of third nameserver.
*/
define void SetNameserver3( any value)
{
SetHnItem( "NAMESERVER_3", value);
}

/**
* Default function to init the value of a widget.
* Used for push buttons.
Expand Down

0 comments on commit a9540ba

Please sign in to comment.