示例#1
0
文件: client.go 项目: Pankov404/juju
// 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
0
文件: controller.go 项目: kat-co/juju
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
0
文件: client.go 项目: exekias/juju
// 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
0
// 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
0
// 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
0
文件: client.go 项目: Pankov404/juju
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
0
// 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
0
文件: client.go 项目: imoapps/juju
// 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
0
文件: show.go 项目: snailwalker/juju
// 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
0
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
0
文件: unit.go 项目: imoapps/juju
// 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
0
文件: show.go 项目: bac/juju
// 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)
}