]> git.proxmox.com Git - pve-network.git/commitdiff
add transport plugin infrastructure
authorAlexandre Derumier <aderumier@odiso.com>
Wed, 27 Mar 2019 17:24:06 +0000 (18:24 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 28 Mar 2019 10:01:16 +0000 (11:01 +0100)
used to generate network configuration for differents kind of plugins (vlan,vxlan....)

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
PVE/Network/Plugin.pm [new file with mode: 0644]

diff --git a/PVE/Network/Plugin.pm b/PVE/Network/Plugin.pm
new file mode 100644 (file)
index 0000000..b186d8f
--- /dev/null
@@ -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;