diff --git a/dash/network/forms.py b/dash/network/forms.py index e69de29..83a34cc 100644 --- a/dash/network/forms.py +++ b/dash/network/forms.py @@ -0,0 +1,20 @@ +from flask_wtf import Form +from flask import flash +from wtforms import StringField, PasswordField, BooleanField, SubmitField, \ + ValidationError, SelectField +from wtforms.validators import Required, Length, Email, Regexp, EqualTo, \ + IPAddress +from ..models import User, Role, Provider + +from flask_login import login_user, logout_user, login_required, \ + current_user + +from keystoneauth1 import identity +from keystoneauth1 import session +from neutronclient.v2_0 import client +from novaclient import client as client_nova + +class AssignFloatingIP(Form): + floatingip = StringField('Floating IP', validators=[Required(), Length(1, 128), + IPAddress()]) + server = SelectField('Server', choices = []) \ No newline at end of file diff --git a/dash/network/views.py b/dash/network/views.py index 458d153..643513b 100644 --- a/dash/network/views.py +++ b/dash/network/views.py @@ -1,8 +1,9 @@ -import datetime, requests, json, string, random +import datetime, requests, json, string, random, pprint from keystoneauth1 import identity from keystoneauth1 import session from neutronclient.v2_0 import client +from novaclient import client as client_nova from flask import render_template, redirect, request, url_for, flash @@ -10,6 +11,8 @@ from flask_login import login_user, logout_user, login_required, \ current_user from flask_principal import Identity, AnonymousIdentity, \ identity_changed + +from .forms import AssignFloatingIP from . import network from .. import db @@ -36,10 +39,10 @@ def print_values(val, type): def index(): return render_template('network/index.html') -@network.route('/list-networks', methods=['GET', 'POST']) +@network.route('/list-ips', methods=['GET', 'POST']) @login_required @requires_roles("user","admin") -def list_networks(): +def list_ips(): user = User.query.get_or_404(current_user.id) provider = Provider.query.get_or_404("1") auth = identity.Password(auth_url=provider.url, @@ -50,12 +53,70 @@ def list_networks(): user_domain_name='Default') sess = session.Session(auth=auth) neutron = client.Client(session=sess) + nova = client_nova.Client('2', session=sess) networks = neutron.list_networks() subnets = neutron.list_subnets() routers = neutron.list_routers() - return render_template('network/list_networks.html', + floatingips = neutron.list_floatingips() + ports = neutron.list_ports() + return render_template('network/list_ips.html', title="List Networks", block_description = "manage all of your networks", - user=user, provider=provider,neutron=neutron, + user=user, provider=provider,neutron=neutron,nova=nova, networks=networks,subnets=subnets,routers=routers, + floatingips=floatingips, ports=ports, + sess=sess) + +@network.route('/assign-floatingip/', methods=['GET', 'POST']) +@login_required +@requires_roles("user","admin") +def assign_floatingip(id): + user = User.query.get_or_404(current_user.id) + provider = Provider.query.get_or_404("1") + form = AssignFloatingIP() + 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) + nova = client_nova.Client('2', session=sess) + servers = nova.servers.list() + networks = neutron.list_networks() + subnets = neutron.list_subnets() + routers = neutron.list_routers() + floatingip = neutron.list_floatingips(id=id) + ports = neutron.list_ports() + return render_template('network/assign_floatingip.html', + title="Assign Floating IP", + block_description = "assign floating ip to server", + user=user, provider=provider,neutron=neutron,nova=nova, + networks=networks,subnets=subnets,routers=routers, + floatingip=floatingip, ports=ports,form=form, + servers=servers, + sess=sess) + +@network.route('/edit-subnet/', methods=['GET', 'POST']) +@login_required +@requires_roles("admin") +def edit_subnet(id): + 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) + nova = client_nova.Client('2', session=sess) + subnet = neutron.list_subnets(id=id) + ports = neutron.list_ports(subnet_id=id) + return render_template('network/edit_subnet.html', + title="Edit Subnet", + block_description = "edit and look subnet details", + subnet=subnet,neutron=neutron,ports=ports,nova=nova, sess=sess) \ No newline at end of file diff --git a/dash/server/views.py b/dash/server/views.py index cc8585f..70c6363 100644 --- a/dash/server/views.py +++ b/dash/server/views.py @@ -38,8 +38,10 @@ def list_servers(): sess = session.Session(auth=auth) nova = client.Client('2', session=sess) servers = nova.servers.list() + for_servers = [(server.id, server.name) + for server in 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 + servers=servers,for_servers=for_servers) \ No newline at end of file diff --git a/dash/templates/network/assign_floatingip.html b/dash/templates/network/assign_floatingip.html new file mode 100644 index 0000000..376099c --- /dev/null +++ b/dash/templates/network/assign_floatingip.html @@ -0,0 +1,82 @@ +{% extends "adminlte/base.html" %} +{% import "adminlte/layout.html" as layout with context %} +{% import "adminlte/widgets.html" as widgets with context %} + +{% block title %}Network - {{ 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 'network/content_header.html' %} +{%- endblock content_header %} + +{% block content -%} + + +
+
+ {{ form.hidden_tag() }} + +
+
+
+

Floating IP Address

+
+
+

+ {{ floatingip.floatingips[0].floating_ip_address }} +

+
+
+
+
+
+
+

Server

+
+
+ + {% if form.server.errors %} +
+ {% for error in form.server.errors %} {{ error }} {% endfor %} + {% endif %} +
+
+
+
+
+
+

Action

+
+
+ +
+
+
+
+
+ + +{%- endblock content %} \ No newline at end of file diff --git a/dash/templates/network/edit_subnet.html b/dash/templates/network/edit_subnet.html new file mode 100644 index 0000000..c667024 --- /dev/null +++ b/dash/templates/network/edit_subnet.html @@ -0,0 +1,207 @@ +{% extends "adminlte/base.html" %} +{% import "adminlte/layout.html" as layout with context %} +{% import "adminlte/widgets.html" as widgets with context %} + +{% block title %}Network - {{ 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 'network/content_header.html' %} +{%- endblock content_header %} + +{% block content -%} + + {{ subnet }} +
+
+ +
+
+
+ + + +
+
+
+ +
+
+
+
+

Name

+
+
+

{{ subnet.subnets[0]['name'] }}

+
+
+
+
+
+
+

Network

+
+
+

{{ neutron.list_networks(id=subnet.subnets[0]['network_id']).networks[0]['name']}}

+
+
+
+
+
+
+

CIDR

+
+
+

{{ subnet.subnets[0]['cidr'] }}

+
+
+
+
+
+
+

IP Range

+
+
+

+ {{ subnet.subnets[0].allocation_pools[0]['start'] }} - + {{ subnet.subnets[0].allocation_pools[0]['end'] }} +

+
+
+
+
+ +
+
+
+
+

DHCP

+
+
+

+ {% if subnet.subnets[0]['enable_dhcp'] %} + Enabled + {% else %} + Disabled + {% endif %} +

+
+
+
+
+
+
+

Gateway

+
+
+

{{ subnet.subnets[0]['gateway_ip']}}

+
+
+
+
+
+
+

DNS Nameservers

+
+
+

+ {% for ns in subnet.subnets[0]['dns_nameservers'] %} + {{ ns }} + {% endfor %} +

+
+
+
+
+
+
+

IP Version

+
+
+

+ IPv{{ subnet.subnets[0].ip_version }} +

+
+
+
+
+ +
+
+
+
+

Subnet Ips

+
+
+ + + + + + + + + + + {% for port in ports.ports %} + {% if port.fixed_ips[0]['subnet_id'] == subnet.subnets[0]['id'] %} + + + + + + + {% endif %} + {% endfor %} + + + + + + + + + +
IP AddressAttachedStatusAction
{{ port.fixed_ips[0]['ip_address'] }} + {% set device_owner = port.device_owner.split(':') %} + {% if device_owner[0] == "compute" %} + {{ nova.servers.get(neutron.list_ports(id=port['id']).ports[0]['device_id']).name }} + {% else %} + {{ device_owner[0] }} : {{ device_owner[1] }} + {% endif %} + {{ port['status'] }} + Edit +
IP AddressAttachedStatusAction
+
+ +
+ +
+ +
+ + +{%- endblock content %} \ No newline at end of file diff --git a/dash/templates/network/list_ips.html b/dash/templates/network/list_ips.html new file mode 100644 index 0000000..2b98bd3 --- /dev/null +++ b/dash/templates/network/list_ips.html @@ -0,0 +1,160 @@ +{% extends "adminlte/base.html" %} +{% import "adminlte/layout.html" as layout with context %} +{% import "adminlte/widgets.html" as widgets with context %} + +{% block title %}Network - {{ 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 'network/content_header.html' %} +{%- endblock content_header %} + +{% block content -%} + + +
+
+
+
+

Floating IPs

+
+
+ + + + + + + + + + + + {% for floatingip in floatingips.floatingips %} + {% if floatingip['tenant_id'] == sess.get_project_id() %} + + + + + + + + {% endif %} + {% endfor %} + + + + + + + + + + +
IP AddressServerMapped Private IPStatusAction
{{ floatingip['floating_ip_address'] }} + {% if floatingip['port_id'] %} + {{ nova.servers.get(neutron.list_ports(id=floatingip['port_id']).ports[0]['device_id']).name }} + {% endif %} + + {% if floatingip['port_id'] %} + {{ floatingip['fixed_ip_address'] }} + {% endif %} + {{ floatingip['status'] }} +
+ + + +
+
IP AddressServerMapped Private IPStatusAction
+
+ +
+
+
+

Private Subnets

+
+
+ + + + + + + + + + + {% for subnet in subnets.subnets %} + {% if subnet['tenant_id'] == sess.get_project_id() %} + + + + + + + {% endif %} + {% endfor %} + + + + + + + + + +
NameSubnetNetworkAction
{{ subnet['name'] }} {{ subnet['cidr'] }} {{ neutron.list_networks(id=subnet['network_id']).networks[0].name }} +
+ + + +
+
NameSubnetNetworkAction
+
+ +
+ +
+ +
+ + +{%- endblock content %} \ No newline at end of file diff --git a/dash/templates/network/list_networks.html b/dash/templates/network/list_networks.html deleted file mode 100644 index 2149b3c..0000000 --- a/dash/templates/network/list_networks.html +++ /dev/null @@ -1,83 +0,0 @@ -{% 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 network in networks.networks %} - - {% if network['tenant_id'] == sess.get_project_id() %} - - - - - {% endif %} - - {% endfor %} - - - - - - - - - -
Network NameSubnetsStatusAction
{{ network['name'] }} - {% for subnet in network['subnets'] %} - {{ neutron.list_subnets(subnet).subnets[loop.index0]['name'] }} | - {{ neutron.list_subnets(subnet).subnets[loop.index0]['cidr'] }} -
- {% endfor %} -
{{ network['status'] }} - Edit - | - Delete -
Network NameSubnetsStatusAction
-
- -
- -
- -
- - -{%- endblock content %} \ No newline at end of file diff --git a/dash/templates/server/list_servers.html b/dash/templates/server/list_servers.html index 62d2080..ad62adc 100644 --- a/dash/templates/server/list_servers.html +++ b/dash/templates/server/list_servers.html @@ -26,7 +26,9 @@ {%- endblock content_header %} {% block content -%} - + + {{ servers }}
+ {{ for_servers }}
@@ -45,7 +47,7 @@ {% for server in servers %} - {{ server.name }} + {{ server.name }} - {{ server.id }} {% for ips in server.networks['private'] %} {{ ips }} | diff --git a/dash/templates/sidebar_menu.html b/dash/templates/sidebar_menu.html index cce4dc1..f17a4c0 100644 --- a/dash/templates/sidebar_menu.html +++ b/dash/templates/sidebar_menu.html @@ -76,9 +76,9 @@
  • - + - List Network + List IPs