diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 4f94175afd..26af92a549 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -4872,6 +4872,7 @@ class InstanceNodeSerializer(BaseSerializer): class InstanceSerializer(BaseSerializer): + show_capabilities = ['edit'] consumed_capacity = serializers.SerializerMethodField() percent_capacity_remaining = serializers.SerializerMethodField() @@ -4917,7 +4918,7 @@ class InstanceSerializer(BaseSerializer): res = super(InstanceSerializer, self).get_related(obj) res['jobs'] = self.reverse('api:instance_unified_jobs_list', kwargs={'pk': obj.pk}) res['instance_groups'] = self.reverse('api:instance_instance_groups_list', kwargs={'pk': obj.pk}) - if settings.IS_K8S and obj.node_type in ('execution', 'hop'): + if settings.IS_K8S and obj.node_type in (Instance.Types.EXECUTION,): res['install_bundle'] = self.reverse('api:instance_install_bundle', kwargs={'pk': obj.pk}) res['peers'] = self.reverse('api:instance_peers_list', kwargs={"pk": obj.pk}) if self.context['request'].user.is_superuser or self.context['request'].user.is_system_auditor: @@ -4950,8 +4951,8 @@ class InstanceSerializer(BaseSerializer): def validate_node_type(self, value): if not self.instance: - if value not in [Instance.Types.EXECUTION, Instance.Types.HOP]: - raise serializers.ValidationError("Can only create execution and hop nodes.") + if value not in (Instance.Types.EXECUTION,): + raise serializers.ValidationError("Can only create execution nodes.") else: if self.instance.node_type != value: raise serializers.ValidationError("Cannot change node type.") diff --git a/awx/api/views/__init__.py b/awx/api/views/__init__.py index 5d95e13b98..7c8b6aaffc 100644 --- a/awx/api/views/__init__.py +++ b/awx/api/views/__init__.py @@ -369,7 +369,9 @@ class InstanceList(ListCreateAPIView): ordering = ('id',) def perform_create(self, serializer): - serializer.save(node_state=models.Instance.States.INSTALLED) + obj = serializer.save(node_state=models.Instance.States.INSTALLED) + for instance in models.Instance.objects.filter(node_type__in=[models.Instance.Types.CONTROL, models.Instance.Types.HYBRID]): + models.InstanceLink.objects.create(source=instance, target=obj, link_state=models.InstanceLink.States.ADDING) class InstanceDetail(RetrieveUpdateAPIView): @@ -384,8 +386,6 @@ class InstanceDetail(RetrieveUpdateAPIView): obj = self.get_object() obj.set_capacity_value() obj.save(update_fields=['capacity']) - for instance in models.Instance.objects.filter(node_type__in=['control', 'hybrid']): - models.InstanceLink.objects.create(source=instance, target=obj) r.data = serializers.InstanceSerializer(obj, context=self.get_serializer_context()).to_representation(obj) return r diff --git a/awx/main/models/ha.py b/awx/main/models/ha.py index 1e52646958..e09b7cb9d4 100644 --- a/awx/main/models/ha.py +++ b/awx/main/models/ha.py @@ -424,7 +424,7 @@ def on_instance_group_saved(sender, instance, created=False, raw=False, **kwargs @receiver(post_save, sender=Instance) def on_instance_saved(sender, instance, created=False, raw=False, **kwargs): # TODO: handle update to instance - if settings.IS_K8S and created and instance.node_type in ('execution', 'hop'): + if settings.IS_K8S and created and instance.node_type in (Instance.Types.EXECUTION,): from awx.main.tasks.receptor import write_receptor_config # prevents circular import # on commit broadcast to all control instance to update their receptor configs diff --git a/awx/main/tasks/receptor.py b/awx/main/tasks/receptor.py index b62f53ae42..95f211bed2 100644 --- a/awx/main/tasks/receptor.py +++ b/awx/main/tasks/receptor.py @@ -641,7 +641,7 @@ RECEPTOR_CONFIG_STARTER = ( def write_receptor_config(): receptor_config = list(RECEPTOR_CONFIG_STARTER) - instances = Instance.objects.exclude(node_type='control') + instances = Instance.objects.filter(node_type=Instance.Types.EXECUTION) for instance in instances: peer = {'tcp-peer': {'address': f'{instance.hostname}:{instance.listener_port}', 'tls': 'tlsclient'}} receptor_config.append(peer)