Skip to content

Commit

Permalink
WebYaST features: bonding and bridging (FATE#313209).
Browse files Browse the repository at this point in the history
  • Loading branch information
vlewin authored and mchf committed Apr 9, 2013
1 parent aab2274 commit 69ae34b
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 32 deletions.
139 changes: 107 additions & 32 deletions src/lan/YaPI/NETWORK.pm
Expand Up @@ -43,17 +43,54 @@ sub Read {
$configuration{'ipaddr'} .= "/" . LanItems->prefix
}
}

$configuration{'mtu'} = LanItems->mtu;
if (LanItems->vlan_id){
$configuration{'vlan_id'} = LanItems->vlan_id;
y2milestone("************* Interface type ", Dumper(LanItems->type));
if(LanItems->type eq "vlan") {
if (LanItems->vlan_id){
$configuration{'vlan_id'} = LanItems->vlan_id;
}

if (LanItems->vlan_etherdevice){
$configuration{'vlan_etherdevice'} = LanItems->vlan_etherdevice;
}
}

if(LanItems->type eq "br" && LanItems->bridge_ports) {
y2milestone("*** BRIDGE DETECTED GET BRIDGE_PORTS ********************");
$configuration{'bridge_ports'} = LanItems->bridge_ports;
}
if (LanItems->vlan_etherdevice){
$configuration{'vlan_etherdevice'} = LanItems->vlan_etherdevice;


if(LanItems->type eq "bond") {
if(@{LanItems->bond_slaves}) {
$configuration{'bond_slaves'} = LanItems->bond_slaves;
}

if(@{LanItems->bond_slaves}) {
$configuration{'bond_slaves'} = LanItems->bond_slaves;
}

if(LanItems->bond_option) {
$configuration{'bond_option'} = LanItems->bond_option;
}
}

if(LanItems->getCurrentItem()->{'hwinfo'}->{'type'} eq "eth") {
$configuration{'vendor'} = LanItems->getCurrentItem()->{"hwinfo"}->{"name"};
}

$interfaces{LanItems->interfacename}=\%configuration;

} elsif (LanItems->getCurrentItem()->{'hwinfo'}->{'type'} eq "eth") {
my $device = LanItems->getCurrentItem()->{"hwinfo"}->{"dev_name"};
$interfaces{$device}= {};
$interfaces{$device}= {};

if(LanItems->getCurrentItem()->{'hwinfo'}->{'type'} eq "eth") {
$interfaces{$device}= {'vendor' => LanItems->getCurrentItem()->{"hwinfo"}->{"name"}};
}

$interfaces{$device}
}
}

