コード例 #1
0
    def _getArg(self, synonyms, args, default=None):
        """
        Return the value from the args dictionary that may be specified with any of the
        argument names in the list of synonyms.

        The synonyms argument may be a Jython list of strings or it may be a string representation
        of a list of names with a comma or space separating each name.

        The args is a dictionary with the keyword value pairs that are the arguments
        that may have one of the names in the synonyms list.

        If the args dictionary does not include the option that may be named by any
        of the given synonyms then the given default value is returned.

        NOTE: This method has to be careful to make explicit checks for value being None
        rather than something that is just logically false.  If value gets assigned 0 from
        the get on the args (command line args) dictionary, that appears as false in a
        condition expression.  However 0 may be a legitimate value for an input parameter
        in the args dictionary.  We need to break out of the loop that is checking synonyms
        as well as avoid assigning the default value if 0 is the value provided in the
        args dictionary.
        """

        value = None
        if (type(synonyms) != type([])):
            synonyms = Utilities.splitString(synonyms)
        #endIf

        for name in synonyms:
            value = args.get(name)
            if (value != None):
                break
        #endIf
        #endFor

        if (value == None and default != None):
            value = default
        #endIf

        return value
コード例 #2
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,"icp4i_install.log")
    
            with open(logFilePath,"a+") as icp4iInstallLogFile:
                self.stackId = cmdLineArgs.get('stackid')
                self.stackName = cmdLineArgs.get('stack-name')
                self.amiID = environ.get('AMI_ID')
                self.cp4iSecret = environ.get('CP4I_SECRET')
                self.ocpSecret = environ.get('OCP_SECRET')
                self.pnSecret = environ.get('PN_SECRET')
                # self.cp4ibucketName = environ.get('ICP4IArchiveBucket')
                self.ICP4IInstallationCompletedURL = environ.get('ICP4IInstallationCompletedURL')
                TR.info(methodName, "amiID %s "% self.amiID)
                # TR.info(methodName, "cp4ibucketName %s "% self.cp4ibucketName)
                TR.info(methodName, "ICP4IInstallationCompletedURL %s "% self.ICP4IInstallationCompletedURL)
                TR.info(methodName, "cp4iSecret %s "% self.cp4iSecret)
                TR.info(methodName, "ocpSecret %s "% self.ocpSecret)
                TR.info(methodName, "pnSecret %s "% self.pnSecret)
                self.__init(self.stackId,self.stackName, icp4iInstallLogFile)
                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=icp4iInstallLogFile)
                self.getSecret(icp4iInstallLogFile)
                
                ocpstart = Utilities.currentTimeMillis()
                self.installOCP(icp4iInstallLogFile)
                ocpend = Utilities.currentTimeMillis()
                self.printTime(ocpstart, ocpend, "Installing OCP")

                storagestart = Utilities.currentTimeMillis()
                self.installDedicatedOCS = Utilities.toBoolean(self.DedicatedOCS)
                self.configureOCS(icp4iInstallLogFile)
                storageend = Utilities.currentTimeMillis()
                self.printTime(storagestart, storageend, "Installing storage")

                if(self.password=="NotProvided"):
                    install_cp4i = ("sudo ./cp4i-deployment/cp4i-install.sh  -n " +  self.Namespace + " -k " + self.apiKey +
                                " -1 " + self.APILM + " -2 " + self.AIDB + " -3 " + self.AIDE + " -4 " + self.OD + " -5 " + self.AR +
                                " -6 " + self.MQ + " -7 " + self.ES + " -8 " + self.GW + " -9 " + self.HST + " | tee -a cp4i-logs.txt")
                else:
                    install_cp4i = ("sudo ./cp4i-deployment/cp4i-install.sh  -n " +  self.Namespace + " -k " + self.apiKey +
                                    " -1 " + self.APILM + " -2 " + self.AIDB + " -3 " + self.AIDE + " -4 " + self.OD + " -5 " + self.AR +
                                    " -6 " + self.MQ + " -7 " + self.ES + " -8 " + self.GW + " -9 " + self.HST + " -p " + self.password + " | tee -a cp4i-logs.txt")
                
                try:
                    process = Popen(install_cp4i,shell=True,stdout=icp4iInstallLogFile,stderr=icp4iInstallLogFile,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 CP4I %s %s" %(stdoutdata,stderrdata))
                time.sleep(30)

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

                get_cp4i_route_cmd = "oc get route -n " + self.Namespace + " | grep 'navigator-pn' | awk '{print $2}'"
                TR.info(methodName, "Get CP4I URL")
                try:
                    self.cp4iURL = check_output(['bash','-c', get_cp4i_route_cmd])
                    TR.info(methodName, "CP4I URL retrieved %s"%self.cp4iURL)
                except CalledProcessError as e:
                    TR.error(methodName,"command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output))

                self.exportResults(self.stackName+"-CP4IURL", "https://"+self.cp4iURL, icp4iInstallLogFile)

                if(self.password=="NotProvided"):
                    get_cp4i_password_cmd = "oc get secrets -n ibm-common-services platform-auth-idp-credentials -ojsonpath='{.data.admin_password}' | base64 --decode && echo """
                    TR.info(methodName, "Get CP4I Password")
                    try:
                        self.cp4iPassword = check_output(['bash','-c', get_cp4i_password_cmd])
                        TR.info(methodName, "CP4I Password retrieved %s"%self.cp4iPassword)
                    except CalledProcessError as e:
                        TR.error(methodName,"command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output))
                else:
                    self.cp4iPassword = self.password

                self.updateSecret(icp4iInstallLogFile)
            #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/cp4i-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 CP4I Install AWS ICP4I Quickstart.  Elapsed time (hh:mm:ss): %d:%02d:%02d" % (eth,etm,ets))
            # TODO update this later
            self.updateStatus(status)
        else:
            success = 'false'
            status = 'FAILURE: Check logs in S3 log bucket or on the Boot node EC2 instance in /ibm/logs/icp4i_install.log and /ibm/logs/post_install.log'
            TR.info(methodName,"FAILED END CP4I Install AWS ICP4I Quickstart.  Elapsed time (hh:mm:ss): %d:%02d:%02d" % (eth,etm,ets))
            # # TODO update this later
            self.updateStatus(status)
           
        #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.ICP4IInstallationCompletedURL
                            ])     
        except CalledProcessError as e:
            TR.error(methodName, "ERROR return code: %s, Exception: %s" % (e.returncode, e), e)
            raise e                                                
コード例 #3
0
    def main(self, argv):
        methodName = "main"
        self.rc = 0

        try:
            beginTime = Utilities.currentTimeMillis()

            self._loadConf()

            if (self.overall_log_file):
                TR.appendTraceLog(self.overall_log_file)

            logFilePath = os.path.join(self.logsHome, "icpd_install.log")

            with open(logFilePath, "a+") as icpdInstallLogFile:
                ocpstart = Utilities.currentTimeMillis()
                TR.info("debug",
                        "change_node_settings= %s" % self.change_node_settings)
                if (self.change_node_settings == "True"):
                    self.changeNodeSettings(icpdInstallLogFile)
                    TR.info("debug", "Finishd the node settings")
                    ocpend = Utilities.currentTimeMillis()
                    self.printTime(ocpstart, ocpend, "Chaning node settings")

                TR.info("debug",
                        "config_image_pull= %s" % self.config_image_pull)
                ocpstart = Utilities.currentTimeMillis()
                if (self.config_image_pull == "True"):
                    self.configImagePull(icpdInstallLogFile)
                    TR.info("debug", "Finishd the image pull configuration")
                    ocpend = Utilities.currentTimeMillis()
                    self.printTime(ocpstart, ocpend, "Configuring image pull")

                if (self.installOSWML == "True"):
                    self.installWML = "True"

                self.installCPD(icpdInstallLogFile)

                self.installStatus = "CPD Installation completed"
                TR.info("debug",
                        "Installation status - %s" % self.installStatus)
            #endWith

        except Exception as e:
            TR.error(methodName, "Exception with message %s" % e)
            self.rc = 1

        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 CPD Quickstart.  Elapsed time (hh:mm:ss): %d:%02d:%02d"
                % (eth, etm, ets))
        else:
            success = 'false'
            status = 'FAILURE: Check logs on the Boot node in /ibm/logs/icpd_install.log and /ibm/logs/post_install.log'
            TR.info(
                methodName,
                "FAILED END CPD Quickstart.  Elapsed time (hh:mm:ss): %d:%02d:%02d"
                % (eth, etm, ets))
