本文整理匯總了Golang中github.com/juju/juju/apiserver/params.ErrorResults.Combine方法的典型用法代碼示例。如果您正苦於以下問題:Golang ErrorResults.Combine方法的具體用法?Golang ErrorResults.Combine怎麽用?Golang ErrorResults.Combine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/juju/juju/apiserver/params.ErrorResults
的用法示例。
在下文中一共展示了ErrorResults.Combine方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: UnshareEnvironment
// UnshareEnvironment removes access to the environment for the given users.
func (c *Client) UnshareEnvironment(users ...names.UserTag) error {
var args params.ModifyEnvironUsers
for _, user := range users {
if &user != nil {
args.Changes = append(args.Changes, params.ModifyEnvironUser{
UserTag: user.String(),
Action: params.RemoveEnvUser,
})
}
}
var result params.ErrorResults
err := c.facade.FacadeCall("ShareEnvironment", args, &result)
if err != nil {
return errors.Trace(err)
}
for i, r := range result.Results {
if r.Error != nil && r.Error.Code == params.CodeNotFound {
logger.Warningf("environment was not previously shared with user %s", users[i].Username())
result.Results[i].Error = nil
}
}
return result.Combine()
}
示例2: modifyControllerUser
func (c *Client) modifyControllerUser(action params.ControllerAction, user, access string) error {
var args params.ModifyControllerAccessRequest
if !names.IsValidUser(user) {
return errors.Errorf("invalid username: %q", user)
}
userTag := names.NewUserTag(user)
args.Changes = []params.ModifyControllerAccess{{
UserTag: userTag.String(),
Action: action,
Access: access,
}}
var result params.ErrorResults
err := c.facade.FacadeCall("ModifyControllerAccess", args, &result)
if err != nil {
return errors.Trace(err)
}
if len(result.Results) != len(args.Changes) {
return errors.Errorf("expected %d results, got %d", len(args.Changes), len(result.Results))
}
return result.Combine()
}
示例3: ShareModel
// ShareModel allows the given users access to the model.
func (c *Client) ShareModel(users ...names.UserTag) error {
var args params.ModifyModelUsers
for _, user := range users {
if &user != nil {
args.Changes = append(args.Changes, params.ModifyModelUser{
UserTag: user.String(),
Action: params.AddModelUser,
})
}
}
var result params.ErrorResults
err := c.facade.FacadeCall("ShareModel", args, &result)
if err != nil {
return errors.Trace(err)
}
for i, r := range result.Results {
if r.Error != nil && r.Error.Code == params.CodeAlreadyExists {
logger.Warningf("model is already shared with %s", users[i].Canonical())
result.Results[i].Error = nil
}
}
return result.Combine()
}
示例4: SetStatus
// SetStatus sets the status of storage entities.
func (st *State) SetStatus(args []params.EntityStatusArgs) error {
var result params.ErrorResults
err := st.facade.FacadeCall("SetStatus", params.SetStatus{args}, &result)
if err != nil {
return err
}
return result.Combine()
}
示例5: SetAgentStatus
// SetAgentStatus sets the status of the unit agents.
func (a API) SetAgentStatus(args params.SetStatus) error {
var result params.ErrorResults
err := a.facade.FacadeCall("SetAgentStatus", args, &result)
if err != nil {
return err
}
return result.Combine()
}
示例6: convert
func (c *Client) convert(found []params.StorageDetailsResult) ([]params.StorageDetails, error) {
var storages []params.StorageDetails
var allErr params.ErrorResults
for _, result := range found {
if result.Error != nil {
allErr.Results = append(allErr.Results, params.ErrorResult{result.Error})
continue
}
storages = append(storages, result.Result)
}
return storages, allErr.Combine()
}
示例7: Remove
// Remove deletes the given IP addresses.
func (api *API) Remove(ipAddresses ...*IPAddress) error {
var results params.ErrorResults
args := params.Entities{
Entities: make([]params.Entity, len(ipAddresses)),
}
for i, ipAddress := range ipAddresses {
args.Entities[i].Tag = ipAddress.Tag().String()
}
if err := api.facade.FacadeCall("Remove", args, &results); err != nil {
return errors.Trace(err)
}
return results.Combine()
}
示例8: List
// List returns blocks that are switched on for current environment.
func (c *Client) List() ([]params.Block, error) {
blocks := params.BlockResults{}
if err := c.facade.FacadeCall("List", nil, &blocks); err != nil {
return nil, errors.Trace(err)
}
all := []params.Block{}
allErr := params.ErrorResults{}
for _, result := range blocks.Results {
if result.Error != nil {
allErr.Results = append(allErr.Results, params.ErrorResult{result.Error})
continue
}
all = append(all, result.Result)
}
return all, allErr.Combine()
}
示例9: Run
// Run implements Command.Run.
func (c *showCommand) Run(ctx *cmd.Context) (err error) {
api := c.api
if api == nil {
api, err = c.NewStorageAPI()
if err != nil {
return err
}
defer api.Close()
}
tags, err := c.getStorageTags()
if err != nil {
return err
}
results, err := api.Show(tags)
if err != nil {
return err
}
var errs params.ErrorResults
var valid []params.StorageDetails
for _, result := range results {
if result.Error != nil {
errs.Results = append(errs.Results, params.ErrorResult{result.Error})
continue
}
if result.Result != nil {
valid = append(valid, *result.Result)
} else {
valid = append(valid, storageDetailsFromLegacy(result.Legacy))
}
}
if len(errs.Results) > 0 {
return errs.Combine()
}
output, err := formatStorageDetails(valid)
if err != nil {
return err
}
return c.out.Write(ctx, output)
}
示例10: modifyModelUser
func (c *Client) modifyModelUser(action params.ModelAction, user, access string, modelUUIDs []string) error {
var args params.ModifyModelAccessRequest
if !names.IsValidUser(user) {
return errors.Errorf("invalid username: %q", user)
}
userTag := names.NewUserTag(user)
accessPermission, err := ParseModelAccess(access)
if err != nil {
return errors.Trace(err)
}
for _, model := range modelUUIDs {
if !names.IsValidModel(model) {
return errors.Errorf("invalid model: %q", model)
}
modelTag := names.NewModelTag(model)
args.Changes = append(args.Changes, params.ModifyModelAccess{
UserTag: userTag.String(),
Action: action,
Access: accessPermission,
ModelTag: modelTag.String(),
})
}
var result params.ErrorResults
err = c.facade.FacadeCall("ModifyModelAccess", args, &result)
if err != nil {
return errors.Trace(err)
}
if len(result.Results) != len(args.Changes) {
return errors.Errorf("expected %d results, got %d", len(args.Changes), len(result.Results))
}
for i, r := range result.Results {
if r.Error != nil && r.Error.Code == params.CodeAlreadyExists {
logger.Warningf("model %q is already shared with %q", modelUUIDs[i], userTag.Canonical())
result.Results[i].Error = nil
}
}
return result.Combine()
}
示例11: AddStorage
// AddStorage adds desired storage instances to a unit.
func (u *Unit) AddStorage(constraints map[string][]params.StorageConstraints) error {
if u.st.facade.BestAPIVersion() < 2 {
return errors.NotImplementedf("AddStorage() (need V2+)")
}
all := make([]params.StorageAddParams, 0, len(constraints))
for storage, cons := range constraints {
for _, one := range cons {
all = append(all, params.StorageAddParams{u.Tag().String(), storage, one})
}
}
args := params.StoragesAddParams{Storages: all}
var results params.ErrorResults
err := u.st.facade.FacadeCall("AddUnitStorage", args, &results)
if err != nil {
return err
}
return results.Combine()
}
示例12: Run
// Run implements Command.Run.
func (c *showCommand) Run(ctx *cmd.Context) (err error) {
api, err := c.newAPIFunc()
if err != nil {
return err
}
defer api.Close()
tags, err := c.getStorageTags()
if err != nil {
return err
}
results, err := api.StorageDetails(tags)
if err != nil {
return err
}
var errs params.ErrorResults
var valid []params.StorageDetails
for _, result := range results {
if result.Error != nil {
errs.Results = append(errs.Results, params.ErrorResult{result.Error})
continue
}
valid = append(valid, *result.Result)
}
if len(errs.Results) > 0 {
return errs.Combine()
}
output, err := formatStorageDetails(valid)
if err != nil {
return err
}
return c.out.Write(ctx, output)
}