31 lines
700 B
Python
31 lines
700 B
Python
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
|
|
def get_vm_port(username):
|
|
user_map = {
|
|
'user0': 9000,
|
|
'user1': 9001,
|
|
'user2': 9002
|
|
}
|
|
return user_map.get(username)
|
|
|
|
def main():
|
|
username = os.environ.get('USER')
|
|
if not username:
|
|
print("Error: Unable to determine username", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
port = 9002 #get_vm_port(username)
|
|
if not port:
|
|
print(f"Error: No VM associated with user {username}", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
# Use os.execvp to replace the current process with ssh
|
|
os.execvp('ssh', ['ssh', '-p', str(port), 'root@localhost'])
|
|
|
|
if __name__ == "__main__":
|
|
main()
|