"""
return self.keystone_client.projects.list(user=user_id)
+ def getUsers(self):
+ """
+ Grabs users from keystone using the client and session build in the constructor
+ """
+ domain_list = self.keystone_client.domains.list()
+ users = []
+ for domain in domain_list:
+ users.extend(self.keystone_client.users.list(domain=domain.id))
+ return users
+
def getUserById(self, user_id):
"""
Grabs user object from keystone using user id
log.info("New user %s created in Grafana", user)
return response_users
+ # Get Grafana users
+ def get_grafana_users(self):
+ response_users = requests.request(
+ "GET",
+ self.url + "/api/users",
+ headers=self.headers,
+ )
+ user_list = []
+ users = json.loads(response_users.text)
+ for user in users:
+ if user["name"] and user["name"] != "admin":
+ user_list.append(user["name"])
+ return user_list
+
# Create Grafana team with member
def create_grafana_teams_members(
self, project_name, user_name, is_admin, proj_list
time.sleep(int(self.conf.get("dashboarder", "interval")))
continue
try:
+ self.grafana_cleanup()
self.create_dashboards()
time.sleep(int(self.conf.get("dashboarder", "interval")))
except Exception:
def create_dashboards(self):
self.service.create_dashboards()
log.debug("Dashboarder Service > create_dashboards called!")
+
+ def grafana_cleanup(self):
+ # Cleaning up non existing users from grafana
+ self.service.delete_non_existing_users()
+ # TODO
+ # Cleanup of teams from grafana
+ log.debug("Deleted non existing users from dashbaorder service")
def create_grafana_user(self, user):
self.grafana.create_grafana_users(user)
+ def delete_non_existing_users(self):
+ if self.keystone:
+ # Get users from keystone
+ users = self.keystone.getUsers()
+ usernames = []
+ for user in users:
+ usernames.append(user.name)
+ grafana_users = self.grafana.get_grafana_users()
+ users_to_be_deleted = list(set(grafana_users) - set(usernames))
+ for grafana_user in users_to_be_deleted:
+ self.grafana.delete_grafana_users(grafana_user)
+
def create_grafana_team_member(
self, project_data, userid=None, project_list=None, user=None
):