From b0ed2beab03198828c5bc1de417d4857b13aaa97 Mon Sep 17 00:00:00 2001 From: Alexandre Derumier Date: Wed, 27 Mar 2019 18:24:09 +0100 Subject: [PATCH] add vnet This allow to define bridges with a tag (can be vxlan or vlan tag), and use configuration from transportzone /etc/pve/network/vnet.cfg vnet1: tag 2 transportzone vlanzone1 name network1 ipv4 10.0.0.1 ipv6 2a03:2880:f003:c07:face:b00c::2 mtu 1500 vnet2: transportzone vlanzone1 tag 3 name network2 ipv6 2a03:2880:f003:c07:face:b00c::2 vnet3: transportzone vxlanmulticastzone1 tag 100000 name network3 mtu 1400 Signed-off-by: Alexandre Derumier --- PVE/Network/Vnet.pm | 94 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 PVE/Network/Vnet.pm diff --git a/PVE/Network/Vnet.pm b/PVE/Network/Vnet.pm new file mode 100644 index 0000000..c20a35d --- /dev/null +++ b/PVE/Network/Vnet.pm @@ -0,0 +1,94 @@ +package PVE::Network::Vnet; + +use strict; +use warnings; + +use PVE::JSONSchema qw(get_standard_option); +use PVE::SectionConfig; + +use base qw(PVE::SectionConfig); + +PVE::Cluster::cfs_register_file('network/vnet.cfg', + sub { __PACKAGE__->parse_config(@_); }, + sub { __PACKAGE__->write_config(@_); }); + + +sub options { + return { + transportzone => { fixed => 1 }, + tag => { fixed => 1 }, + name => { optional => 1 }, + ipv4 => { optional => 1 }, + ipv6 => { optional => 1 }, + name => { optional => 1 }, + mtu => { optional => 1 }, + }; +} + +my $defaultData = { + propertyList => { + transportzone => { + type => 'string', + description => "transportzone id", + optional => 1, + }, + tag => { + type => 'integer', + description => "vlan or vxlan id", + optional => 1, + }, + name => { + type => 'string', + description => "name of the network", + optional => 1, + }, + mtu => { + type => 'integer', + description => "mtu", + optional => 1, + }, + ipv4 => { + description => "Anycast router ipv4 address.", + type => 'string', format => 'ipv4', + optional => 1, + }, + ipv6 => { + description => "Anycast router ipv6 address.", + type => 'string', format => 'ipv6', + optional => 1, + }, + mac => { + type => 'boolean', + description => "Anycast router mac address", + optional => 1, + } + }, +}; + +sub type { + return 'vnet'; +} + +sub private { + return $defaultData; +} + + +sub parse_section_header { + my ($class, $line) = @_; + + if ($line =~ m/^(vnet(\d+)):$/) { + my $type = 'vnet'; + my $errmsg = undef; # set if you want to skip whole section + eval { PVE::JSONSchema::pve_verify_configid($type); }; + $errmsg = $@ if $@; + my $config = {}; # to return additional attributes + return ($type, $1, $errmsg, $config); + } + return undef; +} + +__PACKAGE__->register(); +__PACKAGE__->init(); + +1; -- 2.39.5