Skip to content

Commit

Permalink
Automatically configures bonding slaves.
Browse files Browse the repository at this point in the history
  • Loading branch information
mchf authored and mvidner committed Jul 20, 2012
1 parent 80c12af commit 5095274
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 43 deletions.
32 changes: 16 additions & 16 deletions src/lan/address.ycp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ string fwzone_initial = "";

string hostname_initial = "";

/**
* list of interface names which were recently assigned as a slave to a bond device
*/
list<string> bond_slaves = [];

boolean force_static_ip = ProductFeatures::GetBooleanFeature ("network", "force_static_ip");

/**
Expand Down Expand Up @@ -161,18 +166,22 @@ void StoreVLANSlave(string key, map event)
void InitSlave(string key)
{
settings["SLAVES"] = LanItems::bond_slaves;
y2milestone( "InitSlave bond_slaves: %1", settings[ "SLAVES"]:[]);
UI::ChangeWidget(`id("BONDSLAVE"), `SelectedItems, settings["SLAVES"]:[]);

settings["BONDOPTION"] = LanItems::bond_option;
settings["BONDOPTION"] = LanItems::bond_option;

list items = createUnconfigured(settings["SLAVES"]:[]);
list items = createUnconfigured(settings["SLAVES"]:[]);
map <string, any> configurations = NetworkInterfaces::FilterDevices("netcard");
foreach(string devtype, splitstring(NetworkInterfaces::CardRegex["netcard"]:"", "|"), {
foreach(string devname, (list<string>) Map::Keys(configurations[devtype]:$[]), {
//filter the eth devices (BOOT_PROTO=none
// don't care about STARTMODE (see bnc#652987c6)
if (((string)configurations[devtype, devname, "BOOTPROTO"]:"" == "none")/* && ((string)configurations[devtype, devname, "STARTMODE"]:"" == "off")*/)
items = add (items, `item(`id(devname), sformat("%1 - %2", devname, configurations[devtype, devname, "NAME"]:""), contains(settings["SLAVES"]:[], devname)) );
{
y2milestone( "InitSlave appending bond slave: %1", devname);
items = add (items, `item(`id(devname), sformat("%1 - %2", devname, configurations[devtype, devname, "NAME"]:""), contains(settings["SLAVES"]:[], devname)) );
}

});
});
Expand All @@ -190,10 +199,12 @@ void StoreSlave(string key, map event)
{
settings["SLAVES"] = (list<string>)UI::QueryWidget (`id(key), `SelectedItems);
settings["BONDOPTION"] = UI::QueryWidget (`id("BONDOPTION"), `Value);

LanItems::bond_slaves = settings["SLAVES"]:[];
LanItems::bond_option = settings["BONDOPTION"]:"";
}

bond_slaves = (list<string>) toset( merge( bond_slaves, settings[ "SLAVES"]:[]));
}

