當前位置: 首頁>>代碼示例>>Golang>>正文


Golang T.Infof方法代碼示例

本文整理匯總了Golang中github.com/aws/amazon-ssm-agent/agent/log.T.Infof方法的典型用法代碼示例。如果您正苦於以下問題:Golang T.Infof方法的具體用法?Golang T.Infof怎麽用?Golang T.Infof使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/aws/amazon-ssm-agent/agent/log.T的用法示例。


在下文中一共展示了T.Infof方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: processRegistration

// processRegistration handles flags related to the registration category
func processRegistration(log logger.T) (exitCode int) {
	if activationCode == "" || activationID == "" || region == "" {
		// clear registration
		if clear {
			return clearRegistration(log)
		}
		flagUsage()
		return 1
	}

	// check if previously registered
	if !force && registration.InstanceID() != "" {
		confirmation, err := askForConfirmation()
		if err != nil {
			log.Errorf("Registration failed due to %v", err)
			return 1
		}

		if !confirmation {
			log.Info("Registration canceled by user")
			return 1
		}
	}

	managedInstanceID, err := registerManagedInstance()
	if err != nil {
		log.Errorf("Registration failed due to %v", err)
		return 1
	}

	log.Infof("Successfully registered the instance with AWS SSM using Managed instance-id: %s", managedInstanceID)
	return 0
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:34,代碼來源:agent_parser.go

示例2: validateManifest

// validateManifest makes sure all the fields are provided.
func validateManifest(log log.T, parsedManifest *Manifest, context *updateutil.InstanceContext, packageName string) error {
	if len(parsedManifest.URIFormat) == 0 {
		return fmt.Errorf("folder format cannot be null in the Manifest file")
	}
	fileName := context.FileName(packageName)
	foundPackage := false
	foundFile := false
	for _, p := range parsedManifest.Packages {
		if p.Name == packageName {
			log.Infof("found package %v", packageName)
			foundPackage = true
			for _, f := range p.Files {
				if f.Name == fileName {
					foundFile = true
					if len(f.AvailableVersions) == 0 {
						return fmt.Errorf("at least one available version is required for the %v", fileName)
					}

					log.Infof("found file %v", fileName)
					break
				}
			}
		}
	}

	if !foundPackage {
		return fmt.Errorf("cannot find the %v information in the Manifest file", packageName)
	}
	if !foundFile {
		return fmt.Errorf("cannot find the %v information in the Manifest file", fileName)
	}

	return nil
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:35,代碼來源:parser.go

示例3: installAgent

// install executes the install script for the specific version of agent
func installAgent(mgr *updateManager, log log.T, version string, context *UpdateContext) (err error) {
	log.Infof("Initiating %v %v installation", context.Current.PackageName, version)

	// find the path for the install script
	installerPath := updateutil.InstallerFilePath(
		context.Current.UpdateRoot,
		context.Current.PackageName,
		version)
	// calculate work directory
	workDir := updateutil.UpdateArtifactFolder(
		context.Current.UpdateRoot,
		context.Current.PackageName,
		version)

	// Install version
	if err = mgr.util.ExeCommand(
		log,
		installerPath,
		workDir,
		context.Current.UpdateRoot,
		context.Current.StdoutFileName,
		context.Current.StderrFileName,
		false); err != nil {

		return err
	}

	log.Infof("%v %v installed successfully", context.Current.PackageName, version)
	return nil
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:31,代碼來源:processor.go

示例4: processFingerprint

// processFingerprint handles flags related to the fingerprint category
func processFingerprint(log logger.T) (exitCode int) {
	if err := fingerprint.SetSimilarityThreshold(similarityThreshold); err != nil {
		log.Errorf("Error setting the SimilarityThreshold. %v", err)
		return 1
	}
	log.Infof("Fingerprint SimilarityTHreshold set to %v", similarityThreshold)
	return 0
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:9,代碼來源:agent_parser.go

示例5: start

func start(log logger.T, instanceIDPtr *string, regionPtr *string) (cpm *coremanager.CoreManager, err error) {
	log.Infof("Starting Agent: %v", version.String())
	log.Infof("OS: %s, Arch: %s", runtime.GOOS, runtime.GOARCH)
	log.Flush()

	if cpm, err = coremanager.NewCoreManager(instanceIDPtr, regionPtr, log); err != nil {
		log.Errorf("error occured when starting core manager: %v", err)
		return
	}
	cpm.Start()
	return
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:12,代碼來源:agent.go

示例6: verifyInstallation

// verifyInstallation checks installation result, verifies if agent is running
func verifyInstallation(mgr *updateManager, log log.T, context *UpdateContext, isRollback bool) (err error) {
	// Check if agent is running
	var isRunning = false
	var instanceContext *updateutil.InstanceContext

	if instanceContext, err = mgr.util.CreateInstanceContext(log); err != nil {
		return mgr.failed(context, log, updateutil.ErrorEnvironmentIssue, err.Error(), false)
	}

	log.Infof("Initiating update health check")
	isRunning, err = mgr.util.IsServiceRunning(log, instanceContext)
	if err != nil || !isRunning {
		if !isRollback {
			message := updateutil.BuildMessage(err,
				"failed to update %v to %v, %v",
				context.Current.PackageName,
				context.Current.TargetVersion,
				"failed to start the agent")

			context.Current.AppendError(log, message)
			context.Current.AppendInfo(
				log,
				"Initiating rollback %v to %v",
				context.Current.PackageName,
				context.Current.SourceVersion)
			// Update state to rollback
			if err = mgr.inProgress(context, log, Rollback); err != nil {
				return err
			}
			return mgr.rollback(mgr, log, context)
		}

		message := updateutil.BuildMessage(err,
			"failed to rollback %v to %v, %v",
			context.Current.PackageName,
			context.Current.SourceVersion,
			"failed to start the agent")
		// Rolled back, but service cannot start, Update failed.
		return mgr.failed(context, log, updateutil.ErrorCannotStartService, message, false)
	}

	log.Infof("%v is running", context.Current.PackageName)
	if !isRollback {
		return mgr.succeeded(context, log)
	}

	message := fmt.Sprintf("rolledback %v to %v", context.Current.PackageName, context.Current.SourceVersion)
	log.Infof("message is %v", message)
	return mgr.failed(context, log, updateutil.ErrorCannotStartService, message, false)
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:51,代碼來源:processor.go

示例7: reboot

// reboot is performed by running the following command
// shutdown -r -t 60
// The above command will cause the machine to reboot after 60 seconds
func reboot(log log.T) (err error) {
	log.Infof("rebooting the machine in %v seconds..", timeOutInSecondsBeforeReboot)
	command := exec.Command("shutdown", "-r", "-t", timeOutInSecondsBeforeReboot)
	var stdout, stderr bytes.Buffer
	command.Stderr = &stderr
	command.Stdout = &stdout
	err = command.Start()
	log.Infof("shutdown output: %v\n", stdout.String())

	if stderr.Len() != 0 {
		log.Errorf("shutdown error: %v\n", stderr.String())
	}
	return
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:17,代碼來源:rebooter_windows.go

示例8: reboot

// reboot is performed by running the following command
// /sbin/shutdown -r +1
// The above command will cause the machine to reboot after 1 minute
func reboot(log log.T) (err error) {
	log.Infof("Rebooting the machine in %v Minutes..", timeOutInMinutesBeforeReboot)
	command := exec.Command("/sbin/shutdown", "-r", timeOutInMinutesBeforeReboot)
	command.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
	var stdout, stderr bytes.Buffer
	command.Stderr = &stderr
	command.Stdout = &stdout
	err = command.Start()
	log.Infof("shutdown output: %v\n", stdout.String())

	if stderr.Len() != 0 {
		log.Errorf("shutdown error: %v\n", stderr.String())
	}
	return
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:18,代碼來源:rebooter_unix.go

示例9: downloadAndUnzipArtifact

// downloadAndUnzipArtifact downloads installation package and unzips it
func downloadAndUnzipArtifact(
	mgr *updateManager,
	log log.T,
	downloadInput artifact.DownloadInput,
	context *UpdateContext,
	version string) (err error) {

	log.Infof("Preparing source for version %v", version)
	// download installation zip files
	downloadOutput, err := downloadArtifact(log, downloadInput)
	if err != nil ||
		downloadOutput.IsHashMatched == false ||
		downloadOutput.LocalFilePath == "" {
		if err != nil {
			return fmt.Errorf("failed to download file reliably, %v", err.Error())
		}
		return fmt.Errorf("failed to download file reliably")
	}

	// downloaded successfully, append message
	context.Current.AppendInfo(log, "Successfully downloaded %v", downloadInput.SourceURL)

	// uncompress installation package
	if err = uncompress(
		downloadOutput.LocalFilePath,
		updateutil.UpdateArtifactFolder(context.Current.UpdateRoot, context.Current.PackageName, version)); err != nil {
		return fmt.Errorf("failed to uncompress installation package, %v", err.Error())
	}

	return nil
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:32,代碼來源:processor.go

示例10: prepareInstallationPackages

// prepareInstallationPackages downloads artifacts from public s3 storage
func prepareInstallationPackages(mgr *updateManager, log log.T, context *UpdateContext) (err error) {
	log.Infof("Initiating download %v", context.Current.PackageName)
	var instanceContext *updateutil.InstanceContext
	updateDownload := ""

	if instanceContext, err = mgr.util.CreateInstanceContext(log); err != nil {
		return mgr.failed(context, log, updateutil.ErrorEnvironmentIssue, err.Error(), false)
	}
	if err = validateUpdateVersion(log, context.Current, instanceContext); err != nil {
		return mgr.failed(context, log, updateutil.ErrorEnvironmentIssue, err.Error(), true)
	}

	if updateDownload, err = mgr.util.CreateUpdateDownloadFolder(); err != nil {
		message := updateutil.BuildMessage(
			err,
			"failed to create download folder %v %v",
			context.Current.PackageName,
			context.Current.TargetVersion)
		return mgr.failed(context, log, updateutil.ErrorEnvironmentIssue, message, true)
	}

	// Download source
	downloadInput := artifact.DownloadInput{
		SourceURL:            context.Current.SourceLocation,
		SourceHashValue:      context.Current.SourceHash,
		SourceHashType:       updateutil.HashType,
		DestinationDirectory: updateDownload,
	}

	if err = mgr.download(mgr, log, downloadInput, context, context.Current.SourceVersion); err != nil {
		return mgr.failed(context, log, updateutil.ErrorInvalidPackage, err.Error(), true)
	}

	// Download target
	downloadInput = artifact.DownloadInput{
		SourceURL:            context.Current.TargetLocation,
		SourceHashValue:      context.Current.TargetHash,
		SourceHashType:       updateutil.HashType,
		DestinationDirectory: updateDownload,
	}

	if err = mgr.download(mgr, log, downloadInput, context, context.Current.TargetVersion); err != nil {
		return mgr.failed(context, log, updateutil.ErrorInvalidPackage, err.Error(), true)
	}

	// Update stdout
	context.Current.AppendInfo(
		log,
		"Initiating %v update to %v",
		context.Current.PackageName,
		context.Current.TargetVersion)

	// Update state to Staged
	if err = mgr.inProgress(context, log, Staged); err != nil {
		return err
	}

	// Process update
	return mgr.update(mgr, log, context)
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:61,代碼來源:processor.go

示例11: HandleAwsError

// HandleAwsError logs an AWS error.
func HandleAwsError(log log.T, err error, stopPolicy *StopPolicy) {
	if err != nil {
		// notice that we're using 1, so it will actually log the where
		// the error happened, 0 = this function, we don't want that.
		pc, fn, line, _ := runtime.Caller(1)
		log.Debugf("error in %s[%s:%d] %v", runtime.FuncForPC(pc).Name(), fn, line, err)

		// In case this is aws error, update the stop policy as well.
		if aErr, ok := err.(awserr.Error); ok {
			// Generic AWS Error with Code, Message, and original error (if any)
			log.Debugf("AWS error. Code: %v, Message: %v, origerror: %v ", aErr.Code(), aErr.Message(), aErr.OrigErr())

			// special treatment for Timeout exception - as this is expected
			if aErr.Code() == "RequestError" && aErr.OrigErr() != nil && strings.Contains(aErr.OrigErr().Error(), "Client.Timeout") {
				// resetting the error count to 0 - as these exceptions are all expected
				if stopPolicy != nil {
					resetStopPolicy(stopPolicy)
				}
				return
			}
		}

		log.Errorf("error when calling AWS APIs. error details - %v", err)
		if stopPolicy != nil {
			log.Infof("increasing error count by 1")
			stopPolicy.AddErrorCount(1)
		}

	} else {
		// there is no error,
		resetStopPolicy(stopPolicy)
	}
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:34,代碼來源:awserr.go

示例12: AppendInfo

// AppendInfo appends messages to UpdateContext StandardOut
func (update *UpdateDetail) AppendInfo(log log.T, format string, params ...interface{}) {
	message := fmt.Sprintf(format, params...)
	log.Infof(message)
	if update.StandardOut != "" {
		update.StandardOut = fmt.Sprintf("%v\n%v", update.StandardOut, message)
	} else {
		update.StandardOut = message
	}
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:10,代碼來源:context.go

示例13: isUpdateSupported

func isUpdateSupported(log log.T) (bool, error) {
	var sku string
	var err error

	// Get platform sku information
	if sku, err = getPlatformSku(log); err != nil {
		log.Infof("Failed to fetch sku - %v", err)
		return false, err
	}

	log.Infof("sku: %v", sku)

	// If sku represents nano server, return false
	if sku == ProductDataCenterNanoServer || sku == ProductStandardNanoServer {
		return false, nil
	}

	return true, nil
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:19,代碼來源:updateutil_windows.go

示例14: IsDiskSpaceSufficientForUpdate

// IsDiskSpaceSufficientForUpdate loads disk space info and checks the available bytes
// Returns true if the system has at least 100 Mb for available disk space or false if it is less than 100 Mb
func (util *Utility) IsDiskSpaceSufficientForUpdate(log log.T) (bool, error) {
	var diskSpaceInfo fileutil.DiskSpaceInfo
	var err error

	// Get the available disk space
	if diskSpaceInfo, err = getDiskSpaceInfo(); err != nil {
		log.Infof("Failed to load disk space info - %v", err)
		return false, err
	}

	// Return false if available disk space is less than 100 Mb
	if diskSpaceInfo.AvailBytes < MinimumDiskSpaceForUpdate {
		log.Infof("Insufficient available disk space - %d Mb", diskSpaceInfo.AvailBytes/int64(1024*1024))
		return false, nil
	}

	// Return true otherwise
	return true, nil
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:21,代碼來源:updateutil.go

示例15: ValidateExecutionTimeout

// ValidateExecutionTimeout validates the supplied input interface and converts it into a valid int value.
func ValidateExecutionTimeout(log log.T, input interface{}) int {
	var num int

	switch input.(type) {
	case string:
		num = extractIntFromString(log, input.(string))
	case int:
		num = input.(int)
	case float64:
		f := input.(float64)
		num = int(f)
		log.Infof("Unexpected 'TimeoutSeconds' float value %v received. Applying 'TimeoutSeconds' as %v", f, num)
	default:
		log.Errorf("Unexpected 'TimeoutSeconds' value %v received. Setting 'TimeoutSeconds' to default value %v", input, defaultExecutionTimeoutInSeconds)
	}

	if num < minExecutionTimeoutInSeconds || num > maxExecutionTimeoutInSeconds {
		log.Infof("'TimeoutSeconds' value should be between %v and %v. Setting 'TimeoutSeconds' to default value %v", minExecutionTimeoutInSeconds, maxExecutionTimeoutInSeconds, defaultExecutionTimeoutInSeconds)
		num = defaultExecutionTimeoutInSeconds
	}
	return num
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:23,代碼來源:pluginutil.go


注:本文中的github.com/aws/amazon-ssm-agent/agent/log.T.Infof方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。