[pve-devel] [PATCH pve-network 2/6] add transport plugin infrastructure

Alexandre Derumier aderumier at odiso.com
Wed Mar 27 18:24:06 CET 2019


used to generate network configuration for differents kind of plugins (vlan,vxlan....)

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/Network/Plugin.pm | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 96 insertions(+)
 create mode 100644 PVE/Network/Plugin.pm

diff --git a/PVE/Network/Plugin.pm b/PVE/Network/Plugin.pm
new file mode 100644
index 0000000..b186d8f
--- /dev/null
+++ b/PVE/Network/Plugin.pm
@@ -0,0 +1,96 @@
+package PVE::Network::Plugin;
+
+use strict;
+use warnings;
+
+use PVE::Tools;
+use PVE::JSONSchema;
+use PVE::Cluster;
+
+use Data::Dumper;
+
+use base qw(PVE::SectionConfig);
+
+PVE::Cluster::cfs_register_file('network/transports.cfg',
+				 sub { __PACKAGE__->parse_config(@_); },
+				 sub { __PACKAGE__->write_config(@_); });
+
+my $defaultData = {
+
+    propertyList => {
+	type => { 
+	    description => "Plugin type.",
+	    type => 'string', format => 'pve-configid',
+	    type => 'string',
+	},
+	'uplink-id' => {
+	    type => 'integer',
+	    minimum => 1, maximum => 4096,
+	    description => 'Uplink interface',
+	},
+    },
+};
+
+sub private {
+    return $defaultData;
+}
+
+sub parse_section_header {
+    my ($class, $line) = @_;
+
+    if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
+        my ($type, $transportid) = (lc($1), $2);
+	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, $transportid, $errmsg, $config);
+    }
+    return undef;
+}
+
+sub generate_network_config {
+    my ($class, $plugin_config, $node, $data, $ctime) = @_;
+
+    die "please implement inside plugin";
+}
+
+#helpers
+sub parse_tag_number_or_range {
+    my ($str, $max, $tag) = @_;
+
+    my @elements = split(/,/, $str);
+    my $count = 0;
+    my $allowed = undef;
+
+    die "extraneous commas in list\n" if $str ne join(',', @elements);
+    foreach my $item (@elements) {
+	if ($item =~ m/^([0-9]+)-([0-9]+)$/) {
+	    $count += 2;
+	    my ($port1, $port2) = ($1, $2);
+	    die "invalid port '$port1'\n" if $port1 > $max;
+	    die "invalid port '$port2'\n" if $port2 > $max;
+	    die "backwards range '$port1:$port2' not allowed, did you mean '$port2:$port1'?\n" if $port1 > $port2;
+
+	    if ($tag && $tag >= $port1 && $tag <= $port2){
+		$allowed = 1;
+		last;
+	    }
+
+	} elsif ($item =~ m/^([0-9]+)$/) {
+	    $count += 1;
+	    my $port = $1;
+	    die "invalid port '$port'\n" if $port > $max;
+
+	    if ($tag && $tag == $port){
+		$allowed = 1;
+		last;
+	    }
+	}
+    }
+    die "tag $tag is not allowed" if $tag && !$allowed;
+
+    return (scalar(@elements) > 1);
+}
+
+1;
-- 
2.11.0



More information about the pve-devel mailing list