[pve-devel] [PATCH pve-container] LXC::Setup: Load required host files in new()

Wolfgang Bumiller w.bumiller at proxmox.com
Wed Nov 4 11:29:07 CET 2015


The host's /etc/resolv.conf is required to take over the
host's DNS settings.
---
 src/PVE/LXC/Setup.pm        | 6 +++++-
 src/PVE/LXC/Setup/Base.pm   | 8 ++++----
 src/PVE/LXC/Setup/Redhat.pm | 2 +-
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/PVE/LXC/Setup.pm b/src/PVE/LXC/Setup.pm
index 5ebda97..0e2da81 100644
--- a/src/PVE/LXC/Setup.pm
+++ b/src/PVE/LXC/Setup.pm
@@ -51,8 +51,12 @@ sub new {
     my $plugin_class = $plugins->{$type} ||
 	"no such OS type '$type'\n";
 
-    $self->{plugin} = $plugin_class->new($conf, $rootdir);
+    my $plugin = $plugin_class->new($conf, $rootdir);
+    $self->{plugin} = $plugin;
     $self->{in_chroot} = 0;
+
+    # Cache some host files we need access to:
+    $plugin->{host_resolv_conf} = PVE::INotify::read_file('resolvconf');
     
     return $self;
 }
diff --git a/src/PVE/LXC/Setup/Base.pm b/src/PVE/LXC/Setup/Base.pm
index 857835d..bfb16c5 100644
--- a/src/PVE/LXC/Setup/Base.pm
+++ b/src/PVE/LXC/Setup/Base.pm
@@ -22,7 +22,7 @@ sub new {
 }
 
 sub lookup_dns_conf {
-    my ($conf) = @_;
+    my ($self, $conf) = @_;
 
     my $nameserver = $conf->{nameserver};
     my $searchdomains = $conf->{searchdomain};
@@ -36,7 +36,7 @@ sub lookup_dns_conf {
 	
 	} else {
 
-	    my $host_resolv_conf = PVE::INotify::read_file('resolvconf');
+	    my $host_resolv_conf = $self->{host_resolv_conf};
 
 	    $searchdomains = $host_resolv_conf->{search};
 
@@ -137,7 +137,7 @@ sub template_fixup {
 sub set_dns {
     my ($self, $conf) = @_;
 
-    my ($searchdomains, $nameserver) = lookup_dns_conf($conf);
+    my ($searchdomains, $nameserver) = $self->lookup_dns_conf($conf);
     
     my $data = '';
 
@@ -172,7 +172,7 @@ sub set_hostname {
     my ($ipv4, $ipv6) = PVE::LXC::get_primary_ips($conf);
     my $hostip = $ipv4 || $ipv6;
 
-    my ($searchdomains) = lookup_dns_conf($conf);
+    my ($searchdomains) = $self->lookup_dns_conf($conf);
 
     $etc_hosts_data = update_etc_hosts($etc_hosts_data, $hostip, $oldname, 
 				       $hostname, $searchdomains);
diff --git a/src/PVE/LXC/Setup/Redhat.pm b/src/PVE/LXC/Setup/Redhat.pm
index 33f70a6..956e1da 100644
--- a/src/PVE/LXC/Setup/Redhat.pm
+++ b/src/PVE/LXC/Setup/Redhat.pm
@@ -146,7 +146,7 @@ sub set_hostname {
     my ($ipv4, $ipv6) = PVE::LXC::get_primary_ips($conf);
     my $hostip = $ipv4 || $ipv6;
 
-    my ($searchdomains) = PVE::LXC::Setup::Base::lookup_dns_conf($conf);
+    my ($searchdomains) = $self->lookup_dns_conf($conf);
 
     $etc_hosts_data = PVE::LXC::Setup::Base::update_etc_hosts($etc_hosts_data, $hostip, $oldname,
 							    $hostname, $searchdomains);
-- 
2.1.4





More information about the pve-devel mailing list