]> git.proxmox.com Git - pve-network.git/blob - PVE/Network/SDN/Zones/SimplePlugin.pm
polugin simple: whitespace/cleanups
[pve-network.git] / PVE / Network / SDN / Zones / SimplePlugin.pm
1 package PVE::Network::SDN::Zones::SimplePlugin;
2
3 use strict;
4 use warnings;
5 use PVE::Network::SDN::Zones::Plugin;
6 use PVE::Exception qw(raise raise_param_exc);
7
8 use base('PVE::Network::SDN::Zones::Plugin');
9
10 sub type {
11 return 'simple';
12 }
13
14 sub options {
15 return {
16 nodes => { optional => 1},
17 mtu => { optional => 1 }
18 };
19 }
20
21 # Plugin implementation
22 sub generate_sdn_config {
23 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $interfaces_config, $config) = @_;
24
25 return $config if$config->{$vnetid}; # nothing to do
26
27 my $ipv4 = $vnet->{ipv4};
28 my $ipv6 = $vnet->{ipv6};
29 my $mac = $vnet->{mac};
30 my $alias = $vnet->{alias};
31 my $mtu = $plugin_config->{mtu} if $plugin_config->{mtu};
32
33 # vnet bridge
34 my @iface_config = ();
35 push @iface_config, "address $ipv4" if $ipv4;
36 push @iface_config, "address $ipv6" if $ipv6;
37 push @iface_config, "hwaddress $mac" if $mac;
38 push @iface_config, "bridge_ports none";
39 push @iface_config, "bridge_stp off";
40 push @iface_config, "bridge_fd 0";
41 if ($vnet->{vlanaware}) {
42 push @iface_config, "bridge-vlan-aware yes";
43 push @iface_config, "bridge-vids 2-4094";
44 }
45 push @iface_config, "mtu $mtu" if $mtu;
46 push @iface_config, "alias $alias" if $alias;
47
48 push @{$config->{$vnetid}}, @iface_config;
49
50 return $config;
51 }
52
53 sub status {
54 my ($class, $plugin_config, $zone, $vnetid, $vnet, $status) = @_;
55
56 # ifaces to check
57 my $ifaces = [ $vnetid ];
58 my $err_msg = [];
59 foreach my $iface (@{$ifaces}) {
60 if (!$status->{$iface}->{status}) {
61 push @$err_msg, "missing $iface";
62 } elsif ($status->{$iface}->{status} ne 'pass') {
63 push @$err_msg, "error iface $iface";
64 }
65 }
66 return $err_msg;
67 }
68
69 sub verify_tag {
70 my ($class, $tag) = @_;
71
72 raise_param_exc({ tag => "vlan tag is not allowed on simple bridge"}) if defined($tag);
73 }
74
75 1;
76
77