Skip to content

Commit fc03008

Browse files
committed
Add delete_tenant function for metrics
1 parent 2cb4881 commit fc03008

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

hawkular/metrics.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright 2015-2016 Red Hat, Inc. and/or its affiliates
2+
Copyright 2015-2017 Red Hat, Inc. and/or its affiliates
33
and other contributors.
44
55
Licensed under the Apache License, Version 2.0 (the "License");
@@ -65,7 +65,7 @@ def _get_url(self, metric_type=None):
6565
return self._get_base_url() + '{0}'.format(metric_type)
6666

6767
def _get_metrics_single_url(self, metric_type, metric_id):
68-
return self._get_url(metric_type) + '/{0}'.format(HawkularBaseClient.quote(metric_id))
68+
return self._get_single_id_url(self._get_url(metric_type), metric_id)
6969

7070
def _get_metrics_raw_url(self, metrics_url):
7171
return metrics_url + '/data' if self.legacy_api else metrics_url + '/raw'
@@ -82,6 +82,9 @@ def _get_tenants_url(self):
8282
def _get_status_url(self):
8383
return self._get_base_url() + 'status'
8484

85+
def _get_single_id_url(self, previous_url, id):
86+
return previous_url + '/{0}'.format(HawkularBaseClient.quote(metric_id))
87+
8588
@staticmethod
8689
def _transform_tags(**tags):
8790
return ','.join("%s:%s" % (key,val) for (key,val) in tags.items())
@@ -184,13 +187,13 @@ def query_metric_definitions(self, metric_type=None, id_filter=None, **tags):
184187
:param id_filter: Filter the id with regexp is tag filtering is used, otherwise a list of exact metric ids
185188
:param tags: A dict of tag key/value pairs. Uses Hawkular-Metrics tag query language for syntax
186189
"""
187-
if id is not None and tags is None:
188-
raise HawkularMetricsError('Tags query is required when id filter is used')
189-
190190
params = {}
191191

192+
if id_filter is not None:
193+
params['id'] = id_filter
194+
192195
if metric_type is not None:
193-
params = { 'type': MetricType.short(metric_type) }
196+
params['type'] = MetricType.short(metric_type)
194197

195198
if len(tags) > 0:
196199
params['tags'] = self._transform_tags(**tags)
@@ -220,7 +223,7 @@ def create_metric_definition(self, metric_type, metric_id, **tags):
220223
item = { 'id': metric_id }
221224
if len(tags) > 0:
222225
# We have some arguments to pass..
223-
data_retention = tags.pop('dataRetention',None)
226+
data_retention = tags.pop('dataRetention', None)
224227
if data_retention is not None:
225228
item['dataRetention'] = data_retention
226229

@@ -293,6 +296,13 @@ def create_tenant(self, tenant_id, retentions=None):
293296

294297
self._post(self._get_tenants_url(), json.dumps(item, indent=2))
295298

299+
def delete_tenant(self, tenant_id):
300+
"""
301+
Asynchronously deletes a tenant and all the data associated with the tenant.
302+
:param tenant_id: Tenant id to be sent for deletion process
303+
"""
304+
self._delete(self._get_single_id_url(self._get_tenants_url(), tenant_id))
305+
296306
"""
297307
Static methods
298308
"""

0 commit comments

Comments
 (0)