本文整理汇总了Python中dockertest.containers.DockerContainers.remove_by_obj方法的典型用法代码示例。如果您正苦于以下问题:Python DockerContainers.remove_by_obj方法的具体用法?Python DockerContainers.remove_by_obj怎么用?Python DockerContainers.remove_by_obj使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dockertest.containers.DockerContainers
的用法示例。
在下文中一共展示了DockerContainers.remove_by_obj方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cleanup
# 需要导入模块: from dockertest.containers import DockerContainers [as 别名]
# 或者: from dockertest.containers.DockerContainers import remove_by_obj [as 别名]
def cleanup(self):
super(run, self).cleanup()
# Clean up all containers
dc = DockerContainers(self)
for cobj in dc.list_containers():
self.logwarning("Found leftover container: %s", cobj.container_name)
try:
dc.kill_container_by_obj(cobj)
except ValueError:
pass # already dead
else:
self.logdebug("Killed container %s, waiting up to %d seconds "
"for it to exit", cobj.container_name,
dc.timeout)
dc.wait_by_obj(cobj)
self.logdebug("Removing container %s", cobj.container_name)
dc.remove_by_obj(cobj)
# Clean up all non-default images
fqin = DockerImage.full_name_from_defaults(self.config)
di = DockerImages(self)
def_img_obj = di.list_imgs_with_full_name(fqin)[0]
for img_obj in di.list_imgs():
if img_obj.full_name != def_img_obj.full_name:
self.logwarning("Found leftover image: %s", img_obj)
di.remove_image_by_image_obj(img_obj)
else:
self.logdebug("Not removing default image: %s", def_img_obj)