ListHosts returns hosts that have Docker containers with stats.
(ctx context.Context, page, limit int)
| 421 | |
| 422 | // ListHosts returns hosts that have Docker containers with stats. |
| 423 | func (s *DockerStore) ListHosts(ctx context.Context, page, limit int) ([]HostWithDockerStats, int, error) { |
| 424 | d := s.db.DB(ctx) |
| 425 | skip, take := validatePagination(page, limit, 10000) |
| 426 | |
| 427 | hostIDs, err := d.Queries.GetDistinctDockerHostIDs(ctx) |
| 428 | if err != nil { |
| 429 | return nil, 0, err |
| 430 | } |
| 431 | total := len(hostIDs) |
| 432 | if total == 0 { |
| 433 | return []HostWithDockerStats{}, 0, nil |
| 434 | } |
| 435 | |
| 436 | hostRows, err := d.Queries.ListDockerHostsPaginated(ctx, db.ListDockerHostsPaginatedParams{ |
| 437 | Limit: safeconv.ClampToInt32(take), |
| 438 | Offset: safeconv.ClampToInt32(skip), |
| 439 | }) |
| 440 | if err != nil { |
| 441 | return nil, 0, err |
| 442 | } |
| 443 | |
| 444 | out := make([]HostWithDockerStats, len(hostRows)) |
| 445 | for i := range hostRows { |
| 446 | h := hostRows[i] |
| 447 | stats, _ := d.Queries.GetHostDockerStats(ctx, h.ID) |
| 448 | out[i] = HostWithDockerStats{ |
| 449 | ID: h.ID, |
| 450 | FriendlyName: h.FriendlyName, |
| 451 | Hostname: h.Hostname, |
| 452 | IP: h.Ip, |
| 453 | DockerStats: DockerStats{ |
| 454 | TotalContainers: int(stats.Column1), |
| 455 | RunningContainers: int(stats.Column2), |
| 456 | TotalImages: int(stats.Column3), |
| 457 | }, |
| 458 | } |
| 459 | } |
| 460 | return out, total, nil |
| 461 | } |
| 462 | |
| 463 | // GetHostDockerDetail returns host with containers, images, volumes, networks. |
| 464 | func (s *DockerStore) GetHostDockerDetail(ctx context.Context, hostID string) (*HostDockerDetail, error) { |
nothing calls this directly
no test coverage detected