本文整理汇总了Golang中github.com/juju/juju/jujuclient.ClientStore.CurrentController方法的典型用法代码示例。如果您正苦于以下问题:Golang ClientStore.CurrentController方法的具体用法?Golang ClientStore.CurrentController怎么用?Golang ClientStore.CurrentController使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/jujuclient.ClientStore
的用法示例。
在下文中一共展示了ClientStore.CurrentController方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetCurrentModel
// GetCurrentModel returns the name of the current Juju model.
//
// If $JUJU_MODEL is set, use that. Otherwise, get the current
// controller from controllers.yaml, and then identify the current
// model for that controller in models.yaml. If there is no current
// controller, then an empty string is returned. It is not an error
// to have no current model.
//
// If there is a current controller, but no current model for that
// controller, then GetCurrentModel will return the string
// "<controller>:". If there is a current model as well, it will
// return "<controller>:<model>". Only when $JUJU_MODEL is set,
// will the result possibly be unqualified.
func GetCurrentModel(store jujuclient.ClientStore) (string, error) {
if model := os.Getenv(osenv.JujuModelEnvKey); model != "" {
return model, nil
}
currentController, err := store.CurrentController()
if errors.IsNotFound(err) {
return "", nil
} else if err != nil {
return "", errors.Trace(err)
}
currentModel, err := store.CurrentModel(currentController)
if errors.IsNotFound(err) {
return currentController + ":", nil
} else if err != nil {
return "", errors.Trace(err)
}
return JoinModelName(currentController, currentModel), nil
}