Add peers readonly api and instancelink constraint (#13916)

Add Disconnected link state

introspect_receptor_connections is a periodic
task that examines active receptor connections
and cross-checks it with the InstanceLink info.

Any links that should be active but are not
will be put into a Disconnected state. If
active, it will be in an Established state.

UI - Add hop creation and peers mgmt (#13922)

* add UI for mgmt peers, instance edit and add

* add peer info on detail and bug fix on detail

* remove unused chip and change peer label

* rename lookup, put Instance type disable on edit

---------

Co-authored-by: tanganellilore <lorenzo.tanagnelli@hotmail.it>
This commit is contained in:
Lorenzo Tanganelli
2023-04-27 00:34:26 +02:00
committed by Seth Foster
parent d8abd4912b
commit f7fdb7fe8d
29 changed files with 1068 additions and 83 deletions

View File

@@ -5356,10 +5356,16 @@ class ScheduleSerializer(LaunchConfigurationBaseSerializer, SchedulePreviewSeria
class InstanceLinkSerializer(BaseSerializer):
class Meta:
model = InstanceLink
fields = ('source', 'target', 'link_state')
fields = ('id', 'url', 'related', 'source', 'target', 'link_state')
source = serializers.SlugRelatedField(slug_field="hostname", read_only=True)
target = serializers.SlugRelatedField(slug_field="hostname", read_only=True)
source = serializers.SlugRelatedField(slug_field="hostname", queryset=Instance.objects.all())
target = serializers.SlugRelatedField(slug_field="hostname", queryset=Instance.objects.all())
def get_related(self, obj):
res = super(InstanceLinkSerializer, self).get_related(obj)
res['source_instance'] = self.reverse('api:instance_detail', kwargs={'pk': obj.source.id})
res['target_instance'] = self.reverse('api:instance_detail', kwargs={'pk': obj.target.id})
return res
class InstanceNodeSerializer(BaseSerializer):

14
awx/api/urls/peers.py Normal file
View File

@@ -0,0 +1,14 @@
# Copyright (c) 2017 Ansible, Inc.
# All Rights Reserved.
from django.urls import re_path
from awx.api.views import PeersList, PeersDetail
urls = [
re_path(r'^$', PeersList.as_view(), name='peers_list'),
re_path(r'^(?P<pk>[0-9]+)/$', PeersDetail.as_view(), name='peers_detail'),
]
__all__ = ['urls']

View File

@@ -84,6 +84,7 @@ from .oauth2_root import urls as oauth2_root_urls
from .workflow_approval_template import urls as workflow_approval_template_urls
from .workflow_approval import urls as workflow_approval_urls
from .analytics import urls as analytics_urls
from .peers import urls as peers_urls
v2_urls = [
re_path(r'^$', ApiV2RootView.as_view(), name='api_v2_root_view'),
@@ -153,6 +154,7 @@ v2_urls = [
re_path(r'^bulk/$', BulkView.as_view(), name='bulk'),
re_path(r'^bulk/host_create/$', BulkHostCreateView.as_view(), name='bulk_host_create'),
re_path(r'^bulk/job_launch/$', BulkJobLaunchView.as_view(), name='bulk_job_launch'),
re_path(r'^peers/', include(peers_urls)),
]

View File

@@ -4350,3 +4350,17 @@ 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

View File

@@ -129,6 +129,7 @@ class ApiVersionRootView(APIView):
data['mesh_visualizer'] = reverse('api:mesh_visualizer_view', request=request)
data['bulk'] = reverse('api:bulk', request=request)
data['analytics'] = reverse('api:analytics_root_view', request=request)
data['peers'] = reverse('api:peers_list', request=request)
return Response(data)