]> git.proxmox.com Git - pve-network.git/blame - PVE/Network/Network.pm
write configuration to networks.cfg.new
[pve-network.git] / PVE / Network / Network.pm
CommitLineData
92b6f291
AD
1package PVE::Network::Network;
2
3use strict;
4use warnings;
5use Data::Dumper;
6use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file);
7use PVE::Network::Network::Plugin;
8use PVE::Network::Network::VnetPlugin;
9use PVE::Network::Network::VlanPlugin;
10use PVE::Network::Network::VxlanMulticastPlugin;
11
12PVE::Network::Network::VnetPlugin->register();
13PVE::Network::Network::VlanPlugin->register();
14PVE::Network::Network::VxlanMulticastPlugin->register();
15PVE::Network::Network::Plugin->init();
16
17
18sub network_config {
19 my ($cfg, $networkid, $noerr) = @_;
20
21 die "no network ID specified\n" if !$networkid;
22
23 my $scfg = $cfg->{ids}->{$networkid};
24 die "network '$networkid' does not exists\n" if (!$noerr && !$scfg);
25
26 return $scfg;
27}
28
29sub config {
39d04c82
AD
30 my $config = cfs_read_file("networks.cfg.new");
31 $config = cfs_read_file("networks.cfg") if !keys %{$config->{ids}};
32 return $config;
92b6f291
AD
33}
34
35sub write_config {
36 my ($cfg) = @_;
37
39d04c82 38 cfs_write_file("networks.cfg.new", $cfg);
92b6f291
AD
39}
40
41sub lock_network_config {
42 my ($code, $errmsg) = @_;
43
39d04c82 44 cfs_lock_file("networks.cfg.new", undef, $code);
92b6f291
AD
45 my $err = $@;
46 if ($err) {
47 $errmsg ? die "$errmsg: $err" : die $err;
48 }
49}
50
51sub networks_ids {
52 my ($cfg) = @_;
53
54 return keys %{$cfg->{ids}};
55}
56
57sub complete_network {
58 my ($cmdname, $pname, $cvalue) = @_;
59
60 my $cfg = PVE::Network::Network::config();
61
62 return $cmdname eq 'add' ? [] : [ PVE::Network::Network::networks_ids($cfg) ];
63}
64
651;