コード例 #4
0
    def installCPD(self, icpdInstallLogFile):
        """
        """

        methodName = "installCPD"

        #private_registry = self.image_registry_url
        offline_installation_dir = self.offline_dir_path

        self.logincmd = "oc login -u " + self.ocp_admin_user + " -p " + self.ocp_admin_password
        try:
            call(self.logincmd, shell=True, stdout=icpdInstallLogFile)
        except CalledProcessError as e:
            TR.error(
                methodName,
                "command '{}' return with error (code {}): {}".format(
                    e.cmd, e.returncode, e.output))

        TR.info(methodName, "oc login successfully")

        #Install Cloud Pak Foundation Service
        if (self.installFoundationalService == "True"):
            TR.info(methodName, "Start installing Foundational Service")

            bedrock_start = Utilities.currentTimeMillis()

            install_foundational_service_command = "./install_bedrock.sh " + offline_installation_dir + " " + self.FoundationalService_Case_Name + " " + self.image_registry_url + " " + self.foundation_service_namespace

            TR.info(
                methodName, "Install Foundational Service with command %s" %
                install_foundational_service_command)

            try:
                install_foundational_service_retcode = check_output(
                    ['bash', '-c', install_foundational_service_command])
            except CalledProcessError as e:
                TR.error(
                    methodName,
                    "command '{}' return with error (code {}): {}".format(
                        e.cmd, e.returncode, e.output))
                return
            TR.info(
                methodName,
                "Install Foundational Service with command %s returned %s" %
                (install_foundational_service_command,
                 install_foundational_service_retcode))

            bedrock_end = Utilities.currentTimeMillis()
            TR.info(methodName, "Install Foundational Service completed")
            self.printTime(bedrock_start, bedrock_end,
                           "Install Foundational Service")

        #Install Cloud Pak for Data Control Plane
        if (self.installCPDControlPlane == "True"):
            TR.info(methodName,
                    "Start installing Cloud Pak for Data Control Plane (Zen)")

            zen_core_metadb_storage_class = self.storage_class

            if (self.storage_type == "ocs"):
                zen_core_metadb_storage_class = "ocs-storagecluster-ceph-rbd"

            zen_start = Utilities.currentTimeMillis()

            install_control_plane_command = "./install_zen.sh " + offline_installation_dir + " " + self.CPDControlPlane_Case_Name + " " + self.image_registry_url + " " + self.foundation_service_namespace + " " + self.cpd_operator_namespace + " " + self.cpd_instance_namespace + " " + self.cpd_license + " " + self.storage_class + " " + self.storage_type

            TR.info(
                methodName, "Install Control Plane with command %s" %
                install_control_plane_command)

            try:
                install_control_plane_retcode = check_output(
                    ['bash', '-c', install_control_plane_command])
            except CalledProcessError as e:
                TR.error(
                    methodName,
                    "command '{}' return with error (code {}): {}".format(
                        e.cmd, e.returncode, e.output))
                return
            TR.info(
                methodName,
                "Install Control Plane with command %s returned %s" %
                (install_control_plane_command, install_control_plane_retcode))

            zen_end = Utilities.currentTimeMillis()
            TR.info(methodName, "Install Control Plane completed")
            self.printTime(zen_start, zen_end, "Install Control Plane")

            get_cpd_route_cmd = "oc get route -n " + self.cpd_instance_namespace + " | grep '" + self.cpd_instance_namespace + "' | awk '{print $2}'"
            TR.info(methodName, "Get CPD URL")
            try:
                self.cpdURL = check_output(['bash', '-c', get_cpd_route_cmd])
                TR.info(methodName, "CPD URL retrieved %s" % self.cpdURL)
            except CalledProcessError as e:
                TR.error(
                    methodName,
                    "command '{}' return with error (code {}): {}".format(
                        e.cmd, e.returncode, e.output))
                return

        if (self.installWSL == "True"):
            TR.info(methodName, "Start installing Watson Studio Local")

            wsl_start = Utilities.currentTimeMillis()

            install_wsl_command = "./install_wsl.sh " + offline_installation_dir + " " + self.WSL_Case_Name + " " + self.image_registry_url + " " + self.cpd_operator_namespace + " " + self.cpd_instance_namespace + " " + self.cpd_license + " " + self.storage_type + " " + self.storage_class

            TR.info(
                methodName,
                "Install Watson Studio with command %s" % install_wsl_command)

            try:
                install_wsl_retcode = check_output(
                    ['bash', '-c', install_wsl_command])
            except CalledProcessError as e:
                TR.error(
                    methodName,
                    "command '{}' return with error (code {}): {}".format(
                        e.cmd, e.returncode, e.output))

            TR.info(
                methodName,
                "Install Watson Studio with command %s returned %s" %
                (install_wsl_command, install_wsl_retcode))

            wsl_end = Utilities.currentTimeMillis()
            TR.info(methodName, "Install Watson Studio completed")
            self.printTime(wsl_start, wsl_end, "Install Watson Studio")

        if (self.installWML == "True"):
            TR.info(methodName, "Start installing Watson Machine Learning")
            wml_start = Utilities.currentTimeMillis()
            self.installCCSCatSrc(icpdInstallLogFile)

            install_wml_command = "./install_wml.sh " + offline_installation_dir + " " + self.WML_Case_Name + " " + self.image_registry_url + " " + self.cpd_operator_namespace + " " + self.cpd_instance_namespace + " " + self.cpd_license + " " + self.storage_type + " " + self.storage_class

            TR.info(
                methodName, "Install Watson Machine Learning with command %s" %
                install_wml_command)

            try:
                install_wml_retcode = check_output(
                    ['bash', '-c', install_wml_command])
            except CalledProcessError as e:
                TR.error(
                    methodName,
                    "command '{}' return with error (code {}): {}".format(
                        e.cmd, e.returncode, e.output))

            TR.info(
                methodName,
                "Install Watson Machine Learning with command %s returned %s" %
                (install_wml_command, install_wml_retcode))

            wml_end = Utilities.currentTimeMillis()
            TR.info(methodName, "Install Watson Machine Learning completed")
            self.printTime(wml_start, wml_end,
                           "Install Watson Machine Learning")

        if (self.installOSWML == "True"):
            TR.info(methodName, "Start installing Watson OpenScale")
            wos_start = Utilities.currentTimeMillis()

            install_wos_command = "./install_aiopenscale.sh " + offline_installation_dir + " " + self.WOS_Case_Name + " " + self.image_registry_url + " " + self.cpd_operator_namespace + " " + self.cpd_instance_namespace + " " + self.cpd_license + " " + self.storage_type + " " + self.storage_class

            TR.info(
                methodName, "Install Watson OpenScale with command %s" %
                install_wos_command)

            try:
                install_wos_retcode = check_output(
                    ['bash', '-c', install_wos_command])
            except CalledProcessError as e:
                TR.error(
                    methodName,
                    "command '{}' return with error (code {}): {}".format(
                        e.cmd, e.returncode, e.output))

            TR.info(
                methodName,
                "Install Watson OpenScale with command %s returned %s" %
                (install_wos_command, install_wos_retcode))

            wos_end = Utilities.currentTimeMillis()
            TR.info(methodName, "Install Watson OpenScale completed")
            self.printTime(wos_start, wos_end, "Install Watson OpenScale")

        if (self.installCDE == "True"):
            TR.info(methodName, "Start installing Cognos Dashboards")
            cde_start = Utilities.currentTimeMillis()
            self.installCCSCatSrc(icpdInstallLogFile)

            install_cde_command = "./install_cde.sh " + offline_installation_dir + " " + self.CDE_Case_Name + " " + self.image_registry_url + " " + self.cpd_operator_namespace + " " + self.cpd_instance_namespace + " " + self.cpd_license + " " + self.storage_type + " " + self.storage_class

            TR.info(
                methodName, "Install Cognos Dashboards with command %s" %
                install_cde_command)

            try:
                install_cde_retcode = check_output(
                    ['bash', '-c', install_cde_command])
            except CalledProcessError as e:
                TR.error(
                    methodName,
                    "command '{}' return with error (code {}): {}".format(
                        e.cmd, e.returncode, e.output))

            TR.info(
                methodName,
                "Install Cognos Dashboards with command %s returned %s" %
                (install_cde_command, install_cde_retcode))

            cde_end = Utilities.currentTimeMillis()
            TR.info(methodName, "Install Cognos Dashboards completed")
            self.printTime(cde_start, cde_end, "Install Cognos Dashboards")

        if (self.installRStudio == "True"):
            TR.info(methodName, "Start installing RStudio package")
            rstudiostart = Utilities.currentTimeMillis()
            if (self.installRStudio_load_from == "NA"):
                self.installAssembliesAirgap("rstudio", self.default_load_from,
                                             icpdInstallLogFile)
            else:
                self.installAssembliesAirgap("rstudio",
                                             self.installRStudio_load_from,
                                             icpdInstallLogFile)
            rstudioend = Utilities.currentTimeMillis()
            TR.info(methodName, "RStudio package installation completed")
            self.printTime(rstudiostart, rstudioend, "Installing RStudio")

        if (self.installSPSS == "True"):
            TR.info(methodName, "Start installing SPSS package")
            spssstart = Utilities.currentTimeMillis()
            if (self.installSPSS_load_from == "NA"):
                self.installAssembliesAirgap("spss-modeler",
                                             self.default_load_from,
                                             icpdInstallLogFile)
            else:
                self.installAssembliesAirgap("spss-modeler",
                                             self.installSPSS_load_from,
                                             icpdInstallLogFile)
            spssend = Utilities.currentTimeMillis()
            TR.info(methodName, "SPSS package installation completed")
            self.printTime(spssstart, spssend, "Installing SPSS")

        if (self.installSpark == "True"):
            TR.info(methodName, "Start installing Spark AE package")
            sparkstart = Utilities.currentTimeMillis()
            if (self.installSpark_load_from == "NA"):
                self.installAssembliesAirgap("spark", self.default_load_from,
                                             icpdInstallLogFile)
            else:
                self.installAssembliesAirgap("spark",
                                             self.installSpark_load_from,
                                             icpdInstallLogFile)
            sparkend = Utilities.currentTimeMillis()
            TR.info(methodName, "Spark AE  package installation completed")
            self.printTime(sparkstart, sparkend, "Installing Spark AE")

        if (self.installRuntimeGPUPy37 == "True"):
            TR.info(methodName, "Start installing GPUPy37 package")
            gpupy36start = Utilities.currentTimeMillis()
            if (self.installRuntimeGPUPy37_load_from == "NA"):
                self.installAssembliesAirgap("runtime-addon-py37gpu",
                                             self.default_load_from,
                                             icpdInstallLogFile)
            else:
                self.installAssembliesAirgap(
                    "runtime-addon-py37gpu",
                    self.installRuntimeGPUPy37_load_from, icpdInstallLogFile)
            gpupy36end = Utilities.currentTimeMillis()
            TR.info(methodName, "GPUPy36 package installation completed")
            self.printTime(gpupy36start, gpupy36end, "Installing GPUPy36")

        if (self.installDb2WH == "True"):
            TR.info(methodName, "Start installing Db2WH")
            self.installDb2UOperator(icpdInstallLogFile)
            db2wh_start = Utilities.currentTimeMillis()

            install_db2wh_command = "./install_db2wh.sh " + offline_installation_dir + " " + self.Db2WH_Case_Name + " " + self.image_registry_url + " " + self.foundation_service_namespace + " " + self.cpd_operator_namespace + " " + self.cpd_instance_namespace + " " + self.cpd_license + " " + self.storage_type + " " + self.storage_class

            TR.info(methodName,
                    "Install Db2WH with command %s" % install_db2wh_command)

            try:
                install_db2wh_retcode = check_output(
                    ['bash', '-c', install_db2wh_command])
            except CalledProcessError as e:
                TR.error(
                    methodName,
                    "command '{}' return with error (code {}): {}".format(
                        e.cmd, e.returncode, e.output))

            TR.info(
                methodName, "Install Db2WH with command %s returned %s" %
                (install_db2wh_command, install_db2wh_retcode))

            db2wh_end = Utilities.currentTimeMillis()
            TR.info(methodName, "Install Db2WH completed")
            self.printTime(db2wh_start, db2wh_end, "Install Db2WH")

        if (self.installHEE == "True"):
            TR.info(methodName, "Start installing HEE package")
            heestart = Utilities.currentTimeMillis()
            if (self.installHEE_load_from == "NA"):
                self.installAssembliesAirgap("hadoop-addon",
                                             self.default_load_from,
                                             icpdInstallLogFile)
            else:
                self.installAssembliesAirgap("hadoop-addon",
                                             self.installHEE_load_from,
                                             icpdInstallLogFile)
            heeend = Utilities.currentTimeMillis()
            TR.info(methodName, "HEE package installation completed")
            self.printTime(heestart, heeend, "Installing HEE")

        if (self.installDODS == "True"):
            TR.info(methodName, "Start installing DODS package")
            dodsstart = Utilities.currentTimeMillis()
            if (self.installDODS_load_from == "NA"):
                self.installAssembliesAirgap("dods", self.default_load_from,
                                             icpdInstallLogFile)
            else:
                self.installAssembliesAirgap("dods",
                                             self.installDODS_load_from,
                                             icpdInstallLogFile)
            dodsend = Utilities.currentTimeMillis()
            TR.info(methodName, "DODS package installation completed")
            self.printTime(dodsstart, dodsend, "Installing DODS")

        if (self.installWKC == "True"):

            self.installDb2UOperator(icpdInstallLogFile)

            TR.info(methodName, "Start installing Watson Knowledge Catalog")

            wkcstart = Utilities.currentTimeMillis()

            install_wkc_command = "./install_wkc.sh " + offline_installation_dir + " " + self.WKC_Case_Name + " " + self.image_registry_url + " " + self.foundation_service_namespace + " " + self.cpd_operator_namespace + " " + self.cpd_instance_namespace + " " + self.cpd_license + " " + self.storage_type + " " + self.storage_class
            TR.info(
                methodName,
                "Install Watson Knowledge Catalog with command %s" %
                install_wkc_command)

            install_wkc_retcode = ""
            try:
                install_wkc_retcode = check_output(
                    ['bash', '-c', install_wkc_command])
            except CalledProcessError as e:
                TR.error(
                    methodName,
                    "command '{}' return with error (code {}): {}".format(
                        e.cmd, e.returncode, e.output))

            TR.info(
                methodName,
                "Install Watson Knowledge Catalog with command %s returned %s"
                % (install_wkc_command, install_wkc_retcode))

            wkcend = Utilities.currentTimeMillis()
            TR.info(methodName, "Install Watson Knowledge Catalog completed")
            self.printTime(wkcstart, wkcend,
                           "Install Watson Knowledge Catalog")

        if (self.installDV == "True"):

            self.installDb2UOperator(icpdInstallLogFile)

            TR.info(methodName, "Start installing Data Virtualization")

            dvstart = Utilities.currentTimeMillis()

            install_dv_command = "./install_dv.sh " + offline_installation_dir + " " + self.DV_Case_Name + " " + self.image_registry_url + " " + self.foundation_service_namespace + " " + self.cpd_operator_namespace + " " + self.cpd_instance_namespace + " " + self.cpd_license
            TR.info(
                methodName, "Install Data Virtualization with command %s" %
                install_dv_command)

            install_dv_retcode = ""
            try:
                install_dv_retcode = check_output(
                    ['bash', '-c', install_dv_command])
            except CalledProcessError as e:
                TR.error(
                    methodName,
                    "command '{}' return with error (code {}): {}".format(
                        e.cmd, e.returncode, e.output))

            TR.info(
                methodName,
                "Install Data Virtualization with command %s returned %s" %
                (install_dv_command, install_dv_retcode))

            dvend = Utilities.currentTimeMillis()
            TR.info(methodName, "Install Data Virtualization completed")
            self.printTime(dvstart, dvend, "Install Data Virtualization")

        TR.info(methodName, "Installed all packages.")
