]> git.proxmox.com Git - pve-network.git/commitdiff
add simple plugin
authorAlexandre Derumier <aderumier@odiso.com>
Wed, 1 Jul 2020 07:10:36 +0000 (09:10 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 3 Jul 2020 11:46:52 +0000 (13:46 +0200)
allow to create standalone or simple routed vnets

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

index 10ca6164e99563efd8050d8f5e10a9c07e48b4c5..3e371df44617d95ab988a378d20ff4ea6d26db6c 100644 (file)
@@ -15,6 +15,7 @@ use PVE::Network::SDN::Zones::QinQPlugin;
 use PVE::Network::SDN::Zones::VxlanPlugin;
 use PVE::Network::SDN::Zones::EvpnPlugin;
 use PVE::Network::SDN::Zones::FaucetPlugin;
+use PVE::Network::SDN::Zones::SimplePlugin;
 
 use Storable qw(dclone);
 use PVE::JSONSchema qw(get_standard_option);
index dd2a426b1c95b0facbc4da2a0345c111edaa272a..143d6e5728ce4d447f92548d1400a3dcc721fc3d 100644 (file)
@@ -16,6 +16,7 @@ use PVE::Network::SDN::Zones::QinQPlugin;
 use PVE::Network::SDN::Zones::VxlanPlugin;
 use PVE::Network::SDN::Zones::EvpnPlugin;
 use PVE::Network::SDN::Zones::FaucetPlugin;
+use PVE::Network::SDN::Zones::SimplePlugin;
 use PVE::Network::SDN::Zones::Plugin;
 
 PVE::Network::SDN::Zones::VlanPlugin->register();
@@ -23,6 +24,7 @@ PVE::Network::SDN::Zones::QinQPlugin->register();
 PVE::Network::SDN::Zones::VxlanPlugin->register();
 PVE::Network::SDN::Zones::EvpnPlugin->register();
 PVE::Network::SDN::Zones::FaucetPlugin->register();
+PVE::Network::SDN::Zones::SimplePlugin->register();
 PVE::Network::SDN::Zones::Plugin->init();
 
 my $local_network_sdn_file = "/etc/network/interfaces.d/sdn";
index ba9a4b51e2022582994fc9ec634e9ee4ed4f88cd..8454388d7eb764dea7845808907711eede1f87a4 100644 (file)
@@ -1,4 +1,4 @@
-SOURCES=Plugin.pm VlanPlugin.pm VxlanPlugin.pm FaucetPlugin.pm EvpnPlugin.pm QinQPlugin.pm
+SOURCES=Plugin.pm VlanPlugin.pm VxlanPlugin.pm FaucetPlugin.pm EvpnPlugin.pm QinQPlugin.pm SimplePlugin.pm
 
 
 PERL5DIR=${DESTDIR}/usr/share/perl5
diff --git a/PVE/Network/SDN/Zones/SimplePlugin.pm b/PVE/Network/SDN/Zones/SimplePlugin.pm
new file mode 100644 (file)
index 0000000..60fb7db
--- /dev/null
@@ -0,0 +1,70 @@
+package PVE::Network::SDN::Zones::SimplePlugin;
+
+use strict;
+use warnings;
+use PVE::Network::SDN::Zones::Plugin;
+
+use base('PVE::Network::SDN::Zones::Plugin');
+
+sub type {
+    return 'simple';
+}
+
+sub options {
+
+    return {
+        nodes => { optional => 1},
+       mtu => { optional => 1 }
+    };
+}
+
+# Plugin implementation
+sub generate_sdn_config {
+    my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $interfaces_config, $config) = @_;
+
+    my $ipv4 = $vnet->{ipv4};
+    my $ipv6 = $vnet->{ipv6};
+    my $mac = $vnet->{mac};
+    my $alias = $vnet->{alias};
+    my $mtu = $plugin_config->{mtu} if $plugin_config->{mtu};
+
+    #vnet bridge
+    my @iface_config = ();
+    push @iface_config, "address $ipv4" if $ipv4;
+    push @iface_config, "address $ipv6" if $ipv6;
+    push @iface_config, "hwaddress $mac" if $mac;
+    push @iface_config, "bridge_ports none";
+    push @iface_config, "bridge_stp off";
+    push @iface_config, "bridge_fd 0";
+    if($vnet->{vlanaware}) {
+        push @iface_config, "bridge-vlan-aware yes";
+        push @iface_config, "bridge-vids 2-4094";
+    }
+    push @iface_config, "mtu $mtu" if $mtu;
+    push @iface_config, "alias $alias" if $alias;
+    push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
+
+    return $config;
+}
+
+sub status {
+    my ($class, $plugin_config, $zone, $vnetid, $vnet, $status) = @_;
+
+    my $err_msg = [];
+
+    # ifaces to check
+    my $ifaces = [ $vnetid];
+
+    foreach my $iface (@{$ifaces}) {
+       if (!$status->{$iface}->{status}) {
+           push @$err_msg, "missing $iface";
+        } elsif ($status->{$iface}->{status} ne 'pass') {
+           push @$err_msg, "error iface $iface";
+       }
+    }
+    return $err_msg;
+}
+
+1;
+
+