Using argparse to load OS_* environment variables does not work for the compute service when microversions are in play. With the following code:
cloud_config = os_client_config.OpenStackConfig()
parser = argparse.ArgumentParser()
cloud_config.register_argparse_arguments(parser, sys.argv[1:])
options = parser.parse_args()
cloud = cloud_config.get_one_cloud(argparse=options)
conn = connection.from_config(cloud_config=cloud)
and the OS_COMPUTE_API_VERSION env var set to 2.37, I get the following error:
Traceback (most recent call last):
File "/root/test", line 24, in <module>
f = conn.compute.find_flavor('test')
File "/usr/lib/python2.7/site-packages/openstack/compute/v2/_proxy.py", line 66, in find_flavor
ignore_missing=ignore_missing)
File "/usr/lib/python2.7/site-packages/openstack/proxy2.py", line 105, in _find
**attrs)
File "/usr/lib/python2.7/site-packages/openstack/resource2.py", line 790, in find
return match.get(session)
File "/usr/lib/python2.7/site-packages/openstack/resource2.py", line 590, in get
response = session.get(request.uri, endpoint_filter=self.service)
File "/usr/lib/python2.7/site-packages/keystoneauth1/session.py", line 667, in get
return self.request(url, 'GET', **kwargs)
File "/usr/lib/python2.7/site-packages/openstack/session.py", line 39, in map_exceptions_wrapper
return func(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/openstack/session.py", line 249, in request
return super(Session, self).request(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/positional/__init__.py", line 94, in inner
return func(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/keystoneauth1/session.py", line 484, in request
**endpoint_filter)
File "/usr/lib/python2.7/site-packages/openstack/session.py", line 242, in get_endpoint
filt.requires_project_id)
File "/usr/lib/python2.7/site-packages/openstack/session.py", line 193, in _get_version_match
"Unable to determine endpoint for %s" % service_type)
openstack.exceptions.EndpointNotFound: Unable to determine endpoint for compute
whereas with OS_COMPUTE_API_VERSION=2.1, openstack sdk is able to find the endpoint. There are 2 endpoints returned in my environment, one for version 2.0 and another for version 2.1, and when openstack sdk sees something that doesn't match either of these it doesn't seem to know what to do. But the microversion is supposed to be set in that environment variable, not just 2.1. This is how things work with the openstack CLI and novaclient's CLI. There is no separate env var to indicate the microversion, and without indicating the microversion you can't control which way you expect the API to work.
Since I don't really understand microversions, how am I supposed to get 2.1 from 2.37? I know the 2.37 will be specified in some other header for the request, but when parsing out the service catalog I need to know, at minimum, the major version (i.e., 2) in order to figure anything reasonable out.