aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlice Ferrazzi <alicef@gentoo.org>2017-06-28 03:39:00 +0900
committerAlice Ferrazzi <alicef@gentoo.org>2017-06-28 03:39:00 +0900
commit6eca2eec3572cad0181b3ce61f521ff40fa85ec1 (patch)
tree45f687cfc45f0fb9516fb8a69c352a5403162578
parentRemoved basic auth (diff)
downloadelivepatch-6eca2eec3572cad0181b3ce61f521ff40fa85ec1.tar.gz
elivepatch-6eca2eec3572cad0181b3ce61f521ff40fa85ec1.tar.bz2
elivepatch-6eca2eec3572cad0181b3ce61f521ff40fa85ec1.zip
Added working get function for download the live patch generated
-rw-r--r--elivepatch_client/client/cli.py1
-rw-r--r--elivepatch_client/client/restful.py17
-rw-r--r--elivepatch_server/resources/dispatcher.py23
-rw-r--r--elivepatch_server/resources/livepatch.py6
4 files changed, 27 insertions, 20 deletions
diff --git a/elivepatch_client/client/cli.py b/elivepatch_client/client/cli.py
index 23cd577..3694845 100644
--- a/elivepatch_client/client/cli.py
+++ b/elivepatch_client/client/cli.py
@@ -49,6 +49,7 @@ class Main(object):
current_kernel.send_config(config.url)
current_kernel.send_patch(config.url)
current_kernel.build_livepatch(config.url)
+ current_kernel.get_livepatch(config.url)
elif config.version:
print('elivepatch version: '+str(VERSION))
else:
diff --git a/elivepatch_client/client/restful.py b/elivepatch_client/client/restful.py
index 1e5fea2..f6ee7f2 100644
--- a/elivepatch_client/client/restful.py
+++ b/elivepatch_client/client/restful.py
@@ -3,7 +3,7 @@
import json, base64
import requests
from requests.auth import HTTPBasicAuth
-
+import time
class ManaGer(object):
def __init__(self, server_url):
@@ -30,10 +30,19 @@ class ManaGer(object):
print(r.json())
def get_livepatch(self):
+ from io import BytesIO
url = self.server_url+'/elivepatch/api/v1.0/get_livepatch'
payload = {
'KernelVersion': '4.10.16'
}
- r = requests.post(url, json=payload)
- print(r.text)
- print(r.json()) \ No newline at end of file
+ r = requests.get(url)
+ if r.status_code == requests.codes.ok: # livepatch returned ok
+ b= BytesIO(r.content)
+ with open('myfile.ko', 'wb') as out:
+ out.write(r.content)
+ r.close()
+ print(b)
+ else:
+ r.close()
+ time.sleep(5)
+ return self.get_livepatch() # try to get the livepatch again
diff --git a/elivepatch_server/resources/dispatcher.py b/elivepatch_server/resources/dispatcher.py
index 9784cdc..8fcb2ae 100644
--- a/elivepatch_server/resources/dispatcher.py
+++ b/elivepatch_server/resources/dispatcher.py
@@ -33,7 +33,7 @@ packs = {
}
lpatch = PaTch()
-lpatch.set_kernel_dir('/usr/src/linux-4.10.14-gentoo/')
+lpatch.set_kernel_dir('/usr/src/linux-4.9.29-gentoo/')
kernel_dir = lpatch.get_kernel_dir()
@@ -84,28 +84,19 @@ class GetLivePatch(Resource):
def get(self):
# Getting livepatch build status
- status = lpatch.get_lp_status()
+ status = lpatch.update_lp_status("kpatch-1.ko")
if status == 'done':
with open('kpatch-1.ko', 'rb') as fp:
- response = make_response(fp)
+ #print(str(fp.read()))
+ response = make_response(fp.read())
response.headers['content-type'] = 'application/octet-stream'
return response
return {'packs': [marshal(pack, pack_fields) for pack in packs]}
def post(self):
- args = self.reqparse.parse_args()
- kernel_config = lpatch.get_config()
- kernel_patch = lpatch.get_patch()
- if kernel_config and kernel_patch:
- lpatch.set_lp_status('working')
- lpatch.build_livepatch(kernel_dir, kernel_dir + '/vmlinux')
- pack = {
- 'id': packs['id'] + 1,
- 'KernelVersion': args['KernelVersion'],
- 'LivepatchStatus': lpatch.livepatch_status,
- }
- return {'agent': marshal(pack, pack_fields)}, 201
-
+ return make_response(jsonify({'message': 'These are not the \
+ patches you are looking for'})
+ , 403)
class GetConfig(Resource):
diff --git a/elivepatch_server/resources/livepatch.py b/elivepatch_server/resources/livepatch.py
index efebd68..c22de16 100644
--- a/elivepatch_server/resources/livepatch.py
+++ b/elivepatch_server/resources/livepatch.py
@@ -16,6 +16,7 @@
#
import subprocess
+import os
class PaTch(object):
@@ -38,6 +39,11 @@ class PaTch(object):
def get_lp_status(self):
return self.livepatch_status
+ def update_lp_status(self, file):
+ if os.path.isfile(file):
+ self.livepatch_status = 'done'
+ return self.livepatch_status
+
def set_kernel_version(self, kernel_version):
self.kernel_version = kernel_version