使用Python API创建OpenStack客户端实例时如何指定区域名

2024-06-01 19:04:17 发布

您现在位置:Python中文网/ 问答频道 /正文

在使用pythonapi创建OpenStack客户机实例时,我能够使用关键字RegionName来指定区域名称。就像:

novaclient.Client(Version, User, Password, Project_ID, Auth_URL, RegionName='RegionName')

但在最新版本的OpenStack中,我收到了错误消息:

TypeError: init() got an unexpected keyword argument 'RegionName'

我不得不删除RegionName参数:

^{pr2}$

但我不知道在Python程序中在哪里指定区域名。从OpenStack官方文件中, https://docs.openstack.org/python-novaclient/latest/reference/api/index.html 我找不到有关设置区域名称的任何信息。无论是使用credential还是keysteauth会话,都无法指定区域名称。与其他OpenStack客户端相同。在

我的问题是,在使用pythonapi创建OpenStack客户端实例时,如何指定区域名称?感谢你的回答!在


Tags: 实例project名称client区域客户端pythonapi客户机
2条回答

在创建nova客户机时,需要将region_name作为关键字参数传递,以提到region。在

novaclient.Client(Version, User, Password, Project_ID, Auth_URL, region_name='Region1')

这是Nova客户端类的源代码引用

https://github.com/openstack/python-novaclient/blob/4707422377214829126f1d6352119ea08a7ec104/novaclient/v2/client.py#L80

我想在这里分享我的测试结果:

使用keystneauth会话API和Identity API v3:

from novaclient import client as novaclient
from keystoneauth1.identity import v3
from keystoneauth1 import session
auth = v3.Password(URL,username="username",password="password", project_name="admin", user_domain_id="default", project_domain_id="default")
sess = session.Session(auth=auth)
nova_client = novaclient.Client(2,  session=sess, region_name="RegionName")

很好。在

使用凭据和标识API v2:

从novaclient导入client作为novaclient 新星=novaclient.客户(版本、用户、密码、项目标识、身份验证URL_v2、region_name='RegionName')

很好。在

使用凭据和标识API v3:

^{pr2}$

它实际上不适用于错误消息:

nova.hypervisors.list()
keystoneauth1.exceptions.http.BadRequest: Expecting to find domain in user - the server could not comply with the request since it is either malformed or otherwise incorrect. The client is assumed to be in error. (HTTP 400)

所以我的结论是novaclient不支持3)Identity API V3和凭证。我们可以使用1)Identity API v3与keystoneauth会话,2)使用带凭据的Identity API V2

相关问题 更多 >