Author: gs
Date: Thu Sep 29 10:50:21 2011
New Revision: 66133
URL: http://svn.opensuse.org/viewcvs/yast?rev=66133&view=rev
Log:
use ini agent for reading/writing /etc/fcoe/cfg-ethx
files
Added:
branches/SuSE-Code-11-SP2-Branch/fcoe-client/agents/fcoe_cfg-ethx.scr
Modified:
branches/SuSE-Code-11-SP2-Branch/fcoe-client/src/FcoeClient.ycp
branches/SuSE-Code-11-SP2-Branch/fcoe-client/src/complex.ycp
branches/SuSE-Code-11-SP2-Branch/fcoe-client/src/fcoe-client_auto.ycp
Added: branches/SuSE-Code-11-SP2-Branch/fcoe-client/agents/fcoe_cfg-ethx.scr
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/fcoe-client/agents/fcoe_cfg-ethx.scr?rev=66133&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/fcoe-client/agents/fcoe_cfg-ethx.scr (added)
+++ branches/SuSE-Code-11-SP2-Branch/fcoe-client/agents/fcoe_cfg-ethx.scr Thu Sep 29 10:50:21 2011
@@ -0,0 +1,39 @@
+/**
+ * File: fcoe_cfg-ethx.scr
+ * Summary: Agent for /etc/fcoe/cfg-*
+ * Access: read / write
+ * See: sysconfig.rpm
+ *
+ * General syntax:
+ * # comment0
+ * VAR1=val1 # comment1
+ * VAR2="val 2 #blah" # comment2
+ * VAR3='val3 x #blah2' # comment3
+ *
+ *
+ * <p>Reads/writes <tt>/etc/fcoe/cfg-*</tt>.
+ */
+.fcoe.cfg-ethx
+
+`ag_ini(
+ `IniAgent( [ "/etc/fcoe/cfg-*" ],
+ $[
+ /* values at the top level, allow comments after value */
+ "options" : [ "global_values", "comments_last" ],
+ /* empty lines, comments after value and whole-line comments */
+ "comments" : [ "^[ \t]*$", "[ \t]*#.*$", "^[ \t]*#.*$" ],
+ /* matching rules */
+ "params" : [
+ /* VAR1="val1 'bal x" */
+ $[ "match" : [ "^[ \t]*([a-zA-Z_][a-zA-Z0-9_]*)=\"([^\"`\\$]*)\"", "%s='%s'" ] ],
+ /* VAR1='val1 xxx" xx' */
+ $[ "match" : [ "^[ \t]*([a-zA-Z_][a-zA-Z0-9_]*)='([^']*)'", "%s='%s'" ] ],
+ /* VAR1=val1 */
+ $[ "match" : [ "^[ \t]*([a-zA-Z_][a-zA-Z0-9_]*)=([^ \t\"$`'\\#]*)", "%s='%s'" ] ],
+ ],
+ /* matching rules */
+ "rewrite" : [
+ [ "/etc/fcoe/cfg-(.*)", "/etc/fcoe/cfg-%s" ],
+ ],
+ ]
+))
Modified: branches/SuSE-Code-11-SP2-Branch/fcoe-client/src/FcoeClient.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/fcoe-client/src/FcoeClient.ycp?rev=66133&r1=66132&r2=66133&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/fcoe-client/src/FcoeClient.ycp (original)
+++ branches/SuSE-Code-11-SP2-Branch/fcoe-client/src/FcoeClient.ycp Thu Sep 29 10:50:21 2011
@@ -45,6 +45,7 @@
import "Service";
import "NetworkService";
import "String";
+import "FileUtils";
/**
* Prototypes
@@ -359,12 +360,12 @@
// if AUTO_VLAN is set to "yes"
if ( netcard["auto_vlan"]:"no" == "yes" )
{
- // set file name to cfg-<interface>, e.g. /etc/fcoe/eth3
+ // set file name to cfg-<interface>, e.g. /etc/fcoe/cfg-eth3
file_name = sformat( "/etc/fcoe/cfg-%1", netcard["dev_name"]:"" );
}
else
{
- // set file name to cfg-, e.g. /etc/fcoe/eth3.200
+ // set file name to cfg-, e.g. /etc/fcoe/cfg-eth3.200
file_name = sformat( "/etc/fcoe/cfg-%1", vlan_device_name );
}
@@ -418,14 +419,15 @@
//
// Get status of FCoE config from /etc/fcoe/cfg-<if>.<vlan> or /etc/fcoe/cfg-<if>
//
-global map GetFcoeStatus( string vlan_device_name, map netcard )
+global map GetFcoeStatus( string vlan_device_name, string device_name )
{
map status_map = $[];
string content = "";
boolean file_exists = false;
string file_name = "";
+ string device = vlan_device_name;
- if ( vlan_device_name == "" )
+ if ( vlan_device_name == "" || device_name == "" )
{
y2error( "Interface not valid" );
return $[];
@@ -434,42 +436,36 @@
y2milestone( "VLAN channel %1 found", vlan_device_name );
file_name = sformat( "/etc/fcoe/cfg-%1", vlan_device_name );
- y2milestone( "Reading %1", file_name );
- content = (string)SCR::Read(.target.string, file_name);
- if ( content == "" || content == nil )
+ if ( !FileUtils::Exists( file_name ) )
{
- // try to read /etc/fcoe/cfg-<interface> (interface was automatically created)
- file_name = sformat( "/etc/fcoe/cfg-%1", netcard["dev_name"]:"" );
- y2milestone( "Reading %1", file_name );
- content = (string)SCR::Read(.target.string, file_name);
+ file_name = sformat( "/etc/fcoe/cfg-%1", device_name );
+
+ if ( !FileUtils::Exists( file_name ) )
+ {
+ y2warning( "Cannot read config file for %1 in /etc/fcoe", vlan_device_name );
+ Popup::Warning( sformat(_("Cannot read config file for %1"), vlan_device_name) );
+ return status_map;
+ }
+ device = device_name;
}
+ // for debugging purpose, read only needed values later
+ list values = SCR::Dir( .fcoe.cfg-ethx.value + device );
+ y2milestone( "Available values in %1: %2", file_name, values );
+
+ foreach( string var, ["FCOE_ENABLE", "DCB_REQUIRED", "AUTO_VLAN"], {
+ string value = (string)SCR::Read(.fcoe.cfg-ethx.value + device + var);
+ if ( value == nil )
+ {
+ y2warning( "Cannot read %1", var );
+ continue;
+ }
+ status_map = add( status_map, var, value );
+ });
- // foreach( string var, values, {
- // SCR::Read(.fcoe.cfg-ethx.value + vlan_device_name + var);
- // });
- if ( content != "" )
- {
- list <string> lines = splitstring( content, "\n" );
- foreach( string line, (list<string>)lines, {
- line = deletechars( line, " \t" );
- foreach( string var, ["FCOE_ENABLE", "DCB_REQUIRED", "AUTO_VLAN"], {
- if ( String::StartsWith(line, var) )
- {
- status_map = add( status_map, var,
- deletechars( substring(line, size(var) + 1), "\"") );
- }
- });
+ status_map = add( status_map, "cfg_device", device );
- });
- status_map = add( status_map, "Filename", file_name );
- y2milestone( "Returning: %1", status_map );
- }
- else
- {
- y2warning( "Cannot read /etc/fcoe/%1", file_name );
- Popup::Warning( sformat(_("Cannot read /etc/fcoe/cfg-file for %1"), vlan_device_name) );
- }
+ y2milestone( "Returning: %1", status_map );
return status_map;
}
@@ -616,7 +612,7 @@
//
// dev_name device fcoe_vlan fcoe_enable dcb_required auto_vlan dcb_capable vlan_interface cfg_file
-// eth3 Ethernet card ... eth3.200 yes/no yes/no yes/no yes/no 200 /etc/fcoe/cfg-eth3.200
+// eth3 Ethernet card ... eth3.200 yes/no yes/no yes/no yes/no 200 eth3.200
//
// Detect network interface cards (hardware probe) and get status
//
@@ -672,7 +668,7 @@
if ( fcoe_vlan_interface != "" )
{
- status_map = GetFcoeStatus( fcoe_vlan_interface, card );
+ status_map = GetFcoeStatus( fcoe_vlan_interface, card["dev_name"]:"" );
}
else
{
@@ -706,7 +702,7 @@
}
info_map = add( info_map, "dcb_capable", dcb_capable ); // DCB capable
info_map = add( info_map, "vlan_interface", vlan_interface ); // VLAN interface, e.g. 200
- info_map = add( info_map, "cfg_file", status_map["Filename"]:"" ); // cfg file name, e.g. /etc/fcoe/cfg-eth3.200
+ info_map = add( info_map, "cfg_file", status_map["cfg_device"]:"" ); // part of cfg-file name, e.g. eth3.200
network_interfaces = add( network_interfaces, info_map );
} );
@@ -744,20 +740,18 @@
//
global boolean WriteFcoeConfig()
{
- boolean ret = true;
-
boolean success = (boolean)SCR::Write(add(.fcoe.config, "DEBUG"), GetFcoeConfig()["DEBUG"]:"" );
if ( !success )
- ret = false;
+ return false;
success = (boolean)SCR::Write(add(.fcoe.config, "USE_SYSLOG"), GetFcoeConfig()["USE_SYSLOG"]:"" );
if ( !success )
- ret = false;
+ return false;
// This is very important- it flushes the cache, and stores the configuration on the disk
SCR::Write(.fcoe.config, nil);
- return ret;
+ return true;
}
//
@@ -766,7 +760,7 @@
global boolean WriteCfgFiles()
{
list <map> netcards = GetNetworkCards();
- boolean success = true;
+ boolean success = false;
string command = "";
map output = $[];
@@ -776,46 +770,38 @@
if ( card["fcoe_vlan"]:"" != FcoeClient::NOT_AVAILABLE && // FCoE VLAN is configured
card["fcoe_vlan"]:"" != FcoeClient::NOT_CONFIGURED && Modified() ) // and data are modified
{
- string content = (string)SCR::Read( .target.string, card["cfg_file"]:"" );
- y2debug( "Original content of %1: %2", card["cfg_file"]:"", content );
-
- list <string> lines = (list<string>)splitstring( content, "\n" );
- lines = maplist( string line, lines, {
- if ( !String::StartsWith( line, "#" ) ) line = deletechars( line, " \t" );
-
- if ( String::StartsWith( line, "FCOE_ENABLE" ) )
- {
- return sformat( "FCOE_ENABLE=\"%1\"", card["fcoe_enable"]:"no" );
- }
- else if ( String::StartsWith( line, "DCB_REQUIRED" ) )
- {
- return sformat( "DCB_REQUIRED=\"%1\"", card["dcb_required"]:"no" );
- }
- else if ( String::StartsWith( line, "AUTO_VLAN" ) )
- {
- return sformat( "AUTO_VLAN=\"%1\"", card["auto_vlan"]:"no" );
- }
- else
- {
- return line;
- }
- });
- content = mergestring( lines, "\n" );
- y2milestone( "Writing content: %1", content );
-
- boolean ret = SCR::Write( .target.string, card["cfg_file"]:"", content );
- if ( !ret )
+ y2milestone( "Write .fcoe.cfg-ethx.value.cfg-%1.<var>", card["cfg_file"]:"" );
+ success = SCR::Write(.fcoe.cfg-ethx.value + card["cfg_file"]:"" + "FCOE_ENABLE", card[ "fcoe_enable"]:"no" );
+ if ( !success )
{
- success = ret;
- y2error( "Cannot write %1", card["cfg_file"]:"" );
+ y2error( "Writing FCOE_ENABLE=%1 failed", card[ "fcoe_enable"]:"no" );
+ return false;
}
- else
+ success = SCR::Write(.fcoe.cfg-ethx.value + card["cfg_file"]:"" + "DCB_REQUIRED", card["dcb_required"]:"no" );
+ if ( !success )
+ {
+ y2error( "Writing DCB_REQUIRED=%1 failed", card["dcb_required"]:"no" );
+ return false;
+ }
+ success = SCR::Write(.fcoe.cfg-ethx.value + card["cfg_file"]:"" + "AUTO_VLAN", card["auto_vlan"]:"no" );
+ if ( !success )
{
- y2milestone( "%1 written", card["cfg_file"]:"" );
+ y2error( "Writing AUTO_VLAN=%1 failed", card["auto_vlan"]:"no" );
+ return false;
}
- // enable DCB app fcoe (app:0)
if ( card["dcb_required"]:"no" == "yes" )
{
+ //enable DCB on the interface
+ command = sformat( "dcbtool sc %1 dcb on", card["dev_name"]:"" );
+ y2milestone( "Executing command: %1", command );
+ output = (map)SCR::Execute( .target.bash_output, command );
+ y2milestone( "Output: %1", output );
+ if ( output["exit"]:255 != 0 )
+ {
+ Popup::Error( sformat( _("Command: %1 failed"), command ) );
+ y2error( "Command: %1 failed", command);
+ }
+ // enable App:FCoE on the interface
command = sformat( "dcbtool sc %1 app:0 e:1 a:1 w:1", card["dev_name"]:"" );
y2milestone( "Executing command: %1", command );
@@ -829,8 +815,10 @@
}
}
} );
+ // This is very important- it flushes the cache, and stores the configuration on the disk
+ SCR::Write( .fcoe.cfg-ethx, nil );
- return success;
+ return true;
}
global boolean RestartServiceFcoe()
Modified: branches/SuSE-Code-11-SP2-Branch/fcoe-client/src/complex.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/fcoe-client/src/complex.ycp?rev=66133&r1=66132&r2=66133&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/fcoe-client/src/complex.ycp (original)
+++ branches/SuSE-Code-11-SP2-Branch/fcoe-client/src/complex.ycp Thu Sep 29 10:50:21 2011
@@ -382,7 +382,7 @@
{
y2milestone( "FCoE VLAN interface %1 created/started", fcoe_vlan_interface );
FcoeClient::CreateFcoeConfig( fcoe_vlan_interface, card );
- status_map = FcoeClient::GetFcoeStatus ( fcoe_vlan_interface, card );
+ status_map = FcoeClient::GetFcoeStatus ( fcoe_vlan_interface, card["dev_name"]:"" );
// store command to be able to revert the creation of FCoE VLAN interface in case of 'Abort'
// (also if only 'fipvlan -s <interface>' is called)
FcoeClient::AddRevertCommand( sformat("vconfig rem %1", fcoe_vlan_interface ) );
@@ -407,7 +407,7 @@
card["fcoe_enable"] = status_map["FCOE_ENABLE"]:"";
card["dcb_required"] = status_map["DCB_REQUIRED"]:"";
card["auto_vlan"] = status_map["AUTO_VLAN"]:"";
- card["cfg_file"] = status_map["Filename"]:"";
+ card["cfg_file"] = status_map["cfg_device"]:"";
FcoeClient::SetModified( true );
FcoeClient::SetNetworkCardsValue( FcoeClient::current_card, card );
@@ -450,7 +450,7 @@
if ( output["exit"]:255 == 0 )
{
- command = sformat( "rm %1", card["cfg_file"]:"" );
+ command = sformat( "rm /etc/fcoe/cfg-%1", card["cfg_file"]:"" );
y2milestone( "Calling %1", command );
output = (map)SCR::Execute( .target.bash_output, command );
y2milestone( "Output: %1", output );
Modified: branches/SuSE-Code-11-SP2-Branch/fcoe-client/src/fcoe-client_auto.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/fcoe-client/src/fcoe-client_auto.ycp?rev=66133&r1=66132&r2=66133&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/fcoe-client/src/fcoe-client_auto.ycp (original)
+++ branches/SuSE-Code-11-SP2-Branch/fcoe-client/src/fcoe-client_auto.ycp Thu Sep 29 10:50:21 2011
@@ -205,7 +205,7 @@
y2milestone( "FCoE VLAN interface %1 created/started", fcoe_vlan_interface );
// create /etc/fcoe/ethx file and get values
FcoeClient::CreateFcoeConfig( fcoe_vlan_interface, card );
- status_map = FcoeClient::GetFcoeStatus( fcoe_vlan_interface, card );
+ status_map = FcoeClient::GetFcoeStatus( fcoe_vlan_interface, card["dev_name"]:"" );
// apply modified data
detected_netcards[ index, "fcoe_vlan"] = fcoe_vlan_interface;
detected_netcards[ index, "cfg_file"] = status_map["Filename"]:"";
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org