]>
Commit | Line | Data |
---|---|---|
eec580bf AD |
1 | package PVE::Network::Transport; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | use Data::Dumper; | |
6 | use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file); | |
fb4b3e4a AD |
7 | use PVE::Network::Transport::Plugin; |
8 | use PVE::Network::Transport::VlanPlugin; | |
9 | use PVE::Network::Transport::VxlanMulticastPlugin; | |
eec580bf | 10 | |
fb4b3e4a AD |
11 | PVE::Network::Transport::VlanPlugin->register(); |
12 | PVE::Network::Transport::VxlanMulticastPlugin->register(); | |
13 | PVE::Network::Transport::Plugin->init(); | |
eec580bf AD |
14 | |
15 | ||
16 | sub transport_config { | |
17 | my ($cfg, $transportid, $noerr) = @_; | |
18 | ||
19 | die "no transport ID specified\n" if !$transportid; | |
20 | ||
21 | my $scfg = $cfg->{ids}->{$transportid}; | |
22 | die "transport '$transportid' does not exists\n" if (!$noerr && !$scfg); | |
23 | ||
24 | return $scfg; | |
25 | } | |
26 | ||
27 | sub config { | |
28 | ||
29 | return cfs_read_file("network/transports.cfg"); | |
30 | } | |
31 | ||
32 | sub write_config { | |
33 | my ($cfg) = @_; | |
34 | ||
35 | cfs_write_file("network/transports.cfg", $cfg); | |
36 | } | |
37 | ||
38 | sub lock_transport_config { | |
39 | my ($code, $errmsg) = @_; | |
40 | ||
41 | cfs_lock_file("network/transports.cfg", undef, $code); | |
42 | my $err = $@; | |
43 | if ($err) { | |
44 | $errmsg ? die "$errmsg: $err" : die $err; | |
45 | } | |
46 | } | |
47 | ||
48 | sub transports_ids { | |
49 | my ($cfg) = @_; | |
50 | ||
51 | return keys %{$cfg->{ids}}; | |
52 | } | |
53 | ||
54 | sub complete_transport { | |
55 | my ($cmdname, $pname, $cvalue) = @_; | |
56 | ||
57 | my $cfg = PVE::Network::Transport::config(); | |
58 | ||
59 | return $cmdname eq 'add' ? [] : [ PVE::Network::Transport::transports_ids($cfg) ]; | |
60 | } | |
61 | ||
62 | 1; |