模块'docker.types'没有属性'IPAMPool'

时间:2019-04-25 08:54:35

标签: python-3.x docker

python3.7和docker api 1.39:模块'docker.types'没有属性'IPAMPool'

我是Python的新手,我尝试为docker创建一个网络。我在这里阅读了文档:https://docker-py.readthedocs.io/en/stable/networks.html,但无法创建IPAMPool。

这是我的代码:

#!/usr/bin/env python3

import sys
import docker
import settings

client=docker.from_env()
print(client.version())

print("Checking for existing network:", settings.NETWORK)
existing_nw=client.networks(names=[settings.NETWORK])
if existing_nw:
  print("network exists") 
else: 
  print("network not exists, create it")
  pool=docker.types.IPAMPool(
      subnet=settings.SUBNET,gateway=settings.GATEWAY)
      config=docker.types.IPAMConfig(pool_configs=[pool])
try:
    client.networks.create(name=settings.NETWORK, ipam=config)
except docker.errors.APIError as apierror:
    print("Network create error: {}".format(apierror))
    sys.exit(1)

输出为:

{'Platform': {'Name': 'Docker Engine - Community'}, 'Components': 
 [{'Name': 'Engine', 'Version': '18.09.5', 'Details': {'ApiVersion': 
 '1.39', 'Arch': 'amd64', 'BuildTime': '2019-04- 
 11T04:10:53.000000000+00:00', 'Experimental': 'false', 'GitCommit': 
 'e8ff056', 'GoVersion': 'go1.10.8', 'KernelVersion': '4.19.0-4- 
 amd64', 'MinAPIVersion': '1.12', 'Os': 'linux'}}], 'Version': 
 '18.09.5', 'ApiVersion': '1.39', 'MinAPIVersion': '1.12', 
 'GitCommit': 'e8ff056', 'GoVersion': 'go1.10.8', 'Os': 'linux', 
 'Arch': 'amd64', 'KernelVersion': '4.19.0-4-amd64', 'BuildTime': 
 '2019-04-11T04:10:53.000000000+00:00'}
 AttributeError: module 'docker.types' has no attribute 'IPAMPool'

如何使用IPAMPool?

thx 扎梅克

0 个答案:

没有答案