Exemple #1
0
class ClusterViewSet(CustomFieldModelViewSet):
    queryset = Cluster.objects.prefetch_related("type", "group", "tenant", "site", "tags").annotate(
        device_count=count_related(Device, "cluster"),
        virtualmachine_count=count_related(VirtualMachine, "cluster"),
    )
    serializer_class = serializers.ClusterSerializer
    filterset_class = filters.ClusterFilterSet
Exemple #2
0
class DeviceRoleViewSet(CustomFieldModelViewSet):
    queryset = DeviceRole.objects.annotate(
        device_count=count_related(Device, "device_role"),
        virtualmachine_count=count_related(VirtualMachine, "role"),
    )
    serializer_class = serializers.DeviceRoleSerializer
    filterset_class = filters.DeviceRoleFilterSet
Exemple #3
0
class PlatformViewSet(CustomFieldModelViewSet):
    queryset = Platform.objects.annotate(
        device_count=count_related(Device, "platform"),
        virtualmachine_count=count_related(VirtualMachine, "platform"),
    )
    serializer_class = serializers.PlatformSerializer
    filterset_class = filters.PlatformFilterSet
Exemple #4
0
class RackViewSet(StatusViewSetMixin, CustomFieldModelViewSet):
    queryset = Rack.objects.prefetch_related(
        "site", "group__site", "status", "role", "tenant", "tags").annotate(
            device_count=count_related(Device, "rack"),
            powerfeed_count=count_related(PowerFeed, "rack"),
        )
    serializer_class = serializers.RackSerializer
    filterset_class = filters.RackFilterSet

    @swagger_auto_schema(
        responses={200: serializers.RackUnitSerializer(many=True)},
        query_serializer=serializers.RackElevationDetailFilterSerializer,
    )
    @action(detail=True)
    def elevation(self, request, pk=None):
        """
        Rack elevation representing the list of rack units. Also supports rendering the elevation as an SVG.
        """
        rack = get_object_or_404(self.queryset, pk=pk)
        serializer = serializers.RackElevationDetailFilterSerializer(
            data=request.GET)
        serializer.is_valid(raise_exception=True)
        data = serializer.validated_data

        if data["render"] == "svg":
            # Render and return the elevation as an SVG drawing with the correct content type
            drawing = rack.get_elevation_svg(
                face=data["face"],
                user=request.user,
                unit_width=data["unit_width"],
                unit_height=data["unit_height"],
                legend_width=data["legend_width"],
                include_images=data["include_images"],
                base_url=request.build_absolute_uri("/"),
            )
            return HttpResponse(drawing.tostring(),
                                content_type="image/svg+xml")

        else:
            # Return a JSON representation of the rack units in the elevation
            elevation = rack.get_rack_units(
                face=data["face"],
                user=request.user,
                exclude=data["exclude"],
                expand_devices=data["expand_devices"],
            )

            # Enable filtering rack units by ID
            q = data["q"]
            if q:
                elevation = [
                    u for u in elevation
                    if q in str(u["id"]) or q in str(u["name"])
                ]

            page = self.paginate_queryset(elevation)
            if page is not None:
                rack_units = serializers.RackUnitSerializer(
                    page, many=True, context={"request": request})
                return self.get_paginated_response(rack_units.data)
Exemple #5
0
class RoleViewSet(CustomFieldModelViewSet):
    queryset = Role.objects.annotate(
        prefix_count=count_related(Prefix, "role"),
        vlan_count=count_related(VLAN, "role"),
    )
    serializer_class = serializers.RoleSerializer
    filterset_class = filters.RoleFilterSet
Exemple #6
0
class VRFViewSet(CustomFieldModelViewSet):
    queryset = (VRF.objects.prefetch_related("tenant").prefetch_related(
        "import_targets", "export_targets", "tags").annotate(
            ipaddress_count=count_related(IPAddress, "vrf"),
            prefix_count=count_related(Prefix, "vrf"),
        ))
    serializer_class = serializers.VRFSerializer
    filterset_class = filters.VRFFilterSet
Exemple #7
0
class ManufacturerViewSet(CustomFieldModelViewSet):
    queryset = Manufacturer.objects.annotate(
        devicetype_count=count_related(DeviceType, "manufacturer"),
        inventoryitem_count=count_related(InventoryItem, "manufacturer"),
        platform_count=count_related(Platform, "manufacturer"),
    )
    serializer_class = serializers.ManufacturerSerializer
    filterset_class = filters.ManufacturerFilterSet
