]> git.proxmox.com Git - pve-common.git/commitdiff
fix bug #116, #103: try to keep ordering in /etc/network/interfaces
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 19 Mar 2012 12:30:40 +0000 (13:30 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 19 Mar 2012 12:30:40 +0000 (13:30 +0100)
Makefile
data/PVE/INotify.pm
debian/changelog

index 1b8d0e12e022f8b360ff7d87ec85ec0342dcd944..dac46433c31adddf2122c02069e6a11544adc8ca 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 RELEASE=2.0
 
 VERSION=1.0
 RELEASE=2.0
 
 VERSION=1.0
-PKGREL=19
+PKGREL=20
 
 PACKAGE=libpve-common-perl
 
 
 PACKAGE=libpve-common-perl
 
index 12dc11b6ac0ed75d12514b871844fc905703bc73..110e0341b1c7cf106e31eb125f9ee31021b6fb52 100644 (file)
@@ -727,9 +727,11 @@ sub read_etc_network_interfaces {
 
            my $d = $ifaces->{$i};
            while (defined ($line = <$fh>)) {
 
            my $d = $ifaces->{$i};
            while (defined ($line = <$fh>)) {
-               if ($line =~ m/^#(.*)\s*$/) {
-                   $d->{comment} = '' if !$d->{comment};
-                   $d->{comment} .= PVE::Tools::decode_text($1) . "\n";
+               if ($line =~ m/^\s*#(.*)\s*$/) {
+                   # NOTE: we use 'comments' instead of 'comment' to 
+                   # avoid automatic utf8 conversion
+                   $d->{comments} = '' if !$d->{comments};
+                   $d->{comments} .= "$1\n";
                } elsif ($line =~ m/^\s+((\S+)\s+(.+))$/) {
                    my $option = $1;
                    my ($id, $value) = ($2, $3);
                } elsif ($line =~ m/^\s+((\S+)\s+(.+))$/) {
                    my $option = $1;
                    my ($id, $value) = ($2, $3);
@@ -876,10 +878,10 @@ sub __interface_to_string {
        $raw .= "\t$option\n";
     }
 
        $raw .= "\t$option\n";
     }
 
-    # add comments 
-    my $comment = $d->{comment} || '';
-    foreach my $cl (split(/\n/, $comment)) {
-       $raw .= '#' .  PVE::Tools::encode_text($cl) . "\n";
+    # add comments
+    my $comments = $d->{comments} || '';
+    foreach my $cl (split(/\n/, $comments)) {
+       $raw .= "#$cl\n";
     }
 
     $raw .= "\n";
     }
 
     $raw .= "\n";
@@ -894,14 +896,48 @@ sub write_etc_network_interfaces {
 
     my $printed = {};
 
 
     my $printed = {};
 
+    my $if_type_hash = {
+       loopback => 10,
+       eth => 20,
+       bond => 30,
+       bridge => 40,
+    };
+
+    my $lookup_type_prio = sub {
+       my $iface = shift;
+
+       my $alias = 0;
+       if ($iface =~ m/^(\S+):\d+$/) {
+           $iface = $1;
+           $alias = 1;
+       }
+
+       my $pri;
+       if ($iface eq 'lo') {
+           $pri = $if_type_hash->{loopback};
+       } elsif ($iface =~ m/^eth\d+$/) {
+           $pri = $if_type_hash->{eth} + $alias;
+       } elsif ($iface =~ m/^bond\d+$/) {
+           $pri = $if_type_hash->{bond} + $alias;
+       } elsif ($iface =~ m/^vmbr\d+$/) {
+           $pri = $if_type_hash->{bridge} + $alias;
+       }
+
+       return $pri || ($if_type_hash->{unknown} + $alias);
+    };
+
     foreach my $iface (sort {
        my $ref1 = $ifaces->{$a};
        my $ref2 = $ifaces->{$b};
     foreach my $iface (sort {
        my $ref1 = $ifaces->{$a};
        my $ref2 = $ifaces->{$b};
-       my $p1 = $ref1->{priority} || 100000;
-       my $p2 = $ref2->{priority} || 100000;
+       my $p1 = &$lookup_type_prio($a);
+       my $p2 = &$lookup_type_prio($b);
 
        return $p1 <=> $p2 if $p1 != $p2;
 
 
        return $p1 <=> $p2 if $p1 != $p2;
 
+       $p1 = $ref1->{priority} || 100000;
+       $p2 = $ref2->{priority} || 100000;
+
+       return $p1 <=> $p2 if $p1 != $p2;
 
        return $a cmp $b;
                       } keys %$ifaces) {
 
        return $a cmp $b;
                       } keys %$ifaces) {
index e373585517bd819629518b7ce9b728060c602148..125d073f65fc76a9dff5944a3ccaa7eea9eb1f04 100644 (file)
@@ -1,3 +1,9 @@
+libpve-common-perl (1.0-20) unstable; urgency=low
+
+  * fix bug #116, #103: try to keep ordering in /etc/network/interfaces
+
+ -- Proxmox Support Team <support@proxmox.com>  Mon, 19 Mar 2012 13:30:07 +0100
+
 libpve-common-perl (1.0-19) unstable; urgency=low
 
   * add dns-name format
 libpve-common-perl (1.0-19) unstable; urgency=low
 
   * add dns-name format