]>
git.proxmox.com Git - pve-network.git/blob - PVE/Network/SDN/VnetPlugin.pm
1 package PVE
::Network
::SDN
::VnetPlugin
;
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);
10 PVE
::Cluster
::cfs_register_file
('sdn/vnets.cfg',
11 sub { __PACKAGE__-
>parse_config(@_); },
12 sub { __PACKAGE__-
>write_config(@_); });
14 PVE
::JSONSchema
::register_standard_option
('pve-sdn-vnet-id', {
15 description
=> "The SDN vnet object identifier.",
16 type
=> 'string', format
=> 'pve-sdn-vnet-id',
19 PVE
::JSONSchema
::register_format
('pve-sdn-vnet-id', \
&parse_sdn_vnet_id
);
20 sub parse_sdn_vnet_id
{
21 my ($id, $noerr) = @_;
23 if ($id !~ m/^[a-z][a-z0-9]*[a-z0-9]$/i) {
24 return undef if $noerr;
25 die "vnet ID '$id' contains illegal characters\n";
27 die "vnet ID '$id' can't be more length than 8 characters\n" if length($id) > 8;
34 vnet
=> get_standard_option
('pve-sdn-vnet-id',
35 { completion
=> \
&PVE
::Network
::SDN
::Vnets
::complete_sdn_vnet
}),
51 description
=> "zone id",
54 description
=> "Type",
59 description
=> "vlan or vxlan id",
63 description
=> "alias name of the vnet",
67 description
=> "Anycast router ipv4 address.",
68 type
=> 'string', format
=> 'CIDRv4',
72 description
=> "Anycast router ipv6 address.",
73 type
=> 'string', format
=> 'CIDRv6',
78 description
=> "Anycast router mac address",
79 optional
=> 1, format
=> 'mac-addr'
86 zone
=> { optional
=> 0},
87 tag
=> { optional
=> 0},
88 alias
=> { optional
=> 1 },
89 ipv4
=> { optional
=> 1 },
90 ipv6
=> { optional
=> 1 },
91 mac
=> { optional
=> 1 },
96 my ($class, $sdnid, $vnet_cfg) = @_;
102 my ($class, $vnetid, $vnet_cfg) = @_;
103 # verify that tag is not already defined in another vnet
104 if (defined($vnet_cfg->{ids
}->{$vnetid}->{tag
})) {
105 my $tag = $vnet_cfg->{ids
}->{$vnetid}->{tag
};
106 foreach my $id (keys %{$vnet_cfg->{ids
}}) {
107 next if $id eq $vnetid;
108 my $vnet = $vnet_cfg->{ids
}->{$id};
109 if ($vnet->{type
} eq 'vnet' && defined($vnet->{tag
})) {
110 die "tag $tag already exist in vnet $id" if $tag eq $vnet->{tag
};