-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnection.py
More file actions
70 lines (47 loc) · 1.29 KB
/
connection.py
File metadata and controls
70 lines (47 loc) · 1.29 KB
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
"""Manage connection"""
#!/usr/bin/python
# coding: utf8
import sys
import time
import logging
import requests
import auth
def main():
""" Manage modem connection """
if len(sys.argv) <= 1:
logging.error("host not defined")
sys.exit(0)
if len(sys.argv) <= 2:
logging.error("command (reload or restart) not defined")
sys.exit(0)
host = sys.argv[1]
command = sys.argv[2]
url = f"http://{host}/goform/goform_set_cmd_process"
session = auth.get_auth_session(host)
if session is None:
logging.error("Session not started")
sys.exit(0)
if command == "reload":
logging.info("DISCONNECT_NETWORK")
session.post(url, {
"goformId": "DISCONNECT_NETWORK",
"isTest": "false"
})
time.sleep(5)
logging.info("CONNECT_NETWORK")
session.post(url, {
"goformId": "CONNECT_NETWORK",
"isTest": "false"
})
session.close()
if command == "restart":
logging.info("REBOOT_DEVICE")
try:
session.post(url, {
"goformId": "REBOOT_DEVICE",
"isTest": "false"
})
except requests.exceptions.ReadTimeout:
pass
session.close()
main()