]>
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', |
6939693f AD |
15 | sub { __PACKAGE__->parse_config(@_); }, |
16 | sub { __PACKAGE__->write_config(@_); }); | |
17 | ||
f5eabba0 AD |
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', | |
fe61b14c AD |
21 | }); |
22 | ||
f5eabba0 AD |
23 | PVE::JSONSchema::register_format('pve-sdn-controller-id', \&parse_sdn_controller_id); |
24 | sub parse_sdn_controller_id { | |
25 | my ($id, $noerr) = @_; | |
fe61b14c | 26 | |
7c5b0f6d | 27 | if ($id !~ m/^[a-z][a-z0-9]*[a-z0-9]$/i) { |
fe61b14c | 28 | return undef if $noerr; |
7c5b0f6d | 29 | die "controller ID '$id' contains illegal characters\n"; |
fe61b14c | 30 | } |
7c5b0f6d | 31 | die "controller ID '$id' can't be more length than 10 characters\n" if length($id) > 10; |
f5eabba0 | 32 | return $id; |
fe61b14c AD |
33 | } |
34 | ||
6939693f AD |
35 | my $defaultData = { |
36 | ||
37 | propertyList => { | |
7d35eaf5 | 38 | type => { |
6939693f AD |
39 | description => "Plugin type.", |
40 | type => 'string', format => 'pve-configid', | |
41 | type => 'string', | |
42 | }, | |
f5eabba0 AD |
43 | controller => get_standard_option('pve-sdn-controller-id', |
44 | { completion => \&PVE::Network::SDN::complete_sdn_controller }), | |
6939693f AD |
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*$/) { | |
f5eabba0 | 56 | my ($type, $id) = (lc($1), $2); |
6939693f AD |
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 | |
f5eabba0 | 61 | return ($type, $id, $errmsg, $config); |
6939693f AD |
62 | } |
63 | return undef; | |
64 | } | |
65 | ||
6bffe819 | 66 | sub generate_sdn_config { |
6939693f AD |
67 | my ($class, $plugin_config, $node, $data, $ctime) = @_; |
68 | ||
69 | die "please implement inside plugin"; | |
70 | } | |
71 | ||
8fb1ee7f | 72 | sub generate_controller_config { |
f23633dc AD |
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) = @_; | |
32602a38 AD |
81 | |
82 | die "please implement inside plugin"; | |
83 | } | |
84 | ||
ad03c543 | 85 | sub generate_controller_vnet_config { |
56cdcac9 | 86 | my ($class, $plugin_config, $controller, $zoneid, $vnetid, $config) = @_; |
ad03c543 AD |
87 | |
88 | } | |
89 | ||
9cef13e9 AD |
90 | sub generate_controller_rawconfig { |
91 | my ($class, $plugin_config, $config) = @_; | |
92 | ||
93 | die "please implement inside plugin"; | |
94 | } | |
95 | ||
8fb1ee7f AD |
96 | sub write_controller_config { |
97 | my ($class, $plugin_config, $config) = @_; | |
98 | ||
99 | die "please implement inside plugin"; | |
100 | } | |
101 | ||
fa609bdd AD |
102 | sub controller_reload { |
103 | my ($class) = @_; | |
104 | ||
105 | die "please implement inside plugin"; | |
106 | } | |
107 | ||
fe0c6b9e | 108 | sub on_delete_hook { |
56cdcac9 | 109 | my ($class, $controllerid, $zone_cfg) = @_; |
e8d5906e AD |
110 | |
111 | # do nothing by default | |
112 | } | |
113 | ||
114 | sub on_update_hook { | |
56cdcac9 | 115 | my ($class, $controllerid, $controller_cfg) = @_; |
fe0c6b9e AD |
116 | |
117 | # do nothing by default | |
118 | } | |
119 | ||
6939693f | 120 | 1; |