本文整理汇总了Golang中github.com/evergreen-ci/evergreen/model/host.Host.UpdateReachability方法的典型用法代码示例。如果您正苦于以下问题:Golang Host.UpdateReachability方法的具体用法?Golang Host.UpdateReachability怎么用?Golang Host.UpdateReachability使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/evergreen-ci/evergreen/model/host.Host
的用法示例。
在下文中一共展示了Host.UpdateReachability方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: checkHostReachability
// check reachability for a single host, and take any necessary action
func checkHostReachability(host host.Host, settings *evergreen.Settings) error {
evergreen.Logger.Logf(slogger.INFO, "Running reachability check for host %v...", host.Id)
// get a cloud version of the host
cloudHost, err := providers.GetCloudHost(&host, settings)
if err != nil {
return fmt.Errorf("error getting cloud host for host %v: %v", host.Id, err)
}
// get the cloud status for the host
cloudStatus, err := cloudHost.GetInstanceStatus()
if err != nil {
return fmt.Errorf("error getting cloud status for host %v: %v", host.Id, err)
}
// take different action, depending on how the cloud provider reports the host's status
switch cloudStatus {
case cloud.StatusRunning:
// check if the host is reachable via SSH
reachable, err := cloudHost.IsSSHReachable()
if err != nil {
return fmt.Errorf("error checking ssh reachability for host %v: %v", host.Id, err)
}
// log the status update if the reachability of the host is changing
if host.Status == evergreen.HostUnreachable && reachable {
evergreen.Logger.Logf(slogger.INFO, "Setting host %v as reachable", host.Id)
} else if host.Status != evergreen.HostUnreachable && !reachable {
evergreen.Logger.Logf(slogger.INFO, "Setting host %v as unreachable", host.Id)
}
// mark the host appropriately
if err := host.UpdateReachability(reachable); err != nil {
return fmt.Errorf("error updating reachability for host %v: %v", host.Id, err)
}
case cloud.StatusTerminated:
evergreen.Logger.Logf(slogger.INFO, "Host %v terminated externally; updating db status to terminated", host.Id)
// the instance was terminated from outside our control
if err := host.SetTerminated(); err != nil {
return fmt.Errorf("error setting host %v terminated: %v", host.Id, err)
}
}
// success
return nil
}