[yast-commit] r40648 - in /trunk/network: VERSION agents/ag_udev_persistent package/yast2-network.changes src/clients/save_network.ycp src/modules/LanUdevAuto.ycp
Author: mzugec Date: Fri Aug 31 15:33:58 2007 New Revision: 40648 URL: http://svn.opensuse.org/viewcvs/yast?rev=40648&view=rev Log: autoyast support for udev rules and backport compatibility with old-style network devices names (#303916) Added: trunk/network/src/modules/LanUdevAuto.ycp Modified: trunk/network/VERSION trunk/network/agents/ag_udev_persistent trunk/network/package/yast2-network.changes trunk/network/src/clients/save_network.ycp Modified: trunk/network/VERSION URL: http://svn.opensuse.org/viewcvs/yast/trunk/network/VERSION?rev=40648&r1=40647&r2=40648&view=diff ============================================================================== --- trunk/network/VERSION (original) +++ trunk/network/VERSION Fri Aug 31 15:33:58 2007 @@ -1 +1 @@ -2.15.70 +2.15.71 Modified: trunk/network/agents/ag_udev_persistent URL: http://svn.opensuse.org/viewcvs/yast/trunk/network/agents/ag_udev_persistent?rev=40648&r1=40647&r2=40648&view=diff ============================================================================== --- trunk/network/agents/ag_udev_persistent (original) +++ trunk/network/agents/ag_udev_persistent Fri Aug 31 15:33:58 2007 @@ -14,6 +14,12 @@ my @net_comment = (); my @drivers_comment = (); +sub set_rules_comment(){ + my $class = shift; + my $pointer = \@_; + @net_comment = @{$$pointer[0]}; +} + sub parse_net_rules { my $class = shift; my %hash_table = (); @@ -101,6 +107,22 @@ } +sub write_net_rules(){ + my $class = shift; + my $param = \@_; + + my @output = (); + foreach my $row (@net_comment, @{$$param[0]}){ + push (@output, $row."\n"); + } + + if( open( FILE, "> $net_file" ) ) { + print FILE @output; + } else { + return $class->SetError(summary => sprintf( _("saving %s failed: %s"),$net_file, $!), + code => "OPEN_FAILED"); + } +} sub Execute { my $class = shift; @@ -125,8 +147,13 @@ my $class = shift; my ($path, @args) = @_; if ($path eq '.drivers'){ - my $hash_pointer = $args[0]; - return $class->write_drivers_rules($hash_pointer); + return $class->write_drivers_rules($args[0]); + } + if ($path eq '.rules'){ + return $class->write_net_rules($args[0]); + } + if ($path eq '.rules_comment'){ + return $class->set_rules_comment($args[0]); } } Modified: trunk/network/package/yast2-network.changes URL: http://svn.opensuse.org/viewcvs/yast/trunk/network/package/yast2-network.changes?rev=40648&r1=40647&r2=40648&view=diff ============================================================================== --- trunk/network/package/yast2-network.changes (original) +++ trunk/network/package/yast2-network.changes Fri Aug 31 15:33:58 2007 @@ -1,4 +1,11 @@ ------------------------------------------------------------------- +Fri Aug 31 15:38:31 CEST 2007 - mzugec@suse.cz + +- autoyast support for udev rules and backport compatibility with + old-style network devices names (#303916) +- 2.15.71 + +------------------------------------------------------------------- Tue Aug 28 14:59:38 CEST 2007 - mzugec@suse.cz - write NAME in propose - (#301977) Modified: trunk/network/src/clients/save_network.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/network/src/clients/save_network.ycp?rev=40648&r1=40647&r2=40648&view=diff ============================================================================== --- trunk/network/src/clients/save_network.ycp (original) +++ trunk/network/src/clients/save_network.ycp Fri Aug 31 15:33:58 2007 @@ -20,6 +20,7 @@ import "NetworkStorage"; import "Installation"; import "String"; +import "Mode"; include "network/routines.ycp"; include "network/complex.ycp"; @@ -205,11 +206,10 @@ string ifcfg = sformat("ifcfg-%1", InstallInf["netdevice"]:""); string hw_name = BuildDescription(NetworkDevices::device_type(ifcfg), NetworkDevices::device_num(ifcfg), $["dev_name":InstallInf["netdevice"]:""], hardware); -y2internal("name %1", hw_name); if (size(hw_name)>0) network_configuration = sformat("%1NAME='%2'\n", network_configuration, hw_name); - y2internal("Network Configuration:\n%1\nifcfg file: %2", network_configuration, ifcfg); + y2milestone("Network Configuration:\n%1\nifcfg file: %2", network_configuration, ifcfg); // write only if file doesn't exists string dev_file=sformat("/etc/sysconfig/network/%1", ifcfg); @@ -300,6 +300,12 @@ WFM::SCRClose (new_SCR); WFM::SCRSetDefault (old_SCR); + if (Mode::autoinst()){ + import "LanUdevAuto"; + LanUdevAuto::Write(); + } + + if(ReadInstallInf()){ // string hwcfgname = CreateHardwareFile(); // string ifcfg = sformat("ifcfg-%1", InstallInf["netdevice"]:""); Added: trunk/network/src/modules/LanUdevAuto.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/network/src/modules/LanUdevAuto.ycp?rev=40648&view=auto ============================================================================== --- trunk/network/src/modules/LanUdevAuto.ycp (added) +++ trunk/network/src/modules/LanUdevAuto.ycp Fri Aug 31 15:33:58 2007 @@ -0,0 +1,85 @@ +/** + * File: modules/LanUdevAuto.ycp + * Package: Network configuration + * Summary: Udev rules for autoinstallation + * Authors: Michal Zugec <mzugec@suse.cz> + * + * $Id: Lan.ycp 40537 2007-08-28 13:22:01Z mzugec $ + * + * Representation of the configuration of network cards. + */ + +{ + module "LanUdevAuto"; + textdomain "network"; + + list<map> udev_rules=[]; + +/** + * internal function: + * check if old-style (ifcfg-eth-id-..., ifcfg-eth-bus-... is used) or new-style (ifcfg-eth0) + */ + boolean oldStyle(map ay){ + boolean old_style_found = false; + foreach(map interface, ay["interfaces"]:[], { + if (issubstring(interface["device"]:"", "-id-")) old_style_found=true; + if (issubstring(interface["device"]:"", "-bus-")) old_style_found=true; + }); + y2milestone("old-style found:%1", old_style_found); + return old_style_found; + } + +/** + * internal function: + * for old-slyle create udev rules and rename interface names to new-style + */ + list<map> createUdevFromIfaceName(list<map> interfaces){ + y2milestone("old-style names for interfaces found - convert into new-style"); + y2internal("interfaces %1", interfaces); + integer pos=0; + list<map> tmp_interfaces=[]; + foreach(map interface, interfaces, { + if (issubstring(interface["device"]:"", "-id-")||issubstring(interface["device"]:"", "-bus-")){ + string value = splitstring(interface["device"]:"", "-")[2]:""; + string rule="ATTR{address}"; + if (splitstring(interface["device"]:"", "-")[1]:"" == "bus") rule = "KERNELS"; + interface["device"]=sformat("eth%1", pos); + udev_rules = add(udev_rules, + $[ + "rule" : rule, + "value" : value, + "name" : interface["device"]:"" + ]); + tmp_interfaces=add(tmp_interfaces, interface); + } + pos=pos+1; + }); + y2milestone("converted interfaces: %1", tmp_interfaces); + return tmp_interfaces; + } + + global define boolean Import(map settings) { + if (oldStyle(settings)) settings["interfaces"] = createUdevFromIfaceName(settings["interfaces"]:[]); + else udev_rules = settings["net-udev"]:[]; + y2internal("interfaces: %1", settings["interfaces"]:[]); + y2internal("udev rules:%1", udev_rules); + return true; + } + + global define boolean Write(){ + list<string> comment = ["# Generated by autoyast", + "# program run by the persistent-net-generator.rules rules file.", + "#", + "# You can modify it, as long as you keep each rule on a single line." ]; + list<string> rules = []; + foreach(map rule, udev_rules, { + rules = add(rules, sformat("SUBSYSTEM==\"net\", DRIVERS==\"?*\", %1==\"%2\", NAME=\"%3\"", + rule["rule"]:"", rule["value"]:"", rule["name"]:"")); + }); + SCR::Write(.udev_persistent.rules_comment, comment); + SCR::Write(.udev_persistent.rules, rules); + return true; + } + + +} -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
mzugec@svn.opensuse.org