MCPcopy Create free account
hub / github.com/PatchMon/PatchMon / ListVolumes

Method ListVolumes

server-source-code/internal/store/docker.go:563–620  ·  view source on GitHub ↗

ListVolumes returns volumes with host info.

(ctx context.Context, params VolumeListParams)

Source from the content-addressed store, hash-verified

561
562// ListVolumes returns volumes with host info.
563func (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 = &params.Driver
570 }
571 if params.Search != "" {
572 arg.Search = &params.Search
573 }
574
575 countArg := db.CountVolumesParams{}
576 if params.Driver != "" {
577 countArg.Driver = &params.Driver
578 }
579 if params.Search != "" {
580 countArg.Search = &params.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}

Callers

nothing calls this directly

Calls 7

validatePaginationFunction · 0.85
dockerHostRowToHostInfoFunction · 0.85
dbDockerVolumeToModelFunction · 0.85
DBMethod · 0.65
CountVolumesMethod · 0.65
ListVolumesMethod · 0.65

Tested by

no test coverage detected