当前位置: 首页>>代码示例>>Python>>正文


Python DockerContainers.list_container_names方法代码示例

本文整理汇总了Python中dockertest.containers.DockerContainers.list_container_names方法的典型用法代码示例。如果您正苦于以下问题:Python DockerContainers.list_container_names方法的具体用法?Python DockerContainers.list_container_names怎么用?Python DockerContainers.list_container_names使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dockertest.containers.DockerContainers的用法示例。


在下文中一共展示了DockerContainers.list_container_names方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: cntnr_ip_map

# 需要导入模块: from dockertest.containers import DockerContainers [as 别名]
# 或者: from dockertest.containers.DockerContainers import list_container_names [as 别名]
 def cntnr_ip_map(self):
     """
     Return mapping of container names to IP addresses
     """
     # map container eth0 ifindex's to names
     dc = DockerContainers(self)
     names = dc.list_container_names()
     jsons = [dc.json_by_name(name)[0] for name in names]
     njs = dict(zip(names, jsons))
     result = {}
     for name in [_ for _ in njs if njs[_]["NetworkSettings"]["IPAddress"] != ""]:
         result[name] = njs[name]["NetworkSettings"]["IPAddress"]
         self.logdebug("%s -> %s", name, result[name])
     return result
开发者ID:edsantiago,项目名称:autotest-docker,代码行数:16,代码来源:iptable.py

示例2: cntnr_veth_map

# 需要导入模块: from dockertest.containers import DockerContainers [as 别名]
# 或者: from dockertest.containers.DockerContainers import list_container_names [as 别名]
    def cntnr_veth_map(self):
        """
        Return mapping of container names to veth* devices
        """
        # map ifindex's to ``veth*`` names on host
        tmp_cmd = 'brctl show'
        cmd_result = utils.run(tmp_cmd, verbose=False)
        veths = re.findall(r'veth\w+', cmd_result.stdout)
        ifindex = [int(open('/sys/class/net/%s/ifindex' % veth, 'r').read())
                   for veth in veths]
        index_host = dict(zip(ifindex, veths))
        self.logdebug("Host index to veth: %s", index_host)

        # map container eth0 ifindex's to names
        dc = DockerContainers(self)
        names = dc.list_container_names()
        jsons = [dc.json_by_name(name)[0] for name in names]
        njs = dict(zip(names, jsons))
        result = {}
        for name in [_name for (_name, json) in njs.iteritems()
                     if json["NetworkSettings"]["MacAddress"] != ""]:
            subargs = [name, 'cat', '/sys/class/net/eth0/ifindex']
            dkrcmd = DockerCmd(self, 'exec', subargs, verbose=False)
            dkrcmd.execute()
            if dkrcmd.exit_status == 0:
                # Host's ifindex always one greater than container's
                ifindex = int(dkrcmd.stdout) + 1
                # State could have changed during looping
                if ifindex in index_host:
                    result[name] = index_host[ifindex]
                else:
                    self.logdebug("Host veth %s dissapeared while mapping %s",
                                  ifindex, name)
            else:
                self.logdebug("Can't examine eth0 for container %s", name)
        self.logdebug("Container names to veth: %s", result)
        return result
开发者ID:chuanchang,项目名称:autotest-docker,代码行数:39,代码来源:iptable.py


注:本文中的dockertest.containers.DockerContainers.list_container_names方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。