]> git.proxmox.com Git - pve-network.git/blob - PVE/Network/SDN/Zones/VlanPlugin.pm
remove vxlan|vlan allowed zone option
[pve-network.git] / PVE / Network / SDN / Zones / VlanPlugin.pm
1 package PVE::Network::SDN::Zones::VlanPlugin;
2
3 use strict;
4 use warnings;
5 use PVE::Network::SDN::Zones::Plugin;
6
7 use base('PVE::Network::SDN::Zones::Plugin');
8
9 sub type {
10 return 'vlan';
11 }
12
13 PVE::JSONSchema::register_format('pve-sdn-vlanrange', \&pve_verify_sdn_vlanrange);
14 sub pve_verify_sdn_vlanrange {
15 my ($vlanstr) = @_;
16
17 PVE::Network::SDN::Zones::Plugin::parse_tag_number_or_range($vlanstr, '4096');
18
19 return $vlanstr;
20 }
21
22 sub properties {
23 return {
24 'uplink-id' => {
25 type => 'integer',
26 minimum => 1, maximum => 4096,
27 description => 'Uplink interface',
28 },
29 };
30 }
31
32 sub options {
33
34 return {
35 'uplink-id' => { optional => 0 },
36 };
37 }
38
39 # Plugin implementation
40 sub generate_sdn_config {
41 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $config) = @_;
42
43 my $tag = $vnet->{tag};
44 my $mtu = $vnet->{mtu};
45 my $alias = $vnet->{alias};
46 my $uplink = $plugin_config->{'uplink-id'};
47
48 die "missing vlan tag" if !$tag;
49
50 my $iface = $uplinks->{$uplink}->{name};
51 $iface = "uplink${uplink}" if !$iface;
52 $iface .= ".$tag";
53
54 #tagged interface
55 my @iface_config = ();
56 push @iface_config, "mtu $mtu" if $mtu;
57 push(@{$config->{$iface}}, @iface_config) if !$config->{$iface};
58
59 #vnet bridge
60 @iface_config = ();
61 push @iface_config, "bridge_ports $iface";
62 push @iface_config, "bridge_stp off";
63 push @iface_config, "bridge_fd 0";
64 push @iface_config, "mtu $mtu" if $mtu;
65 push @iface_config, "alias $alias" if $alias;
66 push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
67
68 return $config;
69 }
70
71 sub on_delete_hook {
72 my ($class, $transportid, $sdn_cfg) = @_;
73
74 # verify that no vnet are associated to this transport
75 foreach my $id (keys %{$sdn_cfg->{ids}}) {
76 my $sdn = $sdn_cfg->{ids}->{$id};
77 die "transport $transportid is used by vnet $id"
78 if ($sdn->{type} eq 'vnet' && defined($sdn->{zone}) && $sdn->{zone} eq $transportid);
79 }
80 }
81
82 sub on_update_hook {
83 my ($class, $transportid, $sdn_cfg) = @_;
84
85 }
86
87 1;
88
89