1 package PVE
::Network
::SDN
::Zones
::Plugin
;
11 use PVE
::JSONSchema
qw(get_standard_option);
12 use base
qw(PVE::SectionConfig);
14 PVE
::Cluster
::cfs_register_file
('sdn/zones.cfg',
15 sub { __PACKAGE__-
>parse_config(@_); });
17 PVE
::Cluster
::cfs_register_file
('sdn/zones.cfg.new',
18 sub { __PACKAGE__-
>parse_config(@_); },
19 sub { __PACKAGE__-
>write_config(@_); });
21 PVE
::JSONSchema
::register_standard_option
('pve-sdn-zone-id', {
22 description
=> "The SDN zone object identifier.",
23 type
=> 'string', format
=> 'pve-sdn-zone-id',
26 PVE
::JSONSchema
::register_format
('pve-sdn-zone-id', \
&parse_sdn_zone_id
);
27 sub parse_sdn_zone_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 "SDN zone object ID '$id' contains illegal characters\n";
41 description
=> "Plugin type.",
42 type
=> 'string', format
=> 'pve-configid',
45 nodes
=> get_standard_option
('pve-node-list', { optional
=> 1 }),
46 zone
=> get_standard_option
('pve-sdn-zone-id',
47 { completion
=> \
&PVE
::Network
::SDN
::Zones
::complete_sdn_zone
}),
56 my ($class, $type, $key, $value) = @_;
58 if ($key eq 'nodes') {
61 foreach my $node (PVE
::Tools
::split_list
($value)) {
62 if (PVE
::JSONSchema
::pve_verify_node_name
($node)) {
74 my ($class, $type, $key, $value) = @_;
76 if ($key eq 'nodes') {
77 return join(',', keys(%$value));
83 sub parse_section_header
{
84 my ($class, $line) = @_;
86 if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
87 my ($type, $id) = (lc($1), $2);
88 my $errmsg = undef; # set if you want to skip whole section
89 eval { PVE
::JSONSchema
::pve_verify_configid
($type); };
91 my $config = {}; # to return additional attributes
92 return ($type, $id, $errmsg, $config);
97 sub generate_sdn_config
{
98 my ($class, $plugin_config, $node, $data, $ctime) = @_;
100 die "please implement inside plugin";
103 sub generate_controller_config
{
104 my ($class, $plugin_config, $router, $id, $uplinks, $config) = @_;
106 die "please implement inside plugin";
109 sub generate_controller_vnet_config
{
110 my ($class, $plugin_config, $controller, $transportid, $vnetid, $config) = @_;
114 sub write_controller_config
{
115 my ($class, $plugin_config, $config) = @_;
117 die "please implement inside plugin";
120 sub controller_reload
{
123 die "please implement inside plugin";
127 my ($class, $sndid, $scfg) = @_;
129 # do nothing by default
133 my ($class, $zoneid, $zone_cfg, $controller_cfg) = @_;
135 # do nothing by default
139 sub parse_tag_number_or_range
{
140 my ($str, $max, $tag) = @_;
142 my @elements = split(/,/, $str);
146 die "extraneous commas in list\n" if $str ne join(',', @elements);
147 foreach my $item (@elements) {
148 if ($item =~ m/^([0-9]+)-([0-9]+)$/) {
150 my ($port1, $port2) = ($1, $2);
151 die "invalid port '$port1'\n" if $port1 > $max;
152 die "invalid port '$port2'\n" if $port2 > $max;
153 die "backwards range '$port1:$port2' not allowed, did you mean '$port2:$port1'?\n" if $port1 > $port2;
155 if ($tag && $tag >= $port1 && $tag <= $port2){
160 } elsif ($item =~ m/^([0-9]+)$/) {
163 die "invalid port '$port'\n" if $port > $max;
165 if ($tag && $tag == $port){
171 die "tag $tag is not allowed" if $tag && !$allowed;
173 return (scalar(@elements) > 1);
176 #to be move to Network.pm helper
177 sub get_first_local_ipv4_from_interface
{
178 my ($interface) = @_;
180 my $cmd = ['/sbin/ip', 'address', 'show', 'dev', $interface];
187 if ($line =~ m!^\s*inet\s+($PVE::Tools::IPRE)(?:/\d+|\s+peer\s+)!) {
193 PVE
::Tools
::run_command
($cmd, outfunc
=> $code);