]> git.proxmox.com Git - pve-network.git/blame - PVE/Network/Transport/Plugin.pm
api2: add networkconfig
[pve-network.git] / PVE / Network / Transport / Plugin.pm
CommitLineData
fb4b3e4a 1package PVE::Network::Transport::Plugin;
6939693f
AD
2
3use strict;
4use warnings;
5
6use PVE::Tools;
7use PVE::JSONSchema;
8use PVE::Cluster;
9
10use Data::Dumper;
eec580bf 11use PVE::JSONSchema qw(get_standard_option);
6939693f
AD
12use base qw(PVE::SectionConfig);
13
14PVE::Cluster::cfs_register_file('network/transports.cfg',
15 sub { __PACKAGE__->parse_config(@_); },
16 sub { __PACKAGE__->write_config(@_); });
17
18my $defaultData = {
19
20 propertyList => {
21 type => {
22 description => "Plugin type.",
23 type => 'string', format => 'pve-configid',
24 type => 'string',
25 },
eec580bf
AD
26 transport => get_standard_option('pve-transport-id',
27 { completion => \&PVE::Network::Transport::complete_transport }),
6939693f
AD
28 },
29};
30
31sub private {
32 return $defaultData;
33}
34
35sub parse_section_header {
36 my ($class, $line) = @_;
37
38 if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
39 my ($type, $transportid) = (lc($1), $2);
40 my $errmsg = undef; # set if you want to skip whole section
41 eval { PVE::JSONSchema::pve_verify_configid($type); };
42 $errmsg = $@ if $@;
43 my $config = {}; # to return additional attributes
44 return ($type, $transportid, $errmsg, $config);
45 }
46 return undef;
47}
48
49sub generate_network_config {
50 my ($class, $plugin_config, $node, $data, $ctime) = @_;
51
52 die "please implement inside plugin";
53}
54
55#helpers
56sub parse_tag_number_or_range {
57 my ($str, $max, $tag) = @_;
58
59 my @elements = split(/,/, $str);
60 my $count = 0;
61 my $allowed = undef;
62
63 die "extraneous commas in list\n" if $str ne join(',', @elements);
64 foreach my $item (@elements) {
65 if ($item =~ m/^([0-9]+)-([0-9]+)$/) {
66 $count += 2;
67 my ($port1, $port2) = ($1, $2);
68 die "invalid port '$port1'\n" if $port1 > $max;
69 die "invalid port '$port2'\n" if $port2 > $max;
70 die "backwards range '$port1:$port2' not allowed, did you mean '$port2:$port1'?\n" if $port1 > $port2;
71
72 if ($tag && $tag >= $port1 && $tag <= $port2){
73 $allowed = 1;
74 last;
75 }
76
77 } elsif ($item =~ m/^([0-9]+)$/) {
78 $count += 1;
79 my $port = $1;
80 die "invalid port '$port'\n" if $port > $max;
81
82 if ($tag && $tag == $port){
83 $allowed = 1;
84 last;
85 }
86 }
87 }
88 die "tag $tag is not allowed" if $tag && !$allowed;
89
90 return (scalar(@elements) > 1);
91}
92
931;