Exemple #8
0
class ClusterListView(generic.ObjectListView):
    permission_required = "virtualization.view_cluster"
    queryset = Cluster.objects.annotate(
        device_count=count_related(Device, "cluster"),
        vm_count=count_related(VirtualMachine, "cluster"),
    )
    table = tables.ClusterTable
    filterset = filters.ClusterFilterSet
    filterset_form = forms.ClusterFilterForm
Exemple #9
0
class RIRListView(generic.ObjectListView):
    queryset = RIR.objects.annotate(
        aggregate_count=count_related(Aggregate, "rir"))
    filterset = filters.RIRFilterSet
    filterset_form = forms.RIRFilterForm
    table = tables.RIRTable
    template_name = "ipam/rir_list.html"
Exemple #10
0
class DeviceTypeViewSet(CustomFieldModelViewSet):
    queryset = DeviceType.objects.prefetch_related(
        "manufacturer",
        "tags").annotate(device_count=count_related(Device, "device_type"))
    serializer_class = serializers.DeviceTypeSerializer
    filterset_class = filters.DeviceTypeFilterSet
    brief_prefetch_fields = ["manufacturer"]
Exemple #11
0
class TenantViewSet(CustomFieldModelViewSet):
    queryset = Tenant.objects.prefetch_related("group", "tags").annotate(
        circuit_count=count_related(Circuit, "tenant"),
        device_count=count_related(Device, "tenant"),
        ipaddress_count=count_related(IPAddress, "tenant"),
        prefix_count=count_related(Prefix, "tenant"),
        rack_count=count_related(Rack, "tenant"),
        site_count=count_related(Site, "tenant"),
        virtualmachine_count=count_related(VirtualMachine, "tenant"),
        vlan_count=count_related(VLAN, "tenant"),
        vrf_count=count_related(VRF, "tenant"),
    )
    serializer_class = serializers.TenantSerializer
    filterset_class = filters.TenantFilterSet
Exemple #12
0
class VLANViewSet(StatusViewSetMixin, CustomFieldModelViewSet):
    queryset = VLAN.objects.prefetch_related(
        "group",
        "site",
        "status",
        "role",
        "tags",
        "tenant",
    ).annotate(prefix_count=count_related(Prefix, "vlan"))
    serializer_class = serializers.VLANSerializer
    filterset_class = filters.VLANFilterSet
Exemple #13
0
    def get_extra_context(self, request, instance):

        # Clusters
        clusters = (
            Cluster.objects.restrict(request.user, "view")
            .filter(group=instance)
            .prefetch_related("type", "site", "tenant")
        ).annotate(
            device_count=count_related(Device, "cluster"),
            vm_count=count_related(VirtualMachine, "cluster"),
        )

        cluster_table = tables.ClusterTable(clusters)
        cluster_table.columns.hide("group")

        paginate = {
            "paginator_class": EnhancedPaginator,
            "per_page": get_paginate_count(request),
        }
        RequestConfig(request, paginate).configure(cluster_table)

        return {
            "cluster_table": cluster_table,
        }
Exemple #14
0
class TagViewSet(CustomFieldModelViewSet):
    queryset = Tag.objects.annotate(tagged_items=count_related(TaggedItem, "tag"))
    serializer_class = serializers.TagSerializerVersion13
    filterset_class = filters.TagFilterSet

    def get_serializer_class(self):
        if (
            not self.brief
            and not getattr(self, "swagger_fake_view", False)
            and (
                not hasattr(self.request, "major_version")
                or self.request.major_version > 1
                or (self.request.major_version == 1 and self.request.minor_version < 3)
            )
        ):
            return serializers.TagSerializer
        return super().get_serializer_class()
Exemple #15
0
class SiteViewSet(StatusViewSetMixin, CustomFieldModelViewSet):
    queryset = Site.objects.prefetch_related(
        "region", "status", "tenant", "tags").annotate(
            device_count=count_related(Device, "site"),
            rack_count=count_related(Rack, "site"),
            prefix_count=count_related(Prefix, "site"),
            vlan_count=count_related(VLAN, "site"),
            circuit_count=count_related(Circuit, "terminations__site"),
            virtualmachine_count=count_related(VirtualMachine,
                                               "cluster__site"),
        )
    serializer_class = serializers.SiteSerializer
    filterset_class = filters.SiteFilterSet
