- Also delete sample data
master
Peter Šurda 2 years ago
parent 935124968d
commit bfc4dbecb6
Signed by: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
  1. 6
      config.ini
  2. 1
      data/localhost/meta-data.txt
  3. 2
      data/user-data.txt
  4. 16
      main.py

@ -1,9 +1,9 @@
[server]
server_host = 127.0.0.1
server_host = 0.0.0.0
server_port = 8081
[app]
user_data = user-data.txt
meta_data = meta-data.txt
user_data = user-data
meta_data = meta-data

@ -1 +0,0 @@
suspended:httpd

@ -1,2 +0,0 @@
This is a sample static file to be served
from cherrypy server at user-data url.

@ -18,9 +18,6 @@ meta_data_filename = config["app"].get("meta_data", "meta_data_extra.txt")
class MainApp:
def __init__(self, *args):
self._init_ip()
def _init_ip(self):
"""
Get remote IP
@ -33,14 +30,21 @@ class MainApp:
except:
self.remoteip = cherrypy.request.remote.ip
self.hostinfo = socket.gethostbyaddr(self.remoteip)
try:
self.hostinfo = socket.gethostbyaddr(self.remoteip)
except socket.herror:
self.hostinfo = ('localhost', )
@cherrypy.expose
def user_data(self):
"""
Serves a static file
"""
filepath = os.path.join(PATH, "data", user_data_filename)
self._init_ip()
filepath = os.path.join(PATH, "data", self.hostinfo[0],
user_data_filename)
if not os.path.exists(filepath):
filepath = os.path.join(PATH, "data", user_data_filename)
return serve_file(filepath, "application/x-download", "attachment")
@cherrypy.expose
@ -48,6 +52,7 @@ class MainApp:
"""
Return meta-data in YAML
"""
self._init_ip()
hostname =self.hostinfo[0]
data = {"instance-id": hostname.split(".")[0], "local-hostname": hostname}
@ -67,6 +72,7 @@ class MainApp:
:param data: meta-data to be added
"""
self._init_ip()
folder = os.path.join(PATH, "data", self.hostinfo[0])
if not os.path.exists(folder):
os.makedirs(folder)

Loading…
Cancel
Save