summaryrefslogtreecommitdiff
path: root/src/PVE/Network/SDN/Fabrics.pm
blob: 94f4e97a2f466542957f8c5bd2bbae54bc53d021 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package PVE::Network::SDN::Fabrics;

use strict;
use warnings;

use PVE::Cluster qw(cfs_register_file cfs_read_file cfs_lock_file cfs_write_file);
use PVE::JSONSchema qw(get_standard_option);
use PVE::INotify;
use PVE::RS::SDN::Fabrics;

cfs_register_file(
    'sdn/fabrics.cfg', \&parse_fabrics_config, \&write_fabrics_config,
);

sub parse_fabrics_config {
    my ($filename, $raw) = @_;
    return $raw // '';
}

sub write_fabrics_config {
    my ($filename, $config) = @_;
    return $config // '';
}

sub config {
    my ($running) = @_;

    if ($running) {
        my $running_config = PVE::Network::SDN::running_config();

        # if the config hasn't yet been applied after the introduction of
        # fabrics then the key does not exist in the running config so we
        # default to an empty hash
        my $fabrics_config = $running_config->{fabrics}->{ids} // {};
        return PVE::RS::SDN::Fabrics->running_config($fabrics_config);
    }

    my $fabrics_config = cfs_read_file("sdn/fabrics.cfg");
    return PVE::RS::SDN::Fabrics->config($fabrics_config);
}

sub write_config {
    my ($config) = @_;
    cfs_write_file("sdn/fabrics.cfg", $config->to_raw(), 1);
}

sub get_frr_daemon_status {
    my ($fabric_config) = @_;

    my $daemon_status = {};
    my $nodename = PVE::INotify::nodename();

    my $enabled_daemons = $fabric_config->enabled_daemons($nodename);

    for my $daemon (@$enabled_daemons) {
        $daemon_status->{$daemon} = 1;
    }

    return $daemon_status;
}

sub generate_frr_raw_config {
    my ($fabric_config) = @_;

    my @raw_config = ();

    my $nodename = PVE::INotify::nodename();

    my $frr_config = $fabric_config->get_frr_raw_config($nodename);
    push @raw_config, @$frr_config if @$frr_config;

    return \@raw_config;
}

1;