Exemplo n.º 1
0
class CircuitTerminationSerializer(CableTerminationSerializer, ConnectedEndpointSerializer):
    url = serializers.HyperlinkedIdentityField(view_name="circuits-api:circuittermination-detail")
    circuit = NestedCircuitSerializer()
    site = NestedSiteSerializer(required=False, allow_null=True)
    provider_network = NestedProviderNetworkSerializer(required=False, allow_null=True)
    cable = NestedCableSerializer(read_only=True)

    class Meta:
        model = CircuitTermination
        fields = [
            "id",
            "url",
            "circuit",
            "term_side",
            "site",
            "provider_network",
            "port_speed",
            "upstream_speed",
            "xconnect_id",
            "pp_info",
            "description",
            "cable",
            "cable_peer",
            "cable_peer_type",
            "connected_endpoint",
            "connected_endpoint_type",
            "connected_endpoint_reachable",
        ]
Exemplo n.º 2
0
class ClusterSerializer(TaggedObjectSerializer, CustomFieldModelSerializer):
    url = serializers.HyperlinkedIdentityField(view_name="virtualization-api:cluster-detail")
    type = NestedClusterTypeSerializer()
    group = NestedClusterGroupSerializer(required=False, allow_null=True)
    tenant = NestedTenantSerializer(required=False, allow_null=True)
    site = NestedSiteSerializer(required=False, allow_null=True)
    device_count = serializers.IntegerField(read_only=True)
    virtualmachine_count = serializers.IntegerField(read_only=True)

    class Meta:
        model = Cluster
        fields = [
            "id",
            "url",
            "name",
            "type",
            "group",
            "tenant",
            "site",
            "comments",
            "tags",
            "custom_fields",
            "created",
            "last_updated",
            "device_count",
            "virtualmachine_count",
            "computed_fields",
        ]
        opt_in_fields = ["computed_fields"]
Exemplo n.º 3
0
class PrefixSerializer(TaggedObjectSerializer, StatusModelSerializerMixin,
                       CustomFieldModelSerializer):
    url = serializers.HyperlinkedIdentityField(
        view_name="ipam-api:prefix-detail")
    family = ChoiceField(choices=IPAddressFamilyChoices, read_only=True)
    prefix = IPFieldSerializer()
    site = NestedSiteSerializer(required=False, allow_null=True)
    vrf = NestedVRFSerializer(required=False, allow_null=True)
    tenant = NestedTenantSerializer(required=False, allow_null=True)
    vlan = NestedVLANSerializer(required=False, allow_null=True)
    role = NestedRoleSerializer(required=False, allow_null=True)

    class Meta:
        model = Prefix
        fields = [
            "id",
            "url",
            "family",
            "prefix",
            "site",
            "vrf",
            "tenant",
            "vlan",
            "status",
            "role",
            "is_pool",
            "description",
            "tags",
            "custom_fields",
            "created",
            "last_updated",
            "computed_fields",
        ]
        read_only_fields = ["family"]
        opt_in_fields = ["computed_fields"]
Exemplo n.º 4
0
class VLANGroupSerializer(CustomFieldModelSerializer):
    url = serializers.HyperlinkedIdentityField(view_name="ipam-api:vlangroup-detail")
    site = NestedSiteSerializer(required=False, allow_null=True)
    vlan_count = serializers.IntegerField(read_only=True)

    class Meta:
        model = VLANGroup
        fields = [
            "id",
            "url",
            "name",
            "slug",
            "site",
            "description",
            "vlan_count",
            "custom_fields",
            "created",
            "last_updated",
            "computed_fields",
        ]
        validators = []
        opt_in_fields = ["computed_fields"]

    def validate(self, data):

        # Validate uniqueness of name and slug if a site has been assigned.
        if data.get("site", None):
            for field in ["name", "slug"]:
                validator = UniqueTogetherValidator(queryset=VLANGroup.objects.all(), fields=("site", field))
                validator(data, self)

        # Enforce model validation
        super().validate(data)

        return data
Exemplo n.º 5
0
class CircuitCircuitTerminationSerializer(WritableNestedSerializer):
    url = serializers.HyperlinkedIdentityField(view_name="circuits-api:circuittermination-detail")
    site = NestedSiteSerializer()
    connected_endpoint = NestedInterfaceSerializer()

    class Meta:
        model = CircuitTermination
        fields = [
            "id",
            "url",
            "site",
            "connected_endpoint",
            "port_speed",
            "upstream_speed",
            "xconnect_id",
        ]
Exemplo n.º 6
0
class VLANSerializer(TaggedObjectSerializer, StatusModelSerializerMixin,
                     CustomFieldModelSerializer):
    url = serializers.HyperlinkedIdentityField(
        view_name="ipam-api:vlan-detail")
    site = NestedSiteSerializer(required=False, allow_null=True)
    group = NestedVLANGroupSerializer(required=False, allow_null=True)
    tenant = NestedTenantSerializer(required=False, allow_null=True)
    role = NestedRoleSerializer(required=False, allow_null=True)
    prefix_count = serializers.IntegerField(read_only=True)

    class Meta:
        model = VLAN
        fields = [
            "id",
            "url",
            "site",
            "group",
            "vid",
            "name",
            "tenant",
            "status",
            "role",
            "description",
            "tags",
            "custom_fields",
            "created",
            "last_updated",
            "prefix_count",
            "computed_fields",
        ]
        validators = []
        opt_in_fields = ["computed_fields"]

    def validate(self, data):

        # Validate uniqueness of vid and name if a group has been assigned.
        if data.get("group", None):
            for field in ["vid", "name"]:
                validator = UniqueTogetherValidator(
                    queryset=VLAN.objects.all(), fields=("group", field))
                validator(data, self)

        # Enforce model validation
        super().validate(data)

        return data
Exemplo n.º 7
0
class VirtualMachineSerializer(TaggedObjectSerializer,
                               StatusModelSerializerMixin,
                               CustomFieldModelSerializer):
    url = serializers.HyperlinkedIdentityField(
        view_name="virtualization-api:virtualmachine-detail")
    site = NestedSiteSerializer(read_only=True)
    cluster = NestedClusterSerializer()
    role = NestedDeviceRoleSerializer(required=False, allow_null=True)
    tenant = NestedTenantSerializer(required=False, allow_null=True)
    platform = NestedPlatformSerializer(required=False, allow_null=True)
    primary_ip = NestedIPAddressSerializer(read_only=True)
    primary_ip4 = NestedIPAddressSerializer(required=False, allow_null=True)
    primary_ip6 = NestedIPAddressSerializer(required=False, allow_null=True)
    local_context_schema = NestedConfigContextSchemaSerializer(required=False,
                                                               allow_null=True)

    class Meta:
        model = VirtualMachine
        fields = [
            "id",
            "url",
            "name",
            "status",
            "site",
            "cluster",
            "role",
            "tenant",
            "platform",
            "primary_ip",
            "primary_ip4",
            "primary_ip6",
            "vcpus",
            "memory",
            "disk",
            "comments",
            "local_context_data",
            "local_context_schema",
            "tags",
            "custom_fields",
            "created",
            "last_updated",
            "computed_fields",
        ]
        validators = []
        opt_in_fields = ["computed_fields"]