]> git.proxmox.com Git - pve-network.git/blob - PVE/Network/SDN/VnetPlugin.pm
cleanup old transport/router/sdn_cfg references
[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 base qw(PVE::SectionConfig);
8 use PVE::JSONSchema qw(get_standard_option);
9
10 PVE::Cluster::cfs_register_file('sdn/vnets.cfg',
11 sub { __PACKAGE__->parse_config(@_); });
12
13 PVE::Cluster::cfs_register_file('sdn/vnets.cfg.new',
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 10 characters\n" if length($id) > 10;
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 alias => {
65 type => 'string',
66 description => "alias name of the vnet",
67 optional => 1,
68 },
69 mtu => {
70 type => 'integer',
71 description => "mtu",
72 optional => 1,
73 },
74 ipv4 => {
75 description => "Anycast router ipv4 address.",
76 type => 'string', format => 'CIDRv4',
77 optional => 1,
78 },
79 ipv6 => {
80 description => "Anycast router ipv6 address.",
81 type => 'string', format => 'CIDRv6',
82 optional => 1,
83 },
84 mac => {
85 type => 'string',
86 description => "Anycast router mac address",
87 optional => 1, format => 'mac-addr'
88 }
89 };
90 }
91
92 sub options {
93 return {
94 zone => { optional => 0},
95 tag => { optional => 0},
96 alias => { optional => 1 },
97 ipv4 => { optional => 1 },
98 ipv6 => { optional => 1 },
99 mtu => { optional => 1 },
100 mac => { optional => 1 },
101 };
102 }
103
104 sub on_delete_hook {
105 my ($class, $sdnid, $vnet_cfg) = @_;
106
107 return;
108 }
109
110 sub on_update_hook {
111 my ($class, $vnetid, $vnet_cfg) = @_;
112 # verify that tag is not already defined in another vnet
113 if (defined($vnet_cfg->{ids}->{$vnetid}->{tag})) {
114 my $tag = $vnet_cfg->{ids}->{$vnetid}->{tag};
115 foreach my $id (keys %{$vnet_cfg->{ids}}) {
116 next if $id eq $vnetid;
117 my $vnet = $vnet_cfg->{ids}->{$id};
118 if ($vnet->{type} eq 'vnet' && defined($vnet->{tag})) {
119 die "tag $tag already exist in vnet $id" if $tag eq $vnet->{tag};
120 }
121 }
122 }
123 }
124
125 1;