From 74e5cf6e4070a208e9f9ee7063536bf3585a0e12 Mon Sep 17 00:00:00 2001 From: mxi1 Date: Fri, 27 Mar 2009 18:03:48 +0000 Subject: [PATCH] use %activenics to config /etc/sysconfig/dhcpd git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@3019 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/dhcp.pm | 63 +++++++++++++++++----------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/dhcp.pm b/xCAT-server/lib/xcat/plugins/dhcp.pm index df4c85317..2782cdc80 100644 --- a/xCAT-server/lib/xcat/plugins/dhcp.pm +++ b/xCAT-server/lib/xcat/plugins/dhcp.pm @@ -423,31 +423,6 @@ sub process_request if (grep /^-n$/, @{$req->{arg}}) { - #support for /etc/sysconfig/dhcpd - if(-e "/etc/sysconfig/dhcpd") { - my @dhcpdifs = split / /,`grep '^DHCPD_INTERFACE' /etc/sysconfig/dhcpd |sed -e 's/DHCPD_INTERFACE=\"//' |sed -e 's/\"//'`; - if(scalar @dhcpdifs > 0) { - chomp $dhcpdifs[scalar @dhcpdifs - 1]; - } - #get "mgtifname" from network table - my $nettab = xCAT::Table->new("networks"); - my @nets_ref = $nettab->getAllAttribs('net','mgtifname'); - - foreach(@nets_ref) { - my $if = $_->{mgtifname}; - #add the neccessary mgtifnames to @dhcpifs - my $num = grep /$if/, @dhcpdifs; - next if ($num > 0); - push @dhcpdifs, $if; - } - - #update DHCPINTERFACES in the file /etc/sysconfig/dhcpd - my @tmp = map {"$_ "} @dhcpdifs; - my $output = `sed 's/^DHCPD_INTERFACE=.*$\"/DHCPD_INTERFACE=\"@tmp\"/' /etc/sysconfig/dhcpd`; - open DHCPD_FD, '>', "/etc/sysconfig/dhcpd"; - print DHCPD_FD $output; - close DHCPD_FD; - } if (-e "/etc/dhcpd.conf") { my $bakname = "/etc/dhcpd.conf.xcatbak"; @@ -507,6 +482,44 @@ sub process_request } } } + #add the active nics to /etc/sysconfig/dhcpd + if (-e "/etc/sysconfig/dhcpd") { + open DHCPD_FD, "/etc/sysconfig/dhcpd"; + my $syscfg_dhcpd = ""; + my $found = 0; + my $dhcpd_key = "DHCPDARGS"; + my $os = xCAT::Utils->osver(); + if ($os =~ /sles/i) { + $dhcpd_key = "DHCPD_INTERFACE"; + } + + my $ifarg = "$dhcpd_key=\""; + foreach (keys %activenics) { + $ifarg .= " $_"; + } + $ifarg .= "\"\n"; + + while () { + if ($_ =~ m/^$dhcpd_key/) { + $found = 1; + $syscfg_dhcpd .= $ifarg; + }else { + $syscfg_dhcpd .= $_; + } + } + + if ( $found eq 0 ) { + $syscfg_dhcpd .= $ifarg; + } + close DHCPD_FD; + + open DBG_FD, '>', "/etc/sysconfig/dhcpd"; + print DBG_FD $syscfg_dhcpd; + close DBG_FD; + } else { + $callback->({error=>"The file /etc/sysconfig/dhcpd doesn't exist, check the dhcp server"}); + return; + } unless ($dhcpconf[0]) { #populate an empty config with some starter data... $restartdhcp=1;