Create a project folder jailhouse/python_module and related files, such that
any python package placed in here is installable by pip

Create a python package jailhouse/python_module/pyjailhouse, move JailhouseCell
class used in jailhouse/tools/jailhouse-cell-linux into
jailhouse/python_module/pyjailhouse/cell.py, import JailhouseCell from cell.py
when in jailhouse-cell-linux

Install pyjailhouse using pip when running `make install`

Add .pyc files to .gitignore

Signed-off-by: Chris Goldsworthy <[email protected]>
---
 .gitignore                            |  1 +
 Makefile                              |  3 +++
 python_module/pyjailhouse/__init__.py |  0
 python_module/pyjailhouse/cell.py     | 49 +++++++++++++++++++++++++++++++++++
 python_module/setup.py                | 15 +++++++++++
 tools/jailhouse-cell-linux            | 39 ++--------------------------
 6 files changed, 70 insertions(+), 37 deletions(-)
 create mode 100644 python_module/pyjailhouse/__init__.py
 create mode 100644 python_module/pyjailhouse/cell.py
 create mode 100644 python_module/setup.py

diff --git a/.gitignore b/.gitignore
index 8bd7a16..36bee48 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,3 +26,4 @@ hypervisor/arch/*/include/generated
 *.s
 ci/out
 ci/*.tar.xz
+*.pyc
diff --git a/Makefile b/Makefile
index ce19d1a..1028098 100644
--- a/Makefile
+++ b/Makefile
@@ -48,8 +48,11 @@ firmware_install: $(DESTDIR)$(firmwaredir) modules
 tool_inmates_install: $(DESTDIR)$(libexecdir)/jailhouse
        $(INSTALL_DATA) inmates/tools/$(ARCH)/*.bin $<
 
+# --upgrade forces a re-install, if package is already installed
 install: modules_install firmware_install tool_inmates_install
        $(Q)$(MAKE) -C tools $@ src=.
+       pip install --upgrade ./python_module
+
 
 .PHONY: modules_install install clean firmware_install modules tools docs \
        docs_clean
diff --git a/python_module/pyjailhouse/__init__.py 
b/python_module/pyjailhouse/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/python_module/pyjailhouse/cell.py 
b/python_module/pyjailhouse/cell.py
new file mode 100644
index 0000000..20e8848
--- /dev/null
+++ b/python_module/pyjailhouse/cell.py
@@ -0,0 +1,49 @@
+
+# Jailhouse, a Linux-based partitioning hypervisor
+#
+# Copyright (c) Siemens AG, 2015-2016
+#
+# Authors:
+#  Jan Kiszka <[email protected]>
+#
+# This work is licensed under the terms of the GNU GPL, version 2.  See
+# the COPYING file in the top-level directory.
+
+import ctypes
+import errno
+import fcntl
+import struct
+
+
+class JailhouseCell:
+    JAILHOUSE_CELL_CREATE = 0x40100002
+    JAILHOUSE_CELL_LOAD = 0x40300003
+    JAILHOUSE_CELL_START = 0x40280004
+
+    JAILHOUSE_CELL_ID_UNUSED = -1
+
+    def __init__(self, config):
+        self.name = config.name.encode()
+
+        self.dev = open('/dev/jailhouse')
+
+        cbuf = ctypes.c_buffer(config.data)
+        create = struct.pack('QI4x', ctypes.addressof(cbuf), len(config.data))
+        try:
+            fcntl.ioctl(self.dev, JailhouseCell.JAILHOUSE_CELL_CREATE, create)
+        except IOError as e:
+            if e.errno != errno.EEXIST:
+                raise e
+
+    def load(self, image, address):
+        cbuf = ctypes.create_string_buffer(bytes(image))
+
+        load = struct.pack('i4x32sI4xQQQ8x',
+                           JailhouseCell.JAILHOUSE_CELL_ID_UNUSED, self.name,
+                           1, ctypes.addressof(cbuf), len(image), address)
+        fcntl.ioctl(self.dev, self.JAILHOUSE_CELL_LOAD, load)
+
+    def start(self):
+        start = struct.pack('i4x32s', JailhouseCell.JAILHOUSE_CELL_ID_UNUSED,
+                            self.name)
+        fcntl.ioctl(self.dev, JailhouseCell.JAILHOUSE_CELL_START, start)
diff --git a/python_module/setup.py b/python_module/setup.py
new file mode 100644
index 0000000..55f8e04
--- /dev/null
+++ b/python_module/setup.py
@@ -0,0 +1,15 @@
+
+# pyjailhouse, a python interface for the Jailhouse hypervisor
+#
+# Copyright (c) Christopher Goldsworthy, 2018
+#
+# This script is used to create project metadata when installing pyjailhouse
+# using pip.
+
+from setuptools import setup, find_packages
+
+setup(name="pyjailhouse", version="0.1",
+      description="A Python interface for the Jailhouse Hypervisor",
+      license="GPLv2", url="https://github.com/siemens/jailhouse";,
+      author_email="[email protected]",
+      packages=find_packages())
diff --git a/tools/jailhouse-cell-linux b/tools/jailhouse-cell-linux
index 913b5db..23a3ab5 100755
--- a/tools/jailhouse-cell-linux
+++ b/tools/jailhouse-cell-linux
@@ -12,14 +12,13 @@
 
 from __future__ import print_function
 import argparse
-import ctypes
-import errno
-import fcntl
 import gzip
 import os
 import struct
 import sys
 
+from pyjailhouse.cell import JailhouseCell
+
 libexecdir = None
 
 
@@ -759,40 +758,6 @@ class X86ZeroPage:
         return data + bytearray(0x1000 - len(data))
 
 
-class JailhouseCell:
-    JAILHOUSE_CELL_CREATE = 0x40100002
-    JAILHOUSE_CELL_LOAD = 0x40300003
-    JAILHOUSE_CELL_START = 0x40280004
-
-    JAILHOUSE_CELL_ID_UNUSED = -1
-
-    def __init__(self, config):
-        self.name = config.name.encode()
-
-        self.dev = open('/dev/jailhouse')
-
-        cbuf = ctypes.c_buffer(config.data)
-        create = struct.pack('QI4x', ctypes.addressof(cbuf), len(config.data))
-        try:
-            fcntl.ioctl(self.dev, JailhouseCell.JAILHOUSE_CELL_CREATE, create)
-        except IOError as e:
-            if e.errno != errno.EEXIST:
-                raise e
-
-    def load(self, image, address):
-        cbuf = ctypes.create_string_buffer(bytes(image))
-
-        load = struct.pack('i4x32sI4xQQQ8x',
-                           JailhouseCell.JAILHOUSE_CELL_ID_UNUSED, self.name,
-                           1, ctypes.addressof(cbuf), len(image), address)
-        fcntl.ioctl(self.dev, self.JAILHOUSE_CELL_LOAD, load)
-
-    def start(self):
-        start = struct.pack('i4x32s', JailhouseCell.JAILHOUSE_CELL_ID_UNUSED,
-                            self.name)
-        fcntl.ioctl(self.dev, JailhouseCell.JAILHOUSE_CELL_START, start)
-
-
 def x86_gen_setup_data(config):
     SETUP_TYPE_JAILHOUSE = 6
     MAX_CPUS = 255
-- 
2.7.4

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to