|
1 | 1 | # @summary Start the cluster of Lima VMs
|
2 | 2 | # @param name
|
3 | 3 | # Cluster name
|
| 4 | +# @param jobs |
| 5 | +# How much VMs to start in parallel |
4 | 6 | # @param clusters
|
5 | 7 | # Hash of all defined clusters. Populated from Hiera usually.
|
6 | 8 | # @param target
|
7 | 9 | # The host to run the limactl on
|
8 | 10 | plan lima::cluster::start (
|
9 | 11 | String[1] $name,
|
| 12 | + Integer[0] $jobs = 0, |
10 | 13 | Optional[Hash] $clusters = undef,
|
11 | 14 | TargetSpec $target = 'localhost',
|
12 | 15 | ) {
|
|
36 | 39 | fail_plan("Some nodes are missing: ${missing_nodes}", 'lima/missing-nodes', missing_nodes => $missing_nodes)
|
37 | 40 | }
|
38 | 41 |
|
39 |
| - # Collect and set the target's facts |
40 |
| - if empty(facts($tgt)) { |
41 |
| - without_default_logging() || { |
42 |
| - run_plan('facts', $tgt, _catch_errors => true) |
| 42 | + $start_jobs = if $jobs > 0 { |
| 43 | + $jobs |
| 44 | + } else { |
| 45 | + if $tgt.facts.length < 1 { |
| 46 | + without_default_logging() || { |
| 47 | + run_plan('facts', $tgt, _catch_errors => true) |
| 48 | + } |
43 | 49 | }
|
| 50 | + $cpus = $tgt.facts.get('processors.count', 1) |
| 51 | + if $cpus < 4 { 1 } else { $cpus / 2 } # Assume every VM can consume up to 200% of a CPU core on start |
44 | 52 | }
|
45 |
| - $cpus = facts($tgt).get('processors.count', 1) |
46 |
| - # FIXME: make start_threads configurable |
47 |
| - $start_threads = if $cpus < 4 { 1 } else { $cpus / 2 } # Assume every VM can consume up to 200% of a CPU core on start |
48 | 53 |
|
49 | 54 | # Start stopped nodes
|
50 | 55 | $stopped_nodes = $lima_list.filter |$x| { $x['status'] == 'Stopped' }.map |$x| { $x['name'] }
|
51 |
| - out::verbose("Nodes to start (${start_threads} nodes per batch): ${stopped_nodes}") |
| 56 | + out::verbose("Nodes to start (${start_jobs} nodes per batch): ${stopped_nodes}") |
52 | 57 |
|
53 |
| - # Run in batches of $start_threads VMs in parallel |
54 |
| - $start_res = $stopped_nodes.slice($start_threads).map |$batch| { |
| 58 | + # Run in batches of $start_jobs VMs in parallel |
| 59 | + $start_res = $stopped_nodes.slice($start_jobs).map |$batch| { |
55 | 60 | $batch.parallelize |$node| {
|
56 | 61 | run_task('lima::start', $tgt, name => $node)
|
57 | 62 | }
|
|
0 commit comments