mirror of
https://github.com/peeringdb/peeringdb.git
synced 2024-05-11 05:55:09 +00:00
@@ -826,6 +826,16 @@ class TestJSON(unittest.TestCase):
|
||||
data = self.db_guest.all("poc", visible="Private", limit=100)
|
||||
self.assertEqual(0, len(data))
|
||||
|
||||
##########################################################################
|
||||
|
||||
def test_user_001_GET_as_set(self):
|
||||
data = self.db_guest.all("as_set")
|
||||
networks = Network.objects.filter(status="ok")
|
||||
print(data)
|
||||
for net in networks:
|
||||
self.assertEqual(data[0].get(u"{}".format(net.asn)), net.irr_as_set)
|
||||
|
||||
|
||||
##########################################################################
|
||||
# TESTS WITH USER THAT IS ORGANIZATION MEMBER
|
||||
##########################################################################
|
||||
@@ -1042,6 +1052,28 @@ class TestJSON(unittest.TestCase):
|
||||
|
||||
##########################################################################
|
||||
|
||||
def test_org_admin_002_POST_PUT_DELETE_as_set(self):
|
||||
|
||||
"""
|
||||
The as-set endpoint is readonly, so all of these should
|
||||
fail
|
||||
"""
|
||||
data = self.make_data_net(asn=9000900)
|
||||
|
||||
with self.assertRaises(Exception) as exc:
|
||||
r_data = self.assert_create(self.db_org_admin,"as_set",data)
|
||||
self.assertIn("You do not have permission", str(exc.exception))
|
||||
|
||||
with self.assertRaises(Exception) as exc:
|
||||
self.db_org_admin.update("as_set", {"9000900":"AS-XXX"})
|
||||
self.assertIn("You do not have permission", str(exc.exception))
|
||||
|
||||
with self.assertRaises(Exception) as exc:
|
||||
self.db_org_admin.rm("as_set", SHARED["net_rw_ok"].asn)
|
||||
self.assertIn("You do not have permission", str(exc.exception))
|
||||
|
||||
##########################################################################
|
||||
|
||||
def test_org_admin_002_POST_net_bogon_asn(self):
|
||||
|
||||
# Test bogon asn failure
|
||||
|
||||
@@ -1943,6 +1943,16 @@ class Network(pdb_models.NetworkBase):
|
||||
q = NetworkIXLan.handleref.select_related("ixlan").filter(**filt)
|
||||
return qset.exclude(id__in=[i.network_id for i in q])
|
||||
|
||||
|
||||
@classmethod
|
||||
def as_set_map(cls, qset=None):
|
||||
"""
|
||||
Returns a dict mapping asns to their irr_as_set value
|
||||
"""
|
||||
if not qset:
|
||||
qset = cls.objects.filter(status="ok").order_by("asn")
|
||||
return dict([(net.asn, net.irr_as_set) for net in qset])
|
||||
|
||||
@property
|
||||
def search_result_name(self):
|
||||
"""
|
||||
|
||||
@@ -697,18 +697,52 @@ NetworkIXLanViewSet = model_view_set('NetworkIXLan')
|
||||
OrganizationViewSet = model_view_set('Organization')
|
||||
|
||||
|
||||
class NetworkASNViewSet(NetworkViewSet):
|
||||
class ReadOnlyMixin(object):
|
||||
|
||||
def destroy(self, request, pk, format=None):
|
||||
"""
|
||||
This endpoint is readonly
|
||||
"""
|
||||
return Response(status=status.HTTP_405_METHOD_NOT_ALLOWED)
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
"""
|
||||
This endpoint is readonly
|
||||
"""
|
||||
return Response(status=status.HTTP_405_METHOD_NOT_ALLOWED)
|
||||
|
||||
def update(self, request, *args, **kwargs):
|
||||
"""
|
||||
This endpoint is readonly
|
||||
"""
|
||||
return Response(status=status.HTTP_405_METHOD_NOT_ALLOWED)
|
||||
|
||||
def patch(self, request, *args, **kwargs):
|
||||
"""
|
||||
This endpoint is readonly
|
||||
"""
|
||||
return Response(status=status.HTTP_405_METHOD_NOT_ALLOWED)
|
||||
|
||||
|
||||
|
||||
class ASSetViewSet(ReadOnlyMixin, viewsets.ModelViewSet):
|
||||
"""
|
||||
Rest API end point for Networks (by ASN, readonly)
|
||||
AS-SET endpoint
|
||||
|
||||
lists all as sets mapped by asn
|
||||
"""
|
||||
|
||||
lookup_field = "asn"
|
||||
http_method_names = ["get"]
|
||||
model = Network
|
||||
|
||||
def get_queryset(self):
|
||||
return Network.objects.filter(status="ok").exclude(irr_as_set="")
|
||||
|
||||
def list(self, request):
|
||||
return Response(Network.as_set_map(self.get_queryset()))
|
||||
|
||||
def retrieve(self, request, asn):
|
||||
"""
|
||||
Get network by asn
|
||||
"""
|
||||
|
||||
try:
|
||||
network = Network.objects.get(asn=int(asn))
|
||||
except ValueError:
|
||||
@@ -716,28 +750,11 @@ class NetworkASNViewSet(NetworkViewSet):
|
||||
data={"detail": "Invalid ASN"})
|
||||
except ObjectDoesNotExist:
|
||||
return Response(status=status.HTTP_404_NOT_FOUND)
|
||||
return super(NetworkViewSet, self).retrieve(request, network.id)
|
||||
|
||||
def destroy(self, request, pk, format=None):
|
||||
"""
|
||||
The asn endpoint is readonly, use the /net endpoint to make changes to Network objects
|
||||
"""
|
||||
return Response(status=status.HTTP_405_METHOD_NOT_ALLOWED)
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
"""
|
||||
The asn endpoint is readonly, use the /net endpoint to make changes to Network objects
|
||||
"""
|
||||
return Response(status=status.HTTP_405_METHOD_NOT_ALLOWED)
|
||||
|
||||
def update(self, request, *args, **kwargs):
|
||||
"""
|
||||
The asn endpoint is readonly, use the /net endpoint to make changes to Network objects
|
||||
"""
|
||||
return Response(status=status.HTTP_405_METHOD_NOT_ALLOWED)
|
||||
return Response({network.asn : network.irr_as_set})
|
||||
|
||||
|
||||
# router.register('asn', NetworkASNViewSet, base_name='asn')
|
||||
|
||||
router.register('as_set', ASSetViewSet, base_name='as_set')
|
||||
|
||||
# set here in case we want to add more urls later
|
||||
urls = router.urls
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-4 col-sm-5 col-md-4">{% trans "IRR Macro" %}</div>
|
||||
<div class="col-xs-4 col-sm-5 col-md-4">{% trans "IRR as-set/route-set" %}</div>
|
||||
<div class="col-xs-8 col-sm-7 col-md-8">
|
||||
<div data-edit-type="string"
|
||||
data-edit-value="{{ request.GET.irr_as_set__startswith }}"
|
||||
|
||||
@@ -198,7 +198,7 @@
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-4 col-sm-5 col-md-4">{% trans "IRR Record" %}</div>
|
||||
<div class="col-xs-4 col-sm-5 col-md-4">{% trans "IRR as-set/route-set" %}</div>
|
||||
<div class="col-xs-8 col-sm-7 col-md-8">
|
||||
<div data-edit-type="string"
|
||||
data-edit-name="irr_as_set"></div>
|
||||
|
||||
@@ -61,7 +61,7 @@ Thank you for your suggestion.
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-4 col-sm-5 col-md-4">{% trans "IRR Record" %}</div>
|
||||
<div class="col-xs-4 col-sm-5 col-md-4">{% trans "IRR as-set/route-set" %}</div>
|
||||
<div class="col-xs-8 col-sm-7 col-md-8">
|
||||
<div data-edit-type="string"
|
||||
data-edit-name="irr_as_set"></div>
|
||||
|
||||
@@ -1247,7 +1247,7 @@ def view_network(request, id):
|
||||
"value": network_d.get("asn", dismiss)
|
||||
}, {
|
||||
"name": "irr_as_set",
|
||||
"label": _("IRR Record"),
|
||||
"label": _("IRR as-set/route-set"),
|
||||
"notify_incomplete": True,
|
||||
"value": network_d.get("irr_as_set", dismiss)
|
||||
}, {
|
||||
|
||||
Reference in New Issue
Block a user