]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/perl | |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | use PVE::QemuServer; | |
6 | use PVE::Tools qw(run_command); | |
7 | use PVE::Network; | |
8 | ||
9 | my $iface = shift; | |
10 | ||
11 | my $hotplug = 0; | |
12 | if ($iface eq '--hotplug') { | |
13 | $hotplug = 1; | |
14 | $iface = shift; | |
15 | } | |
16 | ||
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 | ||
25 | my $migratedfrom = $hotplug ? undef : $ENV{PVE_MIGRATED_FROM}; | |
26 | ||
27 | my $conf = PVE::QemuConfig->load_config($vmid, $migratedfrom); | |
28 | ||
29 | my $netconf = $conf->{$netid}; | |
30 | ||
31 | $netconf = $conf->{pending}->{$netid} if !$migratedfrom && defined($conf->{pending}->{$netid}); | |
32 | ||
33 | die "unable to get network config '$netid'\n" | |
34 | if !defined($netconf); | |
35 | ||
36 | my $net = PVE::QemuServer::parse_net($netconf); | |
37 | die "unable to parse network config '$netid'\n" if !$net; | |
38 | ||
39 | PVE::Network::tap_create($iface, $net->{bridge}); | |
40 | ||
41 | PVE::Network::tap_plug($iface, $net->{bridge}, $net->{tag}, $net->{firewall}, $net->{trunks}, $net->{rate}); | |
42 | ||
43 | exit 0; |