]> git.proxmox.com Git - qemu-server.git/blame - vm-network-scripts/pve-bridge
memory: hotplug: sort by numerical ID rather than slot when unplugging
[qemu-server.git] / vm-network-scripts / pve-bridge
CommitLineData
990fc5e2 1#!/usr/bin/perl
1e3baf05
DM
2
3use strict;
990fc5e2 4use warnings;
28e129cc 5
1e3baf05
DM
6use PVE::QemuServer;
7use PVE::Tools qw(run_command);
9f03d50d 8use PVE::Network;
1e3baf05 9
28e129cc
AD
10my $have_sdn;
11eval {
12 require PVE::Network::SDN::Zones;
13 $have_sdn = 1;
14};
15
1e3baf05
DM
16my $iface = shift;
17
50669ed5
WB
18my $hotplug = 0;
19if ($iface eq '--hotplug') {
20 $hotplug = 1;
21 $iface = shift;
22}
23
1e3baf05
DM
24die "no interface specified\n" if !$iface;
25
26die "got strange interface name '$iface'\n"
27 if $iface !~ m/^tap(\d+)i(\d+)$/;
28
29my $vmid = $1;
30my $netid = "net$2";
31
50669ed5 32my $migratedfrom = $hotplug ? undef : $ENV{PVE_MIGRATED_FROM};
d691e6d3 33
ffda963f 34my $conf = PVE::QemuConfig->load_config($vmid, $migratedfrom);
1e3baf05 35
3eec5767
DM
36my $netconf = $conf->{$netid};
37
38$netconf = $conf->{pending}->{$netid} if !$migratedfrom && defined($conf->{pending}->{$netid});
39
1e3baf05 40die "unable to get network config '$netid'\n"
3eec5767 41 if !defined($netconf);
1e3baf05 42
3eec5767 43my $net = PVE::QemuServer::parse_net($netconf);
1e3baf05
DM
44die "unable to parse network config '$netid'\n" if !$net;
45
28e129cc
AD
46if ($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 54exit 0;