[pve-devel] [PATCH common] network interfaces code is split into syntax dependent and independent parts

Igor Vlasenko ivlasenko at gmail.com
Wed May 18 11:33:26 CEST 2016


On Wed, May 18, 2016 at 12:09 PM, Dietmar Maurer <dietmar at proxmox.com> wrote:
>> In fact, systemd-networkd is also another reason to accept refactoring
>> network configuration
>> code to be more abstract.
>> The patch I proposed is the most trivial.
> Sorry, but for me this is not trivial, and I am quite unsure
> it it make things easier. I would keep that code separate.
>
> other opinions?

Well, I was wrong to propose changes in big chunks.
I agree that the change is too big and is not trivial.

Let us start with the following patch below:
It is really short, trivial, passes tests,
and the sub __prewrite_setup_network_interfaces
can be used directly in code that supports etcnet or systemd-networkd.

Signed-off-by: Igor Vlasenko <viy at altlinux.org>
---
 src/PVE/INotify.pm | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm
index c34659f..81bcce0 100644
--- a/src/PVE/INotify.pm
+++ b/src/PVE/INotify.pm
@@ -1170,12 +1170,14 @@ sub write_etc_network_interfaces {
     my $raw = __write_etc_network_interfaces($config);
     PVE::Tools::safe_print($filename, $fh, $raw);
 }
-sub __write_etc_network_interfaces {
+
+# There are unofficial ports of PVE to platforms that use other
network configuration subsystems
+# such as etcnet instead of /etc/network/interfaces. The code below
is independent of
+# the network configuration subsystem used and can be shared between
different platforms.
+sub __prewrite_setup_network_interfaces {
     my ($config) = @_;

     my $ifaces = $config->{ifaces};
-    my @options = @{$config->{options}};
-
     my $used_ports = {};

     foreach my $iface (keys %$ifaces) {
@@ -1253,6 +1255,15 @@ sub __write_etc_network_interfaces {
         }
     }
     }
+}
+
+sub __write_etc_network_interfaces {
+    my ($config) = @_;
+
+    __prewrite_setup_network_interfaces($config);
+
+    my $ifaces = $config->{ifaces};
+    my @options = @{$config->{options}};

     my $raw = <<'NETWORKDOC';
 # network interface settings; autogenerated
-- 
2.6.5



More information about the pve-devel mailing list