本文整理汇总了Golang中github.com/juju/juju/tools.List.Newest方法的典型用法代码示例。如果您正苦于以下问题:Golang List.Newest方法的具体用法?Golang List.Newest怎么用?Golang List.Newest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/tools.List
的用法示例。
在下文中一共展示了List.Newest方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: findCompatibleTools
// findCompatibleTools finds tools in the list that have the same major, minor
// and patch level as version.Current.
//
// Build number is not important to match; uploaded tools will have
// incremented build number, and we want to match them.
func findCompatibleTools(possibleTools coretools.List, version version.Number) (version.Number, coretools.List) {
var compatibleTools coretools.List
for _, tools := range possibleTools {
if isCompatibleVersion(tools.Version.Number, version) {
compatibleTools = append(compatibleTools, tools)
}
}
return compatibleTools.Newest()
}
示例2: SetBootstrapTools
// SetBootstrapTools returns the newest tools from the given tools list,
// and updates the agent-version configuration attribute.
func SetBootstrapTools(environ environs.Environ, possibleTools coretools.List) (coretools.List, error) {
if len(possibleTools) == 0 {
return nil, fmt.Errorf("no bootstrap tools available")
}
var newVersion version.Number
newVersion, toolsList := possibleTools.Newest()
logger.Infof("newest version: %s", newVersion)
cfg := environ.Config()
if agentVersion, _ := cfg.AgentVersion(); agentVersion != newVersion {
cfg, err := cfg.Apply(map[string]interface{}{
"agent-version": newVersion.String(),
})
if err == nil {
err = environ.SetConfig(cfg)
}
if err != nil {
return nil, fmt.Errorf("failed to update environment configuration: %v", err)
}
}
bootstrapVersion := newVersion
// We should only ever bootstrap the exact same version as the client,
// or we risk bootstrap incompatibility. We still set agent-version to
// the newest version, so the agent will immediately upgrade itself.
if !isCompatibleVersion(newVersion, version.Current.Number) {
compatibleVersion, compatibleTools := findCompatibleTools(possibleTools, version.Current.Number)
if len(compatibleTools) == 0 {
logger.Warningf(
"failed to find %s tools, will attempt to use %s",
version.Current.Number, newVersion,
)
} else {
bootstrapVersion, toolsList = compatibleVersion, compatibleTools
}
}
logger.Infof("picked bootstrap tools version: %s", bootstrapVersion)
return toolsList, nil
}
示例3: getBootstrapToolsVersion
// getBootstrapToolsVersion returns the newest tools from the given tools list.
func getBootstrapToolsVersion(possibleTools coretools.List) (coretools.List, error) {
if len(possibleTools) == 0 {
return nil, errors.New("no bootstrap tools available")
}
var newVersion version.Number
newVersion, toolsList := possibleTools.Newest()
logger.Infof("newest version: %s", newVersion)
bootstrapVersion := newVersion
// We should only ever bootstrap the exact same version as the client,
// or we risk bootstrap incompatibility.
if !isCompatibleVersion(newVersion, jujuversion.Current) {
compatibleVersion, compatibleTools := findCompatibleTools(possibleTools, jujuversion.Current)
if len(compatibleTools) == 0 {
logger.Infof(
"failed to find %s tools, will attempt to use %s",
jujuversion.Current, newVersion,
)
} else {
bootstrapVersion, toolsList = compatibleVersion, compatibleTools
}
}
logger.Infof("picked bootstrap tools version: %s", bootstrapVersion)
return toolsList, nil
}