Provide API for allowing full stack emulation
This commit adds an API in order to emulate the full OSM stack. Different
levels of API are added in order to allow flexible scenarios.
The lowest level API only wraps the required components in containers.
The next higher level also abstracts the composition of these low-level
into a working OSM instance.
The third level also abstracts the emulation and configuration of the VIM
layer.
Examples are added for each abstraction level.
Implements Feature 7291.
Change-Id: I156f6625d4ff4010d688c41419c4ece03a339937
Signed-off-by: schillinge <ablu@mail.uni-paderborn.de>
diff --git a/src/emuvim/api/util/docker_utils.py b/src/emuvim/api/util/docker_utils.py
new file mode 100644
index 0000000..39d8a2b
--- /dev/null
+++ b/src/emuvim/api/util/docker_utils.py
@@ -0,0 +1,40 @@
+import logging
+from io import BytesIO
+
+import docker
+
+from emuvim.api.util.path_utils import get_absolute_path
+
+
+def build_dockerfile_dir(folder, tag):
+ dcli = docker.from_env().api
+ folder = get_absolute_path(folder)
+ build_stream = dcli.build(folder, tag=tag)
+ logging.info('Docker build result:')
+ for line in build_stream:
+ logging.info(line)
+
+
+def suffix_tag_name(tag, suffix):
+ if ":" in tag:
+ return "%s_%s" % (tag, suffix)
+ return "%s:latest_%s" % (tag, suffix)
+
+
+def wrap_debian_like(image):
+ dcli = docker.from_env().api
+ dockerfile = '''
+ FROM %s
+ RUN apt update -y && apt install -y net-tools iputils-ping iproute
+ ''' % image
+ f = BytesIO(dockerfile.encode('utf-8'))
+ wrapper_name = suffix_tag_name(image, 'containernet_compatible')
+ logging.info('wrapping image: %s->%s' % (image, wrapper_name))
+ build_stream = dcli.build(fileobj=f, tag=wrapper_name)
+ build_result = [line for line in build_stream]
+ logging.debug('Docker build result:' + '\n'.join(build_result))
+ return wrapper_name
+
+
+# 172.17.0.1 is the ip of the docker0 interface on the host
+DOCKER_HOST_IP = '172.17.0.1'