1 package PVE
::Network
::SDN
::Controllers
::Plugin
;
11 use PVE
::JSONSchema
qw(get_standard_option);
12 use base
qw(PVE::SectionConfig);
14 PVE
::Cluster
::cfs_register_file
('sdn/controllers.cfg',
15 sub { __PACKAGE__-
>parse_config(@_); });
17 PVE
::Cluster
::cfs_register_file
('sdn/controllers.cfg.new',
18 sub { __PACKAGE__-
>parse_config(@_); },
19 sub { __PACKAGE__-
>write_config(@_); });
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',
26 PVE
::JSONSchema
::register_format
('pve-sdn-controller-id', \
&parse_sdn_controller_id
);
27 sub parse_sdn_controller_id
{
28 my ($id, $noerr) = @_;
30 if ($id !~ m/^[a-z][a-z0-9]*[a-z0-9]$/i) {
31 return undef if $noerr;
32 die "controller ID '$id' contains illegal characters\n";
34 die "controller ID '$id' can't be more length than 10 characters\n" if length($id) > 10;
42 description
=> "Plugin type.",
43 type
=> 'string', format
=> 'pve-configid',
46 controller
=> get_standard_option
('pve-sdn-controller-id',
47 { completion
=> \
&PVE
::Network
::SDN
::complete_sdn_controller
}),
55 sub parse_section_header
{
56 my ($class, $line) = @_;
58 if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
59 my ($type, $id) = (lc($1), $2);
60 my $errmsg = undef; # set if you want to skip whole section
61 eval { PVE
::JSONSchema
::pve_verify_configid
($type); };
63 my $config = {}; # to return additional attributes
64 return ($type, $id, $errmsg, $config);
69 sub generate_sdn_config
{
70 my ($class, $plugin_config, $node, $data, $ctime) = @_;
72 die "please implement inside plugin";
75 sub generate_controller_config
{
76 my ($class, $plugin_config, $controller, $id, $uplinks, $config) = @_;
78 die "please implement inside plugin";
81 sub generate_controller_vnet_config
{
82 my ($class, $plugin_config, $controller, $zoneid, $vnetid, $config) = @_;
86 sub write_controller_config
{
87 my ($class, $plugin_config, $config) = @_;
89 die "please implement inside plugin";
92 sub controller_reload
{
95 die "please implement inside plugin";
99 my ($class, $controllerid, $zone_cfg) = @_;
101 # do nothing by default
105 my ($class, $controllerid, $controller_cfg) = @_;
107 # do nothing by default
112 #to be move to Network.pm helper
113 sub get_first_local_ipv4_from_interface
{
114 my ($interface) = @_;
116 my $cmd = ['/sbin/ip', 'address', 'show', 'dev', $interface];
123 if ($line =~ m!^\s*inet\s+($PVE::Tools::IPRE)(?:/\d+|\s+peer\s+)!) {
129 PVE
::Tools
::run_command
($cmd, outfunc
=> $code);