]> git.proxmox.com Git - pve-network.git/blob - PVE/Network/SDN/Zones/SimplePlugin.pm
7006b133d9900e8e601d7f32d82be186d4b8fdc2
[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 use PVE::Cluster;
8 use PVE::Tools;
9
10 use base('PVE::Network::SDN::Zones::Plugin');
11
12 sub type {
13 return 'simple';
14 }
15
16 sub options {
17 return {
18 nodes => { optional => 1},
19 mtu => { optional => 1 }
20 };
21 }
22
23 # Plugin implementation
24 sub generate_sdn_config {
25 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $subnet_cfg, $interfaces_config, $config) = @_;
26
27 return $config if$config->{$vnetid}; # nothing to do
28
29 my $ipv4 = $vnet->{ipv4};
30 my $ipv6 = $vnet->{ipv6};
31 my $mac = $vnet->{mac};
32 my $alias = $vnet->{alias};
33 my $mtu = $plugin_config->{mtu} if $plugin_config->{mtu};
34
35 # vnet bridge
36 my @iface_config = ();
37
38 my @subnets = PVE::Tools::split_list($vnet->{subnets}) if $vnet->{subnets};
39 foreach my $subnet (@subnets) {
40 next if !defined($subnet_cfg->{ids}->{$subnet});
41 push @iface_config, "address $subnet_cfg->{ids}->{$subnet}->{gateway}" if $subnet_cfg->{ids}->{$subnet}->{gateway};
42 }
43
44 push @iface_config, "hwaddress $mac" if $mac;
45 push @iface_config, "bridge_ports none";
46 push @iface_config, "bridge_stp off";
47 push @iface_config, "bridge_fd 0";
48 if ($vnet->{vlanaware}) {
49 push @iface_config, "bridge-vlan-aware yes";
50 push @iface_config, "bridge-vids 2-4094";
51 }
52 push @iface_config, "mtu $mtu" if $mtu;
53 push @iface_config, "alias $alias" if $alias;
54
55 push @{$config->{$vnetid}}, @iface_config;
56
57 return $config;
58 }
59
60 sub status {
61 my ($class, $plugin_config, $zone, $vnetid, $vnet, $status) = @_;
62
63 # ifaces to check
64 my $ifaces = [ $vnetid ];
65 my $err_msg = [];
66 foreach my $iface (@{$ifaces}) {
67 if (!$status->{$iface}->{status}) {
68 push @$err_msg, "missing $iface";
69 } elsif ($status->{$iface}->{status} ne 'pass') {
70 push @$err_msg, "error iface $iface";
71 }
72 }
73 return $err_msg;
74 }
75
76
77 sub vnet_update_hook {
78 my ($class, $vnet) = @_;
79
80 raise_param_exc({ tag => "vlan tag is not allowed on simple bridge"}) if defined($vnet->{tag});
81
82 if (!defined($vnet->{mac})) {
83 my $dc = PVE::Cluster::cfs_read_file('datacenter.cfg');
84 $vnet->{mac} = PVE::Tools::random_ether_addr($dc->{mac_prefix});
85 }
86 }
87
88 1;
89
90