-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd_toolkit.py
25 lines (21 loc) · 979 Bytes
/
cmd_toolkit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import paramiko
import pickle
from toolkit import *
class CMD:
def __init__(self, host):
self.account = 'Tsinghua'
self.password = 'Mooc_2014'
self.host = host
self.config_template = 'Host {}\n Hostname {}\n HostKeyAlias {}\n CheckHostIP no\n Port {}\n User Tsinghua\n'
self.config_file_path = "/Users/Joe/.ssh/config"
def write_config(self):
with open(self.config_file_path, 'a') as config_file:
for i in range(1, 9):
config_file.write(self.config_template.format(self.host + str(i), self.host, self.host + str(i), 1000 + i))
def connect_to_VM(self):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname = self.host, port = 1001, username = self.account, password = self.password)
ssh.exec_command('sudo mkdir /mnt/data')
ssh.exec_command('sudo mount /dev/sdc1 /mnt/data')
ssh.close()