def _usage(self): """ Emit usage info to stdout. The _usage() method is invoked by the --help option. """ methodName = '_usage' if (os.path.exists(HelpFile)): Utilities.showFile(HelpFile) else: TR.info(methodName,"There is no usage information for '%s'" % __name__)
def main(self,argv): methodName ="main" self.rc = 0 self.bootstrap = Bootstrap() try: beginTime = Utilities.currentTimeMillis() cmdLineArgs = Utilities.getInputArgs(self.ArgsSignature,argv[1:]) trace, logFile = self.bootstrap._configureTraceAndLogging(cmdLineArgs) TR.info(methodName,"BOOT0101I BEGIN Bootstrap AWS ICPD Quickstart version 1.0.0.") if (trace): TR.info(methodName,"BOOT0102I Tracing with specification: '%s' to log file: '%s'" % (trace,logFile)) #endIf region = cmdLineArgs.get('region') self.bootstrap.region = region self.bootstrap.role = cmdLineArgs.get('role') self.bootstrap.fqdn = socket.getfqdn() self.bootStackId = cmdLineArgs.get('stackid') self.bootstrap.rootStackName = cmdLineArgs.get('stack-name') self.bootstrap._init(self.bootstrap.rootStackName,self.bootStackId) self.logExporter = LogExporter(region=self.bootstrap.region, bucket=self.bootstrap.ICPDeploymentLogsBucketName, keyPrefix='logs/%s' % self.bootstrap.rootStackName, role=self.bootstrap.role, fqdn=self.bootstrap.fqdn ) self.icpHome = "/opt/icp/%s" % self.bootstrap.ICPVersion installMapPath = os.path.join(self.home,"maps","icpd-install-artifact-map.yaml") self.installMap = self.bootstrap.loadInstallMap(mapPath=installMapPath, version=self.bootstrap.ICPDVersion, region=self.bootstrap.region) icpdS3Path = "{version}/{object}".format(version=self.installMap['version'],object=self.installMap['icpd-base-install-archive']) destPath = "/tmp/icp4d.tar" storageClassCmd = "kubectl get storageclass | nl | grep aws-efs | awk '{print $1}'" TR.info(methodName,"check_output Get StorageClass value from kubectl %s"%(storageClassCmd)) self.storageclassValue=check_output(['bash','-c', storageClassCmd]) TR.info(methodName,"check_output StorageclassValue returned : %s"%(self.storageclassValue)) self.bootstrap.getS3Object(self.bootstrap.ICPDArchiveBucketName, icpdS3Path, destPath) self.stackIds = self.bootstrap._getStackIds(self.bootStackId) self.bootstrap._getHosts(self.stackIds) self.installICPD() except ExitException: pass # ExitException is used as a "goto" end of program after emitting help info except Exception, e: TR.error(methodName,"ERROR: %s" % e, e) self.rc = 1
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
def main(self,argv): """ Main does command line argument processing, sets up trace and then kicks off the methods to do the work. """ methodName = "main" self.rc = 0 try: ####### Start command line processing cmdLineArgs = Utilities.getInputArgs(self.ArgsSignature,argv[1:]) # if trace is set from command line the trace variable holds the trace spec. trace, logFile = self._configureTraceAndLogging(cmdLineArgs) if (cmdLineArgs.get("help")): self._usage() raise ExitException("After emitting help, jump to the end of main.") #endIf beginTime = Utilities.currentTimeMillis() TR.info(methodName,"NINIT0101I BEGIN Node initialization AWS ICP Quickstart version @{VERSION}.") if (trace): TR.info(methodName,"NINIT0102I Tracing with specification: '%s' to log file: '%s'" % (trace,logFile)) #endIf region = cmdLineArgs.get('region') if (not region): raise MissingArgumentException("The AWS region (--region) must be provided.") #endIf self.region = region # The stackId is the "nested" stackId It is used to get input parameter values. stackId = cmdLineArgs.get('stackid') if (not stackId): raise MissingArgumentException("The stack ID (--stackid) must be provided.") #endIf self.stackId = stackId TR.info(methodName,"Stack ID: %s" % stackId) # NOTE: The stackName is the root stack name as that is the name used in # the SSM parameter keys by the boot node stack and the nested stacks. # For communication purposes all stacks must use the same root stack name. stackName = cmdLineArgs.get('stack-name') if (not stackName): raise MissingArgumentException("The stack name (--stack-name) must be provided.") #endIf self.stackName = stackName TR.info(methodName,"Stack name: %s" % stackName) role = cmdLineArgs.get('role') if (not role): raise MissingArgumentException("The role of this node (--role) must be provided.") #endIf self.role = role TR.info(methodName,"Node role: %s" % role) # Additional initialization of the instance. self._init(stackId) # Get the appropriate docker image self.installMap = self.loadInstallMap(version=self.ICPVersion, region=self.region) self.getInstallImages(self.installMap) # The sleep() is a hack to give bootnode time to do get its act together. # PVS: I've run into rare cases where it appears that the the cluster nodes # pick up a bad public key. I think it may be due to accidentally reusing # an ssm parameter. Don't have time to troubleshoot, now. I'm thinking # if the boot node gets to it first, it will overwrite anything old that # may be there. time.sleep(30) authorizedKeyEntry = self.getBootNodePublicKey() self.addAuthorizedKey(authorizedKeyEntry) # NOTE: All CFN outputs, parameters are strings even when the Type is Number. # Hence, the conversion of MasterNodeCount to an int. if (self.role == 'master' and int(self.MasterNodeCount) > 1): efsServer = self.EFSDNSName # An input to the master stack efsVolumes = [EFSVolume(efsServer,mountPoint) for mountPoint in ['/var/lib/registry','/var/lib/icp/audit','/var/log/audit']] self.mountEFSVolumes(efsVolumes) #endIf self.publishReadiness(self.stackName,self.fqdn) # Wait until boot node completes the Docker installation self.getSSMParameterValue("/%s/docker-installation" % self.stackName,expectedValue="COMPLETED") # NOTE: It looks like kubectl gets installed on the master node as part of the ICP install, at least as of ICP 3.1.0. self.publishReadiness(self.stackName,self.fqdn) except ExitException: pass # ExitException is used as a "goto" end of program after emitting help info except Exception, e: TR.error(methodName,"Exception: %s" % e, e) self.rc = 1
pass # ExitException is used as a "goto" end of program after emitting help info except Exception, e: TR.error(methodName,"Exception: %s" % e, e) self.rc = 1 finally: try: # Copy the deployment logs in logsHome to the S3 bucket for logs. self.exportLogs(self.ICPDeploymentLogsBucketName,self.stackName,self.logsHome) except Exception, e: TR.error(methodName,"Exception: %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): TR.info(methodName,"NINIT0103I END Node initialization AWS ICP Quickstart. Elapsed time (hh:mm:ss): %d:%02d:%02d" % (eth,etm,ets)) else: TR.info(methodName,"NINIT0104I FAILED END Node initialization AWS ICP Quickstart. Elapsed time (hh:mm:ss): %d:%02d:%02d" % (eth,etm,ets)) #endIf #endTry if (TR.traceFile): TR.closeTraceLog() #endIf