]> git.proxmox.com Git - pve-network.git/blame - PVE/Network/Transport.pm
api2: add networkconfig
[pve-network.git] / PVE / Network / Transport.pm
CommitLineData
eec580bf
AD
1package PVE::Network::Transport;
2
3use strict;
4use warnings;
5use Data::Dumper;
6use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file);
fb4b3e4a
AD
7use PVE::Network::Transport::Plugin;
8use PVE::Network::Transport::VlanPlugin;
9use PVE::Network::Transport::VxlanMulticastPlugin;
eec580bf 10
fb4b3e4a
AD
11PVE::Network::Transport::VlanPlugin->register();
12PVE::Network::Transport::VxlanMulticastPlugin->register();
13PVE::Network::Transport::Plugin->init();
eec580bf
AD
14
15
16sub 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
27sub config {
28
29 return cfs_read_file("network/transports.cfg");
30}
31
32sub write_config {
33 my ($cfg) = @_;
34
35 cfs_write_file("network/transports.cfg", $cfg);
36}
37
38sub 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
48sub transports_ids {
49 my ($cfg) = @_;
50
51 return keys %{$cfg->{ids}};
52}
53
54sub 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
621;