void initTunnel(string key){
y2internal("initTunnel %1", settings);
Expand All @@ -215,7 +226,6 @@ void enableDisableBootProto(symbol current){
UI::ChangeWidget(`netmask, `Enabled, current==`static);
UI::ChangeWidget(`hostname, `Enabled, current==`static);
UI::ChangeWidget(`ibft, `Enabled, current==`none);
UI::ChangeWidget(`bus_persistent, `Enabled, current==`none);
}

/**
Expand Down Expand Up @@ -306,14 +316,6 @@ symbol handleBootProto (string key, map event) {
UI::ChangeWidget(`id(`hostname), `Value, Hostname::MergeFQ(DNS::hostname, DNS::domain));
}
}
if( current == `none)
{
y2milestone( "Enabling bus id persistency");
if( UI::QueryWidget( `id( `bus_persistent), `Value) == true)
{
LanItems::PushUdevRule( LanItems::CreateBusPersistentUdevRule());
}
}
}
return nil;
}
Expand Down Expand Up @@ -725,9 +727,7 @@ map<string, map<string,any> > widget_descr_local = $[
`HBox(
`RadioButton(`id(`none),`opt(`notify), _("No Link and IP Setup (Bonding Slaves)")),
`HSpacing(1),
`CheckBox(`id(`ibft), `opt(`notify), _("Use iBFT values")),
`HSpacing(1),
`CheckBox(`id(`bus_persistent), `opt(`notify), _("Enable BUS ID based persistency"))
`CheckBox(`id(`ibft), `opt(`notify), _("Use iBFT values"))
)
)),
`Left(`HBox(
Expand Down
52 changes: 44 additions & 8 deletions src/lan/complex.ycp
Original file line number Diff line number Diff line change
Expand Up @@ -233,24 +233,60 @@ boolean shown = false;

void initOverview (string key) ``{

// search for automatic updates
integer current = LanItems::current;

foreach( string dev, bond_slaves,
{
if( LanItems::FindAndSelect( dev))
{
LanItems::SetItem();
}
else
{
integer dev_index = LanItems::FindDeviceIndex( dev);
if( dev_index < 0)
{
y2error( "initOverview: invalid bond slave device name %1", dev);
continue;
}
LanItems::current = dev_index;

AddInterface();

// clear defaults
LanItems::netmask = "";
}

LanItems::startmode = "hotplug";
LanItems::bootproto = "none";
LanItems::GetReplacedItemUdev("KERNELS", LanItems::getCurrentItem()["hwinfo", "busid"]:"");

LanItems::Commit();
});

LanItems::current = current;

// update table with device description
list<term> term_items = maplist (map<string,any> i, (list<map<string,any> >)LanItems::Overview(), {
term t = `item (`id (i["id"]:-1));

foreach (string l, i["table_descr"]:[], {
t = add (t, l);
});
return t;
});
UI::ChangeWidget (`id (`_hw_items), `Items, term_items);

if (!shown)
{
disableItemsIfNM([`_hw_items, `_hw_sum, `add, `edit, `delete], true);
shown = true;
}
else
enableDisableButtons();
if (!shown)
{
disableItemsIfNM([`_hw_items, `_hw_sum, `add, `edit, `delete], true);
shown = true;
}
else
enableDisableButtons();

y2milestone("LanItems %1", LanItems::Items);
y2milestone("LanItems %1", LanItems::Items);
}


Expand Down
37 changes: 18 additions & 19 deletions src/modules/LanItems.ycp
Original file line number Diff line number Diff line change
Expand Up @@ -197,25 +197,6 @@ global list<string> PushUdevRule( string rule)
return new_rules;
}

global string CreateBusPersistentUdevRule()
{
return sformat( "KERNELS==\"%1\" NAME=\"%2\"", getCurrentItem()[ "hwinfo", "busid"]:"", getCurrentItem()[ "ifcfg"]:"");
}

global list<string> PushUdevRule( string rule)
{
list<string> new_rules=[];

new_rules = add(new_rules, rule);

if( size( getCurrentItem()[ "udev", "net"]:[]) == 0)
Items[ current, "udev"] = add( Items[ current, "udev"]:$[], "net", new_rules);
else
Items[current, "udev", "net"] = new_rules;

return new_rules;
}

boolean ReadUdevDriverRules(){
y2milestone ("Reading udev rules ...");
udev_net_rules = (map<string, any>)SCR::Read(.udev_persistent.net);
Expand Down Expand Up @@ -414,6 +395,24 @@ global boolean FindAndSelect(string device){
return found;
}

/**
* search all known devices to find it's index in Items array
*/
global integer FindDeviceIndex( string device)
{
integer ret = -1;

foreach(integer i, map<string, any> a, (map<integer, map<string, any> >)Items,
{
if( a[ "hwinfo", "dev_name"]:"" == device)
{
ret = i;
break;
}
});

return ret;
}

global void ReadHw(){
Items=$[];
Expand Down

0 comments on commit 5095274

Please sign in to comment.