add odbc support for Linux only

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@12908 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
lissav 2012-05-23 13:59:42 +00:00
parent d970f0b2a7
commit e1b1cdb17e

View File

@ -307,9 +307,8 @@ if ($::SETUPODBC)
# set up the ODBC on the Management Node
#
xCAT::MsgUtils->message("I", "setup ODBC is not supported yet.");
#&setupODBC;
&setupODBC;
}
@ -788,9 +787,7 @@ sub setupxcatdb
=head3 setupODBC
Will setup the ODBC. Only needed if C, C++ applications are running
that need access to the PG database for example LoadLeveler.
This code is not supported yet and must be modified for PostgreSQL
Will setup the ODBC interface to the ODBC. Only supported on Linux
=cut
@ -799,20 +796,132 @@ sub setupxcatdb
sub setupODBC
{
if ($::osname eq 'AIX') {
my $message =
"Setup of the ODBC is only supported on Linux.";
xCAT::MsgUtils->message("E", " $cmd failed. $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);
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.";
$message =
"unixODBC* rpm is not installed. Install from the OS CDs.";
xCAT::MsgUtils->message("E", " $cmd failed. $message");
exit(1);
}
$cmd = "rpm -qa | grep postgresql-odbc";
xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC != 0)
{
$message =
"postgresql-odbc* rpm is not installed. Install from the OS CDs.";
xCAT::MsgUtils->message("E", " $cmd failed. $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", " $cmd failed. $message");
exit(1);
}
# get host and password from cfgloc
(my $connstring, my $adminid, my $passwd) = split(/\|/, $output[0]);
(my $database, my $id, my $server) = split(/=/, $connstring);
# 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", " $cmd failed. $message");
exit(1);
}
# setup the DSN odbc.ini file
$cmd = "fgrep -i Pg: $odbcfile";
xCAT::Utils->runcmd($cmd, -1);
if ($::RUNCMD_RC != 0) # then xcat entry not there
{
my $entry =
"[xCATDB]\nDriver = PostgreSQL\nSERVER = $server\nPORT = 3306\nDATABASE = xcatdb";
$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 = xcatdb\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 = "command failed. Could not setup root ODBC file.";
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 Pg";
xCAT::MsgUtils->message("I", "$message");
}
# allow readonly by root
chmod 0600, $rootodbcfile;
# create root role
$cmd = "createuser -SDRP root ";
&runpostgrescmd($cmd);
}
#-----------------------------------------------------------------------------
@ -870,7 +979,7 @@ sub createcfgloc
=head3 restorexcatdb
Restores the database from ~/xcat-dbback and restarts the xcatd using
MySQL
PostgreSQL
=cut