Skip to content

Commit

Permalink
Autoenabling interfaces during installation only .
Browse files Browse the repository at this point in the history
Conflicts:

	src/modules/NetHwDetection.ycp
  • Loading branch information
mchf committed Oct 10, 2012
1 parent 76a6528 commit 5ca6a09
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 23 deletions.
10 changes: 8 additions & 2 deletions src/modules/Lan.ycp
Expand Up @@ -290,8 +290,14 @@ Check configuration manually."));
/* Progress step 2/9 */
if (gui) ProgressNextStage(_("Detecting network devices..."));
// Dont read hardware data in config mode
if(!Mode::config ()) {
if(!NetHwDetection::running) NetHwDetection::Start();
if(!Mode::config ())
{
NetHwDetection::Start();
}
// Start interfaces iff running installation. See bnc#395014 and bnc#782283
if( Mode::installation())
{
SetAllLinksUp();
}
sleep(sl);

Expand Down
24 changes: 3 additions & 21 deletions src/modules/NetHwDetection.ycp
Expand Up @@ -78,7 +78,7 @@ list<string> detection_modules = [];
* WATCH OUT, this is the place where modules are loaded
* @return true if success
*/
define boolean StartEthInterface() {
define boolean LoadNetModules() {

y2milestone("Network detection prepare");

Expand Down Expand Up @@ -114,29 +114,11 @@ define boolean StartEthInterface() {
SCR::Execute (.target.bash, sformat ("/sbin/modprobe --use-blacklist %1 2>&1", mod));
});


string command = "ls /sys/class/net|grep -v \"^lo$\"";
map<string, any> output = (map<string, any>)SCR::Execute(.target.bash_output, command);
if (output["exit"]:-1==0){
list<string> interfaces = filter(string s, splitstring(output["stdout"]:"", "\n"), {return (size(s)>0);});
y2internal("output %1", interfaces);
foreach(string ifc, interfaces, {
// TODO: do some tests before uncomment block bellow
// if ((integer)SCR::Execute(.target.bash, sformat("ip link show %1|head -n1|grep -q \"[^[:alpha:]]UP[^[:alpha:]]\"", ifc))!=0)
// {
y2milestone("Setting link up for interface %1", ifc);
SCR::Execute(.target.bash, sformat("ip link set %1 up", ifc));
// } else y2milestone("Link for %1 interface is already up, nothing to do", ifc);
});
} else y2error("Error while execute %1 : %2", command, output);

y2milestone("Network detection prepare (end)");

return true;
}




/**
* Start the detection
* @return true on success
Expand All @@ -149,7 +131,7 @@ global define boolean Start() {

y2milestone("IFCONFIG1: %1", SCR::Execute(.target.bash_output, "/sbin/ifconfig"));
boolean ret = false;
if(StartEthInterface()) {
if( LoadNetModules()) {
running = true;
ret = true;
}
Expand Down
77 changes: 77 additions & 0 deletions src/routines/routines.ycp
Expand Up @@ -832,6 +832,83 @@ define list<map> ReadHardware(string hwtype) {
return Hardware;
}

/*
* TODO - begin:
* Following functions should be generalized and ported into yast-yast2
*/

boolean IsEmptyString( string str)
{
return ( str == nil) || isempty( str);
}

/**
* @param Shell command to run
* @return Hash in form $[ "exit": <command-exit-status>, "output": [ <1st line>, <2nd line>, ... ] ]
*/
map< string, any> RunAndRead( string command)
{
map< string, any> ret = $[ "exit": false, "output": [] ];
map result = ( map) SCR::Execute( .target.bash_output, command);
string output = result[ "stdout"]:"";

if( regexpmatch( output, ".*\n$"))
output = substring( output, 0, size( output) -1 );

ret[ "output"] = splitstring( output, "\n");
ret[ "exit"] = result[ "exit"]:1 == 0;

if( ( ret[ "exit"]:false == false) || ( IsEmptyString( result[ "stderr"]:"") == false) )
{
y2error( "RunAndRead <%1>: Command execution failed.\n%2", command, result[ "stderr"]:"");
}

return ret;
}

/**
* @param Shell command to run
* @return whether command execution succeeds
*/
boolean Run( string command)
{
boolean ret = SCR::Execute( .target.bash, command) == 0;

if( !ret)
{
y2error( "Run <%1>: Command execution failed.", command);
}

return ret;
}
/* TODO - end */

/**
* Return list of all interfaces present in the system (not only configured ones as NetworkInterfaces::List does).
*
* @return list of interface names.
*/
define list<string> GetAllInterfaces()
{
map<string, any> result = RunAndRead( "ls /sys/class/net");

return result[ "exit"]:false ? result[ "output"]:[] : [];
}

define boolean SetAllLinksUp()
{
list< string> interfaces = GetAllInterfaces();
boolean ret = size( interfaces) > 0;

foreach(string ifc, interfaces,
{
y2milestone("Setting link up for interface %1", ifc);
ret = Run( sformat("ip link set %1 up", ifc) ) && ret;
});

return ret;
}

boolean validPrefixOrNetmask(string ip, string mask){

boolean valid_mask=false;
Expand Down

0 comments on commit 5ca6a09

Please sign in to comment.