First steps torwards pulling pre-build docker images in the fake gatekeeper
authorpeusterm <manuel.peuster@uni-paderborn.de>
Mon, 2 May 2016 18:52:06 +0000 (20:52 +0200)
committerpeusterm <manuel.peuster@uni-paderborn.de>
Mon, 2 May 2016 18:52:06 +0000 (20:52 +0200)
src/emuvim/api/sonata/README.md
src/emuvim/api/sonata/dummygatekeeper.py

index 30586e7..1a51d75 100644 (file)
@@ -20,9 +20,9 @@ The example starts a small network with two data centers.
 
 ## Upload a package (*.son) file:
 
-To upload the file `sonata-demo.son` (from son-schema repo) do:
+To upload the file `sonata-demo-docker.son` (can be found in `son-emu/misc/`) do:
 
-* `curl -i -X POST -F package=@sonata-demo.son http://127.0.0.1:5000/packages`
+* `curl -i -X POST -F package=@sonata-demo-docker.son http://127.0.0.1:5000/packages`
 
 To list all uploaded packages do:
 
index 48a167d..58c9182 100644 (file)
@@ -24,6 +24,9 @@ GK_STORAGE = "/tmp/son-dummy-gk/"
 UPLOAD_FOLDER = os.path.join(GK_STORAGE, "uploads/")
 CATALOG_FOLDER = os.path.join(GK_STORAGE, "catalog/")
 
+# Enable Dockerfile build functionality
+BUILD_DOCKERFILE = False
+
 # flag to indicate that we run without the emulator (only the bare API for integration testing)
 GK_STANDALONE_MODE = False
 
@@ -70,6 +73,7 @@ class Service(object):
         self.nsd = None
         self.vnfds = dict()
         self.local_docker_files = dict()
+        self.remote_docker_image_urls = dict()
         self.instances = dict()
 
     def onboard(self):
@@ -83,11 +87,13 @@ class Service(object):
         self._load_package_descriptor()
         self._load_nsd()
         self._load_vnfd()
-        self._load_docker_files()
         # 3. prepare container images (e.g. download or build Dockerfile)
-        self._build_images_from_dockerfiles()
-        self._download_predefined_dockerimages()
-
+        if BUILD_DOCKERFILE:
+            self._load_docker_files()
+            self._build_images_from_dockerfiles()
+        else:
+            self._load_docker_urls()
+            self._pull_predefined_dockerimages()
         LOG.info("On-boarded service: %r" % self.manifest.get("package_name"))
 
     def start_service(self):
@@ -142,9 +148,11 @@ class Service(object):
         """
         unzip *.son file and store contents in CATALOG_FOLDER/services/<service_uuid>/
         """
+        LOG.info("Unzipping: %r" % self.package_file_path)
         with zipfile.ZipFile(self.package_file_path, "r") as z:
             z.extractall(self.package_content_path)
 
+
     def _load_package_descriptor(self):
         """
         Load the main package descriptor YAML and keep it as dict.
@@ -196,6 +204,17 @@ class Service(object):
                     self.local_docker_files[k] = docker_path
                     LOG.debug("Found Dockerfile: %r" % docker_path)
 
+    def _load_docker_urls(self):
+        """
+        Get all URLs to pre-build docker images in some repo.
+        :return:
+        """
+        for k, v in self.vnfds.iteritems():
+            for vu in v.get("virtual_deployment_units"):
+                if vu.get("vm_image_format") == "docker":
+                    self.remote_docker_image_urls[k] = vu.get("vm_image")
+                    LOG.debug("Found Docker image URL: %r" %  self.remote_docker_image_urls[k])
+
     def _build_images_from_dockerfiles(self):
         """
         Build Docker images for each local Dockerfile found in the package: self.local_docker_files
@@ -209,11 +228,11 @@ class Service(object):
                 LOG.debug("DOCKER BUILD: %s" % line)
             LOG.info("Docker image created: %s" % k)
 
-    def _download_predefined_dockerimages(self):
+    def _pull_predefined_dockerimages(self):
         """
         If the package contains URLs to pre-build Docker images, we download them with this method.
         """
-        # TODO implement this if we want to be able to download docker images instead of building them
+        # TODO implement this
         pass
 
     def _check_docker_image_exists(self, image_name):