Skip to content

Commit

Permalink
Add relations view for data center assets (#3220)
Browse files Browse the repository at this point in the history
At the moment only related cloud hosts are shown. If the idea works
in practice, more relations will be rendered.
  • Loading branch information
romcheg authored and ar4s committed Jan 24, 2018
1 parent 1fd5c78 commit 4c0be63
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/ralph/data_center/admin.py
Expand Up @@ -56,6 +56,7 @@
Database,
VIP
)
from ralph.data_center.views import RelationsView
from ralph.data_importer import resources
from ralph.deployment.mixins import ActiveDeploymentMessageMixin
from ralph.lib.custom_fields.admin import CustomFieldValueAdminMixin
Expand Down Expand Up @@ -330,6 +331,10 @@ class DataCenterAssetSCMInfo(SCMCheckInfo):
url_name = 'datacenterasset_scm_info'


class DataCenterAssetRelationsView(RelationsView):
url = 'datacenterasset_relations'


@register(DataCenterAsset)
class DataCenterAssetAdmin(
SCMStatusCheckInChangeListMixin,
Expand All @@ -352,6 +357,7 @@ class DataCenterAssetAdmin(
DataCenterAssetNetworkView,
DataCenterAssetSecurityInfo,
DataCenterAssetSCMInfo,
DataCenterAssetRelationsView,
DataCenterAssetLicence,
DataCenterAssetSupport,
DataCenterAssetOperation,
Expand Down
@@ -0,0 +1,42 @@
{% extends BASE_TEMPLATE %}
{% load i18n %}

{% block bodyclass %}relations-tab{% endblock%}

{% block view_content %}


<h1>{% trans "Related objects" %}</h1>
{% if related_objects %}
{% for rel_obj_type, objects in related_objects.items %}
{% if rel_obj_type == "cloud_hosts" %}
<h2>{% trans "Cloud hosts" %}</h2>
<table>
<tr>
<th>{% trans "Hostname" %}</th>
<th>{% trans "IP Address" %}</th>
<th>{% trans "Cloud project" %}</th>
<th>{% trans "Cloud provider" %}</th>
</tr>
{% for cloud_host in objects %}
<tr>
<td><a href="{{ cloud_host.get_absolute_url }}">{{ cloud_host.hostname }}</a></td>
<td>
{% for addr in cloud_host.ip_addresses %}
{{ addr }}<br>
{% endfor %}
</td>
<td><a href="{{ cloud_host.cloudproject.get_absolute_url }}">{{ cloud_host.cloudproject.name }}</a></td>
<td><a href="{{ cloud_host.cloudprovider.get_absolute_url }}">{{ cloud_host.cloudprovider.name }}</a></td>
<tr>
{% endfor %}
</table>
{% endif %}
{% endfor %}

{% else %}
<p>{% trans "No related objects found." %}</p>
{% endif %}


{% endblock %}
24 changes: 24 additions & 0 deletions src/ralph/data_center/views.py
@@ -0,0 +1,24 @@
from ralph.admin.views.extra import RalphDetailView


class RelationsView(RalphDetailView):
icon = 'shekel'
label = 'Relations'
name = 'relations'
url_name = 'relations'
template_name = 'data_center/datacenterasset/relations.html'

def _add_cloud_hosts(self, related_objects):
cloud_hosts = list(self.object.cloudhost_set.all())

if cloud_hosts:
related_objects['cloud_hosts'] = cloud_hosts

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

related_objects = {}
self._add_cloud_hosts(related_objects)
context['related_objects'] = related_objects

return context

0 comments on commit 4c0be63

Please sign in to comment.