コード例 #5
0
    def main(self, argv):
        methodName = "main"
        self.rc = 0
        params = {}
        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, "icpd_install.log")

            with open(logFilePath, "a+") as icpdInstallLogFile:
                self.stackId = cmdLineArgs.get('stackid')
                self.stackName = cmdLineArgs.get('stack-name')
                self.cfnResource = boto3.resource('cloudformation',
                                                  region_name=self.region)
                self.cf = boto3.client('cloudformation',
                                       region_name=self.region)
                self.ec2 = boto3.resource('ec2', region_name=self.region)
                self.s3 = boto3.client('s3', region_name=self.region)
                self.elb = boto3.client('elb', region_name=self.region)
                self.secretsmanager = boto3.client('secretsmanager',
                                                   region_name=self.region)
                self.autoScaling = boto3.client('autoscaling',
                                                region_name=self.region)
                self.stackParameters = self.getStackParameters(self.stackId)
                self.stackParameterNames = self.stackParameters.keys()

                list = self.stackParameters.get(
                    "AnsibleAdditionalEnvironmentVariables").split(",")
                params.update((dict(item.split("=", 1) for item in list)))
                self.namespace = params.get('Namespace')
                self.cpdbucketName = params.get('ICPDArchiveBucket')
                self.ICPDInstallationCompletedURL = params.get(
                    'ICPDInstallationCompletedURL')
                self.installWKC = Utilities.toBoolean(params.get('WKC'))
                self.installWSL = Utilities.toBoolean(params.get('WSL'))
                self.installDV = Utilities.toBoolean(params.get('DV'))
                self.installWML = Utilities.toBoolean(params.get('WML'))
                self.installOSWML = Utilities.toBoolean(params.get('OSWML'))
                if (self.installOSWML):
                    self.installWML = True
                #endIf
                self.apikey = params.get('APIKey')
                TR.info(
                    methodName,
                    "Retrieve namespace value from Env Variables %s" %
                    self.namespace)
                self.logExporter = LogExporter(region=self.region,
                                               bucket=self.getOutputBucket(),
                                               keyPrefix='logs/%s' %
                                               self.stackName,
                                               fqdn=socket.getfqdn())
                self.configureEFS()
                self.getS3Object(bucket=self.cpdbucketName,
                                 s3Path="2.5/cpd-linux",
                                 destPath="/ibm/cpd-linux")
                os.chmod("/ibm/cpd-linux", stat.S_IEXEC)
                if not self.apikey:
                    TR.info(methodName, "Downloading repo.yaml from S3 bucket")
                    os.remove("/ibm/repo.yaml")
                    self.getS3Object(bucket=self.cpdbucketName,
                                     s3Path="2.5/repo.yaml",
                                     destPath="/ibm/repo.yaml")
                else:
                    TR.info(methodName,
                            "updating repo.yaml with apikey value provided")
                    self.updateTemplateFile('/ibm/repo.yaml', '<APIKEY>',
                                            self.apikey)
                self.installCPD(icpdInstallLogFile)
                self.validateInstall(icpdInstallLogFile)
                self.manageUser(icpdInstallLogFile)
                if not self.apikey:
                    self.activateLicense(icpdInstallLogFile)
            #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/cpd-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 CPD Install AWS ICPD Quickstart.  Elapsed time (hh:mm:ss): %d:%02d:%02d"
                % (eth, etm, ets))
            self.updateStatus(status)
            os.remove("/ibm/trial.lic")
            #os.remove("/ibm/repo.yaml")
        else:
            success = 'false'
            status = 'FAILURE: Check logs in S3 log bucket or on the AnsibleConfigServer node EC2 instance in /ibm/logs/icpd_install.log and /ibm/logs/post_install.log'
            TR.info(
                methodName,
                "FAILED END CPD Install AWS ICPD Quickstart.  Elapsed time (hh:mm:ss): %d:%02d:%02d"
                % (eth, etm, ets))
            self.updateStatus(status)
            os.remove("/ibm/trial.lic")
            #os.remove("/ibm/repo.yaml")
            #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.ICPDInstallationCompletedURL
            ])
        except CalledProcessError as e:
            TR.error(
                methodName,
                "ERROR return code: %s, Exception: %s" % (e.returncode, e), e)
            raise e
