add setup ODBC support

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/branches/2.7@13276 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
lissav 2012-07-11 12:18:33 +00:00
parent fb20194388
commit dd943d36b3

View File

@ -309,7 +309,7 @@ if ($::SETUPODBC)
xCAT::MsgUtils->message("I", "setup ODBC is not supported yet.");
#&setupODBC;
&setupODBC;
}
@ -799,20 +799,131 @@ sub setupxcatdb
sub setupODBC
{
if ($::osname eq 'AIX') {
my $message =
"Setup of the ODBC is only supported on Linux.";
xCAT::MsgUtils->message("E", "$message");
exit(1);
}
#
# check to see if correct rpms are installed
#
# for all OS need unixODBC rpm
my $message;
my $cmd = "rpm -qa | grep unixODBC";
xCAT::Utils->runcmd($cmd, 0);
xCAT::Utils->runcmd($cmd, -1);
if ($::RUNCMD_RC != 0)
{
my $message =
"\nunixODBC is not installed. If on AIX, it should be first obtained from the xcat dependency tarballs and installed before we can setup the ODBC. If on Linux, install from the OS CDs.";
xCAT::MsgUtils->message("E", " $cmd failed. $message");
$message =
"unixODBC rpm is not installed. Install from the OS CDs.";
xCAT::MsgUtils->message("E", "$message");
exit(1);
}
$cmd = "rpm -qa | grep postgresql-odbc";
xCAT::Utils->runcmd($cmd, -1);
if ($::RUNCMD_RC != 0)
{
$message =
"postgresql-odbc rpm is not installed. Install from the OS CDs.";
xCAT::MsgUtils->message("E", " $message");
exit(1);
}
my $xcatconfig = "/etc/xcat/cfgloc";
if (!(-e $xcatconfig))
{
$message =
"The $xcatconfig file is missing. You need to configure xCAT for PostgreSQL before setting up the ODBC.";
xCAT::MsgUtils->message("E", "$message");
exit(1);
}
$cmd = "fgrep -i host $xcatconfig";
my @output;
@output = xCAT::Utils->runcmd($cmd, -1);
if ($::RUNCMD_RC != 0) # cannot get the necessary hostname or ip
{
$message =
"Cannot find host info in the /etc/xcat/cfgloc file. Configuration of ODBC cannot continue.";
xCAT::MsgUtils->message("E", "$message");
exit(1);
}
# get host and password database from cfgloc
my( $connstring, $adminid, $passwd) = split(/\|/, $output[0]);
my ($hdr, $id, $server) = split(/=/, $connstring);
my ($database,$footer) = split(/;/, $id);
# the odbcinst.ini file should have been created during install of the
# unixODBC and postgresql-ODBC rpms
my $odbcfile = "/etc/odbc.ini";
my $odbcinstfile = "/etc/odbcinst.ini";
if (!( -e $odbcinstfile)) {
$message =
"Cannot find $odbcinstfile. Configuration of ODBC cannot continue.";
xCAT::MsgUtils->message("E", "$message");
exit(1);
}
# setup the DSN odbc.ini file
$cmd = "fgrep -i xcatdb";
xCAT::Utils->runcmd($cmd, -1);
if ($::RUNCMD_RC != 0) # then xcat entry not there
{
my $entry =
"[xCATDB]\nDriver = PostgreSQL\nSERVER = $server\nPORT = 3306\nDATABASE = $database";
$cmd = "echo \"$entry\" >> $odbcfile";
xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC != 0)
{
$message = "$cmd failed. Could not setup ODBC DNS file.";
xCAT::MsgUtils->message("E", "$message");
exit(1);
}
}
else
{ # entry already there
$message = "$odbcfile already configured, will not change.";
xCAT::MsgUtils->message("I", "$message");
}
# setup $roothome/.odbc.ini so root will not have to specify password
# when accessing through ODBC
my $homedir = xCAT::Utils->getHomeDir();
my $rootodbcfile = $homedir;
$rootodbcfile .= "/.odbc.ini";
# setup the DSN odbc.ini file
$cmd = "fgrep -i XCATDB $rootodbcfile";
xCAT::Utils->runcmd($cmd, -1);
if ($::RUNCMD_RC != 0) # then xcat entry not there
{
my $entry =
"[xCATDB]\nSERVER =$server\nDATABASE = $database\nUSER = $adminid\nPASSWORD = $passwd";
$cmd = "echo \"$entry\" >> $rootodbcfile";
# secure passwd in verbose mode
my $tmpv = $::VERBOSE;
$::VERBOSE = 0;
xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC != 0)
{
$message = "Could not setup root ODBC file $rootodbcfile.";
xCAT::MsgUtils->message("E", "$message");
exit(1);
}
$::VERBOSE = $tmpv;
}
else
{ # entry already there
$message = "$rootodbcfile already configured, will not change. Make sure the userid and password are correct for PostgreSQL";
xCAT::MsgUtils->message("I", "$message");
}
# allow readonly by root
chmod 0600, $rootodbcfile;
}
#-----------------------------------------------------------------------------