Search code examples
pythonopenstack

How to specify Region Name when create OpenStack client instance with Python API


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!


Solution

  • 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