]> git.proxmox.com Git - pve-network.git/blame - PVE/Network/SDN/VnetPlugin.pm
add simple plugin
[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 10PVE::Cluster::cfs_register_file('sdn/vnets.cfg',
f5eabba0
AD
11 sub { __PACKAGE__->parse_config(@_); },
12 sub { __PACKAGE__->write_config(@_); });
13
14PVE::JSONSchema::register_standard_option('pve-sdn-vnet-id', {
15 description => "The SDN vnet object identifier.",
16 type => 'string', format => 'pve-sdn-vnet-id',
17});
18
19PVE::JSONSchema::register_format('pve-sdn-vnet-id', \&parse_sdn_vnet_id);
20sub parse_sdn_vnet_id {
21 my ($id, $noerr) = @_;
22
7c5b0f6d 23 if ($id !~ m/^[a-z][a-z0-9]*[a-z0-9]$/i) {
f5eabba0 24 return undef if $noerr;
7c5b0f6d 25 die "vnet ID '$id' contains illegal characters\n";
f5eabba0 26 }
3d273fa9 27 die "vnet ID '$id' can't be more length than 8 characters\n" if length($id) > 8;
f5eabba0
AD
28 return $id;
29}
30
31my $defaultData = {
32
33 propertyList => {
34 vnet => get_standard_option('pve-sdn-vnet-id',
35 { completion => \&PVE::Network::SDN::Vnets::complete_sdn_vnet }),
36 },
37};
46cd4e06 38
6bad73d0
AD
39sub type {
40 return 'vnet';
41}
e7939454 42
f5eabba0
AD
43sub private {
44 return $defaultData;
8fb1ee7f
AD
45}
46
6bad73d0 47sub properties {
e7939454 48 return {
f5eabba0 49 zone => {
e7939454 50 type => 'string',
f5eabba0 51 description => "zone id",
e7939454 52 },
f5eabba0
AD
53 type => {
54 description => "Type",
55 optional => 1,
56 },
e7939454
AD
57 tag => {
58 type => 'integer',
59 description => "vlan or vxlan id",
e7939454 60 },
912fb443
AD
61 vlanaware => {
62 type => 'boolean',
63 description => 'Allow vm VLANs to pass through this vnet.',
64 },
dc7e431e 65 alias => {
e7939454 66 type => 'string',
dc7e431e 67 description => "alias name of the vnet",
e7939454
AD
68 optional => 1,
69 },
e7939454
AD
70 ipv4 => {
71 description => "Anycast router ipv4 address.",
5b31292c 72 type => 'string', format => 'CIDRv4',
e7939454
AD
73 optional => 1,
74 },
75 ipv6 => {
76 description => "Anycast router ipv6 address.",
5b31292c 77 type => 'string', format => 'CIDRv6',
e7939454
AD
78 optional => 1,
79 },
80 mac => {
5b31292c 81 type => 'string',
e7939454 82 description => "Anycast router mac address",
fcfca9ef 83 optional => 1, format => 'mac-addr'
e7939454 84 }
6bad73d0 85 };
e7939454
AD
86}
87
6bad73d0
AD
88sub options {
89 return {
f5eabba0 90 zone => { optional => 0},
205e9166 91 tag => { optional => 0},
dc7e431e 92 alias => { optional => 1 },
6bad73d0
AD
93 ipv4 => { optional => 1 },
94 ipv6 => { optional => 1 },
5b31292c 95 mac => { optional => 1 },
912fb443 96 vlanaware => { optional => 1 },
6bad73d0 97 };
e7939454
AD
98}
99
fe0c6b9e 100sub on_delete_hook {
56cdcac9 101 my ($class, $sdnid, $vnet_cfg) = @_;
fe0c6b9e 102
cf5816ef 103 return;
fe0c6b9e
AD
104}
105
e8d5906e 106sub on_update_hook {
56cdcac9 107 my ($class, $vnetid, $vnet_cfg) = @_;
e8d5906e 108 # verify that tag is not already defined in another vnet
56cdcac9
AD
109 if (defined($vnet_cfg->{ids}->{$vnetid}->{tag})) {
110 my $tag = $vnet_cfg->{ids}->{$vnetid}->{tag};
111 foreach my $id (keys %{$vnet_cfg->{ids}}) {
112 next if $id eq $vnetid;
113 my $vnet = $vnet_cfg->{ids}->{$id};
114 if ($vnet->{type} eq 'vnet' && defined($vnet->{tag})) {
115 die "tag $tag already exist in vnet $id" if $tag eq $vnet->{tag};
6a2db30a
AD
116 }
117 }
118 }
e8d5906e 119}
e7939454
AD
120
1211;