def parseFile(cls, ymlFile):
        with open(ymlFile, "r") as ifp:
            yml = yaml.safe_load(ifp)
            
        img_tag = ImageTag.parse(yml["image"])

        container = cls(yml["name"], img_tag)
        container.hostname = yml.get("hostname", None)

        container.command = yml.get("command", None)
        if container.command:
            ## convert all arguments to strings
            container.command = [ str(a) for a in container.command ]
        
        container.env = yml.get("env", None)
        if container.env is not None:
            for key in container.env:
                ## coerce all values to strings
                container.env[key] = str(container.env[key])
        
        container.volumes = yml.get("volumes", None)
        if container.volumes is not None:
            for v in container.volumes:
                if "ReadWrite" not in container.volumes[v]:
                    container.volumes[v]["ReadWrite"] = True

        container.ports = yml.get("ports", None)
        if container.ports is not None:
            for p in container.ports:
                if "HostIp" not in container.ports[p]:
                    container.ports[p]["HostIp"] = "0.0.0.0"
        
        return container
Пример #2
0
    def parseFile(cls, ymlFile):
        with open(ymlFile, "r") as ifp:
            yml = yaml.safe_load(ifp)

        img_tag = ImageTag.parse(yml["image"])

        container = cls(yml["name"], img_tag)
        container.hostname = yml.get("hostname", None)

        container.command = yml.get("command", None)
        if container.command:
            ## convert all arguments to strings
            container.command = [str(a) for a in container.command]

        container.env = yml.get("env", {})
        for key in container.env:
            ## coerce all values to strings
            container.env[key] = str(container.env[key])

        container.volumes = yml.get("volumes", None)
        if container.volumes is not None:
            for v in container.volumes:
                if "ReadWrite" not in container.volumes[v]:
                    container.volumes[v]["ReadWrite"] = True

        container.ports = yml.get("ports", None)
        if container.ports is not None:
            for p in container.ports:
                if "HostIp" not in container.ports[p]:
                    container.ports[p]["HostIp"] = "0.0.0.0"

        return container
    def getImage(self, name):
        """ returns an Image for the given name, or None if not found """
        retVal = None

        img_data = self.client.inspect_image(name)

        if img_data:
            retVal = Image.fromJson(img_data)
            retVal.tags = [ name if isinstance(name, ImageTag) else ImageTag.parse(name) ]

        return retVal
    def test_parseFile(self):
        cdef = ContainerDefinition.parseFile(
            os.path.join(self.EXAMPLE_DIR, "00-private-registry.yaml"))

        eq_(cdef.name, "private-registry")
        eq_(cdef.image_tag, ImageTag("registry", tag="0.8.1"))
        eq_(cdef.env["SETTINGS_FLAVOR"], "local")
        eq_(cdef.ports["5000/tcp"], {"HostIp": "0.0.0.0", "HostPort": 11003})
        eq_(cdef.volumes["/var/lib/docker/registry"], {
            "HostPath": "/tmp",
            "ReadWrite": True
        })
Пример #5
0
    def getImage(self, name):
        """ returns an Image for the given name, or None if not found """
        retVal = None

        img_data = self.client.inspect_image(name)

        if img_data:
            retVal = Image.fromJson(img_data)
            retVal.tags = [
                name if isinstance(name, ImageTag) else ImageTag.parse(name)
            ]

        return retVal
Пример #6
0
    def test_getImageIdFromRegistry(self):
        docker = DockerSyncWrapper(docker_host=self.DOCKER_HOST_URL)

        httpretty.register_uri(
            httpretty.GET,
            "http://index.docker.io/v1/repositories/some/repo/tags",
            body=json.dumps([
                { "layer": "84422536", "name": "latest" }
            ]),
            content_type="application/json",
        )

        img_id = docker.getImageIdFromRegistry(ImageTag("some/repo", tag="latest"))

        eq_("84422536", img_id)
