【问题标题】:Create an instance from volume in openstach with python-novaclient使用 python-novaclient 从 openstach 中的卷创建一个实例
【发布时间】:2014-11-20 19:52:38
【问题描述】:

我正在尝试使用 python-novaclient 从 openstack 中的可引导卷创建一个实例。

我正在采取的步骤如下:

Step1:创建一个具有 100GB 映像“Centos”的卷。 Step2:使用我在 step1 中创建的卷创建一个实例。

但是,我一定是做错了什么或者遗漏了一些无法完成任务的信息。

这是我在 python shell 中的命令。

import time, getpass
from cinderclient import client
from novaclient.client import Client


project_name = 'project'
region_name = 'region'
keystone_link = 'https://keystone.net:5000/v2.0'
network_zone = "Public"
key_name = 'key_pair'

user = 'user'
pswd = getpass.getpass('Password: ')



# create a connection
cinder = client.Client('1', user, pswd, project_name, keystone_link, region_name = region_name)

# get the volume id that we will attach
print(cinder.volumes.list())
[<Volume: 1d36203e-b90d-458f-99db-8690148b9600>, <Volume: d734f5fc-87f2-41dd-887e-c586bf76d116>]

vol1 = cinder.volumes.list()[1]
vol1.id

block_device_mapping = {'device_name': vol1.id, 'mapping': '/dev/vda'}



### +++++++++++++++++++++++++++++++++++++++++++++++++++++ ###
# now create a connection with nova and create then instance object
nova = Client(2, user, pswd, project_name, keystone_link, region_name = region_name)

# find the image 
image = nova.images.find(name="NETO CentOS 6.4 x86_64 v2.2")

# get the flavor
flavor = nova.flavors.find(name="m1.large")

#get the network and attach
network = nova.networks.find(label=network_zone)
nics = [{'net-id': network.id}]

# get the keyname and attach
key_pair = nova.keypairs.get(key_name)

s1 = 'nova-vol-test'

server = nova.servers.create(name = s1, image = image.id, block_device_mapping = block_device_mapping, flavor = flavor.id, nics = nics, key_name = key_pair.name)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/site-packages/novaclient/v1_1/servers.py", line 902, in create
    **boot_kwargs)
  File "/usr/lib/python2.6/site-packages/novaclient/v1_1/servers.py", line 554, in _boot
    return_raw=return_raw, **kwargs)
  File "/usr/lib/python2.6/site-packages/novaclient/base.py", line 100, in _create
    _resp, body = self.api.client.post(url, body=body)
  File "/usr/lib/python2.6/site-packages/novaclient/client.py", line 490, in post
    return self._cs_request(url, 'POST', **kwargs)
  File "/usr/lib/python2.6/site-packages/novaclient/client.py", line 465, in _cs_request
    resp, body = self._time_request(url, method, **kwargs)
  File "/usr/lib/python2.6/site-packages/novaclient/client.py", line 439, in _time_request
    resp, body = self.request(url, method, **kwargs)
  File "/usr/lib/python2.6/site-packages/novaclient/client.py", line 433, in request
    raise exceptions.from_response(resp, body, url, method)
novaclient.exceptions.BadRequest: Block Device Mapping is Invalid: failed to get volume /dev/vda. (HTTP 400) (Request-ID: req-2b9db4e1-f24f-48c6-8660-822741ca52ad)
>>>

我试图找到任何文档以便我可以自己解决这个问题,但是我无法解决。

如果有人以前尝试过,我将不胜感激。

谢谢, 穆尔塔萨

【问题讨论】:

    标签: python openstack novaclient openstack-cinder


    【解决方案1】:

    我可以通过使用这本词典让它工作:

    block_dev_mapping = {'vda':'uuid of the volume you want to use'}
    

    然后我在 create 方法中这样调用它:

    instance = nova.servers.create(name="python-test3", image='', block_device_mapping=block_dev_mapping,
                                        flavor=flavor, key_name="my-keypair", nics=nics)
    

    【讨论】:

    • 我确实尝试了这个 block_dev_mapping = {'vda':'uuid of the volume you want to use'} 以及其他变体,但是,它们似乎都不起作用。令人惊讶的是它现在有效。感谢您的回复。
    • @MurtazaPitalwala 那么,我们知道为什么它现在出奇地有效吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-11
    • 2021-04-02
    相关资源
    最近更新 更多