15
15
import ibm_cloud_sdk_core
16
16
17
17
18
- CACHE = {}
18
+ CACHE = {} # used to store data that isn't stored in the cluster's config file, e.g. vpc_name.
19
19
ARG_STATUS = Enum ('STATUS' , 'VALID INVALID MISSING' ) # variable possible status.
20
20
21
21
class MSG_STATUS (Enum ):
@@ -167,7 +167,7 @@ def validate_exists(answers, current):
167
167
168
168
169
169
def get_region_by_endpoint (endpoint ):
170
- return re .search ('//(.+?).iaas.cloud.ibm.com' , endpoint ).group (1 )
170
+ return re .search ('//(.+?).iaas.cloud.ibm.com/v1 ' , endpoint ).group (1 )
171
171
172
172
173
173
def find_default (template_dict , objects , name = None , id = None , substring = False ):
@@ -306,14 +306,11 @@ def _prompt_user(path, default_config_file, verify_func, request, default_msg):
306
306
else :
307
307
path = free_dialog (request )['answer' ]
308
308
309
- if not verify_config :
310
- input_path = _prompt_user (input_path , '' , _is_valid_input_file ,
311
- "Provide a path to your existing config file, or leave blank to configure from template" ,
312
- 'Using default input file\n ' )
313
309
output_path = _prompt_user (output_path , os .getcwd (), _is_valid_output_dir ,
314
310
"Provide a custom path for your config file, or leave blank for default output location" ,
315
- 'Using default output path\n ' )
316
- return input_path , output_path
311
+ f"Using default output path: '{ os .getcwd ()} '\n " )
312
+ # currently not supporting input file from user.
313
+ return '' , output_path
317
314
318
315
def verify_iam_api_key (answers , apikey , iam_endpoint = None ):
319
316
"""Terminates the config tool if no IAM_API_KEY matching the provided value exists"""
@@ -383,21 +380,23 @@ def dump_cluster_folder(config, output_folder):
383
380
# create a output_folder and scripts_folder if doesn't exist
384
381
if not os .path .isdir (output_folder ):
385
382
os .mkdir (output_folder )
386
- cluster_folder = os .path .join (output_folder , f"{ config ['cluster_name' ]} " )
387
- scripts_folder = os .path .join (cluster_folder , f"scripts" )
388
- os .makedirs (cluster_folder , exist_ok = True ) # directory already exists
389
- os .makedirs (scripts_folder , exist_ok = True ) # directory already exists
383
+ cluster_folder_name = f"{ config ['cluster_name' ]} -at-" \
384
+ f"{ CACHE ['vpc_name' ]} -in-{ config ['provider' ]['region' ]} "
385
+ cluster_folder_path = os .path .join (output_folder , cluster_folder_name )
386
+ scripts_folder_path = os .path .join (cluster_folder_path , 'scripts' )
387
+ os .makedirs (cluster_folder_path , exist_ok = True )
388
+ os .makedirs (scripts_folder_path , exist_ok = True )
390
389
391
390
cluster_file_name = "config.yaml"
392
- cluster_file_path = os .path .join (cluster_folder , cluster_file_name )
391
+ cluster_file_path = os .path .join (cluster_folder_path , cluster_file_name )
393
392
394
393
# get source path of ssh keys and extract their name
395
394
original_private_key_path = os .path .expanduser (config ['auth' ]['ssh_private_key' ])
396
395
original_public_key_path = original_private_key_path + '.pub'
397
396
private_key_name = original_private_key_path .rsplit ('/' ,1 )[- 1 ]
398
397
399
398
# update ssh key path to output folder
400
- new_private_key_path = os .path .join (cluster_folder , private_key_name )
399
+ new_private_key_path = os .path .join (cluster_folder_path , private_key_name )
401
400
new_public_key_path = new_private_key_path + '.pub'
402
401
config ['auth' ]['ssh_private_key' ] = Path (new_private_key_path ).name
403
402
@@ -410,33 +409,46 @@ def dump_cluster_folder(config, output_folder):
410
409
copy_or_move_file (original_private_key_path , new_private_key_path )
411
410
copy_or_move_file (original_public_key_path , new_public_key_path )
412
411
413
- write_script ('create .sh' ,
414
- scripts_folder ,
415
- [f"ray up -y { cluster_file_name } " ])
412
+ write_script ('up .sh' ,
413
+ scripts_folder_path ,
414
+ [f"ray up -y { cluster_file_name } $@ " ])
416
415
417
416
write_script ('connect.sh' ,
418
- scripts_folder ,
417
+ scripts_folder_path ,
419
418
[f"ray dashboard --port 8265 --remote-port 8265 { cluster_file_name } " ])
420
419
421
- # kill tunnel created by ray dashboard by killing the PIDs involved
420
+ write_script ('tunnel.sh' ,
421
+ scripts_folder_path ,
422
+ [f"ssh -i { private_key_name } -f -N -L $1:localhost:$1 root@$(ray get-head-ip { cluster_file_name } )" ])
423
+
424
+ # kill tunnel created by ray dashboard by killing all the PIDs involved with the port
422
425
write_script ('disconnect.sh' ,
423
- scripts_folder ,
426
+ scripts_folder_path ,
424
427
["lsof -i:8265 | awk 'NR>1 {print $2}' | sort -u | xargs kill" ],
425
428
run_from_cluster_dir = False )
426
429
427
- write_script ('terminate.sh' ,
428
- scripts_folder ,
429
- [f"ray down -y { cluster_file_name } " ])
430
+ write_script ('down.sh' ,
431
+ scripts_folder_path ,
432
+ [f"ray down -y { cluster_file_name } $@" ])
433
+
434
+ write_script ('down-vpc.sh' ,
435
+ scripts_folder_path ,
436
+ [f"ibm-ray-config -c { cluster_file_name } " ])
430
437
431
438
write_script ('stop.sh' ,
432
- scripts_folder ,
433
- [f"ray stop -y { cluster_file_name } " ])
439
+ scripts_folder_path ,
440
+ [f"ray stop -y { cluster_file_name } $@ " ])
434
441
435
442
write_script ('ray.sh' ,
436
- scripts_folder ,
443
+ scripts_folder_path ,
437
444
[f"ray $@" ])
438
445
439
- return cluster_folder
446
+ write_script ('submit.sh' ,
447
+ scripts_folder_path ,
448
+ ["pythonexec=$(realpath $1)\n " ,
449
+ "ray submit " + cluster_file_name + " $pythonexec ${@:2}" ])
450
+
451
+ return cluster_folder_path
440
452
441
453
442
454
class Color (Enum ):
0 commit comments