diff --git a/dash/__init__.py b/dash/__init__.py index 37d8822..08269e5 100644 --- a/dash/__init__.py +++ b/dash/__init__.py @@ -57,6 +57,10 @@ def create_app(config_name): from .profile import profile as profile_blueprint dash.register_blueprint(profile_blueprint, url_prefix='/profile') + # server application + from .server import server as server_blueprint + dash.register_blueprint(server_blueprint, url_prefix='/server') + # admin application from .admin import admin as admin_blueprint dash.register_blueprint(admin_blueprint, url_prefix='/admin') diff --git a/dash/server/__init__.py b/dash/server/__init__.py new file mode 100644 index 0000000..65685df --- /dev/null +++ b/dash/server/__init__.py @@ -0,0 +1,5 @@ +from flask import Blueprint + +server = Blueprint('server', __name__) + +from . import views \ No newline at end of file diff --git a/dash/server/forms.py b/dash/server/forms.py new file mode 100644 index 0000000..e69de29 diff --git a/dash/server/views.py b/dash/server/views.py new file mode 100644 index 0000000..cc8585f --- /dev/null +++ b/dash/server/views.py @@ -0,0 +1,45 @@ +import datetime, requests, json, string, random + +from keystoneauth1 import loading +from keystoneauth1 import session +from novaclient import client + +from flask import render_template, redirect, request, url_for, flash +from flask_login import login_user, logout_user, login_required, \ + current_user +from flask_principal import Identity, AnonymousIdentity, \ + identity_changed + +from . import server +from .. import db +from ..models import User, Role, Provider +from ..email import send_email +from ..decorators import requires_roles + +@server.route('/', methods=['GET', 'POST']) +@login_required +@requires_roles("user","admin") +def index(): + return render_template('server/index.html') + +@server.route('/list-servers', methods=['GET', 'POST']) +@login_required +@requires_roles("user","admin") +def list_servers(): + user = User.query.get_or_404(current_user.id) + provider = Provider.query.get_or_404("1") + loader = loading.get_plugin_loader('password') + auth = loader.load_from_options(auth_url=provider.url, + username=user.username, + password=user.provider_password, + project_name=user.username, + project_domain_name='Default', + user_domain_name='Default') + sess = session.Session(auth=auth) + nova = client.Client('2', session=sess) + servers = nova.servers.list() + return render_template('server/list_servers.html', + title="List Servers", + block_description = "list your servers", + user=user, provider=provider,nova=nova, + servers=servers) \ No newline at end of file diff --git a/dash/templates/admin/create_provider.html b/dash/templates/admin/create_provider.html index ca9b3e0..8945b36 100644 --- a/dash/templates/admin/create_provider.html +++ b/dash/templates/admin/create_provider.html @@ -17,7 +17,7 @@ {% include 'sidebar.html' %} - {% include 'admin/sidebar_menu.html' %} + {% include 'sidebar_menu.html' %} {%- endblock sidebar %} diff --git a/dash/templates/admin/create_user.html b/dash/templates/admin/create_user.html index 5c477f8..08c2d8f 100644 --- a/dash/templates/admin/create_user.html +++ b/dash/templates/admin/create_user.html @@ -17,7 +17,7 @@ {% include 'sidebar.html' %} - {% include 'admin/sidebar_menu.html' %} + {% include 'sidebar_menu.html' %} {%- endblock sidebar %} diff --git a/dash/templates/admin/create_user_provider.html b/dash/templates/admin/create_user_provider.html index adf0b34..b323a2b 100644 --- a/dash/templates/admin/create_user_provider.html +++ b/dash/templates/admin/create_user_provider.html @@ -17,7 +17,7 @@ {% include 'sidebar.html' %} - {% include 'admin/sidebar_menu.html' %} + {% include 'sidebar_menu.html' %} {%- endblock sidebar %} diff --git a/dash/templates/admin/delete_provider.html b/dash/templates/admin/delete_provider.html index 9a0a7a7..96bfc01 100644 --- a/dash/templates/admin/delete_provider.html +++ b/dash/templates/admin/delete_provider.html @@ -17,7 +17,7 @@ {% include 'sidebar.html' %} - {% include 'admin/sidebar_menu.html' %} + {% include 'sidebar_menu.html' %} {%- endblock sidebar %} diff --git a/dash/templates/admin/delete_user.html b/dash/templates/admin/delete_user.html index cf90501..77e99d0 100644 --- a/dash/templates/admin/delete_user.html +++ b/dash/templates/admin/delete_user.html @@ -17,7 +17,7 @@ {% include 'sidebar.html' %} - {% include 'admin/sidebar_menu.html' %} + {% include 'sidebar_menu.html' %} {%- endblock sidebar %} diff --git a/dash/templates/admin/edit_provider.html b/dash/templates/admin/edit_provider.html index de0f292..fcdd20a 100644 --- a/dash/templates/admin/edit_provider.html +++ b/dash/templates/admin/edit_provider.html @@ -17,7 +17,7 @@ {% include 'sidebar.html' %} - {% include 'admin/sidebar_menu.html' %} + {% include 'sidebar_menu.html' %} {%- endblock sidebar %} diff --git a/dash/templates/admin/edit_user.html b/dash/templates/admin/edit_user.html index d69a3f3..8b80a53 100644 --- a/dash/templates/admin/edit_user.html +++ b/dash/templates/admin/edit_user.html @@ -17,7 +17,7 @@ {% include 'sidebar.html' %} - {% include 'admin/sidebar_menu.html' %} + {% include 'sidebar_menu.html' %} {%- endblock sidebar %} diff --git a/dash/templates/admin/index.html b/dash/templates/admin/index.html index 20a5311..332b0a7 100644 --- a/dash/templates/admin/index.html +++ b/dash/templates/admin/index.html @@ -13,7 +13,7 @@ {% include 'sidebar.html' %} - {% include 'admin/sidebar_menu.html' %} + {% include 'sidebar_menu.html' %} {%- endblock sidebar %} diff --git a/dash/templates/admin/list_providers.html b/dash/templates/admin/list_providers.html index a639db4..8321f49 100644 --- a/dash/templates/admin/list_providers.html +++ b/dash/templates/admin/list_providers.html @@ -16,7 +16,7 @@ {% include 'sidebar.html' %} - {% include 'admin/sidebar_menu.html' %} + {% include 'sidebar_menu.html' %} {%- endblock sidebar %} diff --git a/dash/templates/admin/list_users.html b/dash/templates/admin/list_users.html index 809bffa..3bf9cdc 100644 --- a/dash/templates/admin/list_users.html +++ b/dash/templates/admin/list_users.html @@ -16,7 +16,7 @@ {% include 'sidebar.html' %} - {% include 'admin/sidebar_menu.html' %} + {% include 'sidebar_menu.html' %} {%- endblock sidebar %} diff --git a/dash/templates/admin/validate_provider.html b/dash/templates/admin/validate_provider.html index 669133a..e82e9fc 100644 --- a/dash/templates/admin/validate_provider.html +++ b/dash/templates/admin/validate_provider.html @@ -17,7 +17,7 @@ {% include 'sidebar.html' %} - {% include 'admin/sidebar_menu.html' %} + {% include 'sidebar_menu.html' %} {%- endblock sidebar %} diff --git a/dash/templates/index.html b/dash/templates/index.html index 6aea025..94139bf 100644 --- a/dash/templates/index.html +++ b/dash/templates/index.html @@ -13,9 +13,7 @@ {% include 'sidebar.html' %} - {% if current_user.role.name == "admin" %} - {% include 'admin/sidebar_menu.html' %} - {% endif %} + {% include 'sidebar_menu.html' %} {%- endblock sidebar %} diff --git a/dash/templates/server/content_header.html b/dash/templates/server/content_header.html new file mode 100644 index 0000000..c1850af --- /dev/null +++ b/dash/templates/server/content_header.html @@ -0,0 +1,8 @@ +

