]> git.proxmox.com Git - pve-network.git/blame - PVE/Network/SDN/VnetPlugin.pm
vnets: allow duplicate tags in differents zones
[pve-network.git] / PVE / Network / SDN / VnetPlugin.pm
CommitLineData
86d22462 1package PVE::Network::SDN::VnetPlugin;
e7939454
AD
2
3use strict;
4use warnings;
5
f5eabba0
AD
6use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file);
7use base qw(PVE::SectionConfig);
8use PVE::JSONSchema qw(get_standard_option);
1d44ce70 9use PVE::Exception qw(raise raise_param_exc);
e7939454 10
f5eabba0 11PVE::Cluster::cfs_register_file('sdn/vnets.cfg',
f5eabba0
AD
12 sub { __PACKAGE__->parse_config(@_); },
13 sub { __PACKAGE__->write_config(@_); });
14
15PVE::JSONSchema::register_standard_option('pve-sdn-vnet-id', {
16 description => "The SDN vnet object identifier.",
17 type => 'string', format => 'pve-sdn-vnet-id',
18});
19
20PVE::JSONSchema::register_format('pve-sdn-vnet-id', \&parse_sdn_vnet_id);
21sub parse_sdn_vnet_id {
22 my ($id, $noerr) = @_;
23
7c5b0f6d 24 if ($id !~ m/^[a-z][a-z0-9]*[a-z0-9]$/i) {
f5eabba0 25 return undef if $noerr;
7c5b0f6d 26 die "vnet ID '$id' contains illegal characters\n";
f5eabba0 27 }
3d273fa9 28 die "vnet ID '$id' can't be more length than 8 characters\n" if length($id) > 8;
f5eabba0
AD
29 return $id;
30}
31
32my $defaultData = {
33
34 propertyList => {
35 vnet => get_standard_option('pve-sdn-vnet-id',
36 { completion => \&PVE::Network::SDN::Vnets::complete_sdn_vnet }),
37 },
38};
46cd4e06 39
6bad73d0
AD
40sub type {
41 return 'vnet';
42}
e7939454 43
f5eabba0
AD
44sub private {
45 return $defaultData;
8fb1ee7f
AD
46}
47
6bad73d0 48sub properties {
e7939454 49 return {
f5eabba0 50 zone => {
e7939454 51 type => 'string',
f5eabba0 52 description => "zone id",
e7939454 53 },
f5eabba0
AD
54 type => {
55 description => "Type",
56 optional => 1,
57 },
e7939454
AD
58 tag => {
59 type => 'integer',
60 description => "vlan or vxlan id",
e7939454 61 },
912fb443
AD
62 vlanaware => {
63 type => 'boolean',
64 description => 'Allow vm VLANs to pass through this vnet.',
65 },
dc7e431e 66 alias => {
e7939454 67 type => 'string',
dc7e431e 68 description => "alias name of the vnet",
e7939454
AD
69 optional => 1,
70 },
e7939454 71 mac => {
5b31292c 72 type => 'string',
e7939454 73 description => "Anycast router mac address",
fcfca9ef 74 optional => 1, format => 'mac-addr'
e7939454 75 }
6bad73d0 76 };
e7939454
AD
77}
78
6bad73d0
AD
79sub options {
80 return {
f5eabba0 81 zone => { optional => 0},
1d44ce70 82 tag => { optional => 1},
dc7e431e 83 alias => { optional => 1 },
5b31292c 84 mac => { optional => 1 },
912fb443 85 vlanaware => { optional => 1 },
6bad73d0 86 };
e7939454
AD
87}
88
fe0c6b9e 89sub on_delete_hook {
e612faf6 90 my ($class, $vnetid, $vnet_cfg) = @_;
fe0c6b9e 91
e612faf6
AD
92 #verify if subnets are associated
93 my $subnets = PVE::Network::SDN::Vnets::get_subnets($vnetid);
e8736dac 94 raise_param_exc({ vnet => "Can't delete vnet if subnets exists"}) if $subnets;
fe0c6b9e
AD
95}
96
e8d5906e 97sub on_update_hook {
e8736dac
AD
98 my ($class, $vnetid, $vnet_cfg) = @_;
99
100 my $vnet = $vnet_cfg->{ids}->{$vnetid};
101 my $tag = $vnet->{tag};
102 my $vlanaware = $vnet->{vlanaware};
103
104 #don't allow vlanaware change if subnets are defined
105 if($vnet->{vlanaware}) {
106 my $subnets = PVE::Network::SDN::Vnets::get_subnets($vnetid);
107 raise_param_exc({ vlanaware => "vlanaware vnet is not compatible with subnets"}) if $subnets;
108 }
e8d5906e 109}
e7939454
AD
110
1111;