]>
Commit | Line | Data |
---|---|---|
880ae857 AD |
1 | package PVE::Network::SDN::Zones::SimplePlugin; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | use PVE::Network::SDN::Zones::Plugin; | |
1d44ce70 | 6 | use PVE::Exception qw(raise raise_param_exc); |
880ae857 AD |
7 | |
8 | use base('PVE::Network::SDN::Zones::Plugin'); | |
9 | ||
10 | sub type { | |
11 | return 'simple'; | |
12 | } | |
13 | ||
14 | sub options { | |
880ae857 | 15 | return { |
efe1459b | 16 | nodes => { optional => 1}, |
880ae857 AD |
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 | ||
efe1459b TL |
25 | return $config if$config->{$vnetid}; # nothing to do |
26 | ||
880ae857 AD |
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 | ||
efe1459b | 33 | # vnet bridge |
880ae857 AD |
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"; | |
efe1459b | 41 | if ($vnet->{vlanaware}) { |
880ae857 AD |
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; | |
efe1459b TL |
47 | |
48 | push @{$config->{$vnetid}}, @iface_config; | |
880ae857 AD |
49 | |
50 | return $config; | |
51 | } | |
52 | ||
53 | sub status { | |
54 | my ($class, $plugin_config, $zone, $vnetid, $vnet, $status) = @_; | |
55 | ||
880ae857 | 56 | # ifaces to check |
efe1459b TL |
57 | my $ifaces = [ $vnetid ]; |
58 | my $err_msg = []; | |
880ae857 AD |
59 | foreach my $iface (@{$ifaces}) { |
60 | if (!$status->{$iface}->{status}) { | |
61 | push @$err_msg, "missing $iface"; | |
efe1459b | 62 | } elsif ($status->{$iface}->{status} ne 'pass') { |
880ae857 AD |
63 | push @$err_msg, "error iface $iface"; |
64 | } | |
65 | } | |
66 | return $err_msg; | |
67 | } | |
68 | ||
1d44ce70 AD |
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 | ||
880ae857 AD |
75 | 1; |
76 | ||
77 |