]>
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 PVE
::Exception
qw(raise raise_param_exc);
8 use PVE
::JSONSchema
qw(get_standard_option);
10 use PVE
::SectionConfig
;
11 use base
qw(PVE::SectionConfig);
13 PVE
::Cluster
::cfs_register_file
('sdn/vnets.cfg',
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 8 characters\n" if length($id) > 8;
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
=> 'Allow vm VLANs to pass through this vnet.',
70 description
=> "alias name of the vnet",
71 pattern
=> qr/[\(\)-_.\w\d\s]{0,256}/i,
80 zone
=> { optional
=> 0},
81 tag
=> { optional
=> 1},
82 alias
=> { optional
=> 1 },
83 vlanaware
=> { optional
=> 1 },
88 my ($class, $vnetid, $vnet_cfg) = @_;
90 #verify if subnets are associated
91 my $subnets = PVE
::Network
::SDN
::Vnets
::get_subnets
($vnetid);
92 raise_param_exc
({ vnet
=> "Can't delete vnet if subnets exists"}) if $subnets;
96 my ($class, $vnetid, $vnet_cfg) = @_;
98 my $vnet = $vnet_cfg->{ids
}->{$vnetid};
99 my $tag = $vnet->{tag
};
100 my $vlanaware = $vnet->{vlanaware
};
102 #don't allow vlanaware change if subnets are defined
103 if($vnet->{vlanaware
}) {
104 my $subnets = PVE
::Network
::SDN
::Vnets
::get_subnets
($vnetid);
105 raise_param_exc
({ vlanaware
=> "vlanaware vnet is not compatible with subnets"}) if $subnets;