aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlice Ferrazzi <alicef@gentoo.org>2017-07-03 11:34:41 +0900
committerAlice Ferrazzi <alicef@gentoo.org>2017-07-03 11:34:41 +0900
commit884d0cf6125eb9dcd2d6ad8e9240f5858e94484f (patch)
tree3011480f257d49ab8b64299fb1ed3956e32f9f4e
parentreceiving and sending the userid and resending same userid if already (diff)
downloadelivepatch-884d0cf6125eb9dcd2d6ad8e9240f5858e94484f.tar.gz
elivepatch-884d0cf6125eb9dcd2d6ad8e9240f5858e94484f.tar.bz2
elivepatch-884d0cf6125eb9dcd2d6ad8e9240f5858e94484f.zip
receiving and sending the userid and resending same userid if already
present in shelves building vmlinux if not present in the kernel source code import optimized
-rw-r--r--elivepatch_server/elivepatch11
-rw-r--r--elivepatch_server/resources/AgentInfo.py3
-rw-r--r--elivepatch_server/resources/dispatcher.py75
-rw-r--r--elivepatch_server/resources/livepatch.py20
4 files changed, 66 insertions, 43 deletions
diff --git a/elivepatch_server/elivepatch b/elivepatch_server/elivepatch
index 1934e64..bd77565 100644
--- a/elivepatch_server/elivepatch
+++ b/elivepatch_server/elivepatch
@@ -13,6 +13,7 @@ from elivepatch_server.resources import AgentInfo, dispatcher
def create_app():
"""
Create server application
+ RESTful api version 1.0
"""
app = Flask(__name__, static_url_path="")
@@ -20,16 +21,26 @@ def create_app():
api.add_resource(AgentInfo.AgentAPI, '/elivepatch/api/',
endpoint='root')
+
+ # get agento information
api.add_resource(AgentInfo.AgentAPI, '/elivepatch/api/v1.0/agent',
endpoint='agent')
+
+ # where to start the livepatch build
api.add_resource(dispatcher.BuildLivePatch,
'/elivepatch/api/v1.0/build_livepatch',
endpoint='build_livepatch')
+
+ # where to retrieve the live patch when ready
api.add_resource(dispatcher.GetLivePatch,
'/elivepatch/api/v1.0/get_livepatch',
endpoint='get_livepatch')
+
+ # where to receive the config file
api.add_resource(dispatcher.GetConfig, '/elivepatch/api/v1.0/config',
endpoint='config')
+
+ # where to receive the patch file
api.add_resource(dispatcher.GetPatch, '/elivepatch/api/v1.0/patch',
endpoint='patch')
return app
diff --git a/elivepatch_server/resources/AgentInfo.py b/elivepatch_server/resources/AgentInfo.py
index 00be63f..495512a 100644
--- a/elivepatch_server/resources/AgentInfo.py
+++ b/elivepatch_server/resources/AgentInfo.py
@@ -4,8 +4,7 @@
# (c) 2017, Alice Ferrazzi <alice.ferrazzi@gmail.com>
# Distributed under the terms of the GNU General Public License v2 or later
-from flask import Flask, jsonify, abort, make_response
-from flask_restful import Api, Resource, reqparse, fields, marshal
+from flask_restful import Resource, reqparse, fields, marshal
agent_fields = {
'module': fields.String,
diff --git a/elivepatch_server/resources/dispatcher.py b/elivepatch_server/resources/dispatcher.py
index 829624f..bcbdaa1 100644
--- a/elivepatch_server/resources/dispatcher.py
+++ b/elivepatch_server/resources/dispatcher.py
@@ -5,11 +5,12 @@
# Distributed under the terms of the GNU General Public License v2 or later
-from flask import jsonify, make_response
-from flask_restful import Resource, reqparse, fields, marshal
-import werkzeug
import uuid
+
import os
+import werkzeug
+from flask import jsonify, make_response
+from flask_restful import Resource, reqparse, fields, marshal
from elivepatch_server.resources.livepatch import PaTch
@@ -37,6 +38,7 @@ lpatch = PaTch()
kernel_dir = lpatch.get_kernel_dir()
set_kernel_dir(kernel_dir)
+
class BuildLivePatch(Resource):
def __init__(self):
@@ -66,12 +68,18 @@ class BuildLivePatch(Resource):
if args['KernelVersion']:
set_kernel_dir(args['KernelVersion'])
kernel_dir = lpatch.get_kernel_dir()
- kernel_config = lpatch.get_config()
- kernel_patch = lpatch.get_patch()
- if kernel_config and kernel_patch:
- lpatch.set_lp_status('working')
- print("build livepatch: " + str(args))
- lpatch.build_livepatch(kernel_dir, kernel_dir + '/vmlinux')
+ kernel_config = lpatch.get_config()
+ kernel_patch = lpatch.get_patch()
+ if kernel_config and kernel_patch:
+ lpatch.set_lp_status('working')
+ print("build livepatch: " + str(args))
+ # check vmlinux presence if not rebuild the kernel
+ kernel_vmlinux = os.path.join(kernel_dir, 'vmlinux')
+ if not os.path.isdir(kernel_dir):
+ lpatch.get_kernel(kernel_dir, kernel_vmlinux)
+ if not os.path.isfile(kernel_vmlinux):
+ lpatch.build_kernel(kernel_dir)
+ lpatch.build_livepatch(kernel_dir, kernel_vmlinux)
pack = {
'id': packs['id'] + 1,
'KernelVersion': args['KernelVersion'],
@@ -88,9 +96,6 @@ class GetLivePatch(Resource):
self.reqparse.add_argument('KernelVersion', type=str, required=False,
help='No task title provided',
location='json')
- self.reqparse.add_argument('LivepatchStatus', type=str, required=False,
- help='No task title provided',
- location='json')
self.reqparse.add_argument('UserID', type=str, required=False,
help='No task title provided',
location='json')
@@ -125,10 +130,7 @@ class GetConfig(Resource):
self.reqparse = reqparse.RequestParser()
self.reqparse.add_argument('KernelVersion', type=str, required=False,
help='No task title provided',
- location='json')
- self.reqparse.add_argument('LivepatchStatus', type=str, required=False,
- help='No task title provided',
- location='json')
+ location='headers')
self.reqparse.add_argument('UserID', type=str, required=False,
help='No task title provided',
location='headers')
@@ -149,27 +151,23 @@ class GetConfig(Resource):
parse = reqparse.RequestParser()
parse.add_argument('file', type=werkzeug.datastructures.FileStorage,
location='files')
- parse.add_argument('KernelVersion', type=str, required=False,
- location='json')
- parse.add_argument('LivepatchStatus', type=str, required=False,
- location='json')
- parse.add_argument('UserID', type=str, required=False,
- location='headers')
file_args = parse.parse_args()
print("file get config: " + str(file_args))
- audioFile = file_args['file']
- audioFile_name = file_args['file'].filename
- #print('audiofile_name: '+ str(audioFile_name))
- #print('audiofile: '+ str(audioFile))
- audioFile_name = os.path.join('/tmp','elivepatch-' + args['UserID'], audioFile_name)
+ configFile = file_args['file']
+ configFile_name = file_args['file'].filename
+
+ # debug filename
+ #print('configfile_name: '+ str(configFile_name))
+ #print('configfile: '+ str(configFile))
+
+ configFile_name = os.path.join('/tmp','elivepatch-' + args['UserID'], configFile_name)
if not os.path.exists('/tmp/elivepatch-' + args['UserID']):
os.makedirs('/tmp/elivepatch-' + args['UserID'])
- audioFile.save(audioFile_name)
- lpatch.set_config(audioFile_name)
+ configFile.save(configFile_name)
+ lpatch.set_config(configFile_name)
pack = {
'id': packs['id'] + 1,
'KernelVersion': None,
- 'LivepatchStatus': lpatch.livepatch_status,
'UserID' : args['UserID']
}
return {'get_config': marshal(pack, pack_fields)}, 201
@@ -182,9 +180,6 @@ class GetPatch(Resource):
self.reqparse.add_argument('KernelVersion', type=str, required=False,
help='No task title provided',
location='json')
- self.reqparse.add_argument('LivepatchStatus', type=str, required=False,
- help='No task title provided',
- location='json')
self.reqparse.add_argument('UserID', type=str, required=False,
help='No task title provided',
location='headers')
@@ -202,24 +197,24 @@ class GetPatch(Resource):
args['UserID'] = str(id_generate())
else:
print('UserID: ' + str(args['UserID']))
+
# parse file request information's
parse = reqparse.RequestParser()
parse.add_argument('file', type=werkzeug.datastructures.FileStorage,
location='files')
file_args = parse.parse_args()
- audioFile = file_args['file']
- audioFile_name = file_args['file'].filename
+ patchFile = file_args['file']
+ patchFile_name = file_args['file'].filename
#print(audioFile_name)
#print(audioFile)
- audioFile_name = os.path.join('/tmp', 'elivepatch-' + args['UserID'], audioFile_name)
+ patchFile_name = os.path.join('/tmp', 'elivepatch-' + args['UserID'], patchFile_name)
if not os.path.exists('/tmp/elivepatch-'+args['UserID']):
os.makedirs('/tmp/elivepatch-'+args['UserID'])
- audioFile.save(audioFile_name)
- lpatch.set_patch(audioFile_name)
+ patchFile.save(patchFile_name)
+ lpatch.set_patch(patchFile_name)
pack = {
'id': packs['id'] + 1,
'KernelVersion': None,
- 'LivepatchStatus': lpatch.livepatch_status,
'UserID' : args['UserID']
}
return {'get_patch': marshal(pack, pack_fields)}, 201
@@ -245,7 +240,5 @@ class GetID(Resource):
def id_generate():
- #print('no id')
UserID = uuid.uuid4()
- #print(UserID)
return UserID
diff --git a/elivepatch_server/resources/livepatch.py b/elivepatch_server/resources/livepatch.py
index baf9df4..bd919d3 100644
--- a/elivepatch_server/resources/livepatch.py
+++ b/elivepatch_server/resources/livepatch.py
@@ -91,3 +91,23 @@ class PaTch(object):
process = subprocess.Popen(bashCommand, stdout=subprocess.PIPE)
output, error = process.communicate()
print(output)
+
+ def build_kernel(self, kernel_source_dir):
+ bashCommand = (['sudo','make','oldconfig'])
+ print(bashCommand)
+ process = subprocess.Popen(bashCommand, stdout=subprocess.PIPE, cwd=kernel_source_dir)
+ output, error = process.communicate()
+ print(output)
+
+ bashCommand = (['sudo','make'])
+ print(bashCommand)
+ process = subprocess.Popen(bashCommand, stdout=subprocess.PIPE, cwd=kernel_source_dir)
+ output, error = process.communicate()
+ print(output)
+
+ def get_kernel(self, kernel_version):
+ bashCommand = ['sudo','emerge','-q','"=sys-kernel/gentoo-sources-'+kernel_version+'"']
+ print(bashCommand)
+ process = subprocess.Popen(bashCommand, stdout=subprocess.PIPE)
+ output, error = process.communicate()
+ print(output)