]>
Commit | Line | Data |
---|---|---|
fb4b3e4a | 1 | package PVE::Network::Transport::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 | ||
14 | PVE::Cluster::cfs_register_file('network/transports.cfg', | |
15 | sub { __PACKAGE__->parse_config(@_); }, | |
16 | sub { __PACKAGE__->write_config(@_); }); | |
17 | ||
18 | my $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 | ||
31 | sub private { | |
32 | return $defaultData; | |
33 | } | |
34 | ||
35 | sub 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 | ||
49 | sub generate_network_config { | |
50 | my ($class, $plugin_config, $node, $data, $ctime) = @_; | |
51 | ||
52 | die "please implement inside plugin"; | |
53 | } | |
54 | ||
55 | #helpers | |
56 | sub 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 | ||
93 | 1; |