Expand Down Expand Up @@ -141,40 +178,77 @@ sub writeDNS {
sub writeInterfaces {
my $args = shift;
my $ret = {'exit'=>0, 'error'=>''};

y2milestone("interface", Dumper(\$args->{'interface'}));

while (my ($dev, $ifc) = each %{$args->{'interface'}}) {
YaST::YCP::Import ("NetworkInterfaces");
NetworkInterfaces->Read();
NetworkInterfaces->Add() unless NetworkInterfaces->Edit($dev);
NetworkInterfaces->Name($dev);
my %config=("STARTMODE" => defined $ifc->{'startmode'}? $ifc->{'startmode'}: 'auto',
"BOOTPROTO" => defined $ifc->{'bootproto'}? $ifc->{'bootproto'}: 'static',
);
if (defined $ifc->{'ipaddr'}) {
my $prefix = "32";
YaST::YCP::Import ("Netmask");
my @ip_row = split(/\//, $ifc->{'ipaddr'});
$prefix = $ip_row[$#ip_row];
if (Netmask->Check4($prefix) && $prefix =~ /\./){
y2milestone("Valid netmask: ", $prefix, " will change to prefixlen");
$prefix = Netmask->ToBits($prefix);

if (defined $ifc->{'delete'} && $ifc->{'delete'} eq "true") {
y2milestone("Delete virtual interface", Dumper(\$dev));

NetworkInterfaces->Delete($dev);
NetworkInterfaces->Commit();
NetworkInterfaces->Write("");
YaST::YCP::Import ("Service");
Service->Restart("network");

} else {
my %config=("STARTMODE" => defined $ifc->{'startmode'}? $ifc->{'startmode'}: 'auto',
"BOOTPROTO" => defined $ifc->{'bootproto'}? $ifc->{'bootproto'}: 'static',
);
if (defined $ifc->{'ipaddr'}) {
my $prefix = "32";
YaST::YCP::Import ("Netmask");
my @ip_row = split(/\//, $ifc->{'ipaddr'});
$prefix = $ip_row[$#ip_row];
if (Netmask->Check4($prefix) && $prefix =~ /\./){
y2milestone("Valid netmask: ", $prefix, " will change to prefixlen");
$prefix = Netmask->ToBits($prefix);
}
$config{"IPADDR"} = $ip_row[0]."/".$prefix;
}
if (defined $ifc->{'mtu'}) {
$config{"MTU"} = $ifc->{'mtu'};
}
if (defined $ifc->{'vlan_id'}) {
$config{"VLAN_ID"} = $ifc->{'vlan_id'};
}
if (defined $ifc->{'vlan_etherdevice'}) {
$config{"ETHERDEVICE"} = $ifc->{'vlan_etherdevice'};
}

if (defined $ifc->{'bridge'}) {
y2milestone("*** BRIDGE DETECTED ***");
y2milestone(Dumper($ifc->{'bridge_ports'}));
$config{"BRIDGE"} = "yes";
$config{"BRIDGE_PORTS"} = $ifc->{'bridge_ports'};
}

if (defined $ifc->{'bond'}) {
y2milestone("*** bonding settings *******************************");
$config{"BONDING_MASTER_MASTER"} = "yes";
$config{"BONDING_MODULE_OPTS"} = $ifc->{'bond_option'};
#$config{"BONDING_SLAVE"} = $ifc->{'bond_option'};

my @slaves = split(/ /,$ifc->{'bond_slaves'});

for my $i (0 .. length(@slaves)) {
y2milestone("BONDING_SLAVE$i", @slaves[$i]);
$config{"BONDING_SLAVE$i"} = @slaves[$i];
}
$config{"IPADDR"} = $ip_row[0]."/".$prefix;
}
if (defined $ifc->{'mtu'}) {
$config{"MTU"} = $ifc->{'mtu'};
}
if (defined $ifc->{'vlan_id'}) {
$config{"VLAN_ID"} = $ifc->{'vlan_id'};
}
if (defined $ifc->{'vlan_etherdevice'}) {
$config{"ETHERDEVICE"} = $ifc->{'vlan_etherdevice'};
}
NetworkInterfaces->Current(\%config);
NetworkInterfaces->Commit();
NetworkInterfaces->Write("");
YaST::YCP::Import ("Service");
Service->Restart("network");
}


NetworkInterfaces->Current(\%config);
NetworkInterfaces->Commit();
NetworkInterfaces->Write("");
YaST::YCP::Import ("Service");
Service->Restart("network");
}
}
return $ret;
}
Expand All @@ -184,6 +258,7 @@ sub writeInterfaces {
BEGIN{$TYPEINFO{Write} = ["function",
["map","string","any"],["map","string","any"]];
}

sub Write {
my $self = shift;
my $args = shift;
Expand Down
2 changes: 2 additions & 0 deletions src/modules/LanItems.ycp
Expand Up @@ -1003,6 +1003,8 @@ global void SetDeviceVars(map devmap, map defaults) {
vlan_etherdevice = GetDeviceVar(devmap, defaults, "ETHERDEVICE");
vlan_id = GetDeviceVar(devmap, defaults, "VLAN_ID"); // FIXME, remember that it can be implied from the name. probably

bridge_ports = GetDeviceVar(devmap, defaults, "BRIDGE_PORTS");

bond_slaves=[];
foreach(any key, any value, devmap,
{
Expand Down

0 comments on commit 69ae34b

Please sign in to comment.