本文整理汇总了Python中dockertest.containers.DockerContainers.json_by_name方法的典型用法代码示例。如果您正苦于以下问题:Python DockerContainers.json_by_name方法的具体用法?Python DockerContainers.json_by_name怎么用?Python DockerContainers.json_by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dockertest.containers.DockerContainers
的用法示例。
在下文中一共展示了DockerContainers.json_by_name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cntnr_ip_map
# 需要导入模块: from dockertest.containers import DockerContainers [as 别名]
# 或者: from dockertest.containers.DockerContainers import json_by_name [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
示例2: cntnr_veth_map
# 需要导入模块: from dockertest.containers import DockerContainers [as 别名]
# 或者: from dockertest.containers.DockerContainers import json_by_name [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