]>
Commit | Line | Data |
---|---|---|
990fc5e2 | 1 | #!/usr/bin/perl |
1e3baf05 DM |
2 | |
3 | use strict; | |
990fc5e2 | 4 | use warnings; |
1e3baf05 DM |
5 | use PVE::QemuServer; |
6 | use PVE::Tools qw(run_command); | |
9f03d50d | 7 | use PVE::Network; |
1e3baf05 DM |
8 | |
9 | my $iface = shift; | |
10 | ||
50669ed5 WB |
11 | my $hotplug = 0; |
12 | if ($iface eq '--hotplug') { | |
13 | $hotplug = 1; | |
14 | $iface = shift; | |
15 | } | |
16 | ||
1e3baf05 DM |
17 | die "no interface specified\n" if !$iface; |
18 | ||
19 | die "got strange interface name '$iface'\n" | |
20 | if $iface !~ m/^tap(\d+)i(\d+)$/; | |
21 | ||
22 | my $vmid = $1; | |
23 | my $netid = "net$2"; | |
24 | ||
50669ed5 | 25 | my $migratedfrom = $hotplug ? undef : $ENV{PVE_MIGRATED_FROM}; |
d691e6d3 | 26 | |
ffda963f | 27 | my $conf = PVE::QemuConfig->load_config($vmid, $migratedfrom); |
1e3baf05 | 28 | |
3eec5767 DM |
29 | my $netconf = $conf->{$netid}; |
30 | ||
31 | $netconf = $conf->{pending}->{$netid} if !$migratedfrom && defined($conf->{pending}->{$netid}); | |
32 | ||
1e3baf05 | 33 | die "unable to get network config '$netid'\n" |
3eec5767 | 34 | if !defined($netconf); |
1e3baf05 | 35 | |
3eec5767 | 36 | my $net = PVE::QemuServer::parse_net($netconf); |
1e3baf05 DM |
37 | die "unable to parse network config '$netid'\n" if !$net; |
38 | ||
56ccc25d | 39 | PVE::Network::tap_create($iface, $net->{bridge}); |
1e3baf05 | 40 | |
4f4fbeb0 | 41 | PVE::Network::tap_plug($iface, $net->{bridge}, $net->{tag}, $net->{firewall}, $net->{trunks}, $net->{rate}); |
a279a03d | 42 | |
1e3baf05 | 43 | exit 0; |