提供boot_volume而不是映像

时间:2018-11-23 09:30:13

标签: python openstack

  • Openstack版本:Rocky
  • API版本:3

我可以通过提供图像名称从python创建服务器。我可以通过提供没有映像名称的卷名称来从CLI创建服务器。但是从python来说,我无法仅使用boot_volume创建没有映像的服务器。

下面是我的代码和错误:

代码:

def createServer(conn, volume=None):
    print "Create Server:"
    SERVER_NAME = "TestPython"
    IMAGE_NAME = "cirros-040"
    FLAVOR_NAME = "t1-basic-1-2"
    NETWORK_NAME = "private"
    image = conn.compute.find_image(IMAGE_NAME)
    flavor = conn.compute.find_flavor(FLAVOR_NAME)
    network = conn.network.find_network(NETWORK_NAME)
    volume = conn.get_volume(volume)
    keypair = find_keypair(conn)

    server = conn.compute.create_server(
                                name = SERVER_NAME,
                                #image_id = image.id,
                                flavor_id = flavor.id,
                                key_name = keypair.name,
                                networks = [{"uuid": network.id}],
                                boot_volume = volume.id)
                                #volumes = [ volume ],
                                #boot_from_volume = True,
                                #volume_size = 5)

    serv = conn.compute.wait_for_server(server)
    return serv

错误:

  File "<generated-openstack.compute.v2.server>", line 3, in create
  File "/usr/lib/python2.7/site-packages/openstack/proxy.py", line 192, in _create
    return res.create(self)
  File "/usr/lib/python2.7/site-packages/openstack/resource.py", line 763, in create
    self._translate_response(response)
  File "/usr/lib/python2.7/site-packages/openstack/resource.py", line 695, in _translate_response
    exceptions.raise_from_response(response, error_message=error_message)
  File "/usr/lib/python2.7/site-packages/openstack/exceptions.py", line 212, in raise_from_response
    http_status=http_status, request_id=request_id
openstack.exceptions.BadRequestException: BadRequestException: 400: Client Error for url: XXXX, {"badRequest": {"message": "Missing imageRef attribute", "code": 400}}

我可以看到image是一个可选参数,如果给出boot_volume则不需要。

这是错误还是我错过了什么?

0 个答案:

没有答案