mirror of
https://github.com/ansible/awx.git
synced 2026-03-01 16:58:46 -03:30
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:
@@ -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.")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user