]> git.proxmox.com Git - pve-network.git/blob - PVE/Network/SDN/VnetPlugin.pm
controllers: evpn : use frr restart if reload fail
[pve-network.git] / PVE / Network / SDN / VnetPlugin.pm
1 package PVE::Network::SDN::VnetPlugin;
2
3 use strict;
4 use warnings;
5
6 use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file);
7 use PVE::Exception qw(raise raise_param_exc);
8 use PVE::JSONSchema qw(get_standard_option);
9
10 use PVE::SectionConfig;
11 use base qw(PVE::SectionConfig);
12
13 PVE::Cluster::cfs_register_file('sdn/vnets.cfg',
14 sub { __PACKAGE__->parse_config(@_); },
15 sub { __PACKAGE__->write_config(@_); });
16
17 PVE::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
22 PVE::JSONSchema::register_format('pve-sdn-vnet-id', \&parse_sdn_vnet_id);
23 sub parse_sdn_vnet_id {
24 my ($id, $noerr) = @_;
25
26 if ($id !~ m/^[a-z][a-z0-9]*[a-z0-9]$/i) {
27 return undef if $noerr;
28 die "vnet ID '$id' contains illegal characters\n";
29 }
30 die "vnet ID '$id' can't be more length than 8 characters\n" if length($id) > 8;
31 return $id;
32 }
33
34 my $defaultData = {
35
36 propertyList => {
37 vnet => get_standard_option('pve-sdn-vnet-id',
38 { completion => \&PVE::Network::SDN::Vnets::complete_sdn_vnet }),
39 },
40 };
41
42 sub type {
43 return 'vnet';
44 }
45
46 sub private {
47 return $defaultData;
48 }
49
50 sub properties {
51 return {
52 zone => {
53 type => 'string',
54 description => "zone id",
55 },
56 type => {
57 description => "Type",
58 optional => 1,
59 },
60 tag => {
61 type => 'integer',
62 description => "vlan or vxlan id",
63 },
64 vlanaware => {
65 type => 'boolean',
66 description => 'Allow vm VLANs to pass through this vnet.',
67 },
68 alias => {
69 type => 'string',
70 description => "alias name of the vnet",
71 pattern => qr/[\(\)-_.\w\d\s]{0,256}/i,
72 maxLength => 256,
73 optional => 1,
74 },
75 };
76 }
77
78 sub options {
79 return {
80 zone => { optional => 0},
81 tag => { optional => 1},
82 alias => { optional => 1 },
83 vlanaware => { optional => 1 },
84 };
85 }
86
87 sub on_delete_hook {
88 my ($class, $vnetid, $vnet_cfg) = @_;
89
90 #verify if subnets are associated
91 my $subnets = PVE::Network::SDN::Vnets::get_subnets($vnetid);
92 raise_param_exc({ vnet => "Can't delete vnet if subnets exists"}) if $subnets;
93 }
94
95 sub on_update_hook {
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 }
107 }
108
109 1;