diff --git a/app/network/views.py b/app/network/views.py index 2636b81adf7e989c3c55816ab4285a42fc57e0c8..11f0f2a5d5e661cf681bf449c9a084379c3b38dd 100644 --- a/app/network/views.py +++ b/app/network/views.py @@ -585,6 +585,13 @@ def list_networks(): return render_template("network/networks.html", networks=networks) +@bp.route("/networks/view/<vlan_name>") +@login_required +def view_network(vlan_name): + network = models.Network.query.filter_by(vlan_name=vlan_name).first_or_404() + return render_template("network/view_network.html", network=network) + + @bp.route("/networks/create", methods=("GET", "POST")) @login_groups_accepted("admin") def create_network(): diff --git a/app/static/js/hosts.js b/app/static/js/hosts.js index 8336fe3d9fef6c2527e2c7b9bb2e7f5d6e1169dc..b6c590b3912e615fe0ac7fe72cde3e752ed406df 100644 --- a/app/static/js/hosts.js +++ b/app/static/js/hosts.js @@ -9,6 +9,15 @@ $(document).ready(function() { return '<a href="'+ url + '">' + data + '</a>'; } + function render_network_link(data) { + // render funtion to create link to Network view page + if ( data === null ) { + return data; + } + var url = $SCRIPT_ROOT + "/network/networks/view/" + data; + return '<a href="'+ url + '">' + data + '</a>'; + } + if( $("#hostForm").length || $("#editHostForm").length ) { var hostVarsEditor = CodeMirror.fromTextArea(ansible_vars, { lineNumbers: true, @@ -158,6 +167,9 @@ $(document).ready(function() { defaultContent: "", orderable: false }, { data: 'interfaces.0.network', + render: function(data, type, row) { + return render_network_link(data); + }, defaultContent: "", orderable: false } ] diff --git a/app/templates/_helpers.html b/app/templates/_helpers.html index 29c208444355d2644b858c8a8fc551640896d619..353685d4d4ae4af70ef5cfeeee4fff497fb8ca64 100644 --- a/app/templates/_helpers.html +++ b/app/templates/_helpers.html @@ -39,6 +39,10 @@ {% if active %}active{% endif %} {%- endmacro %} +{% macro link_to_network(network) -%} + <a href="{{ url_for('network.view_network', vlan_name=network.vlan_name) }}">{{ network.vlan_name }}</a> +{%- endmacro %} + {% macro link_to_host(host) -%} <a href="{{ url_for('network.view_host', name=host.name) }}">{{ host.fqdn|default(host.name) }}</a> {%- endmacro %} @@ -49,6 +53,12 @@ {% endfor %} {%- endmacro %} +{% macro link_to_interfaces_host(interfaces) -%} + {% for interface in interfaces %} + {{ link_to_host(interface.host) }} + {% endfor %} +{%- endmacro %} + {% macro link_to_item(ics_id) -%} {% if ics_id %} <a href="{{ url_for('inventory.view_item', ics_id=ics_id) }}">{{ ics_id }}</a> diff --git a/app/templates/network/networks.html b/app/templates/network/networks.html index f28dd3ae0f797fb0bd4035e0a556aa2241bf2b70..2b97346bf709df8d9924f4fdf24331417c5c700c 100644 --- a/app/templates/network/networks.html +++ b/app/templates/network/networks.html @@ -1,5 +1,5 @@ {% extends "base-fluid.html" %} -{% from "_helpers.html" import is_active %} +{% from "_helpers.html" import is_active, link_to_network %} {% block title %}Networks - CSEntry{% endblock %} @@ -36,9 +36,9 @@ <tbody> {% for network in networks %} <tr> - <td>{{ network.vlan_name }}</td> + <td>{{ link_to_network(network) }}</td> <td>{{ network.vlan_id }}</td> - <td>{{ network.description }}</td> + <td>{{ network.description | safe }}</td> <td>{{ network.address }}</td> <td>{{ network.first_ip }}</td> <td>{{ network.last_ip }}</td> diff --git a/app/templates/network/view_host.html b/app/templates/network/view_host.html index 38c9b450f7149cae3ba11f4e30b2c10992769f31..a1dda629ba7cf27828dbaf15c6e86e6e65855f45 100644 --- a/app/templates/network/view_host.html +++ b/app/templates/network/view_host.html @@ -1,6 +1,6 @@ {% extends "network/hosts.html" %} {% from "_helpers.html" import link_to_items, link_to_stack_members, - link_to_ansible_groups, + link_to_ansible_groups, link_to_network, delete_button_with_confirmation, render_field, submit_button_with_confirmation %} {% block title %}View Host - CSEntry{% endblock %} @@ -121,7 +121,7 @@ <td>{{ interface.cnames | join(' ') }}</td> <td>{{ interface.ip }}</td> <td>{{ interface.mac }}</td> - <td>{{ interface.network }}</td> + <td>{{ link_to_network(interface.network) }}</td> <td>{{ interface.tags | join(' ') }}</td> </tr> {% endfor %} diff --git a/app/templates/network/view_network.html b/app/templates/network/view_network.html new file mode 100644 index 0000000000000000000000000000000000000000..8527eb91b916803b86e88b9cb2978ad600b2e8ff --- /dev/null +++ b/app/templates/network/view_network.html @@ -0,0 +1,45 @@ +{% extends "network/networks.html" %} +{% from "_helpers.html" import link_to_interfaces_host %} + +{% block title %}View Ansible network - CSEntry{% endblock %} + +{% block networks_nav %} + <li class="nav-item"> + <a class="nav-link active" href="{{ url_for('network.view_network', vlan_name=network.vlan_name) }}">View network</a> + </li> +{% endblock %} + +{% block networks_main %} + <div class="row"> + <div class="col-sm-9"> + <dl class="row"> + <dt class="col-sm-3">Vlan name</dt> + <dd class="col-sm-9">{{ network.vlan_name }}</dd> + <dt class="col-sm-3">Vlan id</dt> + <dd class="col-sm-9">{{ network.vlan_id }}</dd> + <dt class="col-sm-3">Description</dt> + <dd class="col-sm-9">{{ network.description | safe }}</dd> + <dt class="col-sm-3">Address</dt> + <dd class="col-sm-9">{{ network.address }}</dd> + <dt class="col-sm-3">First IP</dt> + <dd class="col-sm-9">{{ network.first_ip }}</dd> + <dt class="col-sm-3">Last IP</dt> + <dd class="col-sm-9">{{ network.last_ip }}</dd> + <dt class="col-sm-3">Gateway</dt> + <dd class="col-sm-9">{{ network.gateway }}</dd> + <dt class="col-sm-3">Network Scope</dt> + <dd class="col-sm-9">{{ network.scope }}</dd> + <dt class="col-sm-3">Domain</dt> + <dd class="col-sm-9">{{ network.domain }}</dd> + <dt class="col-sm-3">Admin only</dt> + <dd class="col-sm-9">{{ network.admin_only }}</dd> + <dt class="col-sm-3">Hosts</dt> + <dd class="col-sm-9">{{ link_to_interfaces_host(network.interfaces) }}</dd> + <dt class="col-sm-3">Created by</dt> + <dd class="col-sm-9">{{ network.user }}</dd> + <dt class="col-sm-3">Created at</dt> + <dd class="col-sm-9">{{ network.created_at }}</dd> + </dl> + </div> + </div> +{%- endblock %}