本文整理匯總了Golang中github.com/juju/juju/state.State.ForModel方法的典型用法代碼示例。如果您正苦於以下問題:Golang State.ForModel方法的具體用法?Golang State.ForModel怎麽用?Golang State.ForModel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/juju/juju/state.State
的用法示例。
在下文中一共展示了State.ForModel方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: exportModel
func (c *MigrateCommand) exportModel(ctx *cmd.Context, st *state.State) error {
ctx.Infof("\nexport %s", c.modelUUID)
// first make sure the uuid is good enough
tag := names.NewModelTag(c.modelUUID)
_, err := st.GetModel(tag)
if err != nil {
return errors.Trace(err)
}
modelState, err := st.ForModel(tag)
if err != nil {
return errors.Trace(err)
}
defer modelState.Close()
model, err := modelState.Export()
if err != nil {
return errors.Trace(err)
}
bytes, err := yaml.Marshal(model)
if err != nil {
return errors.Trace(err)
}
ctx.Stdout.Write(bytes)
return nil
}
示例2: destroyModel
func destroyModel(st *state.State, modelTag names.ModelTag, destroyHostedModels bool) error {
var err error
if modelTag != st.ModelTag() {
if st, err = st.ForModel(modelTag); err != nil {
return errors.Trace(err)
}
defer st.Close()
}
if destroyHostedModels {
envs, err := st.AllModels()
if err != nil {
return errors.Trace(err)
}
for _, env := range envs {
envSt, err := st.ForModel(env.ModelTag())
defer envSt.Close()
if err != nil {
return errors.Trace(err)
}
check := NewBlockChecker(envSt)
if err = check.DestroyAllowed(); err != nil {
return errors.Trace(err)
}
}
} else {
check := NewBlockChecker(st)
if err = check.DestroyAllowed(); err != nil {
return errors.Trace(err)
}
}
env, err := st.Model()
if err != nil {
return errors.Trace(err)
}
if destroyHostedModels {
if err := env.DestroyIncludingHosted(); err != nil {
return err
}
} else {
if err = env.Destroy(); err != nil {
return errors.Trace(err)
}
}
err = sendMetrics(st)
if err != nil {
logger.Warningf("failed to send leftover metrics: %v", err)
}
// Return to the caller. If it's the CLI, it will finish up by calling the
// provider's Destroy method, which will destroy the controllers, any
// straggler instances, and other provider-specific resources. Once all
// resources are torn down, the Undertaker worker handles the removal of
// the environment.
return nil
}
示例3: dumpLogsForEnv
func (c *dumpLogsCommand) dumpLogsForEnv(ctx *cmd.Context, st0 *state.State, tag names.ModelTag) error {
st, err := st0.ForModel(tag)
if err != nil {
return errors.Annotate(err, "failed open model")
}
defer st.Close()
logName := ctx.AbsPath(filepath.Join(c.outDir, fmt.Sprintf("%s.log", tag.Id())))
ctx.Infof("writing to %s", logName)
file, err := os.Create(logName)
if err != nil {
return errors.Annotate(err, "failed to open output file")
}
defer file.Close()
writer := bufio.NewWriter(file)
defer writer.Flush()
tailer, err := state.NewLogTailer(st, &state.LogTailerParams{NoTail: true})
if err != nil {
return errors.Annotate(err, "failed to create a log tailer")
}
logs := tailer.Logs()
for {
rec, ok := <-logs
if !ok {
break
}
writer.WriteString(c.format(
rec.Time,
rec.Level,
rec.Entity.String(),
rec.Module,
rec.Message,
) + "\n")
}
return nil
}