network: followup: move graceful require SDN out from subs

As "require" is evaluated on module load only once,  we either have
it or not, so move it to the top to avoid code duplication

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2020-03-07 18:09:15 +01:00
parent c02d6d1c96
commit 35f2791ffa

View File

@ -13,6 +13,12 @@ use Net::IP;
use POSIX qw(ECONNREFUSED);
use Socket qw(NI_NUMERICHOST NI_NUMERICSERV);
my $have_sdn;
eval {
require PVE::Network::SDN::Zones;
$have_sdn = 1;
};
# host network related utility functions
our $PHYSICAL_NIC_RE = qr/(?:eth\d+|en[^:.]+|ib\d+)/;
@ -272,12 +278,6 @@ my $activate_interface = sub {
sub tap_create {
my ($iface, $bridge) = @_;
my $have_sdn;
eval {
require PVE::Network::SDN::Zones;
$have_sdn = 1;
};
if ($have_sdn) {
my ($bridgesdn, undef) = PVE::Network::SDN::Zones::get_bridge_vlan($bridge);
$bridge = $bridgesdn if $bridgesdn;
@ -297,12 +297,6 @@ sub tap_create {
sub veth_create {
my ($veth, $vethpeer, $bridge, $mac) = @_;
my $have_sdn;
eval {
require PVE::Network::SDN::Zones;
$have_sdn = 1;
};
if ($have_sdn) {
my ($bridgesdn, undef) = PVE::Network::SDN::Zones::get_bridge_vlan($bridge);
$bridge = $bridgesdn if $bridgesdn;
@ -399,12 +393,6 @@ my $cleanup_firewall_bridge = sub {
sub tap_plug {
my ($iface, $bridge, $tag, $firewall, $trunks, $rate) = @_;
my $have_sdn;
eval {
require PVE::Network::SDN::Zones;
$have_sdn = 1;
};
if ($have_sdn) {
my ($bridgesdn, $tag) = PVE::Network::SDN::Zones::get_bridge_vlan($bridge);
$bridge = $bridgesdn if $bridgesdn;