Servers Module
All about create, edit, update and list virtual servers. AKA instances.
This commit is contained in:
parent
d4d5e9fd80
commit
c59d29cc8b
@ -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')
|
||||
|
5
dash/server/__init__.py
Normal file
5
dash/server/__init__.py
Normal file
@ -0,0 +1,5 @@
|
||||
from flask import Blueprint
|
||||
|
||||
server = Blueprint('server', __name__)
|
||||
|
||||
from . import views
|
0
dash/server/forms.py
Normal file
0
dash/server/forms.py
Normal file
45
dash/server/views.py
Normal file
45
dash/server/views.py
Normal file
@ -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)
|
@ -17,7 +17,7 @@
|
||||
|
||||
{% include 'sidebar.html' %}
|
||||
|
||||
{% include 'admin/sidebar_menu.html' %}
|
||||
{% include 'sidebar_menu.html' %}
|
||||
|
||||
{%- endblock sidebar %}
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
{% include 'sidebar.html' %}
|
||||
|
||||
{% include 'admin/sidebar_menu.html' %}
|
||||
{% include 'sidebar_menu.html' %}
|
||||
|
||||
{%- endblock sidebar %}
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
{% include 'sidebar.html' %}
|
||||
|
||||
{% include 'admin/sidebar_menu.html' %}
|
||||
{% include 'sidebar_menu.html' %}
|
||||
|
||||
{%- endblock sidebar %}
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
{% include 'sidebar.html' %}
|
||||
|
||||
{% include 'admin/sidebar_menu.html' %}
|
||||
{% include 'sidebar_menu.html' %}
|
||||
|
||||
{%- endblock sidebar %}
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
{% include 'sidebar.html' %}
|
||||
|
||||
{% include 'admin/sidebar_menu.html' %}
|
||||
{% include 'sidebar_menu.html' %}
|
||||
|
||||
{%- endblock sidebar %}
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
{% include 'sidebar.html' %}
|
||||
|
||||
{% include 'admin/sidebar_menu.html' %}
|
||||
{% include 'sidebar_menu.html' %}
|
||||
|
||||
{%- endblock sidebar %}
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
{% include 'sidebar.html' %}
|
||||
|
||||
{% include 'admin/sidebar_menu.html' %}
|
||||
{% include 'sidebar_menu.html' %}
|
||||
|
||||
{%- endblock sidebar %}
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
{% include 'sidebar.html' %}
|
||||
|
||||
{% include 'admin/sidebar_menu.html' %}
|
||||
{% include 'sidebar_menu.html' %}
|
||||
|
||||
{%- endblock sidebar %}
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
{% include 'sidebar.html' %}
|
||||
|
||||
{% include 'admin/sidebar_menu.html' %}
|
||||
{% include 'sidebar_menu.html' %}
|
||||
|
||||
{%- endblock sidebar %}
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
{% include 'sidebar.html' %}
|
||||
|
||||
{% include 'admin/sidebar_menu.html' %}
|
||||
{% include 'sidebar_menu.html' %}
|
||||
|
||||
{%- endblock sidebar %}
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
{% include 'sidebar.html' %}
|
||||
|
||||
{% include 'admin/sidebar_menu.html' %}
|
||||
{% include 'sidebar_menu.html' %}
|
||||
|
||||
{%- endblock sidebar %}
|
||||
|
||||
|
@ -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 %}
|
||||
|
||||
|
8
dash/templates/server/content_header.html
Normal file
8
dash/templates/server/content_header.html
Normal file
@ -0,0 +1,8 @@
|
||||
<h1>
|
||||
{{ title }}
|
||||
<small>{{ block_description }}</small>
|
||||
</h1>
|
||||
<ol class="breadcrumb">
|
||||
<li><a href="{{ url_for('server.index') }}"><i class="fa fa-dashboard"></i>Server Home</a></li>
|
||||
<li>{{ title }}</li>
|
||||
</ol>
|
121
dash/templates/server/index.html
Normal file
121
dash/templates/server/index.html
Normal file
@ -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 -%}
|
||||
<h4 class="page-header">
|
||||
Resource Overview
|
||||
<small>Small boxes are used for viewing statistics. To create a small box use the <code>widgets.small_box</code> widget.</small>
|
||||
</h4>
|
||||
<!-- Small boxes (Stat box) -->
|
||||
<div class="row">
|
||||
|
||||
{{
|
||||
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="#"
|
||||
)
|
||||
}}
|
||||
|
||||
</div><!-- /.row -->
|
||||
|
||||
<!-- Small boxes (Stat box) -->
|
||||
<div class="row">
|
||||
|
||||
{{
|
||||
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="#"
|
||||
)
|
||||
}}
|
||||
|
||||
</div><!-- /.row -->
|
||||
{%- endblock content %}
|
96
dash/templates/server/list_servers.html
Normal file
96
dash/templates/server/list_servers.html
Normal file
@ -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 -%}
|
||||
<!-- Main content -->
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<div class="box">
|
||||
<div class="box-body">
|
||||
<table id="example2" class="table table-bordered table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Server Name</th>
|
||||
<th>IP</th>
|
||||
<th>Status</th>
|
||||
<th>Task</th>
|
||||
<th>Power</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for server in servers %}
|
||||
<tr>
|
||||
<td>{{ server.name }}</td>
|
||||
<td>
|
||||
{% for ips in server.networks['private'] %}
|
||||
{{ ips }} |
|
||||
{% endfor %}
|
||||
</td>
|
||||
<td>{{ server.status }}</td>
|
||||
<td>{{ server|attr('OS-EXT-STS:task_state') }}</td>
|
||||
<td>
|
||||
{{ 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 %}
|
||||
</td>
|
||||
<td>
|
||||
<a href="{{ url_for('admin.edit_user_admin', id=user.id) }}">Edit</a>
|
||||
|
|
||||
<a href="{{ url_for('admin.delete_user_admin', id=user.id) }}">Delete</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th>Server Name</th>
|
||||
<th>IP</th>
|
||||
<th>Status</th>
|
||||
<th>Task</th>
|
||||
<th>Power</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
<!-- /.box-body -->
|
||||
</div>
|
||||
<!-- /.box -->
|
||||
</div>
|
||||
<!-- /.col -->
|
||||
</div>
|
||||
<!-- /.row -->
|
||||
|
||||
{%- endblock content %}
|
@ -12,34 +12,4 @@
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<ul class="sidebar-menu">
|
||||
<li class="header">Main Menu</li>
|
||||
<li class="active">
|
||||
<a href="{{ url_for('main.index') }}">
|
||||
<i class="fa fa-dashboard"></i> <span>Dashboard</span>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="treeview">
|
||||
<a href="#">
|
||||
<i class="fa fa-server"></i>
|
||||
<span>Servers</span>
|
||||
<i class="fa fa-angle-left pull-right"></i>
|
||||
</a>
|
||||
<ul class="treeview-menu">
|
||||
<li>
|
||||
<a href="">
|
||||
<i class="fa fa-plus"></i>
|
||||
Create Server
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="">
|
||||
<i class="fa fa-list"></i>
|
||||
List Servers
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<!-- /.sidebar -->
|
96
dash/templates/sidebar_menu.html
Normal file
96
dash/templates/sidebar_menu.html
Normal file
@ -0,0 +1,96 @@
|
||||
{% if current_user.role.name == "user" or current_user.role.name == "admin" %}
|
||||
<!-- User Menu -->
|
||||
<ul class="sidebar-menu">
|
||||
<li class="header">Main Menu</li>
|
||||
<li class="active">
|
||||
<a href="{{ url_for('main.index') }}">
|
||||
<i class="fa fa-dashboard"></i> <span>Dashboard</span>
|
||||
</a>
|
||||
</li>
|
||||
<!-- Server Management Menu -->
|
||||
<li class="treeview">
|
||||
<a href="#">
|
||||
<i class="fa fa-server"></i>
|
||||
<span>Servers</span>
|
||||
<i class="fa fa-angle-left pull-right"></i>
|
||||
</a>
|
||||
<ul class="treeview-menu">
|
||||
<li>
|
||||
<a href="">
|
||||
<i class="fa fa-plus"></i>
|
||||
Create Server
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="">
|
||||
<i class="fa fa-list"></i>
|
||||
List Servers
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
||||
{% if current_user.role.name == "admin" %}
|
||||
<!-- Admin Menu -->
|
||||
<ul class="sidebar-menu">
|
||||
<li class="header">Admin Menu</li>
|
||||
<li>
|
||||
<a href="{{ url_for('admin.index') }}">
|
||||
<i class="fa fa-dashboard"></i> <span>Admin Dashboard</span>
|
||||
</a>
|
||||
</li>
|
||||
<!-- Admin User management menu -->
|
||||
<li class="treeview">
|
||||
<a href="#">
|
||||
<i class="fa fa-users"></i>
|
||||
<span>Users</span>
|
||||
<i class="fa fa-angle-left pull-right"></i>
|
||||
</a>
|
||||
<ul class="treeview-menu">
|
||||
<li>
|
||||
<a href="{{ url_for('admin.create_user_admin') }}">
|
||||
<i class="fa fa-user-plus"></i>
|
||||
Create User
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ url_for('admin.list_users') }}">
|
||||
<i class="fa fa-list"></i>
|
||||
List Users
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="">
|
||||
<i class="fa fa-user-secret"></i>
|
||||
List Resellers
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<!-- Provider management menu -->
|
||||
<li class="treeview">
|
||||
<a href="#">
|
||||
<i class="fa fa-cloud"></i>
|
||||
<span>Providers</span>
|
||||
<i class="fa fa-angle-left pull-right"></i>
|
||||
</a>
|
||||
<ul class="treeview-menu">
|
||||
<li>
|
||||
<a href="{{ url_for('admin.create_provider_admin') }}">
|
||||
<i class="fa fa-cloud-upload"></i>
|
||||
Create Provider
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ url_for('admin.list_providers') }}">
|
||||
<i class="fa fa-list"></i>
|
||||
List Providers
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
{% endif %}
|
@ -16,4 +16,6 @@ alembic
|
||||
blinker
|
||||
itsdangerous
|
||||
flask-principal
|
||||
requests
|
||||
requests
|
||||
python-novaclient
|
||||
keystoneauth1
|
Loading…
x
Reference in New Issue
Block a user