(deploymentPath string)
| 565 | } |
| 566 | |
| 567 | func getHosts(deploymentPath string) (hosts []nix.Host, err error) { |
| 568 | |
| 569 | deploymentFile, err := os.Open(deploymentPath) |
| 570 | if err != nil { |
| 571 | return hosts, err |
| 572 | } |
| 573 | |
| 574 | deploymentAbsPath, err := filepath.Abs(deploymentFile.Name()) |
| 575 | if err != nil { |
| 576 | return hosts, err |
| 577 | } |
| 578 | |
| 579 | ctx := getNixContext() |
| 580 | deployment, err := ctx.GetMachines(deploymentAbsPath) |
| 581 | if err != nil { |
| 582 | return hosts, err |
| 583 | } |
| 584 | |
| 585 | matchingHosts, err := filter.MatchHosts(deployment.Hosts, selectGlob) |
| 586 | if err != nil { |
| 587 | return hosts, err |
| 588 | } |
| 589 | |
| 590 | var selectedTags []string |
| 591 | if selectTags != "" { |
| 592 | selectedTags = strings.Split(selectTags, ",") |
| 593 | } |
| 594 | |
| 595 | matchingHosts2 := filter.FilterHostsTags(matchingHosts, selectedTags) |
| 596 | |
| 597 | ordering := deployment.Meta.Ordering |
| 598 | if orderingTags != "" { |
| 599 | ordering = nix.HostOrdering{Tags: strings.Split(orderingTags, ",")} |
| 600 | } |
| 601 | |
| 602 | sortedHosts := filter.SortHosts(matchingHosts2, ordering) |
| 603 | |
| 604 | filteredHosts := filter.FilterHosts(sortedHosts, selectSkip, selectEvery, selectLimit) |
| 605 | |
| 606 | fmt.Fprintf(os.Stderr, "Selected %v/%v hosts (name filter:-%v, limits:-%v):\n", len(filteredHosts), len(deployment.Hosts), len(deployment.Hosts)-len(matchingHosts), len(matchingHosts)-len(filteredHosts)) |
| 607 | for index, host := range filteredHosts { |
| 608 | fmt.Fprintf(os.Stderr, "\t%3d: %s (secrets: %d, health checks: %d, tags: %s)\n", index, host.Name, len(host.Secrets), len(host.HealthChecks.Cmd)+len(host.HealthChecks.Http), strings.Join(host.GetTags(), ",")) |
| 609 | } |
| 610 | fmt.Fprintln(os.Stderr) |
| 611 | |
| 612 | return filteredHosts, nil |
| 613 | } |
| 614 | |
| 615 | func getNixContext() *nix.NixContext { |
| 616 | evalCmd := os.Getenv("MORPH_NIX_EVAL_CMD") |
no test coverage detected