本文整理汇总了Golang中github.com/juju/juju/environs/configstore.EnvironInfo.Destroy方法的典型用法代码示例。如果您正苦于以下问题:Golang EnvironInfo.Destroy方法的具体用法?Golang EnvironInfo.Destroy怎么用?Golang EnvironInfo.Destroy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/environs/configstore.EnvironInfo
的用法示例。
在下文中一共展示了EnvironInfo.Destroy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Run
func (c *createEnvironmentCommand) Run(ctx *cmd.Context) (return_err error) {
client, err := c.getAPI()
if err != nil {
return err
}
defer client.Close()
creds, err := c.ConnectionCredentials()
if err != nil {
return errors.Trace(err)
}
creatingForSelf := true
envOwner := creds.User
if c.Owner != "" {
owner := names.NewUserTag(c.Owner)
user := names.NewUserTag(creds.User)
creatingForSelf = owner == user
envOwner = c.Owner
}
var info configstore.EnvironInfo
var endpoint configstore.APIEndpoint
if creatingForSelf {
logger.Debugf("create cache entry for %q", c.Name)
// Create the configstore entry and write it to disk, as this will error
// if one with the same name already exists.
endpoint, err = c.ConnectionEndpoint()
if err != nil {
return errors.Trace(err)
}
store, err := configstore.Default()
if err != nil {
return errors.Trace(err)
}
info = store.CreateInfo(c.Name)
info.SetAPICredentials(creds)
endpoint.EnvironUUID = ""
if err := info.Write(); err != nil {
if errors.Cause(err) == configstore.ErrEnvironInfoAlreadyExists {
newErr := errors.AlreadyExistsf("environment %q", c.Name)
return errors.Wrap(err, newErr)
}
return errors.Trace(err)
}
defer func() {
if return_err != nil {
logger.Debugf("error found, remove cache entry")
e := info.Destroy()
if e != nil {
logger.Errorf("could not remove environment file: %v", e)
}
}
}()
} else {
logger.Debugf("skipping cache entry for %q as owned %q", c.Name, c.Owner)
}
serverSkeleton, err := client.ConfigSkeleton("", "")
if err != nil {
return errors.Trace(err)
}
attrs, err := c.getConfigValues(ctx, serverSkeleton)
if err != nil {
return errors.Trace(err)
}
// We pass nil through for the account details until we implement that bit.
env, err := client.CreateEnvironment(envOwner, nil, attrs)
if err != nil {
// cleanup configstore
return errors.Trace(err)
}
if creatingForSelf {
// update the cached details with the environment uuid
endpoint.EnvironUUID = env.UUID
info.SetAPIEndpoint(endpoint)
if err := info.Write(); err != nil {
return errors.Trace(err)
}
ctx.Infof("created environment %q", c.Name)
return envcmd.SetCurrentEnvironment(ctx, c.Name)
} else {
ctx.Infof("created environment %q for %q", c.Name, c.Owner)
}
return nil
}