#!/usr/bin/perl -w

#######################################################################
#
# Here is what I did to get the remote Database connection of oscar_server
# on a client node
#
# 1. Install the following rpms
#  - mysql
#  - perl-DBD-MySQL
#  - perl-DBI
#  * a possible way to have oscar install via oscar_wizard
#  * add the following lines to oda/config.xml  
# -----------------------------------------------------
#  <binary-package-list>
#      <filter>
#        <group>oscar_clients</group>
#        <distribution>
#          <name>fc</name>
#        </distribution>
#      </filter>
#
#      <pkg>mysql</pkg>
#      <pkg>perl-DBD-MySQL</pkg>
#      <pkg>perl-DBI</pkg>
#  </binary-package-list>
# -----------------------------------------------------
#
#
# 2. Copy the oda scripts to OSCAR/
#  # mkdir -p /opt/oda/OSCAR
#  # scp oscar_server:/opt/oscar/lib/OSCAR/{oda.pm,Database.pm} /opt/oda/OSCAR
#  - oda.pm
#  - Database.pm
#
# 3. Copy /etc/odapw
#  # scp oscar_server:/etc/odapw /etc/
# * a possible way to copy /etc/odapw via oscar_wizard
# * add the following lines to oda/scripts/post_install
# -----------------------------------------------------
#	my $odapw = "/etc/odapw";
#	print "populating the ODA password $odapw file to all oscar clients\n";
#	$command = ". /etc/profile.d/c3.sh && cexec \'cat $odapw > $odapw\'";
#	print "$command\n";
#	system( $command ) && croak("oda password file $file push failed.");
# -----------------------------------------------------
# 
# 4. Remove the broken path in Database.pm
#  - comment out line 55,
#	use lib "$ENV{OSCAR_HOME}/lib","/usr/lib/perl5/site_perl","./";
#
# 5. Remove the broken module in Database.pm
#  - comment out line 59, OSCAR::PackagePath;
#
# 6. Run this file
#	[root@oscarnode01 oda]# pwd
#	/opt/oda
#	[root@oscarnode01 oda]# ./test.pl
#
#######################################################################

use lib "./";
use OSCAR::oda;
use OSCAR::Database;
use strict;
use Data::Dumper;


print "Testing remote db access\n";

my $node = "oscar_server";
my $password = `cat /etc/odapw`;

print "ODA PASSWORD : $password\n";

chomp($password);

my %options =  ( 'host' => $node,
		 'database' => 'oscar',
		 'user'	=> 'oscar',
		 'password' => $password );

my @error_strings = ();

database_connect(\%options,\@error_strings);

my @results = ();
get_node_package_status_with_node(
	$node,
	\@results,
	\%options,
	\@error_strings,8);

foreach my $ref (@results){
	print Dumper($ref);
}

database_disconnect(\%options,\@error_strings);

exit 0;
