]>
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(@_); });
13 PVE
::Cluster
::cfs_register_file
('sdn/vnets.cfg.new',
14 sub { __PACKAGE__-
>parse_config(@_); },
15 sub { __PACKAGE__-
>write_config(@_); });
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',
22 PVE
::JSONSchema
::register_format
('pve-sdn-vnet-id', \
&parse_sdn_vnet_id
);
23 sub parse_sdn_vnet_id
{
24 my ($id, $noerr) = @_;
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";
30 die "vnet ID '$id' can't be more length than 10 characters\n" if length($id) > 10;
37 vnet
=> get_standard_option
('pve-sdn-vnet-id',
38 { completion
=> \
&PVE
::Network
::SDN
::Vnets
::complete_sdn_vnet
}),
54 description
=> "zone id",
57 description
=> "Type",
62 description
=> "vlan or vxlan id",
66 description
=> "alias name of the vnet",
70 description
=> "Anycast router ipv4 address.",
71 type
=> 'string', format
=> 'CIDRv4',
75 description
=> "Anycast router ipv6 address.",
76 type
=> 'string', format
=> 'CIDRv6',
81 description
=> "Anycast router mac address",
82 optional
=> 1, format
=> 'mac-addr'
89 zone
=> { optional
=> 0},
90 tag
=> { optional
=> 0},
91 alias
=> { optional
=> 1 },
92 ipv4
=> { optional
=> 1 },
93 ipv6
=> { optional
=> 1 },
94 mac
=> { optional
=> 1 },
99 my ($class, $sdnid, $vnet_cfg) = @_;
105 my ($class, $vnetid, $vnet_cfg) = @_;
106 # verify that tag is not already defined in another vnet
107 if (defined($vnet_cfg->{ids
}->{$vnetid}->{tag
})) {
108 my $tag = $vnet_cfg->{ids
}->{$vnetid}->{tag
};
109 foreach my $id (keys %{$vnet_cfg->{ids
}}) {
110 next if $id eq $vnetid;
111 my $vnet = $vnet_cfg->{ids
}->{$id};
112 if ($vnet->{type
} eq 'vnet' && defined($vnet->{tag
})) {
113 die "tag $tag already exist in vnet $id" if $tag eq $vnet->{tag
};