Skip to content

Commit

Permalink
App cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
summerisgone committed Apr 4, 2020
1 parent 0324794 commit 76c88d2
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 534 deletions.
20 changes: 4 additions & 16 deletions app/server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import asyncio
import mimetypes

import aiohttp
import yaml
from os.path import join, dirname
from aiohttp import web
Expand All @@ -20,19 +17,8 @@ def run_playbook(data):
global task_program
extra_vars = ' '.join(['{0}={1}'.format(key, data[key]) for key in data.keys()])
task_program = ['ansible-playbook', 'main.yml', '--extra-vars', extra_vars]
vars = PlaybookCLI(task_program).run()
# TODO: filter only necessary vars
return vars

@routes.get('/static/{path}')
async def handle_static(request):
filepath = request.match_info['path']
mimetype = mimetypes.guess_type(filepath)
try:
with open(join(dirname(__file__), 'static', *filepath.split('/')), 'r') as f:
return web.Response(body=f.read(), content_type=mimetype[0])
except FileNotFoundError:
return web.Response(status=404)
return PlaybookCLI(task_program).run()


@routes.get('/')
async def handle_index(_):
Expand Down Expand Up @@ -102,4 +88,6 @@ async def post_config(request):

app = web.Application()
app.router.add_routes(routes)
app.add_routes([web.static('/static', join(PROJECT_ROOT, 'app', 'static'))])
app.add_routes([web.static('/results', join(PROJECT_ROOT, 'configs'))])
web.run_app(app, port=9000)
Loading

0 comments on commit 76c88d2

Please sign in to comment.