Fix deprecated warnings

This commit is contained in:
Rémy Léone 2018-04-06 11:01:42 +02:00 committed by Toshio Kuratomi
parent 3664c74cb8
commit 98fb47b061
5 changed files with 20 additions and 16 deletions

View file

@ -103,11 +103,12 @@ slug:
sample: foo sample: foo
''' '''
import base64
import json import json
import os import base64
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url from ansible.module_utils.urls import fetch_url
from ansible.module_utils._text import to_bytes
__metaclass__ = type __metaclass__ = type
@ -162,7 +163,7 @@ def grafana_create_dashboard(module, data):
if 'grafana_api_key' in data and data['grafana_api_key']: if 'grafana_api_key' in data and data['grafana_api_key']:
headers['Authorization'] = "Bearer %s" % data['grafana_api_key'] headers['Authorization'] = "Bearer %s" % data['grafana_api_key']
else: else:
auth = base64.encodestring('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', '') auth = base64.b64encode(to_bytes('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', ''))
headers['Authorization'] = 'Basic %s' % auth headers['Authorization'] = 'Basic %s' % auth
grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers) grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers)
@ -220,7 +221,7 @@ def grafana_delete_dashboard(module, data):
if 'grafana_api_key' in data and data['grafana_api_key']: if 'grafana_api_key' in data and data['grafana_api_key']:
headers['Authorization'] = "Bearer %s" % data['grafana_api_key'] headers['Authorization'] = "Bearer %s" % data['grafana_api_key']
else: else:
auth = base64.encodestring('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', '') auth = base64.b64encode(to_bytes('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', ''))
headers['Authorization'] = 'Basic %s' % auth headers['Authorization'] = 'Basic %s' % auth
grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers) grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers)
@ -253,7 +254,7 @@ def grafana_export_dashboard(module, data):
if 'grafana_api_key' in data and data['grafana_api_key']: if 'grafana_api_key' in data and data['grafana_api_key']:
headers['Authorization'] = "Bearer %s" % data['grafana_api_key'] headers['Authorization'] = "Bearer %s" % data['grafana_api_key']
else: else:
auth = base64.encodestring('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', '') auth = base64.b64encode(to_bytes('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', ''))
headers['Authorization'] = 'Basic %s' % auth headers['Authorization'] = 'Basic %s' % auth
grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers) grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers)

View file

@ -249,11 +249,12 @@ after:
"withCredentials": false } "withCredentials": false }
''' '''
import base64
import json import json
import os import base64
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url from ansible.module_utils.urls import fetch_url
from ansible.module_utils._text import to_bytes
__metaclass__ = type __metaclass__ = type
@ -362,7 +363,7 @@ def grafana_create_datasource(module, data):
if 'grafana_api_key' in data and data['grafana_api_key'] is not None: if 'grafana_api_key' in data and data['grafana_api_key'] is not None:
headers['Authorization'] = "Bearer %s" % data['grafana_api_key'] headers['Authorization'] = "Bearer %s" % data['grafana_api_key']
else: else:
auth = base64.encodestring('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', '') auth = base64.b64encode(to_bytes('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', ''))
headers['Authorization'] = 'Basic %s' % auth headers['Authorization'] = 'Basic %s' % auth
grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers) grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers)
@ -422,7 +423,7 @@ def grafana_delete_datasource(module, data):
if 'grafana_api_key' in data and data['grafana_api_key']: if 'grafana_api_key' in data and data['grafana_api_key']:
headers['Authorization'] = "Bearer %s" % data['grafana_api_key'] headers['Authorization'] = "Bearer %s" % data['grafana_api_key']
else: else:
auth = base64.encodestring('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', '') auth = base64.b64encode(to_bytes('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', ''))
headers['Authorization'] = 'Basic %s' % auth headers['Authorization'] = 'Basic %s' % auth
grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers) grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers)

View file

@ -134,19 +134,20 @@ EXAMPLES = '''
service: '{{ pd_window.result.maintenance_window.id }}' service: '{{ pd_window.result.maintenance_window.id }}'
''' '''
import base64
import datetime import datetime
import json import json
import base64
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url from ansible.module_utils.urls import fetch_url
from ansible.module_utils._text import to_bytes
def auth_header(user, passwd, token): def auth_header(user, passwd, token):
if token: if token:
return "Token token=%s" % token return "Token token=%s" % token
auth = base64.encodestring('%s:%s' % (user, passwd)).replace('\n', '') auth = base64.b64encode(to_bytes('%s:%s' % (user, passwd)).replace('\n', ''))
return "Basic %s" % auth return "Basic %s" % auth

View file

@ -88,14 +88,14 @@ EXAMPLES = '''
action: disable action: disable
''' '''
import base64
import json import json
import socket import socket
import traceback import traceback
import base64
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six.moves.urllib.parse import urlencode from ansible.module_utils.six.moves.urllib.parse import urlencode
from ansible.module_utils._text import to_native from ansible.module_utils._text import to_native, to_bytes
from ansible.module_utils.urls import fetch_url from ansible.module_utils.urls import fetch_url
@ -115,7 +115,7 @@ class netscaler(object):
if not len(data_json): if not len(data_json):
data_json = None data_json = None
auth = base64.encodestring('%s:%s' % (self._nsc_user, self._nsc_pass)).replace('\n', '').strip() auth = base64.b64encode(to_bytes('%s:%s' % (self._nsc_user, self._nsc_pass)).replace('\n', '').strip())
headers = { headers = {
'Authorization': 'Basic %s' % auth, 'Authorization': 'Basic %s' % auth,
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',

View file

@ -80,15 +80,16 @@ EXAMPLES = '''
delegate_to: localhost delegate_to: localhost
''' '''
import base64
import json import json
import base64
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url from ansible.module_utils.urls import fetch_url
from ansible.module_utils._text import to_bytes
def request(module, url, user, oauthkey, data='', method='GET'): def request(module, url, user, oauthkey, data='', method='GET'):
auth = base64.encodestring('%s:%s' % (user, oauthkey)).replace('\n', '') auth = base64.b64encode(to_bytes('%s:%s' % (user, oauthkey)).replace('\n', ''))
headers = { headers = {
'Authorization': 'Basic %s' % auth, 'Authorization': 'Basic %s' % auth,
} }