+ {{ title }} + {{ block_description }} +

+ \ No newline at end of file diff --git a/dash/templates/server/index.html b/dash/templates/server/index.html new file mode 100644 index 0000000..9a736ba --- /dev/null +++ b/dash/templates/server/index.html @@ -0,0 +1,121 @@ +{% extends "adminlte/base.html" %} +{% import "adminlte/layout.html" as layout with context %} +{% import "adminlte/widgets.html" as widgets with context %} + +{% block navbar %} + + {% include "navbar.html" %} + +{%- endblock navbar %} + + +{% block sidebar -%} + + {% include 'sidebar.html' %} + + {% include 'sidebar_menu.html' %} + +{%- endblock sidebar %} + + +{% block content_header -%} + {% include 'content_header.html' %} +{%- endblock content_header %} + + +{% block content -%} + + +
+ + {{ + widgets.small_box( + bgcolor="bg-aqua", + header=150, + body="Total Servers", + iconclass="ion ion-cloud", + footerlink="#" + ) + }} + + {{ + widgets.small_box( + bgcolor="bg-green", + header=53, + body="Bounce Rate", + iconclass="ion ion-stats-bars", + footerlink="#" + ) + }} + + {{ + widgets.small_box( + bgcolor="bg-yellow", + header=43, + body="User Registrations", + iconclass="ion ion-person-add", + footerlink="#" + ) + }} + + {{ + widgets.small_box( + bgcolor="bg-red", + header=65, + body="Unique Visitors", + iconclass="ion ion-pie-graph", + footerlink="#" + ) + }} + +
+ + +
+ + {{ + widgets.small_box( + bgcolor="bg-blue", + header=230, + body="Sales", + iconclass="ion ion-ios7-cart-outline", + footerlink="#" + ) + }} + + {{ + widgets.small_box( + bgcolor="bg-purple", + header=80, + percentage=True, + body="Conversion Rate", + iconclass="ion ion-ios7-briefcase-outline", + footerlink="#" + ) + }} + + {{ + widgets.small_box( + bgcolor="bg-teal", + header=14, + body="Notifications", + iconclass="ion ion-ios7-alarm-outline", + footerlink="#" + ) + }} + + {{ + widgets.small_box( + bgcolor="bg-maroon", + header=160, + body="Products", + iconclass="ion ion-ios7-pricetag-outline", + footerlink="#" + ) + }} + +
+{%- endblock content %} diff --git a/dash/templates/server/list_servers.html b/dash/templates/server/list_servers.html new file mode 100644 index 0000000..62d2080 --- /dev/null +++ b/dash/templates/server/list_servers.html @@ -0,0 +1,96 @@ +{% extends "adminlte/base.html" %} +{% import "adminlte/layout.html" as layout with context %} +{% import "adminlte/widgets.html" as widgets with context %} + +{% block title %}Server - {{ title }}{% endblock %} +{% block description %}{{ block_description }}{% endblock %} + +{% block navbar %} + + {% include "navbar.html" %} + +{%- endblock navbar %} + + +{% block sidebar -%} + + {% include 'sidebar.html' %} + + {% include 'sidebar_menu.html' %} + +{%- endblock sidebar %} + + +{% block content_header -%} + {% include 'server/content_header.html' %} +{%- endblock content_header %} + +{% block content -%} + +
+
+
+
+ + + + + + + + + + + + + {% for server in servers %} + + + + + + + + + {% endfor %} + + + + + + + + + + + +
Server NameIPStatusTaskPowerAction
{{ server.name }} + {% for ips in server.networks['private'] %} + {{ ips }} | + {% endfor %} + {{ server.status }}{{ server|attr('OS-EXT-STS:task_state') }} + {{ server|attr('OS-EXT-STS:power_state') }} + {% if server|attr('OS-EXT-STS:power_state') == 1 %} + Running + {% elif server|attr('OS-EXT-STS:power_state') == 2 %} + Shutoff + {% elif server|attr('OS-EXT-STS:power_state') == 3 %} + Paused + {% elif server|attr('OS-EXT-STS:power_state') == 4 %} + Shut Down + {% endif %} + + Edit + | + Delete +
Server NameIPStatusTaskPowerAction
+
+ +
+ +
+ +
+ + +{%- endblock content %} \ No newline at end of file diff --git a/dash/templates/sidebar.html b/dash/templates/sidebar.html index 556c1b2..f62f611 100644 --- a/dash/templates/sidebar.html +++ b/dash/templates/sidebar.html @@ -12,34 +12,4 @@ - \ No newline at end of file diff --git a/dash/templates/sidebar_menu.html b/dash/templates/sidebar_menu.html new file mode 100644 index 0000000..8f42417 --- /dev/null +++ b/dash/templates/sidebar_menu.html @@ -0,0 +1,96 @@ +{% if current_user.role.name == "user" or current_user.role.name == "admin" %} + + +{% endif %} + +{% if current_user.role.name == "admin" %} + + +{% endif %} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 8e93e70..21eed71 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,4 +16,6 @@ alembic blinker itsdangerous flask-principal -requests \ No newline at end of file +requests +python-novaclient +keystoneauth1 \ No newline at end of file