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