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 @@ +
widgets.small_box
widget.
+ Server Name | +IP | +Status | +Task | +Power | +Action | +
---|---|---|---|---|---|
{{ 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 Name | +IP | +Status | +Task | +Power | +Action | +