forked from kunchalavikram1427/gitops-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
37 lines (30 loc) · 951 Bytes
/
app.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
import socket
from uuid import getnode as get_mac
from flask import Flask,jsonify
# Get device details
def get_device_details():
hostname = socket.gethostname()
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
ip = s.getsockname()[0]
s.close()
MAC_address = get_mac()
MAC_address = (':'.join(("%012X" % MAC_address)[i:i+2] for i in range(0, 12, 2)) ).replace(":", "-")
return hostname,ip,MAC_address
app = Flask(__name__)
# Returns device hostname,IP and MAC address
@app.route("/details")
def details():
hostname,ip,mac = get_device_details()
out = "Hello!!!....I'm " + hostname + "....My MAC ID is " + mac + "....and My IP address is "+ip
return out
@app.route("/health")
def health():
return jsonify(
status="up"
)
@app.route("/")
def home():
return "Hello from DevOps Made Easy"
if __name__ == "__main__":
app.run(host="0.0.0.0", port=int("5000"), debug=True)