-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcluster_connection.py
executable file
·83 lines (39 loc) · 1.37 KB
/
cluster_connection.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""
Version: 1.0
Test raspberry pi cluster connection with master
Author: suxing liu
Author-email: suxingliu@gmail.com
USAGE
python3 cluster_connection.py
"""
import subprocess, os
import sys
from datetime import date
def test_connection(host_adr):
cmd_line = "ssh pi@" + ''.join(host_adr) + ' exit'
print(cmd_line)
returned_value = subprocess.call(cmd_line, shell=True)
if returned_value == 0:
print("Rapberry Pi host @{0} was connected...\n".format(''.join(host_adr)))
else:
print("SSH connection failed ...!\n")
def synchonize_date(host_adr, v_date):
set_date_cmd = " sudo date -s " + v_date
cmd_line = "ssh " + ''.join(host_adr) + set_date_cmd + ' & exit'
print(cmd_line)
returned_value = subprocess.call(cmd_line, shell=True)
if returned_value == 0:
print("Rapberry Pi data @ was synchonized...\n".format(''.join(host_adr)))
else:
print("SSH connection failed ...!\n")
def main(args):
'''
PiController = "192.168.1.5"
pi01 = "192.168.1.6"
'''
host_adr = "192.168.1.6"
v_date = "{:%Y-%m-%d}".format(date.today())
test_connection(host_adr)
#synchonize_date(host_adr, v_date)
if __name__ == '__main__':
sys.exit(main(sys.argv))