// Destroy advances all given Alive units' lifecycles as far as // possible. See state/Unit.Destroy(). func (u *UniterAPIV3) Destroy(args params.Entities) (params.ErrorResults, error) { result := params.ErrorResults{ Results: make([]params.ErrorResult, len(args.Entities)), } canAccess, err := u.accessUnit() if err != nil { return params.ErrorResults{}, err } for i, entity := range args.Entities { tag, err := names.ParseUnitTag(entity.Tag) if err != nil { result.Results[i].Error = common.ServerError(common.ErrPerm) continue } err = common.ErrPerm if canAccess(tag) { var unit *state.Unit unit, err = u.getUnit(tag) if err == nil { err = unit.Destroy() } } result.Results[i].Error = common.ServerError(err) } return result, nil }