]> git.proxmox.com Git - pve-network.git/blob - PVE/Network/SDN/FaucetPlugin.pm
9e313c36ed515f423f7b8ce650eeae903450ca87
[pve-network.git] / PVE / Network / SDN / FaucetPlugin.pm
1 package PVE::Network::SDN::FaucetPlugin;
2
3 use strict;
4 use warnings;
5 use PVE::Network::SDN::Plugin;
6 use PVE::Tools;
7 use PVE::INotify;
8 use PVE::JSONSchema qw(get_standard_option);
9 use CPAN::Meta::YAML;
10 use Encode;
11
12 use base('PVE::Network::SDN::Plugin');
13
14 sub type {
15 return 'faucet';
16 }
17
18 sub plugindata {
19 return {
20 role => 'controller',
21 };
22 }
23
24 sub properties {
25 return {
26 };
27 }
28
29 # Plugin implementation
30 sub generate_controller_config {
31 my ($class, $plugin_config, $router, $id, $uplinks, $config) = @_;
32
33 }
34
35 sub 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
51 sub 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
76 sub on_delete_hook {
77 my ($class, $routerid, $sdn_cfg) = @_;
78
79 }
80
81 sub on_update_hook {
82 my ($class, $routerid, $sdn_cfg) = @_;
83
84 }
85
86 sub 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
101 1;
102