MCPcopy Create free account
hub / github.com/DBCDK/morph / getHosts

Function getHosts

morph.go:567–613  ·  view source on GitHub ↗
(deploymentPath string)

Source from the content-addressed store, hash-verified

565}
566
567func 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
615func getNixContext() *nix.NixContext {
616 evalCmd := os.Getenv("MORPH_NIX_EVAL_CMD")

Callers 1

mainFunction · 0.85

Calls 7

MatchHostsFunction · 0.92
FilterHostsTagsFunction · 0.92
SortHostsFunction · 0.92
FilterHostsFunction · 0.92
getNixContextFunction · 0.85
GetMachinesMethod · 0.80
GetTagsMethod · 0.80

Tested by

no test coverage detected