#!/usr/bin/perl
## @file    deploymentConfigPut
# @brief    It uploads deployment.xml file to a defined target.
# @details
# @param    hostname - target hostname
# @param    IP - ip-address of the target host
# @author   Kate Bereznyakova
# @date     May 2008
# @version  1.00 - Initial version
# @version 1.01 - Two colons were removed before shared functions and variables.
use lib "/opt/nortel/base/lib";

use strict;
use warnings;
use baselog;
use base_deploy;
use common_variables;
use Getopt::Long;
use CommonInstallUtils;

## @skipline
sub deploymentConfigPut();
exit(deploymentConfigPut());

###############################################################################
## @fn deploymentConfigPut()
# @brief      Main function.
# @details   It checks input parameters and implements general
#            logic.
# @return    $OK(0)  - configuration file uploaded successfully
# @return    $ERROR(1)  - fail to upload configuration file
# @author    Kate Bereznyakova
# @date      May 2008
sub deploymentConfigPut()
{
   my $hostname;
   my $ip;

   GetOptions("hostname:s" => \$hostname,
              "IP:s"       => \$ip);

   my $retval = $OK;

   # check input parameters section.
   if ((!defined $hostname) or ($hostname eq ''))
   {
      baselog($LOG_ERROR, 'Hostname is undefined.');
      return $ERROR;
   }

   if ((!defined $ip) or ($ip eq ''))
   {
      baselog($LOG_ERROR, 'TLAN is undefined.');
      return $ERROR;
   }

   if (!validateIP($ip))
   {
      baselog($LOG_ERROR, "Invalid TLAN IP data: $ip.");
      return $ERROR;
   }

   # end: check input parameters section.
   my $deployMng = base_deploy::new($hostname, $ip);
   if (!defined $deployMng)
   {
      baselog($LOG_ERROR, 'Cannot create deploy object.');
      return $ERROR;
   }
   baselog($LOG_INFO, "Uploading 'deployment.xml' file to the '$hostname [$ip]' host.");
   if (!$deployMng->transfer_deploy_xml())
   {
      baselog($LOG_ERROR, "Fail to upload 'deployment.xml' file to the '$hostname [$ip]' host.");
      $retval = $ERROR;
   }
   else
   {
      baselog($LOG_INFO, "'deployment.xml' file successfully uploaded to the  '$hostname [$ip]' host.");
   }

   undef $deployMng;
   return $retval;
} ## end sub deploymentConfigPut()
