diff options
| author | Alexandre Derumier <aderumier@odiso.com> | 2019-11-28 09:40:26 +0100 |
|---|---|---|
| committer | Thomas Lamprecht <t.lamprecht@proxmox.com> | 2019-11-28 14:15:25 +0100 |
| commit | 3794e4297275bc74d63ccb281601461ccb919ad6 (patch) | |
| tree | 8432e2836220f066579fd7765c4c531e560203ed | |
| parent | ba7ac021b595726fc2cdd5ec8368fcd89a5119e9 (diff) | |
zones: vlan|qinq: add get_uplink_iface sub
also check that interface is eth or bond
Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
| -rw-r--r-- | PVE/Network/SDN/Zones/Plugin.pm | 26 | ||||
| -rw-r--r-- | PVE/Network/SDN/Zones/QinQPlugin.pm | 13 | ||||
| -rw-r--r-- | PVE/Network/SDN/Zones/VlanPlugin.pm | 15 |
3 files changed, 29 insertions, 25 deletions
diff --git a/PVE/Network/SDN/Zones/Plugin.pm b/PVE/Network/SDN/Zones/Plugin.pm index 4d0732e..217ee65 100644 --- a/PVE/Network/SDN/Zones/Plugin.pm +++ b/PVE/Network/SDN/Zones/Plugin.pm @@ -179,4 +179,30 @@ sub parse_tag_number_or_range { return (scalar(@elements) > 1); } +#helper + +sub get_uplink_iface { + my ($interfaces_config, $uplink) = @_; + + my $iface = undef; + foreach my $id (keys %{$interfaces_config->{ifaces}}) { + my $interface = $interfaces_config->{ifaces}->{$id}; + if (my $iface_uplink = $interface->{'uplink-id'}) { + next if $iface_uplink ne $uplink; + if($interface->{type} ne 'eth' && $interface->{type} ne 'bond') { + warn "uplink $uplink is not a physical or bond interface"; + next; + } + $iface = $id; + } + } + + #create a dummy uplink interface if no uplink found + if(!$iface) { + warn "can't find uplink $uplink in physical interface"; + $iface = "uplink${uplink}"; + } + + return $iface; +} 1; diff --git a/PVE/Network/SDN/Zones/QinQPlugin.pm b/PVE/Network/SDN/Zones/QinQPlugin.pm index 63f4528..d36f0d8 100644 --- a/PVE/Network/SDN/Zones/QinQPlugin.pm +++ b/PVE/Network/SDN/Zones/QinQPlugin.pm @@ -50,19 +50,8 @@ sub generate_sdn_config { die "missing vlan tag" if !$tag; die "missing zone vlan tag" if !$zone_tag; - #check uplinks - my $uplinks = {}; - foreach my $id (keys %{$interfaces_config->{ifaces}}) { - my $interface = $interfaces_config->{ifaces}->{$id}; - if (my $uplink = $interface->{'uplink-id'}) { - die "uplink-id $uplink is already defined on $uplinks->{$uplink}" if $uplinks->{$uplink}; - $interface->{name} = $id; - $uplinks->{$interface->{'uplink-id'}} = $interface; - } - } + my $iface = PVE::Network::SDN::Zones::Plugin::get_uplink_iface($interfaces_config, $uplink); - my $iface = $uplinks->{$uplink}->{name}; - $iface = "uplink${uplink}" if !$iface; $iface .= ".$zone_tag"; #tagged interface diff --git a/PVE/Network/SDN/Zones/VlanPlugin.pm b/PVE/Network/SDN/Zones/VlanPlugin.pm index adb698f..63db8ab 100644 --- a/PVE/Network/SDN/Zones/VlanPlugin.pm +++ b/PVE/Network/SDN/Zones/VlanPlugin.pm @@ -48,19 +48,8 @@ sub generate_sdn_config { die "missing vlan tag" if !$tag; - #check uplinks - my $uplinks = {}; - foreach my $id (keys %{$interfaces_config->{ifaces}}) { - my $interface = $interfaces_config->{ifaces}->{$id}; - if (my $uplink = $interface->{'uplink-id'}) { - die "uplink-id $uplink is already defined on $uplinks->{$uplink}" if $uplinks->{$uplink}; - $interface->{name} = $id; - $uplinks->{$interface->{'uplink-id'}} = $interface; - } - } - - my $iface = $uplinks->{$uplink}->{name}; - $iface = "uplink${uplink}" if !$iface; + my $iface = PVE::Network::SDN::Zones::Plugin::get_uplink_iface($interfaces_config, $uplink); + $iface .= ".$tag"; #tagged interface |
