本文整理匯總了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
}