Network Module

List networks
This commit is contained in:
kelepirci 2016-09-06 00:20:22 +03:00
parent c59d29cc8b
commit 86628b054e
21 changed files with 801 additions and 4 deletions

View File

@ -60,6 +60,18 @@ def create_app(config_name):
# server application
from .server import server as server_blueprint
dash.register_blueprint(server_blueprint, url_prefix='/server')
# image application
from .image import image as image_blueprint
dash.register_blueprint(image_blueprint, url_prefix='/image')
# security application
from .security import security as security_blueprint
dash.register_blueprint(security_blueprint, url_prefix='/security')
# network application
from .network import network as network_blueprint
dash.register_blueprint(network_blueprint, url_prefix='/network')
# admin application
from .admin import admin as admin_blueprint

5
dash/image/__init__.py Normal file
View File

@ -0,0 +1,5 @@
from flask import Blueprint
image = Blueprint('image', __name__)
from . import views

0
dash/image/forms.py Normal file
View File

46
dash/image/views.py Normal file
View File

@ -0,0 +1,46 @@
import datetime, requests, json, string, random
import humanize as humanize
from keystoneauth1 import loading
from keystoneauth1 import session
import glanceclient.v2.client as glclient
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 image
from .. import db
from ..models import User, Role, Provider
from ..email import send_email
from ..decorators import requires_roles
@image.route('/', methods=['GET', 'POST'])
@login_required
@requires_roles("user","admin")
def index():
return render_template('image/index.html')
@image.route('/list-images', methods=['GET', 'POST'])
@login_required
@requires_roles("user","admin")
def list_images():
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)
glance = glclient.Client('2', session=sess)
images = glance.images.list()
return render_template('image/list_images.html',humanize=humanize,
title="List Imags",
block_description = "list images and applications",
user=user, provider=provider,glance=glance,
images=images)

5
dash/network/__init__.py Normal file
View File

@ -0,0 +1,5 @@
from flask import Blueprint
network = Blueprint('network', __name__)
from . import views

0
dash/network/forms.py Normal file
View File

61
dash/network/views.py Normal file
View File

@ -0,0 +1,61 @@
import datetime, requests, json, string, random
from keystoneauth1 import identity
from keystoneauth1 import session
from neutronclient.v2_0 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 network
from .. import db
from ..models import User, Role, Provider
from ..email import send_email
from ..decorators import requires_roles
def print_values(val, type):
if type == 'ports':
val_list = val['ports']
if type == 'networks':
val_list = val['networks']
if type == 'routers':
val_list = val['routers']
for p in val_list:
for k, v in p.items():
print("%s : %s" % (k, v))
print('\n')
@network.route('/', methods=['GET', 'POST'])
@login_required
@requires_roles("user","admin")
def index():
return render_template('network/index.html')
@network.route('/list-networks', methods=['GET', 'POST'])
@login_required
@requires_roles("user","admin")
def list_networks():
user = User.query.get_or_404(current_user.id)
provider = Provider.query.get_or_404("1")
auth = identity.Password(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)
neutron = client.Client(session=sess)
networks = neutron.list_networks()
subnets = neutron.list_subnets()
routers = neutron.list_routers()
return render_template('network/list_networks.html',
title="List Networks",
block_description = "manage all of your networks",
user=user, provider=provider,neutron=neutron,
networks=networks,subnets=subnets,routers=routers,
sess=sess)

View File

@ -0,0 +1,5 @@
from flask import Blueprint
security = Blueprint('security', __name__)
from . import views

0
dash/security/forms.py Normal file
View File

22
dash/security/views.py Normal file
View File

@ -0,0 +1,22 @@
import datetime, requests, json, string, random
from keystoneauth1 import loading
from keystoneauth1 import session
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 security
from .. import db
from ..models import User, Role, Provider
from ..email import send_email
from ..decorators import requires_roles
@security.route('/', methods=['GET', 'POST'])
@login_required
@requires_roles("user","admin")
def index():
return render_template('security/index.html')

View 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>Image & Application Home</a></li>
<li>{{ title }}</li>
</ol>

View 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 %}

View File

