mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add user_agent into FlashBlade API calls (#46221)
This commit is contained in:
parent
92d9569bc9
commit
bba8c23585
1 changed files with 12 additions and 8 deletions
|
@ -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…
Reference in a new issue