From 65356f78ee46917a0504307621973be0546ad422 Mon Sep 17 00:00:00 2001 From: lissav Date: Mon, 25 Feb 2008 13:05:21 +0000 Subject: [PATCH] Add plugins to support setup of Service Nodes. git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@556 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server-2.0/lib/xcat/plugins/DHCPsn.pm | 119 ++++++++++++++ xCAT-server-2.0/lib/xcat/plugins/DNSsn.pm | 178 +++++++++++++++++++++ xCAT-server-2.0/lib/xcat/plugins/NFSsn.pm | 58 +++---- xCAT-server-2.0/lib/xcat/plugins/TFTPsn.pm | 135 ++++++++++++++++ 4 files changed, 457 insertions(+), 33 deletions(-) create mode 100644 xCAT-server-2.0/lib/xcat/plugins/DHCPsn.pm create mode 100644 xCAT-server-2.0/lib/xcat/plugins/DNSsn.pm create mode 100644 xCAT-server-2.0/lib/xcat/plugins/TFTPsn.pm diff --git a/xCAT-server-2.0/lib/xcat/plugins/DHCPsn.pm b/xCAT-server-2.0/lib/xcat/plugins/DHCPsn.pm new file mode 100644 index 000000000..d92a54d93 --- /dev/null +++ b/xCAT-server-2.0/lib/xcat/plugins/DHCPsn.pm @@ -0,0 +1,119 @@ +#!/usr/bin/env perl +# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html +#------------------------------------------------------- +package xCAT_plugin::DHCPsn; +use xCAT::Table; + +use xCAT::Utils; + +use xCAT::MsgUtils; +use Getopt::Long; + +#------------------------------------------------------- + +=head1 + xCAT plugin package to setup of DHCP + + +#------------------------------------------------------- + +=head3 handled_commands + +Check to see if on a Service Node +Check database to see if this node is a DHCP server +Call setup_DHCP + +=cut + +#------------------------------------------------------- + +sub handled_commands +{ + my $rc = 0; + if (xCAT::Utils->isServiceNode()) + { + my @nodeinfo = xCAT::Utils->determinehostname; + my $nodename = $nodeinfo[0]; + my $nodeipaddr = $nodeinfo[1]; + my $service = "dhcpserver"; + + $rc = xCAT::Utils->isServiceReq($nodename, $service, $nodeipaddr); + if ($rc == 1) + { + + # service needed on this Service Node + $rc = &setup_DHCP($nodename); # setup DHCP + } + } + return $rc; +} + +#------------------------------------------------------- + +=head3 process_request + + Process the command + +=cut + +#------------------------------------------------------- +sub process_request +{ + return; +} + +#----------------------------------------------------------------------------- + +=head3 setup_DHCP + + Sets up DHCP services + +=cut + +#----------------------------------------------------------------------------- +sub setup_DHCP +{ + my ($nodename) = @_; + my $rc = 0; + my $cmd; + my @output; + + # read DB for nodeinfo + my $retdata = xCAT::Utils->readSNInfo($nodename); + if ($retdata->{'arch'}) + { # no error + my $master = $retdata->{'master'}; + my $os = $retdata->{'os'}; + my $arch = $retdata->{'arch'}; + + # run makedhcp + $XCATROOT = "/opt/xcat"; # default + + if ($ENV{'XCATROOT'}) + { + $XCATROOT = $ENV{'XCATROOT'}; + } + $cmd = "$XCATROOT/sbin/makedhcp -n"; + @output = xCAT::Utils->runcmd($cmd, -1); + if ($::RUNCMD_RC != 0) + { + xCAT::MsgUtils->message("S", "Error from $cmd, output=@output"); + return 1; + } + $cmd = "service dhcpd restart"; + xCAT::Utils->runcmd($cmd, -1); + if ($::RUNCMD_RC != 0) + { + xCAT::MsgUtils->message("S", "Error from $cmd"); + return 1; + } + + } + else + { # error reading Db + $rc = 1; + } + xCAT::Utils->update_xCATSN("dhcp"); + return $rc; +} +1; diff --git a/xCAT-server-2.0/lib/xcat/plugins/DNSsn.pm b/xCAT-server-2.0/lib/xcat/plugins/DNSsn.pm new file mode 100644 index 000000000..be85985af --- /dev/null +++ b/xCAT-server-2.0/lib/xcat/plugins/DNSsn.pm @@ -0,0 +1,178 @@ +#!/usr/bin/env perl +# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html +#------------------------------------------------------- +package xCAT_plugin::DNSsn; +use xCAT::Table; + +use xCAT::Utils; + +use xCAT::MsgUtils; +use Getopt::Long; + +#------------------------------------------------------- + +=head1 + xCAT plugin package to setup of DNS + + +#------------------------------------------------------- + +=head3 handled_commands + +Check to see if on a Service Node +Check database to see if this node is a DNS server +Call setup_DNS + +=cut + +#------------------------------------------------------- + +sub handled_commands +{ + my $rc=0; + if (xCAT::Utils->isServiceNode()) + { + my @nodeinfo = xCAT::Utils->determinehostname; + my $nodename = $nodeinfo[0]; + my $nodeipaddr = $nodeinfo[1]; + my $service = "nameservers"; + + $rc = xCAT::Utils->isServiceReq($nodename, $service, $nodeipaddr); + if ($rc == 1) + { + + # service needed on this Service Node + $rc = &setup_DNS($nodename); # setup DNS + } + } + return $rc; +} + +#------------------------------------------------------- + +=head3 process_request + + Process the command + +=cut + +#------------------------------------------------------- +sub process_request +{ + return; +} + +#----------------------------------------------------------------------------- + +=head3 setup_DNS + + Sets up Domain Name service + http://www.adminschoice.com/docs/domain_name_service.htm#Introduction + +=cut + +#----------------------------------------------------------------------------- +sub setup_DNS +{ + my ($nodename) = @_; + + # backup the original + if ((-e "/etc/named.conf") && (!(-e "/etc/named.conf.ORIG"))) + { + `cp /etc/named.conf /etc/named.conf.ORIG`; + } + + # read DB for nodeinfo + my $master; + my $os; + my $arch; + my $retdata = xCAT::Utils->readSNInfo($nodename); + if ($retdata->{'arch'}) + { # no error + $master = $retdata->{'master'}; + $os = $retdata->{'os'}; + $arch = $retdata->{'arch'}; + + # build the named.conf file + if (($os =~ /rh/i) || ($os =~ /fe/i)) + { + my $namedconfig = "/etc/named.conf"; + my @nameconfigtemplate; + $nameconfigtemplate[0] = "options {directory \"/var/named\";\n"; + $nameconfigtemplate[1] = + " dump-file \"/var/named/data/cache_dump.db\";\n"; + $nameconfigtemplate[2] = + " statistics-file \"/var/named/data/named_stats.txt\";\n"; + $nameconfigtemplate[3] = " forward only;\n"; + $nameconfigtemplate[4] = " forwarders{$master;\n };\n"; + $nameconfigtemplate[5] = "};\n"; + $nameconfigtemplate[6] = "\n"; + $nameconfigtemplate[7] = "controls {\n"; + $nameconfigtemplate[8] = + " inet 127.0.0.1 allow { localhost; } keys { rndckey; };\n"; + $nameconfigtemplate[9] = "};\n"; + $nameconfigtemplate[10] = "\n"; + $nameconfigtemplate[11] = "zone \".\" IN {\n"; + $nameconfigtemplate[12] = " type hint;\n"; + $nameconfigtemplate[13] = " file \"named.ca\";\n"; + $nameconfigtemplate[14] = "};\n\n"; + $nameconfigtemplate[15] = "zone \"localdomain\" IN {\n"; + $nameconfigtemplate[16] = " type master;\n"; + $nameconfigtemplate[17] = " file \"localdomain.zone\";\n"; + $nameconfigtemplate[18] = " allow-update { none; };\n"; + $nameconfigtemplate[19] = "};\n"; + $nameconfigtemplate[20] = "\n"; + $nameconfigtemplate[21] = "zone \"localhost\" IN {\n"; + $nameconfigtemplate[22] = " type master;\n"; + $nameconfigtemplate[23] = " file \"localhost.zone\";\n"; + $nameconfigtemplate[24] = " allow-update { none; };\n"; + $nameconfigtemplate[25] = "};\n"; + $nameconfigtemplate[26] = "\n"; + $nameconfigtemplate[27] = "zone \"0.0.127.in-addr.arpa\" IN {\n"; + $nameconfigtemplate[28] = " type master;\n"; + $nameconfigtemplate[29] = " file \"named.local\";\n"; + $nameconfigtemplate[30] = " allow-update { none; };\n"; + $nameconfigtemplate[31] = "};\n"; + $nameconfigtemplate[32] = "\n"; + $nameconfigtemplate[33] = + "zone \"0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa\" IN { \n"; + $nameconfigtemplate[34] = " type master; \n"; + $nameconfigtemplate[35] = " file \"named.ip6.local\";\n"; + $nameconfigtemplate[36] = " allow-update { none; };\n"; + $nameconfigtemplate[37] = "};\n"; + $nameconfigtemplate[38] = "\n"; + $nameconfigtemplate[39] = "zone \"255.in-addr.arpa\" IN {\n "; + $nameconfigtemplate[40] = " type master; \n"; + $nameconfigtemplate[41] = " file \"named.broadcast\";\n"; + $nameconfigtemplate[42] = " allow-update { none; };\n"; + $nameconfigtemplate[43] = "};\n"; + $nameconfigtemplate[44] = "\n"; + $nameconfigtemplate[45] = "zone \"0.in-addr.arpa\" IN {\n "; + $nameconfigtemplate[46] = " type master;\n "; + $nameconfigtemplate[47] = " file \"named.zero\";\n"; + $nameconfigtemplate[48] = " allow-update { none; };\n"; + $nameconfigtemplate[49] = "};\n"; + $nameconfigtemplate[50] = "\n"; + $nameconfigtemplate[51] = "include \"/etc/rndc.key\";\n "; + + open(DNSCFG, ">$namedconfig") + or xCAT::MsgUtils->message('S', + "Cannot open $named.conf for DNS setup \n"); + print DNSCFG @nameconfigtemplate; + close DNSCFG; + + # turn DNS on + + `cp /etc/named.conf /var/named/chroot/etc`; + `chkconfig --level 345 named on`; + `service named restart`; + xCAT::Utils->update_xCATSN("dns"); + } + } + else + { # error reading DB + return 1; + } + return 0; +} +1; diff --git a/xCAT-server-2.0/lib/xcat/plugins/NFSsn.pm b/xCAT-server-2.0/lib/xcat/plugins/NFSsn.pm index bff5d7bb2..ade9d7b85 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/NFSsn.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/NFSsn.pm @@ -31,15 +31,15 @@ Call setup_NFS sub handled_commands { - my $rc=0; + my $rc = 0; if (xCAT::Utils->isServiceNode()) { - my @nodeinfo = xCAT::Utils->determinehostname; + my @nodeinfo = xCAT::Utils->determinehostname; my $nodename = $nodeinfo[0]; my $nodeipaddr = $nodeinfo[1]; # service needed on this Service Node - $rc=&setup_NFS($nodename); # setup NFS + $rc = &setup_NFS($nodename); # setup NFS } return $rc; } @@ -60,32 +60,6 @@ sub process_request #----------------------------------------------------------------------------- -=head3 determine_hostname - - Figures out what my hostname is for the database read - Right now just using hostname command, probably need better way - -=cut - -#----------------------------------------------------------------------------- -sub determine_hostname -{ - my $hostname; - my $hostnamecmd = "/bin/hostname"; - my @thostname = xCAT::Utils->runcmd($hostnamecmd); - if ($? != 0) - { # could not get hostname - xCAT::MsgUtils->message("S", "Error $? from hostname command\n"); - exit $?; - } - $hostname = $thostname[0]; - my ($hcp, $aliases, $addtype, $length, @addrs) = gethostbyname($hostname); - my ($a, $b , $c, $d) = unpack ('C4', $addrs[0]); - return $hostname; -} - -#----------------------------------------------------------------------------- - =head3 setup_NFS Sets up NFS services and mounts /install and /tftpboot @@ -168,7 +142,7 @@ sub setup_NFS if ($::RUNCMD_RC != 0) { # error xCAT::MsgUtils->message("S", "Error starting NFS"); - return -1; + return 1; } my $cmd = "chkconfig nfs on"; xCAT::Utils->runcmd($cmd, 0); @@ -183,7 +157,7 @@ sub setup_NFS if ($::RUNCMD_RC != 0) { # error xCAT::MsgUtils->message("S", "exportfs -a failed"); - return -1; + return 1; } # check to see if install and tftp directory already mounted @@ -208,8 +182,8 @@ sub setup_NFS { # need to mount the directory - my $cmd = - " mount -o ro,nolock $master:$directory $directory"; + my $cmd = + " mount -o ro,nolock $master:$directory $directory"; xCAT::Utils->runcmd($cmd, 0); if ($::RUNCMD_RC != 0) { # error @@ -230,6 +204,24 @@ sub setup_NFS { # error reading Db $rc = 1; } + if ($rc == 0) + { + + # update fstab so they will mount on reboot + $cmd = "grep $master:$tftpdir $tftpdir /etc/fstab "; + xCAT::Utils->runcmd($cmd, -1); + if ($::RUNCMD_RC != 0) + { + `echo "$master:$tftpdir $tftpdir nfs timeo=14,intr 1 2" >>/etc/fstab`; + } + $cmd = "grep $master:$installdir $installdir /etc/fstab "; + xCAT::Utils->runcmd($cmd, -1); + if ($::RUNCMD_RC != 0) + { + `echo "$master:$installdir $installdir nfs timeo=14,intr 1 2" >>/etc/fstab`; + } + xCAT::Utils->update_xCATSN("nfs"); + } return $rc; } 1; diff --git a/xCAT-server-2.0/lib/xcat/plugins/TFTPsn.pm b/xCAT-server-2.0/lib/xcat/plugins/TFTPsn.pm new file mode 100644 index 000000000..284b14cf9 --- /dev/null +++ b/xCAT-server-2.0/lib/xcat/plugins/TFTPsn.pm @@ -0,0 +1,135 @@ +#!/usr/bin/env perl +# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html +#------------------------------------------------------- +package xCAT_plugin::TFTPsn; +use xCAT::Table; + +use xCAT::Utils; + +use xCAT::MsgUtils; +use Getopt::Long; + +#------------------------------------------------------- + +=head1 + xCAT plugin package to setup of tftp + + +#------------------------------------------------------- + +=head3 handled_commands + +Check to see if on a Service Node +Check database to see if this node is a TFTP server +Call setup_TFTP + +=cut + +#------------------------------------------------------- + +sub handled_commands +{ + my $rc = 0; + if (xCAT::Utils->isServiceNode()) + { + my @nodeinfo = xCAT::Utils->determinehostname; + my $nodename = $nodeinfo[0]; + my $nodeipaddr = $nodeinfo[1]; + my $service = "tftpserver"; + + $rc = xCAT::Utils->isServiceReq($nodename, $service, $nodeipaddr); + if ($rc == 1) + { + + # service needed on this Service Node + $rc=&setup_TFTP($nodename); # setup TFTP + } + } + return $rc; +} + +#------------------------------------------------------- + +=head3 process_request + + Process the command + +=cut + +#------------------------------------------------------- +sub process_request +{ + return; +} + +#----------------------------------------------------------------------------- + +=head3 setup_TFTP + + Sets up TFTP services + Check to see installed + Enables in /etc/xinetd.d/tftp + Makes /tftpboot directory + Starts with xinetd + +=cut + +#----------------------------------------------------------------------------- +sub setup_TFTP +{ + my ($nodename) = @_; + my $tftpdir = "/tftpboot"; # default + my $msg = "Install: Setup TFTPD"; + + # check to see if tftp is installed + + my $cmd = "/usr/sbin/in.tftpd -V"; + xCAT::Utils->runcmd($cmd, -1); + if ($::RUNCMD_RC != 0) + { # not installed + xCAT::MsgUtils->message("S", "tftp is not installed"); + return 1; + } + + # read tftp directory from database, if it exists + my @tftpdir1 = xCAT::Utils->get_site_attribute("tftpdir"); + if ($tftpdir1[0]) + { + $tftpdir = $tftpdir1[0]; + } + if (!(-e $tftpdir)) + { # if it does not already exist + mkdir($tftpdir); # creates the tftp directory + } + if (xCAT::Utils->isLinux()) + { + + # enable tftp + + + my $cmd = "chkconfig tftp on"; + xCAT::Utils->runcmd($cmd, -1); + if ($::RUNCMD_RC != 0) + { + xCAT::MsgUtils->message("S", "Error running $cmd"); + return 1; + } + my $cmd = "service xinetd restart"; + xCAT::Utils->runcmd($cmd, -1); + if ($::RUNCMD_RC != 0) + { + xCAT::MsgUtils->message("S", "Error running $cmd"); + return 1; + } + + } + else # AIX + { + + # TBD AIX tftp may already be enabled + + } + xCAT::Utils->update_xCATSN("tftp"); + return 0; +} +1;