mirror of
https://github.com/ansible/awx.git
synced 2024-11-01 16:51:11 +03:00
Adds JSON and YAML export of the network topology.
Adds views that export the entire network topology as JSON and YAML.
This commit is contained in:
parent
257cf6a7d7
commit
640e687f3e
@ -2,6 +2,7 @@
|
||||
from awx.network_ui.models import Topology, Device, Link, Interface
|
||||
from django.db.models import Q
|
||||
import yaml
|
||||
import json
|
||||
|
||||
NetworkAnnotatedInterface = Interface.objects.values('name',
|
||||
'id',
|
||||
@ -13,7 +14,7 @@ NetworkAnnotatedInterface = Interface.objects.values('name',
|
||||
'to_link__from_interface__name')
|
||||
|
||||
|
||||
def yaml_serialize_topology(topology_id):
|
||||
def topology_data(topology_id):
|
||||
|
||||
data = dict(devices=[],
|
||||
links=[])
|
||||
@ -54,5 +55,12 @@ def yaml_serialize_topology(topology_id):
|
||||
from_interface_id=link.from_interface.id,
|
||||
to_interface_id=link.to_interface.id,
|
||||
network=link.pk))
|
||||
return data
|
||||
|
||||
return yaml.safe_dump(data, default_flow_style=False)
|
||||
|
||||
def yaml_serialize_topology(topology_id):
|
||||
return yaml.safe_dump(topology_data(topology_id), default_flow_style=False)
|
||||
|
||||
|
||||
def json_serialize_topology(topology_id):
|
||||
return json.dumps(topology_data(topology_id))
|
||||
|
11
awx/network_ui/templates/network_ui/index.html
Normal file
11
awx/network_ui/templates/network_ui/index.html
Normal file
@ -0,0 +1,11 @@
|
||||
<ul>
|
||||
<li><a href="/#/topology/">New</a></li>
|
||||
{%for o in topologies%}
|
||||
<li>
|
||||
<a href="/#/topology?topology_id={{o.pk}}">{{o.pk}} {{o}}</a>
|
||||
{%for device in o.device_set.all%}
|
||||
{{device}}
|
||||
{%endfor%}
|
||||
</li>
|
||||
{%endfor%}
|
||||
</ul>
|
@ -1,11 +0,0 @@
|
||||
<ul>
|
||||
<li><a href="/static/prototype/index.html">New</a></li>
|
||||
{%for o in topologies%}
|
||||
<li>
|
||||
<a href="/static/prototype/index.html#!?topology_id={{o.pk}}">{{o.pk}} {{o}}</a>
|
||||
{%for device in o.device_set.all%}
|
||||
{{device}}
|
||||
{%endfor%}
|
||||
</li>
|
||||
{%endfor%}
|
||||
</ul>
|
@ -6,6 +6,8 @@ import awx.network_ui.routing
|
||||
|
||||
app_name = 'network_ui'
|
||||
urlpatterns = [
|
||||
url(r'^$', views.index, name='index'),
|
||||
url(r'^topology.json$', views.json_topology_data, name='json_topology_data'),
|
||||
url(r'^topology.yaml$', views.yaml_topology_data, name='json_topology_data'),
|
||||
url(r'^$', views.index, name='index'),
|
||||
]
|
||||
|
||||
|
@ -1,8 +1,36 @@
|
||||
from django.shortcuts import render
|
||||
from django import forms
|
||||
from django.http import JsonResponse, HttpResponseBadRequest, HttpResponse
|
||||
import yaml
|
||||
|
||||
|
||||
# Create your views here.
|
||||
from .models import Topology
|
||||
from .serializers import topology_data
|
||||
|
||||
|
||||
def index(request):
|
||||
return render(request, "network_ui/index.html", dict(topologies=Topology.objects.all().order_by('-pk')))
|
||||
|
||||
|
||||
class TopologyForm(forms.Form):
|
||||
topology_id = forms.IntegerField()
|
||||
|
||||
|
||||
def json_topology_data(request):
|
||||
form = TopologyForm(request.GET)
|
||||
if form.is_valid():
|
||||
return JsonResponse(topology_data(form.cleaned_data['topology_id']))
|
||||
else:
|
||||
return HttpResponseBadRequest(form.errors)
|
||||
|
||||
|
||||
def yaml_topology_data(request):
|
||||
form = TopologyForm(request.GET)
|
||||
if form.is_valid():
|
||||
return HttpResponse(yaml.safe_dump(topology_data(form.cleaned_data['topology_id']),
|
||||
default_flow_style=False),
|
||||
content_type='application/yaml')
|
||||
else:
|
||||
return HttpResponseBadRequest(form.errors)
|
||||
|
||||
|
@ -15,6 +15,7 @@ urlpatterns = [
|
||||
url(r'^api/', include('awx.api.urls', namespace='api')),
|
||||
url(r'^sso/', include('awx.sso.urls', namespace='sso')),
|
||||
url(r'^sso/', include('social_django.urls', namespace='social')),
|
||||
url(r'^network_ui/', include('awx.network_ui.urls', namespace='network_uiui', app_name='network_ui')),
|
||||
url(r'^(?:api/)?400.html$', handle_400),
|
||||
url(r'^(?:api/)?403.html$', handle_403),
|
||||
url(r'^(?:api/)?404.html$', handle_404),
|
||||
|
Loading…
Reference in New Issue
Block a user