0
votes

I was able to use keyword RegionName to specify Region Name when create OpenStack client instance with Python API. It is like:

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

But in the latest version OpenStack, I got error message:

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

I had to remove RegionName parameter:

novaclient.Client(Version, User, Password, Project_ID, Auth_URL)

But I do not know where to specify Region Name in my Python program. From OpenStack official document, https://docs.openstack.org/python-novaclient/latest/reference/api/index.html I cannot find any information about setting Region Name. Either with credential or keystoneauth session, no way to specify Region Name. Same to other OpenStack clients.

My question is how I can specify Region Name when create OpenStack client instance with Python API? Appreciate your answer!

2

2 Answers

1
votes

You need to pass region_name as keyword argument to mention region while creating nova client.

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

Here is source reference for Nova Client class,

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

0
votes

I want to share my testing result here:

With keystoneauth session API and 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")

It is good.

With Credentials and Identity API v2:

from novaclient import client as novaclient nova=novaclient.Client(Version, User, Password,Project_ID, Auth_URL_v2, region_name='RegionName')

It is good.

With Credentials and Identity API v3:

from novaclient import client as novaclient
nova=novaclient.Client(Version, User, Password,Project_ID, Auth_URL_v3, region_name='RegionName')

it does not work actually with error messages:

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)

So my conclusion is novaclient does not support 3) - Identity API V3 with credentials. We can use 1) - Identity API v3 with keystoneauth session and 2) - Identity API V2 with credentials