]> git.proxmox.com Git - pve-common.git/commitdiff
network: followup: move graceful require SDN out from subs
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Sat, 7 Mar 2020 17:09:15 +0000 (18:09 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Sat, 7 Mar 2020 17:10:58 +0000 (18:10 +0100)
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>
src/PVE/Network.pm

index bdbf3d680cbd579be0c31c36a09a3d907d9b7782..f5bf34934191977c59af5e8aa6e370117d9f4571 100644 (file)
@@ -13,6 +13,12 @@ use Net::IP;
 use POSIX qw(ECONNREFUSED);
 use Socket qw(NI_NUMERICHOST NI_NUMERICSERV);
 
 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+)/;
 # 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) = @_;
 
 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;
     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) = @_;
 
 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;
     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) = @_;
 
 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;
     if ($have_sdn) {
        my ($bridgesdn, $tag) = PVE::Network::SDN::Zones::get_bridge_vlan($bridge);
        $bridge = $bridgesdn if $bridgesdn;