aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlice Ferrazzi <alicef@gentoo.org>2017-07-01 04:06:54 +0900
committerAlice Ferrazzi <alicef@gentoo.org>2017-07-01 04:06:54 +0900
commit8e05dcdc35a9c56983a9b77cdfcb49a7fa7cd314 (patch)
tree44a6e32cff49bac06364192ec8c537de0f1f7c81
parentchecking file extension using regular expression (diff)
downloadelivepatch-8e05dcdc35a9c56983a9b77cdfcb49a7fa7cd314.tar.gz
elivepatch-8e05dcdc35a9c56983a9b77cdfcb49a7fa7cd314.tar.bz2
elivepatch-8e05dcdc35a9c56983a9b77cdfcb49a7fa7cd314.zip
dynamically passing kernel version
-rw-r--r--elivepatch_client/client/checkers.py41
-rw-r--r--elivepatch_client/client/cli.py11
-rw-r--r--elivepatch_client/client/restful.py7
3 files changed, 26 insertions, 33 deletions
diff --git a/elivepatch_client/client/checkers.py b/elivepatch_client/client/checkers.py
index d3c784e..b6ef93a 100644
--- a/elivepatch_client/client/checkers.py
+++ b/elivepatch_client/client/checkers.py
@@ -15,20 +15,17 @@ import re
class Kernel(object):
- def __init__(self):
- self.minor = 0
- self.major = 0
- self.revision = 0
+ def __init__(self, url):
self.config = ''
self.patch = ''
+ self.url = url
+ self.kernel_version = self.get_version()
+ self.rest_manager = restful.ManaGer(url, self.kernel_version)
def get_version(self):
- tmp = os.uname()[2].split(".")
- self.major = tmp[0]
- self.minor = tmp[1]
- tmp[2] = tmp[2].split("-")
- self.revision = tmp[2][0]
- return self.major, self.minor, self.revision
+ tmp = os.uname()[2]
+ version = tmp
+ return version
def set_config(self, config_path):
self.config = config_path
@@ -36,8 +33,8 @@ class Kernel(object):
def set_patch(self, patch_path):
self.patch = patch_path
- def send_config(self, url):
- print('conifg path: '+ str(self.config) + 'server url: ' + str(url))
+ def send_config(self):
+ print('conifg path: '+ str(self.config) + 'server url: ' + str(self. url))
print (os.path.basename(self.config))
path, file = (os.path.split(self.config))
if re.findall("[.]gz\Z", self.config):
@@ -46,24 +43,20 @@ class Kernel(object):
path, file = f_action.ungz()
# if the file is .gz the configuration path is the tmp folder uncompressed config file
self.config = os.path.join(path,file)
- rest_manager = restful.ManaGer(url)
# we are sending only uncompressed configuration files
- rest_manager.send_file(self.config, file, '/elivepatch/api/v1.0/config')
+ self.rest_manager.send_file(self.config, file, '/elivepatch/api/v1.0/config')
- def send_patch(self, url):
- print("self.patch: "+ self.patch + ' url: '+url)
- rest_manager = restful.ManaGer(url)
+ def send_patch(self):
+ print("self.patch: "+ self.patch + ' url: '+ self.url)
path, file = (os.path.split(self.patch))
print('file :'+ file)
- rest_manager.send_file(self.patch, file, '/elivepatch/api/v1.0/patch')
+ self.rest_manager.send_file(self.patch, file, '/elivepatch/api/v1.0/patch')
- def build_livepatch(self, url):
- rest_manager = restful.ManaGer(url)
- rest_manager.build_livepatch()
+ def build_livepatch(self):
+ self.rest_manager.build_livepatch()
- def get_livepatch(self, url):
- rest_manager = restful.ManaGer(url)
- rest_manager.get_livepatch()
+ def get_livepatch(self):
+ self.rest_manager.get_livepatch()
class CVE(object):
diff --git a/elivepatch_client/client/cli.py b/elivepatch_client/client/cli.py
index ce7fde8..90fbb8e 100644
--- a/elivepatch_client/client/cli.py
+++ b/elivepatch_client/client/cli.py
@@ -29,16 +29,15 @@ class Main(object):
print(str(config))
if config.cve:
print('working on cve')
- Kernel()
elif config.patch:
print('working with patch')
- current_kernel = Kernel()
+ current_kernel = Kernel(config.url)
current_kernel.set_config(config.config)
current_kernel.set_patch(config.patch)
- current_kernel.send_config(config.url)
- current_kernel.send_patch(config.url)
- current_kernel.build_livepatch(config.url)
- current_kernel.get_livepatch(config.url)
+ current_kernel.send_config()
+ current_kernel.send_patch()
+ current_kernel.build_livepatch()
+ current_kernel.get_livepatch()
elif config.version:
print('elivepatch version: '+str(VERSION))
else:
diff --git a/elivepatch_client/client/restful.py b/elivepatch_client/client/restful.py
index 60c89a3..0aee10d 100644
--- a/elivepatch_client/client/restful.py
+++ b/elivepatch_client/client/restful.py
@@ -10,8 +10,9 @@ from requests.auth import HTTPBasicAuth
import time
class ManaGer(object):
- def __init__(self, server_url):
+ def __init__(self, server_url, kernel_version):
self.server_url = server_url
+ self.kernel_version = kernel_version
def version(self):
url = self.server_url + '/elivepatch/api/v1.0/agent'
@@ -27,7 +28,7 @@ class ManaGer(object):
def build_livepatch(self):
url = self.server_url+'/elivepatch/api/v1.0/build_livepatch'
payload = {
- 'KernelVersion': '4.10.16'
+ 'KernelVersion': self.kernel_version
}
r = requests.post(url, json=payload)
print(r.text)
@@ -37,7 +38,7 @@ class ManaGer(object):
from io import BytesIO
url = self.server_url+'/elivepatch/api/v1.0/get_livepatch'
payload = {
- 'KernelVersion': '4.10.16'
+ 'KernelVersion': self.kernel_version
}
r = requests.get(url)
if r.status_code == requests.codes.ok: # livepatch returned ok