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'") new_users = [] # all temporary users were created with random passwords. # It is impossible to restore that passwords, so let's change passwords # to be to reuse that users USER_PASSWORD = "password" for user in users: keystone.update_user(password=user) user_info = admin.to_dict() user_info["password"] = USER_PASSWORD user_info["username"] = user.name user_info["tenant_name"] = [p.name for p in projects if p.id == user.project_id][0] new_users.append({"credential": objects.Credential(**user_info), "tenant_id": user.project_id}) SERVICES_TO_CLEANUP = ["nova", "neutron", "cinder", "glance"] # modify list of services manager.cleanup(names=SERVICES_TO_CLEANUP, admin={"credential": admin}, users=new_users)