コード例 #6
0
    def installCPD(self, icpdInstallLogFile):
        """
        Installs pre-requsites for cpd installation by running mkfifo and install-sem playbooks
        prepares oc cluster with required user and roles
        copies certificates from node instance to ansible server and configures internal docker registry to push images
        creates a OC project with user defined name
        Downloads binary file from S3 and extracts it to /ibm folder
        installs wkc wml and wsl package by pushing images to local registry and using local registry.

        """

        methodName = "installCPD"
        check_cmd = "checkmodule -M -m -o mkfifo.mod mkfifo.te"
        call(check_cmd, shell=True, stdout=icpdInstallLogFile)

        package_cmd = "semodule_package -o mkfifo.pp -m mkfifo.mod"
        call(package_cmd, shell=True, stdout=icpdInstallLogFile)
        TR.info(
            methodName,
            "ansible-playbook: install-mkfifo.yaml started, find log here %s" %
            (os.path.join(self.logsHome, "install-mkfifo.log")))

        retcode = call(
            'ansible-playbook /ibm/playbooks/install-mkfifo.yaml >> %s 2>&1' %
            (os.path.join(self.logsHome, "install-mkfifo.log")),
            shell=True,
            stdout=icpdInstallLogFile)
        if (retcode != 0):
            TR.error(
                methodName,
                "Error calling ansible-playbook install-mkfifo.yaml. Return code: %s"
                % retcode)
            raise Exception(
                "Error calling ansible-playbook install-mkfifo.yaml. Return code: %s"
                % retcode)
        else:
            TR.info(methodName,
                    "ansible-playbook: install-mkfifo.yaml completed.")

        retcode = call(
            'ansible-playbook /ibm/playbooks/install-sem.yaml >> %s 2>&1' %
            (os.path.join(self.logsHome, "install-sem.log")),
            shell=True,
            stdout=icpdInstallLogFile)
        if (retcode != 0):
            TR.error(
                methodName,
                "Error calling ansible-playbook install-sem.yaml. Return code: %s"
                % retcode)
            raise Exception(
                "Error calling ansible-playbook install-sem.yaml. Return code: %s"
                % retcode)
        else:
            TR.info(methodName, "ansible-playbook:install-sem.yaml completed.")

        retlogin = check_output(['bash', '-c', 'oc login -u system:admin'])
        TR.info(methodName,
                "Logged in as system:admin with retcode %s" % retlogin)

        retproj = check_output(['bash', '-c', 'oc project default'])
        TR.info(methodName, "Switched to default project %s" % retproj)

        registry_cmd = "oc get route | grep 'docker-registry'| awk {'print $2'}"
        registry_url = check_output(['bash', '-c',
                                     registry_cmd]).rstrip("\n\r")
        TR.info(methodName,
                "Get url from docker-registry route %s" % registry_url)

        self.docker_registry = registry_url + ":443/" + self.namespace
        TR.info(methodName, " registry url %s" % self.docker_registry)

        retcode = call(
            'oc adm policy add-cluster-role-to-user cluster-admin admin',
            shell=True,
            stdout=icpdInstallLogFile)
        TR.info(methodName,
                "Added cluster admin role to admin user %s" % retcode)

        oc_login = "******" + self.getPassword()
        retcode = call(oc_login, shell=True, stdout=icpdInstallLogFile)
        TR.info(methodName, "Log in to OC with admin user %s" % retcode)

        oc_new_project = "oc new-project " + self.namespace
        retcode = call(oc_new_project, shell=True, stdout=icpdInstallLogFile)
        TR.info(
            methodName,
            "Create new project with user defined project name %s,retcode=%s" %
            (self.namespace, retcode))

        nodeIP = self.getNodeIP()
        add_to_hosts = "echo " + nodeIP + " " + registry_url + " >> /etc/hosts"
        retcode = call(add_to_hosts, shell=True, stdout=icpdInstallLogFile)
        TR.info(methodName, "add entry to host file %s" % add_to_hosts)

        copycerts = "scp -r root@" + nodeIP + ":/etc/docker/certs.d/docker-registry.default.svc:5000 /etc/docker/certs.d/" + registry_url + ":443"
        retcode = call(copycerts, shell=True, stdout=icpdInstallLogFile)
        TR.info(methodName, "Copy certs from compute node %s" % retcode)

        self.token = self.getToken(icpdInstallLogFile)
        # self.updateTemplateFile('/ibm/local_repo.yaml', '<REGISTRYURL>', self.docker_registry)
        # self.updateTemplateFile('/ibm/local_repo.yaml', '<PASSWORD>', self.token)
        # TR.info(methodName,"Update local repo file with sa token")

        # TR.info(methodName,"Download install package from S3 bucket %s" %self.cpdbucketName)
        # s3start =Utilities.currentTimeMillis()
        # self.getS3Object(bucket=self.cpdbucketName, s3Path="2.5/cpd.tar", destPath='/tmp/cpd.tar')
        # s3end = Utilities.currentTimeMillis()
        # TR.info(methodName,"Downloaded install package from S3 bucket %s" %self.cpdbucketName)
        # self.printTime(s3start,s3end, "S3 download of cpd tar")

        # TR.info(methodName,"Extract install package")
        # call('tar -xvf /tmp/cpd.tar -C /ibm/',shell=True, stdout=icpdInstallLogFile)
        # extractend = Utilities.currentTimeMillis()
        # TR.info(methodName,"Extracted install package")
        # self.printTime(s3end, extractend, "Extracting cpd tar")
        litestart = Utilities.currentTimeMillis()
        TR.info(methodName, "Start installing Lite package")
        self.installAssemblies("lite", "v2.5.0.0", icpdInstallLogFile)
        liteend = Utilities.currentTimeMillis()
        self.printTime(litestart, liteend, "Installing Lite")
        self.configureCPDRoute(icpdInstallLogFile)

        if (self.installWSL):
            TR.info(methodName, "Start installing WSL package")
            wslstart = Utilities.currentTimeMillis()
            self.installAssemblies("wsl", "2.1.0", icpdInstallLogFile)
            wslend = Utilities.currentTimeMillis()
            TR.info(methodName, "WSL package installation completed")
            self.printTime(wslstart, wslend, "Installing WSL")

        if (self.installDV):
            TR.info(methodName, "Start installing DV package")
            TR.info(methodName, "Delete configmap node-config-compute-infra")
            delete_cm = "oc delete configmap -n openshift-node node-config-compute-infra"
            retcode = check_output(['bash', '-c', delete_cm])
            TR.info(methodName,
                    "Deleted configmap node-config-compute-infra %s" % retcode)
            TR.info(methodName, "Create configmap node-config-compute-infra")
            create_cm = "oc create -f /ibm/node-config-compute-infra.yaml"
            retcode = check_output(['bash', '-c', create_cm])
            TR.info(methodName,
                    "Created configmap node-config-compute-infra %s" % retcode)
            dvstart = Utilities.currentTimeMillis()
            self.installAssemblies("dv", "v1.3.0.0", icpdInstallLogFile)
            dvend = Utilities.currentTimeMillis()
            TR.info(methodName, "DV package installation completed")
            self.printTime(dvstart, dvend, "Installing DV")

        if (self.installWML):
            TR.info(methodName, "Start installing WML package")
            wmlstart = Utilities.currentTimeMillis()
            self.installAssemblies("wml", "2.1.0.0", icpdInstallLogFile)
            wmlend = Utilities.currentTimeMillis()
            TR.info(methodName, "WML package installation completed")
            self.printTime(wmlstart, wmlend, "Installing WML")

        if (self.installWKC):
            TR.info(methodName, "Start installing WKC package")
            wkcstart = Utilities.currentTimeMillis()
            self.installAssemblies("wkc", "3.0.333", icpdInstallLogFile)
            wkcend = Utilities.currentTimeMillis()
            TR.info(methodName, "WKC package installation completed")
            self.printTime(wkcstart, wkcend, "Installing WKC")

        if (self.installOSWML):
            TR.info(methodName, "Start installing AI Openscale package")
            aiostart = Utilities.currentTimeMillis()
            self.installAssemblies("aiopenscale", "v2.5.0.0",
                                   icpdInstallLogFile)
            aioend = Utilities.currentTimeMillis()
            TR.info(methodName, "AI Openscale package installation completed")
            self.printTime(aiostart, aioend, "Installing AI Openscale")

        TR.info(methodName, "Installed all packages.")