ListVolumes returns volumes with host info.
(ctx context.Context, params VolumeListParams)
| 561 | |
| 562 | // ListVolumes returns volumes with host info. |
| 563 | func (s *DockerStore) ListVolumes(ctx context.Context, params VolumeListParams) ([]VolumeWithHost, int, error) { |
| 564 | d := s.db.DB(ctx) |
| 565 | skip, take := validatePagination(params.Page, params.Limit, 10000) |
| 566 | |
| 567 | arg := db.ListVolumesParams{Limit: safeconv.ClampToInt32(take), Offset: safeconv.ClampToInt32(skip)} |
| 568 | if params.Driver != "" { |
| 569 | arg.Driver = ¶ms.Driver |
| 570 | } |
| 571 | if params.Search != "" { |
| 572 | arg.Search = ¶ms.Search |
| 573 | } |
| 574 | |
| 575 | countArg := db.CountVolumesParams{} |
| 576 | if params.Driver != "" { |
| 577 | countArg.Driver = ¶ms.Driver |
| 578 | } |
| 579 | if params.Search != "" { |
| 580 | countArg.Search = ¶ms.Search |
| 581 | } |
| 582 | |
| 583 | total, err := d.Queries.CountVolumes(ctx, countArg) |
| 584 | if err != nil { |
| 585 | return nil, 0, err |
| 586 | } |
| 587 | |
| 588 | volumes, err := d.Queries.ListVolumes(ctx, arg) |
| 589 | if err != nil { |
| 590 | return nil, 0, err |
| 591 | } |
| 592 | |
| 593 | if len(volumes) == 0 { |
| 594 | return []VolumeWithHost{}, int(total), nil |
| 595 | } |
| 596 | |
| 597 | hostIDs := make([]string, len(volumes)) |
| 598 | for i := range volumes { |
| 599 | hostIDs[i] = volumes[i].HostID |
| 600 | } |
| 601 | |
| 602 | hosts, err := d.Queries.GetDockerHostsMinimalByIDs(ctx, hostIDs) |
| 603 | if err != nil { |
| 604 | return nil, 0, err |
| 605 | } |
| 606 | hostMap := make(map[string]*HostInfo) |
| 607 | for i := range hosts { |
| 608 | h := dockerHostRowToHostInfo(hosts[i]) |
| 609 | hostMap[h.ID] = h |
| 610 | } |
| 611 | |
| 612 | out := make([]VolumeWithHost, len(volumes)) |
| 613 | for i := range volumes { |
| 614 | out[i] = VolumeWithHost{ |
| 615 | DockerVolume: dbDockerVolumeToModel(volumes[i]), |
| 616 | Hosts: hostMap[volumes[i].HostID], |
| 617 | } |
| 618 | } |
| 619 | return out, int(total), nil |
| 620 | } |
nothing calls this directly
no test coverage detected