]>
Commit | Line | Data |
---|---|---|
86d22462 | 1 | package PVE::Network::SDN::VnetPlugin; |
e7939454 AD |
2 | |
3 | use strict; | |
4 | use warnings; | |
5 | ||
f5eabba0 AD |
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); | |
e7939454 | 9 | |
f5eabba0 AD |
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 | ||
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 | ||
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 | }; | |
46cd4e06 | 41 | |
6bad73d0 AD |
42 | sub type { |
43 | return 'vnet'; | |
44 | } | |
e7939454 | 45 | |
f5eabba0 AD |
46 | sub private { |
47 | return $defaultData; | |
8fb1ee7f AD |
48 | } |
49 | ||
6bad73d0 | 50 | sub 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 |
92 | sub 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 | 104 | sub on_delete_hook { |
56cdcac9 | 105 | my ($class, $sdnid, $vnet_cfg) = @_; |
fe0c6b9e | 106 | |
cf5816ef | 107 | return; |
fe0c6b9e AD |
108 | } |
109 | ||
e8d5906e | 110 | sub on_update_hook { |
56cdcac9 | 111 | my ($class, $vnetid, $vnet_cfg) = @_; |
e8d5906e | 112 | # verify that tag is not already defined in another vnet |
56cdcac9 AD |
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}; | |
6a2db30a AD |
120 | } |
121 | } | |
122 | } | |
e8d5906e | 123 | } |
e7939454 AD |
124 | |
125 | 1; |