-
Notifications
You must be signed in to change notification settings - Fork 39
Set up VS Code on OpenMind compute node (Method 01)
First, have your VS Code ready on your local laptop.
For example:
For example:
srun -n 12 --mem=64GB -t 300 --exclude node058,node055,node057,node056,node091 --pty bash
Change n_cpu (12 in this case), memory (64GB), and time (300min) settings based on your needs. Don't require resource more than you need :)
Get the compute node number (e.g., 094
)
Go to your VS Code View->Command Palette
-> Remote-SSH: Open SSH Configuration File...
-> open your config
file (e.g., Users/yibeichen/.ssh/config
, add the following (User
should be your username for openmind):
Host om
HostName openmind7.mit.edu
User yibei
IdentityFile ~/.ssh/id_rsa
Host omnode
HostName node094
ProxyJump om
User yibei
Save the following script as update_ssh_config.py
(or whatever name you prefer)
#!/usr/bin/env python3
import sys
import os
import re
def backup_config_file(config_path):
"""Create a backup of the config file."""
backup_path = config_path + ".backup"
with open(config_path, "r") as src, open(backup_path, "w") as dst:
dst.writelines(src.readlines())
print(f"Backup created at: {backup_path}")
if __name__ == '__main__':
if len(sys.argv) != 2:
print("Usage: omnode <3-digit-code>")
sys.exit(1)
new_code = sys.argv[1]
if len(new_code) != 3 or not new_code.isdigit():
print("Usage: omnode <3-digit-code>")
sys.exit(1)
config_path = os.path.join(os.path.expanduser('~'), ".ssh", "config")
try:
# Create a backup before making changes
backup_config_file(config_path)
# Read in the file
with open(config_path, "r") as f:
lines = f.readlines()
# Update the relevant line
updated = False
for i, line in enumerate(lines):
if "Host omnode" in line:
for j in range(i+1, len(lines)):
if re.search(r"HostName node\d{3}", lines[j]):
lines[j] = re.sub(r"node\d{3}", "node" + new_code, lines[j])
updated = True
break
if updated:
break
# Write the file out again
with open(config_path, "w") as f:
f.writelines(lines)
except FileNotFoundError:
print(f"Error: File {config_path} not found.")
except PermissionError:
print(f"Error: No permission to read or write to {config_path}.")
except Exception as e:
print(f"Unexpected error: {e}")%
Run the script as
python update_ssh_config.py 3-digits-omnode # for example python update_ssh_config.py 094
Go to your VS Code View->Command Palette
-> Remote-SSH: Connect to Host...
-> Choose omnode
Suppose there are no error messages, DONE! you've successfully connected to the openmind compute node!
On VS Code, click Open
, input your folder path.
More useful information: