Merge "Add Gnocchi datasource for Grafana"
This commit is contained in:
commit
9cbe044a30
2 changed files with 46 additions and 6 deletions
|
@ -61,6 +61,9 @@ def present(name,
|
||||||
basic_auth=False,
|
basic_auth=False,
|
||||||
basic_auth_user='',
|
basic_auth_user='',
|
||||||
basic_auth_password='',
|
basic_auth_password='',
|
||||||
|
mode=None,
|
||||||
|
domain='default',
|
||||||
|
project=None,
|
||||||
is_default=False,
|
is_default=False,
|
||||||
profile='grafana'):
|
profile='grafana'):
|
||||||
'''
|
'''
|
||||||
|
@ -97,6 +100,15 @@ def present(name,
|
||||||
basic_auth_password
|
basic_auth_password
|
||||||
Optional - HTTP basic auth password.
|
Optional - HTTP basic auth password.
|
||||||
|
|
||||||
|
mode
|
||||||
|
Optional - Gnocchi authentication mode.
|
||||||
|
|
||||||
|
domain
|
||||||
|
Optional - Gnocchi domain, defaults to "default".
|
||||||
|
|
||||||
|
project
|
||||||
|
Optional - Keystone user for Gnocchi.
|
||||||
|
|
||||||
is_default
|
is_default
|
||||||
Optional - Set data source as default. Default: False
|
Optional - Set data source as default. Default: False
|
||||||
'''
|
'''
|
||||||
|
@ -113,6 +125,9 @@ def present(name,
|
||||||
basic_auth=basic_auth,
|
basic_auth=basic_auth,
|
||||||
basic_auth_user=basic_auth_user,
|
basic_auth_user=basic_auth_user,
|
||||||
basic_auth_password=basic_auth_password,
|
basic_auth_password=basic_auth_password,
|
||||||
|
mode=mode,
|
||||||
|
domain=domain,
|
||||||
|
project=project,
|
||||||
is_default=is_default)
|
is_default=is_default)
|
||||||
|
|
||||||
if datasource:
|
if datasource:
|
||||||
|
@ -194,21 +209,20 @@ def _get_datasource(profile, name):
|
||||||
for datasource in data:
|
for datasource in data:
|
||||||
if datasource['name'] == name:
|
if datasource['name'] == name:
|
||||||
return datasource
|
return datasource
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def _get_headers(profile):
|
def _get_headers(profile):
|
||||||
|
|
||||||
headers = {'Content-type': 'application/json'}
|
headers = {'Content-type': 'application/json'}
|
||||||
|
|
||||||
if profile.get('grafana_token', False):
|
if profile.get('grafana_token'):
|
||||||
headers['Authorization'] = 'Bearer {0}'.format(profile['grafana_token'])
|
headers['Authorization'] = 'Bearer {0}'.format(profile['grafana_token'])
|
||||||
|
|
||||||
return headers
|
return headers
|
||||||
|
|
||||||
|
|
||||||
def _get_auth(profile):
|
def _get_auth(profile):
|
||||||
if profile.get('grafana_token', False):
|
if profile.get('grafana_token'):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return requests.auth.HTTPBasicAuth(
|
return requests.auth.HTTPBasicAuth(
|
||||||
|
@ -227,10 +241,13 @@ def _get_json_data(name,
|
||||||
basic_auth=False,
|
basic_auth=False,
|
||||||
basic_auth_user='',
|
basic_auth_user='',
|
||||||
basic_auth_password='',
|
basic_auth_password='',
|
||||||
|
mode=None,
|
||||||
|
domain=None,
|
||||||
|
project=None,
|
||||||
is_default=False,
|
is_default=False,
|
||||||
type_logo_url='public/app/plugins/datasource/influxdb/img/influxdb_logo.svg',
|
type_logo_url='public/app/plugins/datasource/influxdb/img/influxdb_logo.svg',
|
||||||
with_credentials=False):
|
with_credentials=False):
|
||||||
return {
|
data = {
|
||||||
'name': name,
|
'name': name,
|
||||||
'type': type,
|
'type': type,
|
||||||
'url': url,
|
'url': url,
|
||||||
|
@ -245,6 +262,18 @@ def _get_json_data(name,
|
||||||
'typeLogoUrl': type_logo_url,
|
'typeLogoUrl': type_logo_url,
|
||||||
'withCredentials': with_credentials,
|
'withCredentials': with_credentials,
|
||||||
}
|
}
|
||||||
|
if data['type'] == 'gnocchixyz-gnocchi-datasource':
|
||||||
|
json_data = {}
|
||||||
|
for special in ['mode', 'domain', 'project', 'user', 'password']:
|
||||||
|
value = locals().get(special)
|
||||||
|
if value is not None:
|
||||||
|
if special == 'user':
|
||||||
|
json_data['username'] = value
|
||||||
|
else:
|
||||||
|
json_data[special] = value
|
||||||
|
if json_data:
|
||||||
|
data['jsonData'] = json_data
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
def _diff(old, new):
|
def _diff(old, new):
|
||||||
|
@ -252,7 +281,7 @@ def _diff(old, new):
|
||||||
old = old.copy()
|
old = old.copy()
|
||||||
new = new.copy()
|
new = new.copy()
|
||||||
for key in old_keys:
|
for key in old_keys:
|
||||||
if key == 'id' or key == 'orgId':
|
if key in ['id', 'orgId']:
|
||||||
del old[key]
|
del old[key]
|
||||||
# New versions of Grafana can introduce new keys that are not present
|
# New versions of Grafana can introduce new keys that are not present
|
||||||
# in _get_json_data.
|
# in _get_json_data.
|
||||||
|
|
|
@ -9,7 +9,11 @@ grafana_client_datasource_{{ datasource_name }}:
|
||||||
grafana3_datasource.present:
|
grafana3_datasource.present:
|
||||||
- name: {{ datasource.name|default(datasource_name) }}
|
- name: {{ datasource.name|default(datasource_name) }}
|
||||||
- type: {{ datasource.type }}
|
- type: {{ datasource.type }}
|
||||||
- url: http://{{ datasource.host }}:{{ datasource.get('port', 80) }}
|
{%- if datasource.port is defined %}
|
||||||
|
- url: {{ datasource.get('protocol', 'http') }}://{{ datasource.host }}:{{ datasource.port }}{{ datasource.get('url_path', '') }}
|
||||||
|
{%- else %}
|
||||||
|
- url: {{ datasource.get('protocol', 'http') }}://{{ datasource.host }}{{ datasource.get('url_path', '') }}
|
||||||
|
{%- endif %}
|
||||||
{%- if datasource.access is defined %}
|
{%- if datasource.access is defined %}
|
||||||
- access: proxy
|
- access: proxy
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
@ -23,6 +27,13 @@ grafana_client_datasource_{{ datasource_name }}:
|
||||||
{%- if datasource.database is defined %}
|
{%- if datasource.database is defined %}
|
||||||
- database: {{ datasource.database }}
|
- database: {{ datasource.database }}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
{%- if datasource.mode is defined %}
|
||||||
|
- mode: {{ datasource.mode }}
|
||||||
|
{%- if datasource.mode == 'keystone' %}
|
||||||
|
- domain: {{ datasource.get('domain', 'default') }}
|
||||||
|
- project: {{ datasource.get('project', 'service') }}
|
||||||
|
{%- endif %}
|
||||||
|
{%- endif %}
|
||||||
|
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue