本文整理匯總了Golang中github.com/juju/juju/jujuclient.ClientStore.AllControllers方法的典型用法代碼示例。如果您正苦於以下問題:Golang ClientStore.AllControllers方法的具體用法?Golang ClientStore.AllControllers怎麽用?Golang ClientStore.AllControllers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/juju/juju/jujuclient.ClientStore
的用法示例。
在下文中一共展示了ClientStore.AllControllers方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: updateController
// updateController prompts for a controller name and updates the
// controller and account details in the given client store.
// It returns the name of the updated controller.
func (c *registerCommand) updateController(
ctx *cmd.Context,
store jujuclient.ClientStore,
defaultControllerName string,
controllerDetails jujuclient.ControllerDetails,
accountDetails jujuclient.AccountDetails,
) (string, error) {
// Check that the same controller isn't already stored, so that we
// can avoid needlessly asking for a controller name in that case.
all, err := store.AllControllers()
if err != nil {
return "", errors.Trace(err)
}
for name, ctl := range all {
if ctl.ControllerUUID == controllerDetails.ControllerUUID {
// TODO(rogpeppe) lp#1614010 Succeed but override the account details in this case?
return "", errors.Errorf("controller is already registered as %q", name)
}
}
controllerName, err := c.promptControllerName(store, defaultControllerName, ctx.Stderr, ctx.Stdin)
if err != nil {
return "", errors.Trace(err)
}
if err := store.AddController(controllerName, controllerDetails); err != nil {
return "", errors.Trace(err)
}
if err := store.UpdateAccount(controllerName, accountDetails); err != nil {
return "", errors.Annotatef(err, "cannot update account information: %v", err)
}
return controllerName, nil
}
示例2: translateControllerError
func translateControllerError(store jujuclient.ClientStore, err error) error {
if !errors.IsNotFound(err) {
return err
}
controllers, err2 := store.AllControllers()
if err2 != nil {
return err2
}
if len(controllers) == 0 {
return errors.Wrap(err, ErrNoControllersDefined)
}
return errors.Wrap(err, ErrNoCurrentController)
}
示例3: newCacheStore
func newCacheStore(store jujuclient.ClientStore) (*cacheStore, error) {
controllers, err := store.AllControllers()
if err != nil {
return nil, errors.Trace(err)
}
accounts := make(map[string]jujuclient.AccountDetails)
for controller := range controllers {
acct, err := store.AccountDetails(controller)
if err != nil {
if !errors.IsNotFound(err) {
return nil, errors.Annotatef(err, "cannot get account details for %q", controller)
}
} else {
accounts[controller] = *acct
}
}
return &cacheStore{
accounts: accounts,
origStore: store,
controllers: controllers,
updatedAccounts: make(map[string]bool),
}, nil
}