本文整理汇总了Golang中github.com/juju/juju/tools.List类的典型用法代码示例。如果您正苦于以下问题:Golang List类的具体用法?Golang List怎么用?Golang List使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了List类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: assertToolsList
func assertToolsList(c *gc.C, list coretools.List, expected []version.Binary) {
urls := list.URLs()
c.Check(urls, gc.HasLen, len(expected))
for _, vers := range expected {
c.Assert(urls[vers], gc.Not(gc.Equals), "")
}
}
示例2: 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()
}
示例3: checkToolsSeries
// checkToolsSeries verifies that all the given possible tools are for the
// given OS series.
func checkToolsSeries(toolsList coretools.List, series string) error {
toolsSeries := toolsList.AllSeries()
if len(toolsSeries) != 1 {
return fmt.Errorf("expected single series, got %v", toolsSeries)
}
if toolsSeries[0] != series {
return fmt.Errorf("tools mismatch: expected series %v, got %v", series, toolsSeries[0])
}
return nil
}
示例4: matchHostArchTools
// matchHostArchTools filters the given list of tools to the host architecture.
func matchHostArchTools(allTools tools.List) (tools.List, error) {
arch := arch.HostArch()
archTools, err := allTools.Match(tools.Filter{Arch: arch})
if err == tools.ErrNoMatches {
return nil, errors.Errorf(
"need tools for arch %s, only found %s",
arch, allTools.Arches(),
)
} else if err != nil {
return nil, errors.Trace(err)
}
return archTools, nil
}
示例5: 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
}
示例6: 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
}
示例7: TestURLs
func (s *ListSuite) TestURLs(c *gc.C) {
empty := tools.List{}
c.Check(empty.URLs(), gc.DeepEquals, map[version.Binary]string{})
full := tools.List{t100precise, t190quantal, t2001precise}
c.Check(full.URLs(), gc.DeepEquals, map[version.Binary]string{
t100precise.Version: t100precise.URL,
t190quantal.Version: t190quantal.URL,
t2001precise.Version: t2001precise.URL,
})
}
示例8: TestURLs
func (s *ListSuite) TestURLs(c *gc.C) {
empty := tools.List{}
c.Check(empty.URLs(), gc.DeepEquals, map[version.Binary][]string{})
alt := *t100quantal
alt.URL = strings.Replace(alt.URL, "testing.invalid", "testing.invalid2", 1)
full := tools.List{
t100precise,
t190quantal,
t100quantal,
&alt,
t2001precise,
}
c.Check(full.URLs(), gc.DeepEquals, map[version.Binary][]string{
t100precise.Version: []string{t100precise.URL},
t100quantal.Version: []string{t100quantal.URL, alt.URL},
t190quantal.Version: []string{t190quantal.URL},
t2001precise.Version: []string{t2001precise.URL},
})
}
示例9: bootstrapImageMetadata
// bootstrapImageMetadata returns the image metadata to use for bootstrapping
// the given environment. If the environment provider does not make use of
// simplestreams, no metadata will be returned.
//
// If a bootstrap image ID is specified, image metadat will be synthesised
// using that image ID, and the architecture and series specified by the
// initiator. In addition, the custom image metadat that is saved into the
// state database will have the synthesised image metadata added to it.
func bootstrapImageMetadata(
environ environs.Environ,
availableTools coretools.List,
bootstrapImageId string,
customImageMetadata *[]*imagemetadata.ImageMetadata,
) ([]*imagemetadata.ImageMetadata, error) {
hasRegion, ok := environ.(simplestreams.HasRegion)
if !ok {
if bootstrapImageId != "" {
// We only support specifying image IDs for providers
// that use simplestreams for now.
return nil, errors.NotSupportedf(
"specifying bootstrap image for %q provider",
environ.Config().Type(),
)
}
// No region, no metadata.
return nil, nil
}
region, err := hasRegion.Region()
if err != nil {
return nil, errors.Trace(err)
}
if bootstrapImageId != "" {
arches := availableTools.Arches()
if len(arches) != 1 {
return nil, errors.NotValidf("multiple architectures with bootstrap image")
}
allSeries := availableTools.AllSeries()
if len(allSeries) != 1 {
return nil, errors.NotValidf("multiple series with bootstrap image")
}
seriesVersion, err := series.SeriesVersion(allSeries[0])
if err != nil {
return nil, errors.Trace(err)
}
// The returned metadata does not have information about the
// storage or virtualisation type. Any provider that wants to
// filter on those properties should allow for empty values.
meta := &imagemetadata.ImageMetadata{
Id: bootstrapImageId,
Arch: arches[0],
Version: seriesVersion,
RegionName: region.Region,
Endpoint: region.Endpoint,
Stream: environ.Config().ImageStream(),
}
*customImageMetadata = append(*customImageMetadata, meta)
return []*imagemetadata.ImageMetadata{meta}, nil
}
// For providers that support making use of simplestreams
// image metadata, search public image metadata. We need
// to pass this onto Bootstrap for selecting images.
sources, err := environs.ImageMetadataSources(environ)
if err != nil {
return nil, errors.Trace(err)
}
imageConstraint := imagemetadata.NewImageConstraint(simplestreams.LookupParams{
CloudSpec: region,
Series: availableTools.AllSeries(),
Arches: availableTools.Arches(),
Stream: environ.Config().ImageStream(),
})
publicImageMetadata, _, err := imagemetadata.Fetch(sources, imageConstraint)
if err != nil {
return nil, errors.Annotate(err, "searching image metadata")
}
return publicImageMetadata, nil
}
示例10: Bootstrap
//.........这里部分代码省略.........
return err
}
constraintsValidator.UpdateVocabulary(constraints.Arch, architectures.SortedValues())
bootstrapConstraints, err := constraintsValidator.Merge(
args.ModelConstraints, args.BootstrapConstraints,
)
if err != nil {
return errors.Trace(err)
}
// The arch we use to find tools isn't the boostrapConstraints arch.
// We copy the constraints arch to a separate variable and
// update it from the host arch if not specified.
// (axw) This is still not quite right:
// For e.g. if there is a MAAS with only ARM64 machines,
// on an AMD64 client, we're going to look for only AMD64 tools,
// limiting what the provider can bootstrap anyway.
var bootstrapArch string
if bootstrapConstraints.Arch != nil {
bootstrapArch = *bootstrapConstraints.Arch
} else {
// If no arch is specified as a constraint, we'll bootstrap
// on the same arch as the client used to bootstrap.
bootstrapArch = arch.HostArch()
// We no longer support controllers on i386.
// If we are bootstrapping from an i386 client,
// we'll look for amd64 tools.
if bootstrapArch == arch.I386 {
bootstrapArch = arch.AMD64
}
}
var availableTools coretools.List
if !args.BuildAgent {
ctx.Infof("Looking for packaged Juju agent version %s for %s", args.AgentVersion, bootstrapArch)
availableTools, err = findPackagedTools(environ, args.AgentVersion, &bootstrapArch, bootstrapSeries)
if err != nil && !errors.IsNotFound(err) {
return err
}
}
// If there are no prepackaged tools and a specific version has not been
// requested, look for or build a local binary.
var builtTools *sync.BuiltAgent
if len(availableTools) == 0 && (args.AgentVersion == nil || isCompatibleVersion(*args.AgentVersion, jujuversion.Current)) {
if args.BuildAgentTarball == nil {
return errors.New("cannot build agent binary to upload")
}
if err := validateUploadAllowed(environ, &bootstrapArch, bootstrapSeries, constraintsValidator); err != nil {
return err
}
if args.BuildAgent {
ctx.Infof("Building local Juju agent binary version %s for %s", args.AgentVersion, bootstrapArch)
} else {
ctx.Infof("No packaged binary found, preparing local Juju agent binary")
}
var forceVersion version.Number
availableTools, forceVersion = locallyBuildableTools(bootstrapSeries)
builtTools, err = args.BuildAgentTarball(args.BuildAgent, &forceVersion, cfg.AgentStream())
if err != nil {
return errors.Annotate(err, "cannot package bootstrap agent binary")
}
defer os.RemoveAll(builtTools.Dir)
for i, tool := range availableTools {
if tool.URL != "" {
continue