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