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