From: Thomas Lamprecht Date: Sat, 7 Mar 2020 17:09:15 +0000 (+0100) Subject: network: followup: move graceful require SDN out from subs X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=commitdiff_plain;h=35f2791ffa3f855c8f24a10f1f09f1262e3d9fab;ds=sidebyside 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 --- diff --git a/src/PVE/Network.pm b/src/PVE/Network.pm index bdbf3d6..f5bf349 100644 --- a/src/PVE/Network.pm +++ b/src/PVE/Network.pm @@ -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;