simulator: make lxc/qemu optional
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 31 Jan 2017 10:15:22 +0000 (11:15 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 6 Feb 2017 10:59:18 +0000 (11:59 +0100)
src/PVE/FirewallSimulator.pm

index c924b41..f2c2fbc 100644 (file)
@@ -6,8 +6,20 @@ use Data::Dumper;
 use PVE::Firewall;
 use File::Basename;
 use Net::IP;
-use PVE::LXC;
-use PVE::QemuServer;
+
+# dynamically include PVE::QemuServer and PVE::LXC
+# to avoid dependency problems
+my $have_qemu_server;
+eval {
+    require PVE::QemuServer;
+    $have_qemu_server = 1;
+};
+
+my $have_lxc;
+eval {
+    require PVE::LXC;
+    $have_lxc = 1;
+};
 
 my $mark;
 my $trace;
@@ -530,11 +542,13 @@ sub simulate_firewall {
        $from_info->{iface} = 'tapXYZ';
        $start_state = 'from-bport';
     } elsif ($from =~ m/^ct(\d+)$/) {
+       return 'SKIPPED' if !$have_lxc;
        my $vmid = $1;
        $from_info = extract_ct_info($vmdata, $vmid, 0);
        $start_state = 'fwbr-out'; 
        $pkg->{mac_source} = $from_info->{macaddr};
     } elsif ($from =~ m/^vm(\d+)(i(\d))?$/) {
+       return 'SKIPPED' if !$have_qemu_server;
        my $vmid = $1;
        my $netnum = $3 || 0;
        $from_info = extract_vm_info($vmdata, $vmid, $netnum);
@@ -563,10 +577,12 @@ sub simulate_firewall {
        $target->{bridge} = 'vmbr0';
        $target->{iface} = 'tapXYZ';
     } elsif ($to =~ m/^ct(\d+)$/) {
+       return 'SKIPPED' if !$have_lxc;
        my $vmid = $1;
        $target = extract_ct_info($vmdata, $vmid, 0);
        $target->{iface} = $target->{tapdev};
    } elsif ($to =~ m/^vm(\d+)$/) {
+       return 'SKIPPED' if !$have_qemu_server;
        my $vmid = $1;
        $target = extract_vm_info($vmdata, $vmid, 0);
        $target->{iface} = $target->{tapdev};