Skip to content

Commit 112bc65

Browse files
author
Himani Anil Deshpande
committed
Modifying pcluster_fleet_config_generator.py to make --output-file and --total-min-count as mutually exclusive arguments
1 parent cf735aa commit 112bc65

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

cookbooks/aws-parallelcluster-slurm/files/default/head_node_slurm/slurm/pcluster_fleet_config_generator.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,25 @@ def _load_cluster_config(input_file_path):
196196
with open(input_file_path, encoding="utf-8") as input_file:
197197
return yaml.load(input_file, Loader=yaml.SafeLoader)
198198

199+
def get_total_min_count(input_file: str):
200+
"Gives total count of Static Nodes in a cluster."
201+
cluster_config = _load_cluster_config(input_file)
202+
queue_name, compute_resource_name = None, None
203+
try:
204+
total_min_count = 0
205+
for queue_config in cluster_config["Scheduling"]["SlurmQueues"]:
206+
for compute_resource_config in queue_config["ComputeResources"]:
207+
total_min_count = total_min_count + compute_resource_config["MinCount"]
208+
except (KeyError, AttributeError) as e:
209+
if isinstance(e, KeyError):
210+
message = f"Unable to find key {e} in the configuration file."
211+
else:
212+
message = f"Error parsing configuration file. {e}. {traceback.format_exc()}."
213+
message += f" Queue: {queue_name}" if queue_name else ""
214+
log.error(message)
215+
raise CriticalError(message)
216+
return total_min_count
217+
199218

200219
def main():
201220
try:
@@ -204,14 +223,19 @@ def main():
204223
)
205224
log.info("Running ParallelCluster Fleet Config Generator")
206225
parser = argparse.ArgumentParser(description="Take in fleet configuration generator related parameters")
207-
parser.add_argument("--output-file", help="The output file for generated json fleet config", required=True)
208226
parser.add_argument(
209227
"--input-file",
210228
help="Yaml file containing pcluster CLI configuration file with default values",
211229
required=True,
212230
)
231+
exclusive_group = parser.add_mutually_exclusive_group(required=True)
232+
exclusive_group.add_argument("--output-file", help="The output file for generated json fleet config")
233+
exclusive_group.add_argument("--total-min-count", help="Gets the total min count of Scheduler", action='store_true')
213234
args = parser.parse_args()
214-
generate_fleet_config_file(args.output_file, args.input_file)
235+
if args.total_min_count:
236+
log.info(f"The total MinCount of cluster is {get_total_min_count(args.input_file)}")
237+
else:
238+
generate_fleet_config_file(args.output_file, args.input_file)
215239
except Exception as e:
216240
log.exception("Failed to generate Fleet configuration, exception: %s", e)
217241
raise

cookbooks/aws-parallelcluster-slurm/libraries/helpers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def wait_cluster_ready
179179
end
180180

181181
def get_static_node_count
182-
cmd = Mixlib::ShellOut.new("cat #{node['cluster']['slurm']['install_dir']}/etc/slurm_parallelcluster.conf | grep -o '#TOTAL_MIN_COUNT=\([0-9]*\)' | cut -d'=' -f2")
182+
cmd = Mixlib::ShellOut.new("#{cookbook_virtualenv_path}/bin/python #{node['cluster']['scripts_dir']}/slurm/pcluster_fleet_config_generator.py --input-file #{node['cluster']['cluster_config_path']} --total-min-count | grep -o 'The total MinCount of cluster is =\([0-9]*\)' | cut -d'=' -f2")
183183
cmd.run_command.stdout.strip
184184
end
185185

0 commit comments

Comments
 (0)