-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_reboot.py
executable file
·55 lines (38 loc) · 1.04 KB
/
api_reboot.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
#!/usr/bin/env python
from flask import Flask, request
from flask_restful import Resource, Api, reqparse
from common import connect_ssh as conn
import paramiko
from socket import error, gaierror
app = Flask(__name__)
api = Api(app)
# add arguments
options = reqparse.RequestParser()
options.add_argument(
'user', dest='user',
location='form', required=True,
help='The username is required',
)
options.add_argument(
'server', dest='server',
location='form', required=True,
help='The server name is required',
)
options.add_argument(
'passwd', dest='passwd',
location='form', required=True,
help='The user password is required',
)
class Reboot(Resource):
def post(self):
args = options.parse_args()
server = args.server
user = args.user
passwd = args.passwd
command = 'fdisk -l'
sudo_command = "sudo -S %s" % command
out = conn.connect_ssh(server, user, passwd, sudo_command)
return {'response' : out}
api.add_resource(Reboot, '/')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)