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;