Exemple #16
0
class ProviderBulkDeleteView(generic.BulkDeleteView):
    queryset = Provider.objects.annotate(
        count_circuits=count_related(Circuit, "provider"))
    filterset = filters.ProviderFilterSet
    table = tables.ProviderTable
Exemple #17
0
class ProviderListView(generic.ObjectListView):
    queryset = Provider.objects.annotate(
        count_circuits=count_related(Circuit, "provider"))
    filterset = filters.ProviderFilterSet
    filterset_form = forms.ProviderFilterForm
    table = tables.ProviderTable
Exemple #18
0
class PowerPanelViewSet(ModelViewSet):
    queryset = PowerPanel.objects.prefetch_related(
        "site", "rack_group").annotate(
            powerfeed_count=count_related(PowerFeed, "power_panel"))
    serializer_class = serializers.PowerPanelSerializer
    filterset_class = filters.PowerPanelFilterSet
Exemple #19
0
class ClusterGroupViewSet(CustomFieldModelViewSet):
    queryset = ClusterGroup.objects.annotate(cluster_count=count_related(Cluster, "group"))
    serializer_class = serializers.ClusterGroupSerializer
    filterset_class = filters.ClusterGroupFilterSet
Exemple #20
0
class ClusterTypeViewSet(CustomFieldModelViewSet):
    queryset = ClusterType.objects.annotate(cluster_count=count_related(Cluster, "type"))
    serializer_class = serializers.ClusterTypeSerializer
    filterset_class = filters.ClusterTypeFilterSet
Exemple #21
0
class VLANGroupBulkDeleteView(generic.BulkDeleteView):
    queryset = VLANGroup.objects.prefetch_related("site").annotate(vlan_count=count_related(VLAN, "group"))
    filterset = filters.VLANGroupFilterSet
    table = tables.VLANGroupTable
Exemple #22
0
class RIRViewSet(CustomFieldModelViewSet):
    queryset = RIR.objects.annotate(
        aggregate_count=count_related(Aggregate, "rir"))
    serializer_class = serializers.RIRSerializer
    filterset_class = filters.RIRFilterSet
Exemple #23
0
class RoleListView(generic.ObjectListView):
    queryset = Role.objects.annotate(
        prefix_count=count_related(Prefix, "role"),
        vlan_count=count_related(VLAN, "role"),
    )
    table = tables.RoleTable
Exemple #24
0
class RIRBulkDeleteView(generic.BulkDeleteView):
    queryset = RIR.objects.annotate(aggregate_count=count_related(Aggregate, "rir"))
    filterset = filters.RIRFilterSet
    table = tables.RIRTable
Exemple #25
0
class ClusterGroupListView(generic.ObjectListView):
    queryset = ClusterGroup.objects.annotate(
        cluster_count=count_related(Cluster, "group"))
    table = tables.ClusterGroupTable
Exemple #26
0
class ClusterTypeBulkDeleteView(generic.BulkDeleteView):
    queryset = ClusterType.objects.annotate(
        cluster_count=count_related(Cluster, "type"))
    table = tables.ClusterTypeTable
Exemple #27
0
class CircuitTypeListView(generic.ObjectListView):
    queryset = CircuitType.objects.annotate(
        circuit_count=count_related(Circuit, "type"))
    table = tables.CircuitTypeTable
Exemple #28
0
class VLANGroupListView(generic.ObjectListView):
    queryset = VLANGroup.objects.prefetch_related("site").annotate(vlan_count=count_related(VLAN, "group"))
    filterset = filters.VLANGroupFilterSet
    filterset_form = forms.VLANGroupFilterForm
    table = tables.VLANGroupTable
Exemple #29
0
class TagViewSet(CustomFieldModelViewSet):
    queryset = Tag.objects.annotate(
        tagged_items=count_related(TaggedItem, "tag"))
    serializer_class = serializers.TagSerializer
    filterset_class = filters.TagFilterSet
Exemple #30
0
class VLANGroupViewSet(CustomFieldModelViewSet):
    queryset = VLANGroup.objects.prefetch_related("site").annotate(
        vlan_count=count_related(VLAN, "group"))
    serializer_class = serializers.VLANGroupSerializer
    filterset_class = filters.VLANGroupFilterSet