Skip to content

Commit

Permalink
add Controller Server and supporting template files
Browse files Browse the repository at this point in the history
  • Loading branch information
avinassh committed Jan 31, 2014
1 parent bcdcbae commit cc3ee18
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
49 changes: 49 additions & 0 deletions ControllerServer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/python

# Services exposed by the VM Manager
# The REST url :
# http://host-name/api/1.0/disk-usage
# http://host-name/api/1.0/running-time
# http://host-name/api/1.0/mem-usage
# http://host-name/api/1.0/running-processes
# http://host-name/api/1.0/cpu-load
# http://host-name/api/1.0/execute/<command>

import urlparse
import os

# bunch of tornado imports
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
from tornado.options import define, options

import Controller


define("port", default=8000, help="run on the given port", type=int)


class MainHandler(tornado.web.RequestHandler):
def get(self):
self.render('index.html')

def post(self):
post_data = dict(urlparse.parse_qsl(self.request.body))
c = Controller.Controller()
self.write(c.test_lab(post_data['lab_id'], post_data['lab_src_url'], post_data.get('version', None)))


if __name__ == "__main__":
tornado.options.parse_command_line()
app = tornado.web.Application(
handlers=[
(r"/", MainHandler)
],
template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"),
debug = True)
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
22 changes: 22 additions & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<html>
<head>
<title>{% block title %}OVPL{% end %}</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css">
<style type="text/css">{% block CSS %}{% end %}</style>
</head>
<body>
<div id="container">
<header>
<h1>{% block header %}OVPL{% end %}</h1>
</header>
<div id="main">
{% block body %}{% end %}
</div>
<footer>
{% block footer %}
<a href="http://github.com/vlead/ovpl">OVPL - Github</a>
{% end %}
</footer>
</div>
</body>
</html>
38 changes: 38 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{% extends "base.html" %}

{% block CSS %}
body {
text-align: center;
font-family: georgia;
}

#container {
margin: 0 auto;
width: 960px;
}

h1 {
font-size: 40px
}

p {
font-size: 20px
}
{% end %}

{% block title %}
Controller - OVPL
{% end %}

{% block header %}
Test Your Lab!
{% end %}

{% block body %}
<form action="/" method="post">
<p> Lab ID: <input type="text" name="lab_id" id="lab_id"></p><br>
<p> Repo url: <input type="text" name="lab_src_url" id="lab_src_url"></p><br>
<p> Tag: <input type="text" name="version" id="version"></p><br>
<input type="submit"><br />
</form>
{% end %}

0 comments on commit cc3ee18

Please sign in to comment.