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