First steps torwards pulling pre-build docker images in the fake gatekeeper
[osm/vim-emu.git] / src / emuvim / api / sonata / dummygatekeeper.py
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):