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 4d0037c
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
@@ -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(dirname(__file__), 'static'))])
app.add_routes([web.static('/results', join(dirname(dirname(__file__)), 'configs'))])
web.run_app(app, port=9000)

0 comments on commit 4d0037c

Please sign in to comment.