-#!/usr/bin/perl -w
+#!/usr/bin/perl
use strict;
+use warnings;
use PVE::QemuServer;
use PVE::Tools qw(run_command);
use PVE::Network;
my $vmid = $1;
my $netid = "net$2";
-my $conf = PVE::QemuServer::load_config ($vmid);
+my $migratedfrom = $ENV{PVE_MIGRATED_FROM};
-die "unable to get network config '$netid'\n"
- if !$conf->{$netid};
-
-my $net = PVE::QemuServer::parse_net($conf->{$netid});
-die "unable to parse network config '$netid'\n" if !$net;
+my $conf = PVE::QemuServer::load_config($vmid, $migratedfrom);
-my $bridge = $net->{bridge};
-die "unable to get bridge setting\n" if !$bridge;
+my $netconf = $conf->{$netid};
-system ("/sbin/ifconfig $iface 0.0.0.0 promisc up") == 0 ||
- die "interface activation failed\n";
-
-if ($net->{rate}) {
+$netconf = $conf->{pending}->{$netid} if !$migratedfrom && defined($conf->{pending}->{$netid});
+
+die "unable to get network config '$netid'\n"
+ if !defined($netconf);
- my $debug = 0;
- my $rate = int($net->{rate}*1024*1024);
- my $burst = 1024*1024;
+my $net = PVE::QemuServer::parse_net($netconf);
+die "unable to parse network config '$netid'\n" if !$net;
- PVE::Network::setup_tc_rate_limit($iface, $rate, $burst, $debug);
-}
+PVE::Network::tap_create($iface, $net->{bridge});
-my $newbridge = PVE::Network::activate_bridge_vlan($bridge, $net->{tag});
-PVE::Network::copy_bridge_config($bridge, $newbridge) if $bridge ne $newbridge;
+# if ovs is under this bridge all traffic control settings will be flushed.
+# so we need to call tap_rate_limit after tap_plug
+PVE::Network::tap_plug($iface, $net->{bridge}, $net->{tag}, $net->{firewall});
-system ("/usr/sbin/brctl addif $newbridge $iface") == 0 ||
- die "can't add interface to bridge\n";
+PVE::Network::tap_rate_limit($iface, $net->{rate}) if $net->{rate};
exit 0;