Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Deleting Gnocchi metric with Keystone auth
#!/usr/bin/env python
import os
from concurrent.futures import thread
from gnocchiclient import client
from keystoneauth1 import identity
from keystoneauth1 import session
auth = identity.Password(auth_url=os.getenv("OS_AUTH_URL"),
username=os.getenv("OS_USERNAME"),
project_name=os.getenv("OS_PROJECT_NAME"),
password=os.getenv("OS_PASSWORD"))
# import gnocchiclient.auth
# auth = gnocchiclient.auth.GnocchiBasicPlugin(
# "admin", os.getenv("PIFPAF_GNOCCHI_HTTP_URL"))
g = client.Client(1, session.Session(auth=auth))
def delete_metric(g, metric_id):
try:
g.metric.delete(metric_id)
except Exception as e:
print("Unable to delete metric '%s': %s" % (metric_id, e))
else:
print("Deleted metric '%s'" % metric_id)
last_metric_id = None
with thread.ThreadPoolExecutor(max_workers=10) as p:
while True:
metrics = list(g.metric.list(limit=1000, marker=last_metric_id,
sorts=["id:desc"]))
if not metrics:
break
for metric in metrics[:]:
if metric['archive_policy']['name'] == 'low':
metrics.remove(metric)
p.submit(delete_metric, g, metric['id'])
if metrics:
last_metric_id = metrics[-1]['id']
else:
last_metric_id = None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.