def main()

in scripts/cp4s_install.py [0:0]


    def main(self,argv):
        methodName = "main"
        self.rc = 0
        try:
            beginTime = Utilities.currentTimeMillis()
            cmdLineArgs = Utilities.getInputArgs(self.ArgsSignature,argv[1:])
            trace, logFile = self._configureTraceAndLogging(cmdLineArgs)
            self.region = cmdLineArgs.get('region')
            if (logFile):
                TR.appendTraceLog(logFile)   
            if (trace):
                TR.info(methodName,"Tracing with specification: '%s' to log file: '%s'" % (trace,logFile))

            logFilePath = os.path.join(self.logsHome,"icp4s_install.log")
    
            with open(logFilePath,"a+") as icp4sInstallLogFile:
                self.stackId = cmdLineArgs.get('stackid')
                self.stackName = cmdLineArgs.get('stack-name')
                self.amiID = environ.get('AMI_ID')
                self.cp4sSecret = environ.get('CP4S_SECRET')
                self.ocpSecret = environ.get('OCP_SECRET')
                self.ICP4SInstallationCompletedURL = environ.get('ICP4SInstallationCompletedURL')
                TR.info(methodName, "amiID %s "% self.amiID)
                TR.info(methodName, "ICP4SInstallationCompletedURL %s "% self.ICP4SInstallationCompletedURL)
                TR.info(methodName, "cp4sSecret %s "% self.cp4sSecret)
                TR.info(methodName, "ocpSecret %s "% self.ocpSecret)
                self.__init(self.stackId,self.stackName, icp4sInstallLogFile)
                self.zones = Utilities.splitString(self.AvailabilityZones)
                TR.info(methodName," AZ values %s" % self.zones)

                TR.info(methodName,"RedhatPullSecret %s" %self.RedhatPullSecret)
                secret = self.RedhatPullSecret.split('/',1)
                TR.info(methodName,"Pull secret  %s" %secret)  
                self.pullSecret = "/ibm/pull-secret"
                s3_cp_cmd = "aws s3 cp "+self.RedhatPullSecret+" "+self.pullSecret
                TR.info(methodName,"s3 cp cmd %s"%s3_cp_cmd)
                call(s3_cp_cmd, shell=True,stdout=icp4sInstallLogFile)
                self.getSecret(icp4sInstallLogFile)
                
                ocpstart = Utilities.currentTimeMillis()
                self.installOCP(icp4sInstallLogFile)
                ocpend = Utilities.currentTimeMillis()
                self.printTime(ocpstart, ocpend, "Installing OCP")

                install_cps = ("bash install.sh " + self.apiKey + " " + self.CPSFQDN + " " + "api." +
                                self.ClusterName + "." + self.DomainName + ":6443 " + self.password)
                
                try:
                    process = Popen(install_cps,shell=True,stdout=icp4sInstallLogFile,stderr=icp4sInstallLogFile,close_fds=True)
                    stdoutdata,stderrdata=process.communicate()
                except CalledProcessError as e:
                    TR.error(methodName, "ERROR return code: %s, Exception: %s" % (e.returncode, e), e)
                    raise e    
                TR.info(methodName,"Installation of CP4S %s %s" %(stdoutdata,stderrdata))
                time.sleep(30)

                self.exportResults(self.stackName+"-OpenshiftURL", "https://"+self.openshiftURL, icp4sInstallLogFile)

                self.exportResults(self.stackName+"-CP4SURL", "https://"+self.CPSFQDN+"/console", icp4sInstallLogFile)

                self.updateSecret(icp4sInstallLogFile)
            #endWith    
            
        except Exception as e:
            TR.error(methodName,"Exception with message %s" %e)
            self.rc = 1
        finally:
            try:
            # Copy icpHome/logs to the S3 bucket for logs.
                self.logExporter.exportLogs("/var/log/")
                self.logExporter.exportLogs("/ibm/cp4s-linux-workspace/Logs")
                self.logExporter.exportLogs("%s" % self.logsHome)
            except Exception as  e:
                TR.error(methodName,"ERROR: %s" % e, e)
                self.rc = 1
            #endTry          
        endTime = Utilities.currentTimeMillis()
        elapsedTime = (endTime - beginTime)/1000
        etm, ets = divmod(elapsedTime,60)
        eth, etm = divmod(etm,60) 

        if (self.rc == 0):
            success = 'true'
            status = 'SUCCESS'
            TR.info(methodName,"SUCCESS END CP4S Install AWS ICP4S Quickstart.  Elapsed time (hh:mm:ss): %d:%02d:%02d" % (eth,etm,ets))
        else:
            success = 'false'
            status = 'FAILURE: Check logs in S3 log bucket or on the Boot node EC2 instance in /ibm/logs/icp4s_install.log and /ibm/logs/post_install.log'
            TR.info(methodName,"FAILED END CP4S Install AWS ICP4S Quickstart.  Elapsed time (hh:mm:ss): %d:%02d:%02d" % (eth,etm,ets))

        #endIf 
        try:
            data = "%s: IBM Cloud Pak installation elapsed time: %d:%02d:%02d" % (status,eth,etm,ets)    
            check_call(['cfn-signal', 
                            '--success', success, 
                            '--id', self.stackId, 
                            '--reason', status, 
                            '--data', data, 
                            self.ICP4SInstallationCompletedURL
                            ])     
        except CalledProcessError as e:
            TR.error(methodName, "ERROR return code: %s, Exception: %s" % (e.returncode, e), e)
            raise e