1 package PVE
::Network
::SDN
::Plugin
;
11 use PVE
::JSONSchema
qw(get_standard_option);
12 use base
qw(PVE::SectionConfig);
14 PVE
::Cluster
::cfs_register_file
('sdn.cfg',
15 sub { __PACKAGE__-
>parse_config(@_); });
17 PVE
::Cluster
::cfs_register_file
('sdn.cfg.new',
18 sub { __PACKAGE__-
>parse_config(@_); },
19 sub { __PACKAGE__-
>write_config(@_); });
21 PVE
::JSONSchema
::register_standard_option
('pve-sdn-id', {
22 description
=> "The SDN object identifier.",
23 type
=> 'string', format
=> 'pve-sdn-id',
26 PVE
::JSONSchema
::register_format
('pve-sdn-id', \
&parse_sdn_id
);
28 my ($sdnid, $noerr) = @_;
30 if ($sdnid !~ m/^[a-z][a-z0-9\-\_\.]*[a-z0-9]$/i) {
31 return undef if $noerr;
32 die "SDN object ID '$sdnid' contains illegal characters\n";
41 description
=> "Plugin type.",
42 type
=> 'string', format
=> 'pve-configid',
45 sdn
=> get_standard_option
('pve-sdn-id',
46 { completion
=> \
&PVE
::Network
::SDN
::complete_sdn
}),
54 sub parse_section_header
{
55 my ($class, $line) = @_;
57 if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
58 my ($type, $sdnid) = (lc($1), $2);
59 my $errmsg = undef; # set if you want to skip whole section
60 eval { PVE
::JSONSchema
::pve_verify_configid
($type); };
62 my $config = {}; # to return additional attributes
63 return ($type, $sdnid, $errmsg, $config);
68 sub generate_sdn_config
{
69 my ($class, $plugin_config, $node, $data, $ctime) = @_;
71 die "please implement inside plugin";
74 sub generate_controller_config
{
75 my ($class, $plugin_config, $router, $id, $uplinks, $config) = @_;
77 die "please implement inside plugin";
80 sub write_controller_config
{
81 my ($class, $plugin_config, $config) = @_;
83 die "please implement inside plugin";
87 my ($class, $sndid, $scfg) = @_;
89 # do nothing by default
93 my ($class, $sdnid, $scfg) = @_;
95 # do nothing by default
99 sub parse_tag_number_or_range
{
100 my ($str, $max, $tag) = @_;
102 my @elements = split(/,/, $str);
106 die "extraneous commas in list\n" if $str ne join(',', @elements);
107 foreach my $item (@elements) {
108 if ($item =~ m/^([0-9]+)-([0-9]+)$/) {
110 my ($port1, $port2) = ($1, $2);
111 die "invalid port '$port1'\n" if $port1 > $max;
112 die "invalid port '$port2'\n" if $port2 > $max;
113 die "backwards range '$port1:$port2' not allowed, did you mean '$port2:$port1'?\n" if $port1 > $port2;
115 if ($tag && $tag >= $port1 && $tag <= $port2){
120 } elsif ($item =~ m/^([0-9]+)$/) {
123 die "invalid port '$port'\n" if $port > $max;
125 if ($tag && $tag == $port){
131 die "tag $tag is not allowed" if $tag && !$allowed;
133 return (scalar(@elements) > 1);
136 #to be move to Network.pm helper
137 sub get_first_local_ipv4_from_interface
{
138 my ($interface) = @_;
140 my $cmd = ['/sbin/ip', 'address', 'show', 'dev', $interface];
147 if ($line =~ m!^\s*inet\s+($PVE::Tools::IPRE)(?:/\d+|\s+peer\s+)!) {
153 PVE
::Tools
::run_command
($cmd, outfunc
=> $code);