Skip to content

Commit d53608a

Browse files
committed
update cluster name scheme
1 parent 671b0bb commit d53608a

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

src/ibm_ray_config/modules/gen2/ray/defaults.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# An unique identifier for the head node and workers of this cluster.
2-
cluster_name: default
2+
cluster_name:
33

44
# The maximum number of workers nodes to launch in addition to the head
55
# node.

src/ibm_ray_config/modules/gen2/ray/defaults_pr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# An unique identifier for the head node and workers of this cluster.
2-
cluster_name: default
2+
cluster_name:
33

44
# The maximum number of workers nodes to launch in addition to the head
55
# node.

src/ibm_ray_config/modules/gen2/ray/workers.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,39 @@
11
import re
22
import copy
33
from typing import Any, Dict
4-
4+
from uuid import uuid4
55
import inquirer
66
from ibm_ray_config.modules.config_builder import ConfigBuilder
7-
from ibm_ray_config.modules.utils import validate_cluster_name, get_profile_resources
7+
from ibm_ray_config.modules.utils import CACHE, free_dialog, validate_name, get_profile_resources
88

99
class WorkersConfig(ConfigBuilder):
10+
def __init__(self, base_config: Dict[str, Any]) -> None:
11+
super().__init__(base_config)
12+
self.cluster_name_scheme = f'cluster-at-{CACHE["vpc_name"]}-{str(uuid4())[:5]}'
13+
1014

1115
def run(self) -> Dict[str, Any]:
12-
default_cluster_name = self.base_config.get('cluster_name', 'default')
16+
default_cluster_prefix = self.base_config.get('cluster_name')
17+
if not default_cluster_prefix:
18+
default_cluster_prefix = self.cluster_name_scheme.split('-at',1)[0]
1319
default_min_workers = self.base_config.get('min_workers', '0')
1420
default_max_workers = default_min_workers
1521

1622
question = [
17-
inquirer.Text(
18-
'name', message="Enter cluster name following the pattern `[a-z]|[a-z][-a-z0-9]*[a-z0-9]`", validate = validate_cluster_name, default=default_cluster_name),
1923
inquirer.Text('min_workers', message="Minimum number of worker nodes",
2024
default=default_min_workers, validate=lambda _, x: re.match('^[+]?[0-9]+$', x)),
2125
inquirer.Text('max_workers', message="Maximum number of worker nodes", default=default_max_workers,
2226
validate=lambda answers, x: re.match('^[+]?[0-9]+$', x) and int(x) >= int(answers['min_workers']))
2327
]
28+
29+
print(f"\ncluster name is {self.cluster_name_scheme}")
30+
cluster_prefix = free_dialog(msg= f"Pick a custom name to replace: '{default_cluster_prefix}'(or Enter for default)",
31+
default=default_cluster_prefix,
32+
validate=validate_name)['answer']
2433
answers = inquirer.prompt(question, raise_keyboard_interrupt=True)
25-
self.base_config['cluster_name'] = answers['name']
34+
# replaces first word of self.cluster_name_scheme with user input.
35+
cluster_name = self.cluster_name_scheme.replace(default_cluster_prefix, cluster_prefix)
36+
self.base_config['cluster_name'] = cluster_name
2637
self.base_config['max_workers'] = int(answers['max_workers'])
2738

2839
if self.base_config.get('worker_instance_profile', None):

0 commit comments

Comments
 (0)