[pve-devel] [PATCH pve-network 2/3] write configuration to networks.cfg.new
Alexandre Derumier
aderumier at odiso.com
Mon May 6 14:47:13 CEST 2019
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/Network/Network.pm | 9 +++++----
PVE/Network/Network/Plugin.pm | 3 +++
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/PVE/Network/Network.pm b/PVE/Network/Network.pm
index 8bd272f..ee0b973 100644
--- a/PVE/Network/Network.pm
+++ b/PVE/Network/Network.pm
@@ -27,20 +27,21 @@ sub network_config {
}
sub config {
-
- return cfs_read_file("networks.cfg");
+ my $config = cfs_read_file("networks.cfg.new");
+ $config = cfs_read_file("networks.cfg") if !keys %{$config->{ids}};
+ return $config;
}
sub write_config {
my ($cfg) = @_;
- cfs_write_file("networks.cfg", $cfg);
+ cfs_write_file("networks.cfg.new", $cfg);
}
sub lock_network_config {
my ($code, $errmsg) = @_;
- cfs_lock_file("networks.cfg", undef, $code);
+ cfs_lock_file("networks.cfg.new", undef, $code);
my $err = $@;
if ($err) {
$errmsg ? die "$errmsg: $err" : die $err;
diff --git a/PVE/Network/Network/Plugin.pm b/PVE/Network/Network/Plugin.pm
index e834434..6c34711 100644
--- a/PVE/Network/Network/Plugin.pm
+++ b/PVE/Network/Network/Plugin.pm
@@ -12,6 +12,9 @@ use PVE::JSONSchema qw(get_standard_option);
use base qw(PVE::SectionConfig);
PVE::Cluster::cfs_register_file('networks.cfg',
+ sub { __PACKAGE__->parse_config(@_); });
+
+PVE::Cluster::cfs_register_file('networks.cfg.new',
sub { __PACKAGE__->parse_config(@_); },
sub { __PACKAGE__->write_config(@_); });
--
2.11.0
More information about the pve-devel
mailing list