]> git.proxmox.com Git - pve-network.git/blame - PVE/Network/SDN/Controllers/Plugin.pm
controllers: evpn : use frr restart if reload fail
[pve-network.git] / PVE / Network / SDN / Controllers / Plugin.pm
CommitLineData
f5eabba0 1package PVE::Network::SDN::Controllers::Plugin;
6939693f
AD
2
3use strict;
4use warnings;
5
6use PVE::Tools;
7use PVE::JSONSchema;
8use PVE::Cluster;
9
10use Data::Dumper;
eec580bf 11use PVE::JSONSchema qw(get_standard_option);
6939693f
AD
12use base qw(PVE::SectionConfig);
13
f5eabba0 14PVE::Cluster::cfs_register_file('sdn/controllers.cfg',
3f557f26
TL
15 sub { __PACKAGE__->parse_config(@_); },
16 sub { __PACKAGE__->write_config(@_); }
17);
6939693f 18
f5eabba0
AD
19PVE::JSONSchema::register_standard_option('pve-sdn-controller-id', {
20 description => "The SDN controller object identifier.",
21 type => 'string', format => 'pve-sdn-controller-id',
fe61b14c
AD
22});
23
f5eabba0
AD
24PVE::JSONSchema::register_format('pve-sdn-controller-id', \&parse_sdn_controller_id);
25sub parse_sdn_controller_id {
26 my ($id, $noerr) = @_;
fe61b14c 27
f81ad67f 28 if ($id !~ m/^[a-z][a-z0-9_-]*[a-z0-9]$/i) {
fe61b14c 29 return undef if $noerr;
7c5b0f6d 30 die "controller ID '$id' contains illegal characters\n";
fe61b14c 31 }
c08eeb0f 32 die "controller ID '$id' can't be more length than 64 characters\n" if length($id) > 64;
f5eabba0 33 return $id;
fe61b14c
AD
34}
35
6939693f
AD
36my $defaultData = {
37
38 propertyList => {
7d35eaf5 39 type => {
6939693f
AD
40 description => "Plugin type.",
41 type => 'string', format => 'pve-configid',
42 type => 'string',
43 },
f5eabba0
AD
44 controller => get_standard_option('pve-sdn-controller-id',
45 { completion => \&PVE::Network::SDN::complete_sdn_controller }),
6939693f
AD
46 },
47};
48
49sub private {
50 return $defaultData;
51}
52
53sub parse_section_header {
54 my ($class, $line) = @_;
55
56 if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
f5eabba0 57 my ($type, $id) = (lc($1), $2);
6939693f
AD
58 my $errmsg = undef; # set if you want to skip whole section
59 eval { PVE::JSONSchema::pve_verify_configid($type); };
60 $errmsg = $@ if $@;
61 my $config = {}; # to return additional attributes
f5eabba0 62 return ($type, $id, $errmsg, $config);
6939693f
AD
63 }
64 return undef;
65}
66
6bffe819 67sub generate_sdn_config {
6939693f
AD
68 my ($class, $plugin_config, $node, $data, $ctime) = @_;
69
70 die "please implement inside plugin";
71}
72
8fb1ee7f 73sub generate_controller_config {
f23633dc
AD
74 my ($class, $plugin_config, $controller_cfg, $id, $uplinks, $config) = @_;
75
76 die "please implement inside plugin";
77}
78
79
80sub generate_controller_zone_config {
81 my ($class, $plugin_config, $controller, $controller_cfg, $id, $uplinks, $config) = @_;
32602a38
AD
82
83 die "please implement inside plugin";
84}
85
ad03c543 86sub generate_controller_vnet_config {
56cdcac9 87 my ($class, $plugin_config, $controller, $zoneid, $vnetid, $config) = @_;
ad03c543
AD
88
89}
90
9cef13e9
AD
91sub generate_controller_rawconfig {
92 my ($class, $plugin_config, $config) = @_;
93
94 die "please implement inside plugin";
95}
96
8fb1ee7f
AD
97sub write_controller_config {
98 my ($class, $plugin_config, $config) = @_;
99
100 die "please implement inside plugin";
101}
102
fa609bdd
AD
103sub controller_reload {
104 my ($class) = @_;
105
106 die "please implement inside plugin";
107}
108
fe0c6b9e 109sub on_delete_hook {
56cdcac9 110 my ($class, $controllerid, $zone_cfg) = @_;
e8d5906e
AD
111
112 # do nothing by default
113}
114
115sub on_update_hook {
56cdcac9 116 my ($class, $controllerid, $controller_cfg) = @_;
fe0c6b9e
AD
117
118 # do nothing by default
119}
120
6939693f 1211;