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


Golang Environ.SetConfig方法代碼示例

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


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

示例1: UploadTools

// UploadTools uploads tools for the specified series and any other relevant series to
// the environment storage, after which it sets the agent-version. If forceVersion is true,
// we allow uploading even when the agent-version is already set in the environment.
func UploadTools(ctx environs.BootstrapContext, env environs.Environ, toolsArch *string, forceVersion bool, bootstrapSeries ...string) error {
    logger.Infof("checking that upload is possible")
    // Check the series are valid.
    for _, series := range bootstrapSeries {
        if _, err := ubuntu.SeriesVersion(series); err != nil {
            return err
        }
    }
    // See that we are allowed to upload the tools.
    if err := validateUploadAllowed(env, toolsArch, forceVersion); err != nil {
        return err
    }

    // Make storage interruptible.
    interrupted := make(chan os.Signal, 1)
    interruptStorage := make(chan struct{})
    ctx.InterruptNotify(interrupted)
    defer ctx.StopInterruptNotify(interrupted)
    defer close(interrupted)
    go func() {
        defer close(interruptStorage) // closing interrupts all uploads
        if _, ok := <-interrupted; ok {
            ctx.Infof("cancelling tools upload")
        }
    }()
    stor := newInterruptibleStorage(env.Storage(), interruptStorage)

    cfg := env.Config()
    explicitVersion := uploadVersion(version.Current.Number, nil)
    uploadSeries := SeriesToUpload(cfg, bootstrapSeries)
    ctx.Infof("uploading tools for series %s", uploadSeries)
    tools, err := sync.Upload(stor, &explicitVersion, uploadSeries...)
    if err != nil {
        return err
    }
    cfg, err = cfg.Apply(map[string]interface{}{
        "agent-version": tools.Version.Number.String(),
    })
    if err == nil {
        err = env.SetConfig(cfg)
    }
    if err != nil {
        return fmt.Errorf("failed to update environment configuration: %v", err)
    }
    return nil
}
開發者ID:jameinel,項目名稱:core,代碼行數:49,代碼來源:synctools.go

示例2: GenerateSystemSSHKey

// GenerateSystemSSHKey creates a new key for the system identity. The
// authorized_keys in the environment config is updated to include the public
// key for the generated key.
func GenerateSystemSSHKey(env environs.Environ) (privateKey string, err error) {
    logger.Debugf("generate a system ssh key")
    // Create a new system ssh key and add that to the authorized keys.
    privateKey, publicKey, err := ssh.GenerateKey(config.JujuSystemKey)
    if err != nil {
        return "", fmt.Errorf("failed to create system key: %v", err)
    }
    authorized_keys := config.ConcatAuthKeys(env.Config().AuthorizedKeys(), publicKey)
    newConfig, err := env.Config().Apply(map[string]interface{}{
        config.AuthKeysConfig: authorized_keys,
    })
    if err != nil {
        return "", fmt.Errorf("failed to create new config: %v", err)
    }
    if err = env.SetConfig(newConfig); err != nil {
        return "", fmt.Errorf("failed to set new config: %v", err)
    }
    return privateKey, nil
}
開發者ID:jameinel,項目名稱:core,代碼行數:22,代碼來源:bootstrap.go

示例3: 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
}
開發者ID:jameinel,項目名稱:core,代碼行數:39,代碼來源:bootstrap.go


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