import copy from rally import api from rally.common import objects from rally import osclients from rally import plugins from rally.plugins.openstack.cleanup import manager from rally.plugins.openstack.context.keystone import users from rally.plugins.openstack.services.identity import identity deployment_uuid = "PUT HERE RALLY DEPLOYMENT UUID" task_uuid = "PUT HERE TASK UUID TO CLEANUP RESOURCES FOR" # obtain admin credentials from db rapi = api.API() deployment = rapi.deployment.get(deployment_uuid) admin = objects.Credential(**deployment["admin"]) # load all rally plugins plugins.load() # initialize helper for keystone keystone = identity.Identity(osclients.Clients(admin)) # discover all projects and users for particular task projects = [p for p in keystone.list_projects() if users.UserGenerator.name_matches_object(p.name, task_id=task_uuid)] users = [u for u in keystone.list_users() if users.UserGenerator.name_matches_object(u.name, task_id=task_uuid)] print("Projects created by rally:") for p in projects: print("Name: %s\tID:%s" % (p.name, p.id)) print("\n\nUsers created by rally:") for u in users: print("Name: %s\tID:%s" % (u.name, u.id)) raise Exception("Remove this line when use ensure that list of projects and users are not 'real'") def make_user(project): user = copy.deepcopy(admin) user.tenant_name = project.name return {"credential": user, "tenant_id": project.id} specific_users = [make_user(p) for p in projects] SERVICES_TO_CLEANUP = ["nova", "neutron", "cinder", "glance"] # modify list of services manager.cleanup(names=SERVICES_TO_CLEANUP, admin={"credential": admin}, users=specific_users) # all resources should be cleaned at that moment for u in users: keystone.delete_user(u.id) for p in projects: keystone.delete_project(p.id)