Skip to content

Commit 0a2cc7f

Browse files
lu-zeroaliceinwire
authored andcommitted
Move away elivepatch_server/elivepatch_server.py
Fixes #28 Now both `python run.py` and `python setup.py install` work.
1 parent 37afc3d commit 0a2cc7f

7 files changed

Lines changed: 98 additions & 77 deletions

File tree

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,20 @@
11
# elivepatch-server
22
Flexible Distributed Linux Kernel Live Patching
3+
4+
5+
## Setup
6+
`elivepatch-server` is a [flask](https://www.palletsprojects.com/p/flask/)-based application.
7+
8+
You can use [virtualenv](https://virtualenv.pypa.io/en/stable/) to have a separate python3 environment.
9+
``` sh
10+
$ cd elivepatch-server
11+
$ virtualenv .venv
12+
$ source .venv/bin/activate
13+
$ pip install -r requirements
14+
```
15+
16+
``` sh
17+
$ python elivepatch-server
18+
```
19+
20+
Will run the server using [werkzeug](https://palletsprojects.com/p/werkzeug/)

elivepatch_server/__init__.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,73 @@
77
__version__ = '0.1'
88
__author__ = 'Alice Ferrazzi'
99
__license__ = 'GNU GPLv2+'
10+
11+
from flask import Flask
12+
from flask_restful import Api
13+
import multiprocessing
14+
import argparse
15+
from .resources import AgentInfo, dispatcher
16+
17+
18+
def parse_args():
19+
parser = argparse.ArgumentParser()
20+
21+
parser.add_argument('-j', '--jobs', type=int,
22+
default=multiprocessing.cpu_count(),
23+
help='Specify the number of make jobs')
24+
25+
parser.add_argument('-H', '--host', type=str,
26+
default='0.0.0.0',
27+
help='Specify the host')
28+
29+
parser.add_argument('-P', '--port', type=int,
30+
default='5000',
31+
help='Specify the port')
32+
33+
parser.add_argument('-T', '--threaded', action='store_true',
34+
help='Enable threading')
35+
36+
parser.add_argument('-d', '--debug', action='store_true',
37+
help='Enable debugging')
38+
39+
return parser.parse_args()
40+
41+
42+
def create_app(cmdline_args):
43+
"""
44+
Create server application
45+
RESTful api version 1.0
46+
"""
47+
48+
app = Flask(__name__, static_url_path="")
49+
api = Api(app)
50+
51+
api.add_resource(AgentInfo.AgentAPI, '/elivepatch/api/',
52+
endpoint='root')
53+
54+
# get agento information
55+
api.add_resource(AgentInfo.AgentAPI, '/elivepatch/api/v1.0/agent',
56+
endpoint='agent')
57+
58+
# where to retrieve the live patch when ready
59+
api.add_resource(dispatcher.SendLivePatch,
60+
'/elivepatch/api/v1.0/send_livepatch',
61+
endpoint='send_livepatch')
62+
63+
# where to receive the config file
64+
api.add_resource(dispatcher.GetFiles, '/elivepatch/api/v1.0/get_files',
65+
endpoint='config',
66+
resource_class_kwargs={'cmdline_args': cmdline_args})
67+
return app
68+
69+
70+
def run():
71+
cmdline_args = parse_args()
72+
app = create_app(cmdline_args)
73+
app.run(debug=cmdline_args.debug,
74+
host=cmdline_args.host, port=cmdline_args.port,
75+
threaded=cmdline_args.threaded)
76+
77+
78+
if __name__ == '__main__':
79+
run()

elivepatch_server/elivepatch_server.py

Lines changed: 0 additions & 72 deletions
This file was deleted.

run.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from elivepatch_server import run
2+
3+
run()

setup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
author='Alice Ferrazzi',
2828
author_email='alice.ferrazzi@gmail.com',
2929
license='GNU GPLv2+',
30-
packages=['elivepatch_server','elivepatch_server.resources'],
31-
scripts=['elivepatch_server/elivepatch_server'],
30+
packages=['elivepatch_server/'],
31+
entry_points = {
32+
'console_scripts': ['elivepatch_server=elivepatch_server:run']
33+
}
3234
)

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os.path
33
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))
44

5-
from elivepatch_server.elivepatch_server import create_app
5+
from elivepatch_server import create_app
66
import pytest
77
from flask_restful import Api as api
88
from flask_testing import TestCase

tests/test_app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from elivepatch_server.elivepatch_server import create_app
1+
from elivepatch_server import create_app
22
import pytest
33
from flask_restful import Api as api
44
from conftest import app
@@ -21,7 +21,7 @@ def setUp(self):
2121
def test_not_found(self):
2222
response = self.app.get('/')
2323
assert response.status_code == 404
24-
24+
2525
def test_found(self):
2626
response = self.app.get('/elivepatch/api/')
2727
assert response.status_code == 200

0 commit comments

Comments
 (0)