]>
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);
9 use PVE
::Exception
qw(raise raise_param_exc);
11 PVE
::Cluster
::cfs_register_file
('sdn/vnets.cfg',
12 sub { __PACKAGE__-
>parse_config(@_); },
13 sub { __PACKAGE__-
>write_config(@_); });
15 PVE
::JSONSchema
::register_standard_option
('pve-sdn-vnet-id', {
16 description
=> "The SDN vnet object identifier.",
17 type
=> 'string', format
=> 'pve-sdn-vnet-id',
20 PVE
::JSONSchema
::register_format
('pve-sdn-vnet-id', \
&parse_sdn_vnet_id
);
21 sub parse_sdn_vnet_id
{
22 my ($id, $noerr) = @_;
24 if ($id !~ m/^[a-z][a-z0-9]*[a-z0-9]$/i) {
25 return undef if $noerr;
26 die "vnet ID '$id' contains illegal characters\n";
28 die "vnet ID '$id' can't be more length than 8 characters\n" if length($id) > 8;
35 vnet
=> get_standard_option
('pve-sdn-vnet-id',
36 { completion
=> \
&PVE
::Network
::SDN
::Vnets
::complete_sdn_vnet
}),
52 description
=> "zone id",
55 description
=> "Type",
60 description
=> "vlan or vxlan id",
64 description
=> 'Allow vm VLANs to pass through this vnet.',
68 description
=> "alias name of the vnet",
73 description
=> "Anycast router mac address",
74 optional
=> 1, format
=> 'mac-addr'
81 zone
=> { optional
=> 0},
82 tag
=> { optional
=> 1},
83 alias
=> { optional
=> 1 },
84 mac
=> { optional
=> 1 },
85 vlanaware
=> { optional
=> 1 },
90 my ($class, $vnetid, $vnet_cfg) = @_;
92 #verify if subnets are associated
93 my $subnets = PVE
::Network
::SDN
::Vnets
::get_subnets
($vnetid);
95 foreach my $subnetid (sort keys %{$subnets}) {
96 push @subnetlist, $subnetid;
98 raise_param_exc
({ vnet
=> "Vnet is attached to following subnets:". join(',', @subnetlist)}) if @subnetlist > 0;
102 my ($class, $vnetid, $vnet_cfg, $subnet_cfg) = @_;
104 #fixme : don't allow change zone if subnets are defined
105 #fixme : don't vlanaware change if subnets are defined
106 # my $subnets = PVE::Network::SDN::Vnets::get_subnets($vnetid);
108 # verify that tag is not already defined in another vnet
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 raise_param_exc
({ tag
=> "tag $tag already exist in vnet $id"}) if $tag eq $vnet->{tag
};