Exemplo n.º 1
0
 def _run_load_metadata(self, container_id):
     """Load container metadata from container JSON payload"""
     # get container metadata unless we are dealing with a simple directory
     # tree in which case we don't have metadata
     if Config.conf['location']:
         container_dir = ""
         container_json = []
     else:
         container_structure = \
             ContainerStructure(self.localrepo, container_id)
         (container_dir, container_json) = \
             container_structure.get_container_attr()
         if not container_dir:
             return(None, None)
         # load metadata from container
         if not self.opt["nometa"]:
             if not self.opt["user"]:
                 self.opt["user"] = \
                     container_structure.get_container_meta(
                         "User", "", container_json)
             if not self.opt["cwd"]:
                 self.opt["cwd"] = \
                     container_structure.get_container_meta(
                         "WorkingDir", "", container_json)
             if not self.opt["hostname"]:
                 self.opt["hostname"] = \
                     container_structure.get_container_meta(
                         "Hostname", "", container_json)
             if not self.opt["domain"]:
                 self.opt["domain"] = \
                     container_structure.get_container_meta(
                         "Domainname", "", container_json)
             if self.opt["entryp"] is False:
                 self.opt["entryp"] = \
                     container_structure.get_container_meta(
                         "Entrypoint", [], container_json)
                 if not self.opt["cmd"]:
                     self.opt["cmd"] = \
                         container_structure.get_container_meta(
                             "Cmd", [], container_json)
             elif not self.opt["entryp"]:
                 self.opt["entryp"] = []
             else:
                 if isinstance(self.opt["entryp"], str):
                     self.opt["entryp"] = \
                         self.opt["entryp"].strip().split(' ')
             self.opt["Volumes"] = \
                 container_structure.get_container_meta(
                     "Volumes", [], container_json)
             self.opt["portsexp"].extend(
                 container_structure.get_container_meta(
                     "ExposedPorts", [], container_json))
             self.opt["env"].extendif(
                 container_structure.get_container_meta(
                     "Env", [], container_json))
     return(container_dir, container_json)
Exemplo n.º 2
0
    def test_03_get_container_meta(self):
        """Test03 ContainerStructure().get_container_meta()."""
        container_json = {
            "architecture": "amd64",
            "author": "https://github.com/CentOS/sig-cloud-instance-images",
            "config": {
                "AttachStderr":
                False,
                "AttachStdin":
                False,
                "AttachStdout":
                False,
                "Cmd": ["/bin/bash"],
                "Domainname":
                "",
                "Entrypoint":
                None,
                "Env": [
                    "PATH=\
                    /usr/local/sbin:\
                    /usr/local/bin:/usr/sbin:\
                    /usr/bin:/sbin:\
                    /bin"
                ],
                "Hostname":
                "9aac06993d69",
                "Image":
                "sha256:4f64745dd34556af8f644a7886fcf" +
                "cb11c059f64e1b0a753cb41188656ec8b33",
                "Labels": {
                    "build-date": "20161102",
                    "license": "GPLv2",
                    "name": "CentOS Base Image",
                    "vendor": "CentOS"
                },
                "OnBuild":
                None,
                "OpenStdin":
                False,
                "StdinOnce":
                False,
                "Tty":
                False,
                "User":
                "",
                "Volumes":
                None,
                "WorkingDir":
                ""
            },
        }
        prex = ContainerStructure(self.local)
        status = prex.get_container_meta("Cmd", "", container_json)
        self.assertEqual(status, "/bin/bash")

        prex = ContainerStructure(self.local)
        status = prex.get_container_meta("XXX", "", container_json)
        self.assertEqual(status, "")

        prex = ContainerStructure(self.local)
        status = prex.get_container_meta("Entrypoint", "BBB", container_json)
        self.assertEqual(status, "BBB")