]> git.proxmox.com Git - pve-container.git/commitdiff
debian setup: dhcp, manual and unmanaged network
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 24 Jul 2015 07:14:56 +0000 (09:14 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 24 Jul 2015 11:08:27 +0000 (13:08 +0200)
src/PVE/LXCSetup/Debian.pm
src/test/test-debian-002/config
src/test/test-debian-003/config

index 21da86f8f29e6b1920f2b1712e1d0b4a07327683..7635e08045e3e06da1ef000b75d09d16674c542f 100644 (file)
@@ -113,24 +113,31 @@ sub setup_network {
        if ($d->{name}) {
            my $net = {};
            if (defined($d->{ip})) {
        if ($d->{name}) {
            my $net = {};
            if (defined($d->{ip})) {
-               my $ipinfo = PVE::LXC::parse_ipv4_cidr($d->{ip});
-               $net->{address} = $ipinfo->{address};
-               $net->{netmask} = $ipinfo->{netmask};
+               if ($d->{ip} =~ /^(?:dhcp|manual)$/) {
+                   $net->{address} = $d->{ip};
+               } else {
+                   my $ipinfo = PVE::LXC::parse_ipv4_cidr($d->{ip});
+                   $net->{address} = $ipinfo->{address};
+                   $net->{netmask} = $ipinfo->{netmask};
+               }
            }
            if (defined($d->{'gw'})) {
                $net->{gateway} = $d->{'gw'};
            }
            if (defined($d->{ip6})) {
            }
            if (defined($d->{'gw'})) {
                $net->{gateway} = $d->{'gw'};
            }
            if (defined($d->{ip6})) {
-               if ($d->{ip6} !~ /^($IPV6RE)\/(\d+)$/) {
+               if ($d->{ip6} =~ /^(?:dhcp|manual)$/) {
+                   $net->{address6} = $d->{ip6};
+               } elsif ($d->{ip6} !~ /^($IPV6RE)\/(\d+)$/) {
                    die "unable to parse ipv6 address/prefix\n";
                    die "unable to parse ipv6 address/prefix\n";
+               } else {
+                   $net->{address6} = $1;
+                   $net->{netmask6} = $2;
                }
                }
-               $net->{address6} = $1;
-               $net->{netmask6} = $2;
            }
            if (defined($d->{'gw6'})) {
                $net->{gateway6} = $d->{'gw6'};
            }
            }
            if (defined($d->{'gw6'})) {
                $net->{gateway6} = $d->{'gw6'};
            }
-           $networks->{$d->{name}} = $net;
+           $networks->{$d->{name}} = $net if keys %$net;
        }
     }
 
        }
     }
 
