]> git.proxmox.com Git - pve-network.git/blob - PVE/Network/SDN/VnetPlugin.pm
zones: evpn: move vnet mac option to evpn zone plugin
[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 optional => 1,
72 },
73 };
74 }
75
76 sub options {
77 return {
78 zone => { optional => 0},
79 tag => { optional => 1},
80 alias => { optional => 1 },
81 vlanaware => { optional => 1 },
82 };
83 }
84
85 sub on_delete_hook {
86 my ($class, $vnetid, $vnet_cfg) = @_;
87
88 #verify if subnets are associated
89 my $subnets = PVE::Network::SDN::Vnets::get_subnets($vnetid);
90 raise_param_exc({ vnet => "Can't delete vnet if subnets exists"}) if $subnets;
91 }
92
93 sub on_update_hook {
94 my ($class, $vnetid, $vnet_cfg) = @_;
95
96 my $vnet = $vnet_cfg->{ids}->{$vnetid};
97 my $tag = $vnet->{tag};
98 my $vlanaware = $vnet->{vlanaware};
99
100 #don't allow vlanaware change if subnets are defined
101 if($vnet->{vlanaware}) {
102 my $subnets = PVE::Network::SDN::Vnets::get_subnets($vnetid);
103 raise_param_exc({ vlanaware => "vlanaware vnet is not compatible with subnets"}) if $subnets;
104 }
105 }
106
107 1;