Пример #7
0
    def getImages(self):
        """ returns a dict of image_tag => Image instance """
        
        self.images = {}
        
        for img in self.client.images(all=True):
            tags = [ ImageTag.parse(t) for t in img["RepoTags"] ]

            image = Image(img["Id"])
            image.tags = tags
            
            for t in image.tags:
                if t:
                    self.images[t] = image
            
        return self.images
Пример #8
0
    def getImages(self):
        """ returns a dict of image_tag => Image instance """

        self.images = {}

        for img in self.client.images(all=True):
            tags = [ImageTag.parse(t) for t in img["RepoTags"]]

            image = Image(img["Id"])
            image.tags = tags

            for t in image.tags:
                if t:
                    self.images[t] = image

        return self.images
Пример #9
0
 def getImage(self, name):
     """ returns an Image for the given name, or None if not found """
     
     retVal = None
     
     img_data = self.client.inspect_image(name)
     
     if img_data:
         img_cfg = img_data.get("config", {})
         
         retVal = Image(img_data["id"])
         retVal.tags = [ name if isinstance(name, ImageTag) else ImageTag.parse(name) ]
         
         retVal.entrypoint = img_cfg.get("Entrypoint", [None])
         retVal.command = img_cfg.get("Cmd", [None])
     
     return retVal
Пример #10
0
    def test_getImages(self):
        docker = DockerSyncWrapper(docker_host=self.DOCKER_HOST_URL)

        httpretty.register_uri(
            httpretty.GET,
            self.DOCKER_HOST_URL + "/v%s/images/json" % (self.VERSION),
            body=json.dumps([
                {
                   "RepoTags": [
                     "ubuntu:12.04",
                     "ubuntu:precise",
                     "ubuntu:latest"
                   ],
                   "Id": "8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c",
                   "Created": 1365714795,
                   "Size": 131506275,
                   "VirtualSize": 131506275
                },
                {
                   "RepoTags": [
                     "ubuntu:12.10",
                     "ubuntu:quantal"
                   ],
                   "ParentId": "27cf784147099545",
                   "Id": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
                   "Created": 1364102658,
                   "Size": 24653,
                   "VirtualSize": 180116135
                }
            ]),
            content_type="application/json",
        )

        images = docker.getImages()

        eq_(httpretty.last_request().querystring["all"], ["1"])

        assert ImageTag.parse("ubuntu:12.10") in images, "tag not found"
Пример #11
0
 def test_remote_registry_with_tag(self):
     eq_(ImageTag(repository="some/repo", tag="aTag", registry="remote.registry:5000"), ImageTag.parse("remote.registry:5000/some/repo:aTag"))
Пример #12
0
 def test_official_repo_only(self):
     # http://index.docker.io/v1/repositories/ubuntu/tags/latest
     eq_(ImageTag(repository="ubuntu", tag="latest"), ImageTag.parse("ubuntu"))
Пример #13
0
 def test_official_repo_with_simple_tag(self):
     eq_(ImageTag(repository="ubuntu", tag="12.04"), ImageTag.parse("ubuntu:12.04"))
Пример #14
0
 def test_official_repo_with_latest(self):
     eq_(ImageTag(repository="ubuntu", tag="latest"), ImageTag.parse("ubuntu:latest"))
Пример #15
0
 def test_untagged(self):
     eq_(None, ImageTag.parse("<none>:<none>"))
Пример #16
0
 def test_remote_registry(self):
     eq_(ImageTag(repository="some/repo", tag="latest", registry="remote.registry:5000"), ImageTag.parse("remote.registry:5000/some/repo"))
Пример #17
0
 def test_repo_with_path_and_tag(self):
     eq_(ImageTag(repository="some/repo", tag="aTag"), ImageTag.parse("some/repo:aTag"))
Пример #18
0
 def test_repo_with_path(self):
     eq_(ImageTag(repository="some/repo", tag="latest"), ImageTag.parse("some/repo"))