Change PeersSerializer to SlugRelatedField

Get rid of PeersSerializer and just use SlugRelatedField,
which should be more a straightforward approach.

Other changes:
- cleanup code related to the already-removed api/v2/peers
endpoint
- add "hybrid" node type into more instance_peers test cases
This commit is contained in:
Seth Foster
2023-08-08 22:56:36 -04:00
committed by Seth Foster
parent 70ba32b5b2
commit c47acc5988
5 changed files with 26 additions and 53 deletions

View File

@@ -5374,11 +5374,6 @@ class InstanceNodeSerializer(BaseSerializer):
fields = ('id', 'hostname', 'node_type', 'node_state', 'enabled')
class PeersSerializer(serializers.StringRelatedField):
def to_internal_value(self, value):
return Instance.objects.get(hostname=value)
class InstanceSerializer(BaseSerializer):
show_capabilities = ['edit']
@@ -5387,7 +5382,7 @@ class InstanceSerializer(BaseSerializer):
jobs_running = serializers.IntegerField(help_text=_('Count of jobs in the running or waiting state that are targeted for this instance'), read_only=True)
jobs_total = serializers.IntegerField(help_text=_('Count of all jobs that target this instance'), read_only=True)
health_check_pending = serializers.SerializerMethodField()
peers = PeersSerializer(many=True, required=False)
peers = serializers.SlugRelatedField(many=True, required=False, slug_field="hostname", queryset=Instance.objects.all())
class Meta:
model = Instance
@@ -5493,7 +5488,7 @@ class InstanceSerializer(BaseSerializer):
if peers_from_control_nodes and node_type not in (Instance.Types.EXECUTION, Instance.Types.HOP):
raise serializers.ValidationError(_("peers_from_control_nodes can only be enabled for execution or hop nodes."))
if node_type == Instance.Types.CONTROL:
if node_type in [Instance.Types.CONTROL, Instance.Types.HYBRID]:
if self.instance and 'peers' in attrs and set(self.instance.peers.all()) != set(attrs['peers']):
raise serializers.ValidationError(
_("Setting peers manually for control nodes is not allowed. Enable peers_from_control_nodes on the hop and execution nodes instead.")

View File

@@ -4349,17 +4349,3 @@ class WorkflowApprovalDeny(RetrieveAPIView):
return Response({"error": _("This workflow step has already been approved or denied.")}, status=status.HTTP_400_BAD_REQUEST)
obj.deny(request)
return Response(status=status.HTTP_204_NO_CONTENT)
class PeersList(ListAPIView):
name = _("Peers")
model = models.InstanceLink
serializer_class = serializers.InstanceLinkSerializer
search_fields = ('source', 'target', 'link_state')
class PeersDetail(RetrieveAPIView):
name = _("Peers Detail")
always_allow_superuser = True
model = models.InstanceLink
serializer_class = serializers.InstanceLinkSerializer