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