]> git.proxmox.com Git - pve-network.git/blame - PVE/Network/Network/VnetPlugin.pm
vxlanmulticast: add mtu to vxlan interface too.
[pve-network.git] / PVE / Network / Network / VnetPlugin.pm
CommitLineData
6bad73d0 1package PVE::Network::Network::VnetPlugin;
e7939454
AD
2
3use strict;
4use warnings;
6bad73d0 5use PVE::Network::Network::Plugin;
e7939454 6
6bad73d0 7use base('PVE::Network::Network::Plugin');
e7939454 8
aa38ba46
AD
9use PVE::Cluster;
10use PVE::LXC;
11use PVE::LXC::Config;
12use PVE::QemuServer;
13use PVE::QemuConfig;
14
6bad73d0
AD
15sub type {
16 return 'vnet';
17}
e7939454 18
e7939454
AD
19
20
6bad73d0 21sub properties {
e7939454 22 return {
e7939454
AD
23 transportzone => {
24 type => 'string',
25 description => "transportzone id",
e7939454
AD
26 },
27 tag => {
28 type => 'integer',
29 description => "vlan or vxlan id",
e7939454 30 },
dc7e431e 31 alias => {
e7939454 32 type => 'string',
dc7e431e 33 description => "alias name of the vnet",
e7939454
AD
34 optional => 1,
35 },
36 mtu => {
37 type => 'integer',
38 description => "mtu",
39 optional => 1,
40 },
41 ipv4 => {
42 description => "Anycast router ipv4 address.",
43 type => 'string', format => 'ipv4',
44 optional => 1,
45 },
46 ipv6 => {
47 description => "Anycast router ipv6 address.",
48 type => 'string', format => 'ipv6',
49 optional => 1,
50 },
51 mac => {
52 type => 'boolean',
53 description => "Anycast router mac address",
54 optional => 1,
55 }
6bad73d0 56 };
e7939454
AD
57}
58
6bad73d0
AD
59sub options {
60 return {
205e9166
AD
61 transportzone => { optional => 0},
62 tag => { optional => 0},
dc7e431e 63 alias => { optional => 1 },
6bad73d0
AD
64 ipv4 => { optional => 1 },
65 ipv6 => { optional => 1 },
6bad73d0
AD
66 mtu => { optional => 1 },
67 };
e7939454
AD
68}
69
fe0c6b9e
AD
70sub on_delete_hook {
71 my ($class, $networkid, $scfg) = @_;
72
73 # verify than no vm or ct have interfaces in this bridge
aa38ba46
AD
74 my $vmdata = read_local_vm_config();
75
76 foreach my $vmid (sort keys %{$vmdata->{qemu}}) {
77 my $conf = $vmdata->{qemu}->{$vmid};
78 foreach my $netid (sort keys %$conf) {
79 next if $netid !~ m/^net(\d+)$/;
80 my $net = PVE::QemuServer::parse_net($conf->{$netid});
81 die "vnet $networkid is used by vm $vmid" if $net->{bridge} eq $networkid;
82 }
83 }
84
85 foreach my $vmid (sort keys %{$vmdata->{lxc}}) {
86 my $conf = $vmdata->{lxc}->{$vmid};
87 foreach my $netid (sort keys %$conf) {
88 next if $netid !~ m/^net(\d+)$/;
89 my $net = PVE::LXC::Config->parse_lxc_network($conf->{$netid});
90 die "vnet $networkid is used by ct $vmid" if $net->{bridge} eq $networkid;
91 }
92 }
93
fe0c6b9e
AD
94}
95
e8d5906e
AD
96sub on_update_hook {
97 my ($class, $networkid, $scfg) = @_;
98
99 # verify that tag is not already defined in another vnet
100
101}
e7939454 102
aa38ba46
AD
103sub read_local_vm_config {
104
105 my $qemu = {};
106 my $lxc = {};
107
108 my $vmdata = { qemu => $qemu, lxc => $lxc };
109
110 my $vmlist = PVE::Cluster::get_vmlist();
111 return $vmdata if !$vmlist || !$vmlist->{ids};
112 my $ids = $vmlist->{ids};
113
114 foreach my $vmid (keys %$ids) {
115 next if !$vmid;
116 my $d = $ids->{$vmid};
117 next if !$d->{node};
118 next if !$d->{type};
119 if ($d->{type} eq 'qemu') {
120 my $cfspath = PVE::QemuConfig->cfs_config_path($vmid);
121 if (my $conf = PVE::Cluster::cfs_read_file($cfspath)) {
122 $qemu->{$vmid} = $conf;
123 }
124 } elsif ($d->{type} eq 'lxc') {
125 my $cfspath = PVE::LXC::Config->cfs_config_path($vmid);
126 if (my $conf = PVE::Cluster::cfs_read_file($cfspath)) {
127 $lxc->{$vmid} = $conf;
128 }
129 }
130 }
131
132 return $vmdata;
133};
134
e7939454 1351;