ListContainers returns containers with host info.
(ctx context.Context, params ContainerListParams)
| 119 | |
| 120 | // ListContainers returns containers with host info. |
| 121 | func (s *DockerStore) ListContainers(ctx context.Context, params ContainerListParams) ([]ContainerWithHost, int, error) { |
| 122 | d := s.db.DB(ctx) |
| 123 | skip, take := validatePagination(params.Page, params.Limit, 10000) |
| 124 | |
| 125 | arg := db.ListContainersParams{Limit: safeconv.ClampToInt32(take), Offset: safeconv.ClampToInt32(skip)} |
| 126 | if params.Status != "" { |
| 127 | arg.Status = ¶ms.Status |
| 128 | } |
| 129 | if params.HostID != "" { |
| 130 | arg.HostID = ¶ms.HostID |
| 131 | } |
| 132 | if params.ImageID != "" { |
| 133 | arg.ImageID = ¶ms.ImageID |
| 134 | } |
| 135 | if params.Search != "" { |
| 136 | arg.Search = ¶ms.Search |
| 137 | } |
| 138 | |
| 139 | countArg := db.CountContainersParams{} |
| 140 | if params.Status != "" { |
| 141 | countArg.Status = ¶ms.Status |
| 142 | } |
| 143 | if params.HostID != "" { |
| 144 | countArg.HostID = ¶ms.HostID |
| 145 | } |
| 146 | if params.ImageID != "" { |
| 147 | countArg.ImageID = ¶ms.ImageID |
| 148 | } |
| 149 | if params.Search != "" { |
| 150 | countArg.Search = ¶ms.Search |
| 151 | } |
| 152 | |
| 153 | total, err := d.Queries.CountContainers(ctx, countArg) |
| 154 | if err != nil { |
| 155 | return nil, 0, err |
| 156 | } |
| 157 | |
| 158 | containers, err := d.Queries.ListContainers(ctx, arg) |
| 159 | if err != nil { |
| 160 | return nil, 0, err |
| 161 | } |
| 162 | |
| 163 | if len(containers) == 0 { |
| 164 | return []ContainerWithHost{}, int(total), nil |
| 165 | } |
| 166 | |
| 167 | hostIDs := make(map[string]bool) |
| 168 | for _, c := range containers { |
| 169 | hostIDs[c.HostID] = true |
| 170 | } |
| 171 | ids := make([]string, 0, len(hostIDs)) |
| 172 | for id := range hostIDs { |
| 173 | ids = append(ids, id) |
| 174 | } |
| 175 | |
| 176 | hosts, err := d.Queries.GetDockerHostsMinimalByIDs(ctx, ids) |
| 177 | if err != nil { |
| 178 | return nil, 0, err |
nothing calls this directly
no test coverage detected