2013-10-01 13:14:49 +02:00
#!/usr/bin/perl
2011-08-23 07:47:04 +02:00
use strict;
2013-10-01 13:14:49 +02:00
use warnings;
2011-08-23 07:47:04 +02:00
use PVE::QemuServer;
use PVE::Tools qw(run_command);
2012-03-28 10:37:28 +02:00
use PVE::Network;
2011-08-23 07:47:04 +02:00
my $iface = shift;
2015-11-13 16:16:01 +01:00
my $hotplug = 0;
if ($iface eq '--hotplug') {
$hotplug = 1;
$iface = shift;
}
2011-08-23 07:47:04 +02:00
die "no interface specified\n" if !$iface;
die "got strange interface name '$iface'\n"
if $iface !~ m/^tap(\d+)i(\d+)$/;
my $vmid = $1;
my $netid = "net$2";
2015-11-13 16:16:01 +01:00
my $migratedfrom = $hotplug ? undef : $ENV{PVE_MIGRATED_FROM};
2012-08-23 07:26:41 +02:00
2016-03-07 12:41:12 +01:00
my $conf = PVE::QemuConfig->load_config($vmid, $migratedfrom);
2011-08-23 07:47:04 +02:00
2014-11-25 06:58:33 +01:00
my $netconf = $conf->{$netid};
$netconf = $conf->{pending}->{$netid} if !$migratedfrom && defined($conf->{pending}->{$netid});
2011-08-23 07:47:04 +02:00
die "unable to get network config '$netid'\n"
2014-11-25 06:58:33 +01:00
if !defined($netconf);
2011-08-23 07:47:04 +02:00
2014-11-25 06:58:33 +01:00
my $net = PVE::QemuServer::parse_net($netconf);
2011-08-23 07:47:04 +02:00
die "unable to parse network config '$netid'\n" if !$net;
2013-03-05 10:22:16 +01:00
PVE::Network::tap_create($iface, $net->{bridge});
2011-08-23 07:47:04 +02:00
2016-03-08 13:55:13 +01:00
PVE::Network::tap_plug($iface, $net->{bridge}, $net->{tag}, $net->{firewall}, $net->{trunks}, $net->{rate});
2015-04-07 14:01:13 +02:00
2011-08-23 07:47:04 +02:00
exit 0;