本文整理汇总了Golang中github.com/juju/juju/environs/configstore.Default函数的典型用法代码示例。如果您正苦于以下问题:Golang Default函数的具体用法?Golang Default怎么用?Golang Default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Default函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: generateUserJenv
func generateUserJenv(envName, user, password, outPath string) error {
store, err := configstore.Default()
if err != nil {
return errors.Trace(err)
}
storeInfo, err := store.ReadInfo(envName)
if err != nil {
return errors.Trace(err)
}
endpoint := storeInfo.APIEndpoint()
outputInfo := configstore.EnvironInfoData{
User: user,
Password: password,
EnvironUUID: endpoint.EnvironUUID,
StateServers: endpoint.Addresses,
CACert: endpoint.CACert,
}
yaml, err := cmd.FormatYaml(outputInfo)
if err != nil {
return errors.Trace(err)
}
outFile, err := os.Create(outPath)
if err != nil {
return errors.Trace(err)
}
defer outFile.Close()
outFile.Write(yaml)
if err != nil {
return errors.Trace(err)
}
return nil
}
示例2: GenerateUserJenv
func GenerateUserJenv(envName, user, password, outPath string) error {
store, err := configstore.Default()
if err != nil {
return errors.Trace(err)
}
storeInfo, err := store.ReadInfo(envName)
if err != nil {
return errors.Trace(err)
}
outputInfo := configstore.EnvironInfoData{}
outputInfo.User = user
outputInfo.Password = password
outputInfo.StateServers = storeInfo.APIEndpoint().Addresses
outputInfo.CACert = storeInfo.APIEndpoint().CACert
yaml, err := cmd.FormatYaml(outputInfo)
if err != nil {
return errors.Trace(err)
}
outFile, err := os.Create(outPath)
if err != nil {
return errors.Trace(err)
}
defer outFile.Close()
outFile.Write(yaml)
if err != nil {
return errors.Trace(err)
}
return nil
}
示例3: TestSystemKillCallsEnvironDestroyOnHostedEnviron
func (s *cmdControllerSuite) TestSystemKillCallsEnvironDestroyOnHostedEnviron(c *gc.C) {
st := s.Factory.MakeEnvironment(c, &factory.EnvParams{
Name: "foo",
})
defer st.Close()
st.SwitchBlockOn(state.DestroyBlock, "TestBlockDestroyEnvironment")
st.Close()
opc := make(chan dummy.Operation, 200)
dummy.Listen(opc)
conn, err := juju.NewAPIState(s.AdminUserTag(c), s.Environ, api.DialOpts{})
c.Assert(err, jc.ErrorIsNil)
s.AddCleanup(func(*gc.C) { conn.Close() })
client := undertakerapi.NewClient(conn)
startTime := time.Date(2015, time.September, 1, 17, 2, 1, 0, time.UTC)
mClock := testing.NewClock(startTime)
undertaker.NewUndertaker(client, mClock)
store, err := configstore.Default()
_, err = store.ReadInfo("dummyenv")
c.Assert(err, jc.ErrorIsNil)
s.run(c, "kill-controller", "dummyenv", "-y")
// Ensure that Destroy was called on the hosted environment ...
opRecvTimeout(c, st, opc, dummy.OpDestroy{})
// ... and that the configstore was removed.
_, err = store.ReadInfo("dummyenv")
c.Assert(err, jc.Satisfies, errors.IsNotFound)
}
示例4: Run
func (c *DestroyEnvironmentCommand) Run(ctx *cmd.Context) (result error) {
store, err := configstore.Default()
if err != nil {
return fmt.Errorf("cannot open environment info storage: %v", err)
}
environ, err := environs.NewFromName(c.envName, store)
if err != nil {
if environs.IsEmptyConfig(err) {
// Delete the .jenv file and call it done.
ctx.Infof("removing empty environment file")
return environs.DestroyInfo(c.envName, store)
}
return err
}
if !c.assumeYes {
fmt.Fprintf(ctx.Stdout, destroyEnvMsg, environ.Name(), environ.Config().Type())
scanner := bufio.NewScanner(ctx.Stdin)
scanner.Scan()
err := scanner.Err()
if err != nil && err != io.EOF {
return fmt.Errorf("Environment destruction aborted: %s", err)
}
answer := strings.ToLower(scanner.Text())
if answer != "y" && answer != "yes" {
return errors.New("environment destruction aborted")
}
}
// If --force is supplied, then don't attempt to use the API.
// This is necessary to destroy broken environments, where the
// API server is inaccessible or faulty.
if !c.force {
defer func() {
if result == nil {
return
}
logger.Errorf(`failed to destroy environment %q
If the environment is unusable, then you may run
juju destroy-environment --force
to forcefully destroy the environment. Upon doing so, review
your environment provider console for any resources that need
to be cleaned up.
`, c.envName)
}()
apiclient, err := juju.NewAPIClientFromName(c.envName)
if err != nil {
return fmt.Errorf("cannot connect to API: %v", err)
}
defer apiclient.Close()
err = apiclient.DestroyEnvironment()
if err != nil && !params.IsCodeNotImplemented(err) {
return fmt.Errorf("destroying environment: %v", err)
}
}
return environs.Destroy(environ, store)
}
示例5: environFromName
// environFromName loads an existing environment or prepares a new
// one. If there are no errors, it returns the environ and a closure to
// clean up in case we need to further up the stack. If an error has
// occurred, the environment and cleanup function will be nil, and the
// error will be filled in.
func environFromName(
ctx *cmd.Context,
envName string,
action string,
) (env environs.Environ, cleanup func(), err error) {
store, err := configstore.Default()
if err != nil {
return nil, nil, err
}
envExisted := false
if environInfo, err := store.ReadInfo(envName); err == nil {
envExisted = true
logger.Warningf(
"ignoring environments.yaml: using bootstrap config in %s",
environInfo.Location(),
)
} else if !errors.IsNotFound(err) {
return nil, nil, err
}
if env, err = environs.PrepareFromName(envName, ctx, store); err != nil {
return nil, nil, err
}
cleanup = func() {
if !envExisted {
destroyPreparedEnviron(ctx, env, store, action)
}
}
return env, cleanup, nil
}
示例6: Run
// Run implements Command.Run
func (c *destroyCommand) Run(ctx *cmd.Context) error {
store, err := configstore.Default()
if err != nil {
return errors.Annotate(err, "cannot open controller info storage")
}
cfgInfo, err := store.ReadInfo(c.ModelName())
if err != nil {
return errors.Annotate(err, "cannot read controller info")
}
// Verify that we're destroying a controller
apiEndpoint := cfgInfo.APIEndpoint()
if apiEndpoint.ServerUUID != "" && apiEndpoint.ModelUUID != apiEndpoint.ServerUUID {
return errors.Errorf("%q is not a controller; use juju model destroy to destroy it", c.ModelName())
}
if !c.assumeYes {
if err = confirmDestruction(ctx, c.ModelName()); err != nil {
return err
}
}
// Attempt to connect to the API. If we can't, fail the destroy. Users will
// need to use the controller kill command if we can't connect.
api, err := c.getControllerAPI()
if err != nil {
return c.ensureUserFriendlyErrorLog(errors.Annotate(err, "cannot connect to API"), ctx, nil)
}
defer api.Close()
// Obtain bootstrap / controller environ information
controllerEnviron, err := c.getControllerEnviron(cfgInfo, api)
if err != nil {
return errors.Annotate(err, "cannot obtain bootstrap information")
}
// Attempt to destroy the controller.
err = api.DestroyController(c.destroyEnvs)
if err != nil {
return c.ensureUserFriendlyErrorLog(errors.Annotate(err, "cannot destroy controller"), ctx, api)
}
ctx.Infof("Destroying controller %q", c.ModelName())
if c.destroyEnvs {
ctx.Infof("Waiting for hosted model resources to be reclaimed.")
updateStatus := newTimedStatusUpdater(ctx, api, apiEndpoint.ModelUUID)
for ctrStatus, envsStatus := updateStatus(0); hasUnDeadEnvirons(envsStatus); ctrStatus, envsStatus = updateStatus(2 * time.Second) {
ctx.Infof(fmtCtrStatus(ctrStatus))
for _, envStatus := range envsStatus {
ctx.Verbosef(fmtEnvStatus(envStatus))
}
}
ctx.Infof("All hosted models reclaimed, cleaning up controller machines")
}
return environs.Destroy(controllerEnviron, store)
}
示例7: Run
func (c *restoreCommand) Run(ctx *cmd.Context) error {
if c.showDescription {
fmt.Fprintf(ctx.Stdout, "%s\n", c.Info().Purpose)
return nil
}
if err := c.Log.Start(ctx); err != nil {
return err
}
agentConf, err := extractConfig(c.backupFile)
if err != nil {
return errors.Annotate(err, "cannot extract configuration from backup file")
}
progress("extracted credentials from backup file")
store, err := configstore.Default()
if err != nil {
return err
}
cfg, err := c.Config(store)
if err != nil {
return err
}
env, err := rebootstrap(cfg, ctx, c.Constraints)
if err != nil {
return errors.Annotate(err, "cannot re-bootstrap environment")
}
progress("connecting to newly bootstrapped instance")
var apiState *api.State
// The state server backend may not be ready to accept logins so we retry.
// We'll do up to 8 retries over 2 minutes to give the server time to come up.
// Typically we expect only 1 retry will be needed.
attempt := utils.AttemptStrategy{Delay: 15 * time.Second, Min: 8}
for a := attempt.Start(); a.Next(); {
apiState, err = juju.NewAPIState(env, api.DefaultDialOpts())
if err == nil || errors.Cause(err).Error() != "EOF" {
break
}
progress("bootstrapped instance not ready - attempting to redial")
}
if err != nil {
return errors.Annotate(err, "cannot connect to bootstrap instance")
}
progress("restoring bootstrap machine")
machine0Addr, err := restoreBootstrapMachine(apiState, c.backupFile, agentConf)
if err != nil {
return errors.Annotate(err, "cannot restore bootstrap machine")
}
progress("restored bootstrap machine")
apiState, err = juju.NewAPIState(env, api.DefaultDialOpts())
progress("opening state")
if err != nil {
return errors.Annotate(err, "cannot connect to api server")
}
progress("updating all machines")
if err := updateAllMachines(apiState, machine0Addr); err != nil {
return errors.Annotate(err, "cannot update machines")
}
return nil
}
示例8: setUpConn
func (s *JujuConnSuite) setUpConn(c *gc.C) {
if s.RootDir != "" {
panic("JujuConnSuite.setUpConn without teardown")
}
s.RootDir = c.MkDir()
s.oldHome = utils.Home()
home := filepath.Join(s.RootDir, "/home/ubuntu")
err := os.MkdirAll(home, 0777)
c.Assert(err, gc.IsNil)
utils.SetHome(home)
s.oldJujuHome = osenv.SetJujuHome(filepath.Join(home, ".juju"))
err = os.Mkdir(osenv.JujuHome(), 0777)
c.Assert(err, gc.IsNil)
err = os.MkdirAll(s.DataDir(), 0777)
c.Assert(err, gc.IsNil)
s.PatchEnvironment(osenv.JujuEnvEnvKey, "")
// TODO(rog) remove these files and add them only when
// the tests specifically need them (in cmd/juju for example)
s.writeSampleConfig(c, osenv.JujuHomePath("environments.yaml"))
err = ioutil.WriteFile(osenv.JujuHomePath("dummyenv-cert.pem"), []byte(testing.CACert), 0666)
c.Assert(err, gc.IsNil)
err = ioutil.WriteFile(osenv.JujuHomePath("dummyenv-private-key.pem"), []byte(testing.CAKey), 0600)
c.Assert(err, gc.IsNil)
store, err := configstore.Default()
c.Assert(err, gc.IsNil)
s.ConfigStore = store
ctx := testing.Context(c)
environ, err := environs.PrepareFromName("dummyenv", ctx, s.ConfigStore)
c.Assert(err, gc.IsNil)
// sanity check we've got the correct environment.
c.Assert(environ.Config().Name(), gc.Equals, "dummyenv")
s.PatchValue(&dummy.DataDir, s.DataDir())
s.LogDir = c.MkDir()
s.PatchValue(&dummy.LogDir, s.LogDir)
versions := PreferredDefaultVersions(environ.Config(), version.Binary{Number: version.Current.Number, Series: "precise", Arch: "amd64"})
versions = append(versions, version.Current)
// Upload tools for both preferred and fake default series
envtesting.MustUploadFakeToolsVersions(environ.Storage(), versions...)
err = bootstrap.Bootstrap(ctx, environ, bootstrap.BootstrapParams{})
c.Assert(err, gc.IsNil)
s.BackingState = environ.(GetStater).GetStateInAPIServer()
s.State, err = newState(environ, s.BackingState.MongoConnectionInfo())
c.Assert(err, gc.IsNil)
s.APIState, err = juju.NewAPIState(environ, api.DialOpts{})
c.Assert(err, gc.IsNil)
s.Environ = environ
}
示例9: SetUpTest
func (s *EnvConfigSuite) SetUpTest(c *gc.C) {
s.FakeJujuHomeSuite.SetUpTest(c)
s.envName = "test-env"
s.client = &fakeEnvGetter{results: createBootstrapInfo(c, s.envName)}
var err error
s.store, err = configstore.Default()
c.Assert(err, jc.ErrorIsNil)
}
示例10: modelUUID
func (c *updateAllocationCommand) modelUUID() (string, error) {
store, err := configstore.Default()
if err != nil {
return "", errors.Trace(err)
}
modelInfo, err := store.ReadInfo(c.ModelName())
if err != nil {
return "", errors.Trace(err)
}
return modelInfo.APIEndpoint().ModelUUID, nil
}
示例11: getConfigstoreEnvironments
func getConfigstoreEnvironments() (set.Strings, error) {
store, err := configstore.Default()
if err != nil {
return nil, errors.Annotate(err, "failed to get config store")
}
other, err := store.List()
if err != nil {
return nil, errors.Annotate(err, "failed to list environments in config store")
}
return set.NewStrings(other...), nil
}
示例12: NewConnFromName
// NewConnFromName returns a Conn pointing at the environName environment, or the
// default environment if not specified.
func NewConnFromName(environName string) (*Conn, error) {
store, err := configstore.Default()
if err != nil {
return nil, err
}
environ, err := environs.NewFromName(environName, store)
if err != nil {
return nil, err
}
return NewConn(environ)
}
示例13: newAPIClient
func newAPIClient(envName string, bClient *httpbakery.Client) (api.Connection, error) {
store, err := configstore.Default()
if err != nil {
return nil, errors.Trace(err)
}
st, err := newAPIFromStore(envName, store, defaultAPIOpen, bClient)
if err != nil {
return nil, errors.Trace(err)
}
return st, nil
}
示例14: newAPIClient
func newAPIClient(envName string) (*api.State, error) {
store, err := configstore.Default()
if err != nil {
return nil, errors.Trace(err)
}
st, err := newAPIFromStore(envName, store, defaultAPIOpen)
if err != nil {
return nil, errors.Trace(err)
}
return st.(*api.State), nil
}
示例15: resetJujuHome
// resetJujuHome restores an new, clean Juju home environment without tools.
func resetJujuHome(c *gc.C, envName string) environs.Environ {
jenvDir := gitjujutesting.HomePath(".juju", "environments")
err := os.RemoveAll(jenvDir)
c.Assert(err, jc.ErrorIsNil)
coretesting.WriteEnvironments(c, envConfig)
dummy.Reset()
store, err := configstore.Default()
c.Assert(err, jc.ErrorIsNil)
env, err := environs.PrepareFromName(envName, envcmd.BootstrapContext(cmdtesting.NullContext(c)), store)
c.Assert(err, jc.ErrorIsNil)
return env
}