Set proper user_agent string

The user_agent is not fixed by keystoneauth when being passed to the
request method so we need to set that on the adapter. Move the version
string to prevent circular imports and add it and os-client-config
versions to the user_agent.
This commit is contained in:
Jamie Lennox 2016-04-11 16:14:39 +10:00
parent 7d559eacb6
commit 78dfff9891
3 changed files with 33 additions and 8 deletions

View File

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
@ -12,8 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import pbr.version
from os_http import version
__version__ = pbr.version.VersionInfo(
'os_http').version_string()
__version__ = version.version_string

View File

@ -30,12 +30,21 @@ except ImportError:
from keystoneauth1 import adapter
from keystoneauth1 import exceptions
from keystoneauth1 import loading
from keystoneauth1 import session as ksa_session
from keystoneauth1 import session
import os_client_config
import pbr.version
from os_http import version
LOG = logging.getLogger(__name__)
# FIXME(jamielennox): OCC should advertise its own version.
# Fix: https://review.openstack.org/#/c/303913/
try:
_occ_version = pbr.version.VersionInfo('os_client_config').version_string()
except Exception:
_occ_version = "unknown"
def main(argv=sys.argv[1:]):
parser = argparse.ArgumentParser(
@ -73,7 +82,10 @@ def main(argv=sys.argv[1:]):
# FIXME(jamielennox): These things should be handled by os-client-config
adap.logger = LOG
adap.user_agent = 'os-http'
adap.user_agent = 'os-http/%s os-client-config/%s %s' % (
version.version_string,
_occ_version,
session.DEFAULT_USER_AGENT)
adap.version = opts.os_api_version
headers = {'Accept': 'application/json'}

16
os_http/version.py Normal file
View File

@ -0,0 +1,16 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import pbr.version
version_string = pbr.version.VersionInfo('os_http').version_string()