@@ -156,7 +163,9 @@ sub setup_network {
 
            $interfaces .= "auto $section->{ifname}\n" if $new;
 
 
            $interfaces .= "auto $section->{ifname}\n" if $new;
 
-           if ($net->{address}) {
+           if ($net->{address} =~ /^(dhcp|manual)$/) {
+               $interfaces .= "iface $section->{ifname} inet $1\n";
+           } elsif ($net->{address}) {
                $interfaces .= "iface $section->{ifname} inet static\n";
                $interfaces .= "\taddress $net->{address}\n" if defined($net->{address});
                $interfaces .= "\tnetmask $net->{netmask}\n" if defined($net->{netmask});
                $interfaces .= "iface $section->{ifname} inet static\n";
                $interfaces .= "\taddress $net->{address}\n" if defined($net->{address});
                $interfaces .= "\tnetmask $net->{netmask}\n" if defined($net->{netmask});
@@ -164,8 +173,6 @@ sub setup_network {
                foreach my $attr (@{$section->{attr}}) {
                    $interfaces .= "\t$attr\n";
                }
                foreach my $attr (@{$section->{attr}}) {
                    $interfaces .= "\t$attr\n";
                }
-           } else {
-               $interfaces .= "iface $section->{ifname} inet manual\n";                
            }
            
            $interfaces .= "\n";
            }
            
            $interfaces .= "\n";
@@ -173,7 +180,9 @@ sub setup_network {
        } elsif ($section->{type} eq 'ipv6') {
            $done_v6_hash->{$section->{ifname}} = 1;
            
        } elsif ($section->{type} eq 'ipv6') {
            $done_v6_hash->{$section->{ifname}} = 1;
            
-           if ($net->{address6}) {
+           if ($net->{address6} =~ /^(dhcp|manual)$/) {
+               $interfaces .= "iface $section->{ifname} inet6 $1\n";
+           } elsif ($net->{address6}) {
                $interfaces .= "iface $section->{ifname} inet6 static\n";
                $interfaces .= "\taddress $net->{address6}\n" if defined($net->{address6});
                $interfaces .= "\tnetmask $net->{netmask6}\n" if defined($net->{netmask6});
                $interfaces .= "iface $section->{ifname} inet6 static\n";
                $interfaces .= "\taddress $net->{address6}\n" if defined($net->{address6});
                $interfaces .= "\tnetmask $net->{netmask6}\n" if defined($net->{netmask6});
@@ -206,8 +215,9 @@ sub setup_network {
                }
                next;
            }
                }
                next;
            }
-           if ($line =~ m/^iface\s+(\S+)\s+inet\s+(\S+)\s*$/) {
+           if ($line =~ m/^\s*iface\s+(\S+)\s+inet\s+(\S+)\s*$/) {
                my $ifname = $1;
                my $ifname = $1;
+               &$print_section(); # print previous section
                if (!$networks->{$ifname}) {
                    $interfaces .= "$line\n";
                    next;
                if (!$networks->{$ifname}) {
                    $interfaces .= "$line\n";
                    next;
@@ -215,8 +225,9 @@ sub setup_network {
                $section = { type => 'ipv4', ifname => $ifname, attr => []};
                next;
            }
                $section = { type => 'ipv4', ifname => $ifname, attr => []};
                next;
            }
-           if ($line =~ m/^iface\s+(\S+)\s+inet6\s+(\S+)\s*$/) {
+           if ($line =~ m/^\s*iface\s+(\S+)\s+inet6\s+(\S+)\s*$/) {
                my $ifname = $1;
                my $ifname = $1;
+               &$print_section(); # print previous section
                if (!$networks->{$ifname}) {
                    $interfaces .= "$line\n";
                    next;
                if (!$networks->{$ifname}) {
                    $interfaces .= "$line\n";
                    next;
@@ -224,6 +235,17 @@ sub setup_network {
                $section = { type => 'ipv6', ifname => $ifname, attr => []};
                next;
            }
                $section = { type => 'ipv6', ifname => $ifname, attr => []};
                next;
            }
+           # Handle other section delimiters:
+           if ($line =~ m/^\s*(?:mapping\s
+                                |auto\s
+                                |allow-
+                                |source\s
+                                |source-directory\s
+                              )/x) {
+               &$print_section();
+               $interfaces .= "$line\n";
+               next;
+           }
            if ($section && $line =~ m/^\s*((\S+)\s(.*))$/) {
                my ($adata, $aname) = ($1, $2);
                if ($aname eq 'address' || $aname eq 'netmask' ||
            if ($section && $line =~ m/^\s*((\S+)\s(.*))$/) {
                my ($adata, $aname) = ($1, $2);
                if ($aname eq 'address' || $aname eq 'netmask' ||
index 73b98ff3937a82cf077b7c47e00b6e641940ee14..cf54bcc372dd61cdcdc12bc54e8945d05a7dad22 100644 (file)
@@ -14,3 +14,4 @@ lxc.network.type = veth
 pve.network.bridge = vmbr0
 lxc.network.name = eth2
 lxc.network.veth.pair = veth100i2
 pve.network.bridge = vmbr0
 lxc.network.name = eth2
 lxc.network.veth.pair = veth100i2
+pve.network.ip = manual
index c57b6cb13d0bf75d2a0c20e5d4a1f75bcb21f72c..cf83d343ba75b956a6717eaa83645847282a377c 100644 (file)
@@ -8,3 +8,4 @@ lxc.network.hwaddr = 26:2B:CC:E5:7F:F9
 pve.network.bridge = vmbr0
 lxc.network.name = eth0
 lxc.network.veth.pair = veth100.0
 pve.network.bridge = vmbr0
 lxc.network.name = eth0
 lxc.network.veth.pair = veth100.0
+pve.network.ip = manual