Add user_agent into FlashBlade API calls (#46221)

pull/47742/head
Simon Dodsley 6 years ago committed by John R Barker
parent 92d9569bc9
commit bba8c23585

@ -45,8 +45,9 @@ from os import environ
from os import path from os import path
import platform import platform
VERSION = 1.1 VERSION = 1.2
USER_AGENT_BASE = 'Ansible' USER_AGENT_BASE = 'Ansible'
API_AGENT_VERSION = 1.5
def get_system(module): def get_system(module):
@ -75,13 +76,12 @@ def get_system(module):
def get_blade(module): def get_blade(module):
"""Return System Object or Fail""" """Return System Object or Fail"""
# Note: user_agent not included in FlashBlade API 1.1 user_agent = '%(base)s %(class)s/%(version)s (%(platform)s)' % {
# user_agent = '%(base)s %(class)s/%(version)s (%(platform)s)' % { 'base': USER_AGENT_BASE,
# 'base': USER_AGENT_BASE, 'class': __name__,
# 'class': __name__, 'version': VERSION,
# 'version': VERSION, 'platform': platform.platform()
# 'platform': platform.platform() }
# }
blade_name = module.params['fb_url'] blade_name = module.params['fb_url']
api = module.params['api_token'] api = module.params['api_token']
@ -90,6 +90,8 @@ def get_blade(module):
blade.disable_verify_ssl() blade.disable_verify_ssl()
try: try:
blade.login(api) blade.login(api)
if API_AGENT_VERSION in blade.api_version.list_versions().versions:
blade._api_client.user_agent = user_agent
except rest.ApiException as e: except rest.ApiException as e:
module.fail_json(msg="Pure Storage FlashBlade authentication failed. Check your credentials") module.fail_json(msg="Pure Storage FlashBlade authentication failed. Check your credentials")
elif environ.get('PUREFB_URL') and environ.get('PUREFB_API'): elif environ.get('PUREFB_URL') and environ.get('PUREFB_API'):
@ -97,6 +99,8 @@ def get_blade(module):
blade.disable_verify_ssl() blade.disable_verify_ssl()
try: try:
blade.login(environ.get('PUREFB_API')) blade.login(environ.get('PUREFB_API'))
if API_AGENT_VERSION in blade.api_version.list_versions().versions:
blade._api_client.user_agent = user_agent
except rest.ApiException as e: except rest.ApiException as e:
module.fail_json(msg="Pure Storage FlashBlade authentication failed. Check your credentials") module.fail_json(msg="Pure Storage FlashBlade authentication failed. Check your credentials")
else: else:

Loading…
Cancel
Save