]> git.proxmox.com Git - pve-network.git/blame - PVE/Network/SDN/FaucetPlugin.pm
add evpnplugin (splitted from vxlanplugin)
[pve-network.git] / PVE / Network / SDN / FaucetPlugin.pm
CommitLineData
ad03c543
AD
1package PVE::Network::SDN::FaucetPlugin;
2
3use strict;
4use warnings;
5use PVE::Network::SDN::Plugin;
6use PVE::Tools;
7use PVE::INotify;
8use PVE::JSONSchema qw(get_standard_option);
9use CPAN::Meta::YAML;
10use Encode;
11
12use base('PVE::Network::SDN::Plugin');
13
14sub type {
15 return 'faucet';
16}
17
18sub plugindata {
19 return {
20 role => 'controller',
21 };
22}
23
24sub properties {
25 return {
26 };
27}
28
29# Plugin implementation
30sub generate_controller_config {
31 my ($class, $plugin_config, $router, $id, $uplinks, $config) = @_;
32
33}
34
35sub generate_controller_transport_config {
36 my ($class, $plugin_config, $router, $id, $uplinks, $config) = @_;
37
38 my $dpid = $plugin_config->{'dp-id'};
39 my $dphex = printf("%x",$dpid);
40
41 my $transport_config = {
42 dp_id => $dphex,
43 hardware => "Open vSwitch",
44 };
45
46 $config->{faucet}->{dps}->{$id} = $transport_config;
47
48}
49
50
51sub generate_controller_vnet_config {
52 my ($class, $plugin_config, $controller, $transportid, $vnetid, $config) = @_;
53
54 my $mac = $plugin_config->{mac};
55 my $ipv4 = $plugin_config->{ipv4};
56 my $ipv6 = $plugin_config->{ipv6};
57 my $tag = $plugin_config->{tag};
58 my $alias = $plugin_config->{alias};
59
60 my @ips = ();
61 push @ips, $ipv4 if $ipv4;
62 push @ips, $ipv6 if $ipv6;
63
64 my $vlan_config = { vid => $tag };
65
66 $vlan_config->{description} = $alias if $alias;
67 $vlan_config->{faucet_mac} = $mac if $mac;
68 $vlan_config->{faucet_vips} = \@ips if scalar @ips > 0;
69
70 $config->{faucet}->{vlans}->{$vnetid} = $vlan_config;
71
72 push(@{$config->{faucet}->{routers}->{$transportid}->{vlans}} , $vnetid);
73
74}
75
76sub on_delete_hook {
77 my ($class, $routerid, $sdn_cfg) = @_;
78
79}
80
81sub on_update_hook {
82 my ($class, $routerid, $sdn_cfg) = @_;
83
84}
85
86sub write_controller_config {
87 my ($class, $plugin_config, $config) = @_;
88
89 my $rawconfig = encode('UTF-8', CPAN::Meta::YAML::Dump($config->{faucet}));
90
91 return if !$rawconfig;
92 return if !-d "/etc/faucet";
93
94 my $frr_config_file = "/etc/faucet/faucet.yaml";
95
96 my $writefh = IO::File->new($frr_config_file,">");
97 print $writefh $rawconfig;
98 $writefh->close();
99}
100
1011;
102