From: peusterm Date: Mon, 2 May 2016 18:52:06 +0000 (+0200) Subject: First steps torwards pulling pre-build docker images in the fake gatekeeper X-Git-Tag: v3.1~134^2~2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=82d406e3a7836e4b53997417044d273085e54019;p=osm%2Fvim-emu.git First steps torwards pulling pre-build docker images in the fake gatekeeper --- diff --git a/src/emuvim/api/sonata/README.md b/src/emuvim/api/sonata/README.md index 30586e7..1a51d75 100644 --- a/src/emuvim/api/sonata/README.md +++ b/src/emuvim/api/sonata/README.md @@ -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: diff --git a/src/emuvim/api/sonata/dummygatekeeper.py b/src/emuvim/api/sonata/dummygatekeeper.py index 48a167d..58c9182 100644 --- a/src/emuvim/api/sonata/dummygatekeeper.py +++ b/src/emuvim/api/sonata/dummygatekeeper.py @@ -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// """ + 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):