@ -0,0 +1,87 @@
{% 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>Image Name</th>
<th>Type</th>
<th>Status</th>
<th>Format</th>
<th>Size</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{% for image in images %}
<tr>
<td>{{ image.name.title() }}</td>
<td>
{% if image.image_location %}
{{ image.image_location.title() }}
{% else %}
Image
{% endif %}
</td>
<td>{{ image.status.title() }}</td>
<td>{{ image.disk_format.upper() }}</td>
<td>{{ humanize.naturalsize(image.size) }}</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>Image Name</th>
<th>Type</th>
<th>Status</th>
<th>Format</th>
<th>Size</th>
<th>Action</th>
</tr>
</tfoot>
</table>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
{%- endblock content %}

View 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>Neworking Home</a></li>
<li>{{ title }}</li>
</ol>

View 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 %}

View File

@ -0,0 +1,83 @@
{% 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>Network Name</th>
<th>Subnets</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{% for network in networks.networks %}
<tr>
{% if network['tenant_id'] == sess.get_project_id() %}
<td>{{ network['name'] }}</td>
<td>
{% for subnet in network['subnets'] %}
{{ neutron.list_subnets(subnet).subnets[loop.index0]['name'] }} |
{{ neutron.list_subnets(subnet).subnets[loop.index0]['cidr'] }}
<br />
{% endfor %}
</td>
<td>{{ network['status'] }}</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>
{% endif %}
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr>
<th>Network Name</th>
<th>Subnets</th>
<th>Status</th>
<th>Action</th>
</tr>
</tfoot>
</table>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
{%- endblock content %}

View 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>Security Home</a></li>
<li>{{ title }}</li>
</ol>

View 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 %}

View File

@ -9,7 +9,7 @@
</li>
<!-- Server Management Menu -->
<li class="treeview">
<a href="#">
<a href="{{ url_for('server.index') }}">
<i class="fa fa-server"></i>
<span>Servers</span>
<i class="fa fa-angle-left pull-right"></i>
@ -22,7 +22,7 @@
</a>
</li>
<li>
<a href="">
<a href=" {{ url_for('server.list_servers') }} ">
<i class="fa fa-list"></i>
List Servers
</a>
@ -32,6 +32,87 @@
</ul>
{% endif %}
{% if current_user.role.name == "user" or current_user.role.name == "admin" %}
<!-- Image Management Menu -->
<ul class="sidebar-menu">
<li class="treeview">
<a href="#">
<i class="fa fa-picture-o"></i>
<span>Images</span>
<i class="fa fa-angle-left pull-right"></i>
</a>
<ul class="treeview-menu">
<li>
<a href="{{ url_for('image.index') }}">
<i class="fa fa-plus"></i>
Create Image
</a>
</li>
<li>
<a href="{{ url_for('image.list_images') }}">
<i class="fa fa-list"></i>
List Images
</a>
</li>
</ul>
</li>
</ul>
{% endif %}
{% if current_user.role.name == "user" or current_user.role.name == "admin" %}
<!-- Networking Management Menu -->
<ul class="sidebar-menu">
<li class="treeview">
<a href="#">
<i class="fa fa-arrows"></i>
<span>Networking</span>
<i class="fa fa-angle-left pull-right"></i>
</a>
<ul class="treeview-menu">
<li>
<a href="{{ url_for('network.index') }}">
<i class="fa fa-plus"></i>
Create Network
</a>
</li>
<li>
<a href="{{ url_for('network.index') }}">
<i class="fa fa-list"></i>
List Network
</a>
</li>
</ul>
</li>
</ul>
{% endif %}
{% if current_user.role.name == "user" or current_user.role.name == "admin" %}
<!-- Security Management Menu -->
<ul class="sidebar-menu">
<li class="treeview">
<a href="#">
<i class="fa fa-shield"></i>
<span>Security</span>
<i class="fa fa-angle-left pull-right"></i>
</a>
<ul class="treeview-menu">
<li>
<a href="{{ url_for('security.index') }}">
<i class="fa fa-plus"></i>
List Security
</a>
</li>
<li>
<a href="{{ url_for('security.index') }}">
<i class="fa fa-list"></i>
List Security
</a>
</li>
</ul>
</li>
</ul>
{% endif %}
{% if current_user.role.name == "admin" %}
<!-- Admin Menu -->
<ul class="sidebar-menu">

View File

@ -2,9 +2,9 @@
Account
Dash Board
Servers
Images & APPs
Security
Images
Networking
Security
API
Logs
Settings

View File

@ -18,4 +18,7 @@ itsdangerous
flask-principal
requests
python-novaclient
python-glanceclient
python-neutronclient
humanize
keystoneauth1