本文整理汇总了Golang中github.com/juju/core/state.State.EnvironConfig方法的典型用法代码示例。如果您正苦于以下问题:Golang State.EnvironConfig方法的具体用法?Golang State.EnvironConfig怎么用?Golang State.EnvironConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/core/state.State
的用法示例。
在下文中一共展示了State.EnvironConfig方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: MachineConfig
// MachineConfig returns information from the environment config that is
// needed for machine cloud-init (for non-state servers only).
// It is exposed for testing purposes.
// TODO(rog) fix environs/manual tests so they do not need to
// call this, or move this elsewhere.
func MachineConfig(st *state.State, machineId, nonce, dataDir string) (*cloudinit.MachineConfig, error) {
environConfig, err := st.EnvironConfig()
if err != nil {
return nil, err
}
// Get the machine so we can get its series and arch.
// If the Arch is not set in hardware-characteristics,
// an error is returned.
machine, err := st.Machine(machineId)
if err != nil {
return nil, err
}
hc, err := machine.HardwareCharacteristics()
if err != nil {
return nil, err
}
if hc.Arch == nil {
return nil, fmt.Errorf("arch is not set for %q", machine.Tag())
}
// Find the appropriate tools information.
env, err := environs.New(environConfig)
if err != nil {
return nil, err
}
tools, err := findInstanceTools(env, machine.Series(), *hc.Arch)
if err != nil {
return nil, err
}
// Find the secrets and API endpoints.
auth, err := environs.NewEnvironAuthenticator(env)
if err != nil {
return nil, err
}
stateInfo, apiInfo, err := auth.SetupAuthentication(machine)
if err != nil {
return nil, err
}
// Find requested networks.
includeNetworks, excludeNetworks, err := machine.RequestedNetworks()
if err != nil {
return nil, err
}
mcfg := environs.NewMachineConfig(machineId, nonce, includeNetworks, excludeNetworks, stateInfo, apiInfo)
if dataDir != "" {
mcfg.DataDir = dataDir
}
mcfg.Tools = tools
err = environs.FinishMachineConfig(mcfg, environConfig, constraints.Value{})
if err != nil {
return nil, err
}
return mcfg, nil
}
示例2: New
// New returns a new worker that maintains the mongo replica set
// with respect to the given state.
func New(st *state.State) (worker.Worker, error) {
cfg, err := st.EnvironConfig()
if err != nil {
return nil, err
}
return newWorker(&stateShim{
State: st,
mongoPort: cfg.StatePort(),
apiPort: cfg.APIPort(),
}, newPublisher(st)), nil
}
示例3: GetStorage
// GetStorage creates an Environ from the config in state and returns
// its storage interface.
func GetStorage(st *state.State) (storage.Storage, error) {
envConfig, err := st.EnvironConfig()
if err != nil {
return nil, fmt.Errorf("cannot get environment config: %v", err)
}
env, err := New(envConfig)
if err != nil {
return nil, fmt.Errorf("cannot access environment: %v", err)
}
return env.Storage(), nil
}
示例4: NewConnFromState
// NewConnFromState returns a Conn that uses an Environ
// made by reading the environment configuration.
// The resulting Conn uses the given State - closing
// it will close that State.
func NewConnFromState(st *state.State) (*Conn, error) {
cfg, err := st.EnvironConfig()
if err != nil {
return nil, err
}
environ, err := environs.New(cfg)
if err != nil {
return nil, err
}
return &Conn{
Environ: environ,
State: st,
}, nil
}