]> git.proxmox.com Git - pve-network.git/blame - PVE/Network/SDN/VnetPlugin.pm
limit vnet/zones/controller to 10 characters
[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);
e7939454 9
f5eabba0
AD
10PVE::Cluster::cfs_register_file('sdn/vnets.cfg',
11 sub { __PACKAGE__->parse_config(@_); });
12
13PVE::Cluster::cfs_register_file('sdn/vnets.cfg.new',
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 }
7c5b0f6d 30 die "vnet ID '$id' can't be more length than 10 characters\n" if length($id) > 10;
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 },
dc7e431e 64 alias => {
e7939454 65 type => 'string',
dc7e431e 66 description => "alias name of the vnet",
e7939454
AD
67 optional => 1,
68 },
69 mtu => {
70 type => 'integer',
71 description => "mtu",
72 optional => 1,
73 },
74 ipv4 => {
75 description => "Anycast router ipv4 address.",
5b31292c 76 type => 'string', format => 'CIDRv4',
e7939454
AD
77 optional => 1,
78 },
79 ipv6 => {
80 description => "Anycast router ipv6 address.",
5b31292c 81 type => 'string', format => 'CIDRv6',
e7939454
AD
82 optional => 1,
83 },
84 mac => {
5b31292c 85 type => 'string',
e7939454 86 description => "Anycast router mac address",
fcfca9ef 87 optional => 1, format => 'mac-addr'
e7939454 88 }
6bad73d0 89 };
e7939454
AD
90}
91
6bad73d0
AD
92sub options {
93 return {
f5eabba0 94 zone => { optional => 0},
205e9166 95 tag => { optional => 0},
dc7e431e 96 alias => { optional => 1 },
6bad73d0
AD
97 ipv4 => { optional => 1 },
98 ipv6 => { optional => 1 },
6bad73d0 99 mtu => { optional => 1 },
5b31292c 100 mac => { optional => 1 },
6bad73d0 101 };
e7939454
AD
102}
103
fe0c6b9e 104sub on_delete_hook {
6bffe819 105 my ($class, $sdnid, $sdn_cfg) = @_;
fe0c6b9e 106
cf5816ef 107 return;
fe0c6b9e
AD
108}
109
e8d5906e 110sub on_update_hook {
6bffe819 111 my ($class, $sdnid, $sdn_cfg) = @_;
e8d5906e 112 # verify that tag is not already defined in another vnet
6bffe819
AD
113 if (defined($sdn_cfg->{ids}->{$sdnid}->{tag})) {
114 my $tag = $sdn_cfg->{ids}->{$sdnid}->{tag};
115 foreach my $id (keys %{$sdn_cfg->{ids}}) {
116 next if $id eq $sdnid;
117 my $sdn = $sdn_cfg->{ids}->{$id};
118 if ($sdn->{type} eq 'vnet' && defined($sdn->{tag})) {
119 die "tag $tag already exist in vnet $id" if $tag eq $sdn->{tag};
6a2db30a
AD
120 }
121 }
122 }
e8d5906e 123}
e7939454
AD
124
1251;