diff --git a/app.py b/app.py index 553e7d8..f21612d 100644 --- a/app.py +++ b/app.py @@ -1,115 +1,117 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- # # This file is part of the Keystone browser # # Copyright (c) 2017 Bryan Davis and contributors # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. # # You should have received a copy of the GNU General Public License along # with this program. If not, see . import flask import werkzeug.contrib.fixers from keystone_browser import glance from keystone_browser import keystone from keystone_browser import ldap from keystone_browser import nova +from keystone_browser import proxies from keystone_browser import stats app = flask.Flask(__name__) app.wsgi_app = werkzeug.contrib.fixers.ProxyFix(app.wsgi_app) @app.route('/') def projects(): ctx = {} try: cached = 'purge' not in flask.request.args ctx.update({ 'usage': stats.usage(cached), 'projects': keystone.all_projects(), }) except Exception: app.logger.exception('Error collecting information for projects') return flask.render_template('projects.html', **ctx) @app.route('/project/') def project(name): ctx = { 'project': name, } try: users = keystone.project_users_by_role(name) admins = users['admin'] + users['projectadmin'] ctx.update({ 'project': name, 'admins': ldap.get_users_by_uid(admins), 'users': ldap.get_users_by_uid(users['user']), 'servers': nova.project_servers(name), 'flavors': nova.flavors(name), 'images': glance.images(), + 'proxies': proxies.project_proxies(name), }) except Exception: app.logger.exception( 'Error collecting information for project "%s"', name) return flask.render_template('project.html', **ctx) @app.route('/user/') def user(uid): ctx = { 'uid': uid, } try: ctx.update({ 'user': ldap.get_users_by_uid([uid]), 'projects': keystone.projects_for_user(uid), }) if ctx['user']: ctx['user'] = ctx['user'][0] except Exception: app.logger.exception( 'Error collecting information for user "%s"', uid) return flask.render_template('user.html', **ctx) @app.route('/server/') def server(fqdn): name, project, tld = fqdn.split('.', 2) ctx = { 'fqdn': fqdn, 'project': project, } try: ctx.update({ 'server': nova.server(fqdn), 'flavors': nova.flavors(project), 'images': glance.images(), }) if 'user_id' in ctx['server']: user = ldap.get_users_by_uid([ctx['server']['user_id']]) if user: ctx['owner'] = user[0] except Exception: app.logger.exception( 'Error collecting information for server "%s"', fqdn) return flask.render_template('server.html', **ctx) @app.errorhandler(404) def page_not_found(e): return flask.redirect(flask.url_for('projects')) diff --git a/templates/project.html b/templates/project.html index b76db5b..93ce059 100644 --- a/templates/project.html +++ b/templates/project.html @@ -1,117 +1,147 @@ {% extends "layout.html" %} {% block title %}Project {{ project }} - {{ super() }}{% endblock %} {% block content %} -{% if admins or users or servers %} +{% if admins or users or servers or proxies %}
{% if admins %}
    {% for u in admins|sort(attribute='cn') %}
  • {{ u.cn }}
  • {% endfor %}
{% endif %} {% if users %}
    {% for u in users|sort(attribute='cn') %}
  • {{ u.cn }}
  • {% endfor %}
{% endif %} + {% if proxies %} +
+ + + + + + + + + + {% for proxy in proxies %} + + + + + {% endfor %} + +
DomainBackend
{{ proxy.doamin }} + {% for backend in proxies.backends %} + {{ backend }} + {% endfor %} +
+
+ {% endif %} {% if servers %}
{% for server in servers %} {% set image = images[server.image.id]|default('') %} {% set flavor = flavors[server.flavor.id]|default('') %} {% set fqdn = server.name ~ '.' ~ project ~ '.eqiad.wmflabs' %} {% if 'public' in server.addresses %} {% else %} {% endif %} {% endfor %}
FQDN Type Image IP CPUs RAM Storage Last modified
{{ fqdn }} {{ flavor.name|default('UNKNOWN') }} {{ image.name|default('UNKNOWN') }}{{ server.addresses.public[0].addr }}-{{ flavor.vcpus|default('-') }} {{ flavor.ram|default('-') }}M {{ flavor.disk|default('-') }}G {{ server.updated }}
{% endif %}
{% else %}

Unknown project '{{ project }}'. Are you just guessing?

{% endif %} {% endblock %}