Follow up on new execution node creation

- hop nodes are descoped
- links need to be created on execution node creation
- expose the 'edit' capabilities on the instance serializer
This commit is contained in:
Jeff Bradberry 2022-08-30 12:12:03 -04:00
parent dba03616f4
commit 3bc86ca8cb
4 changed files with 9 additions and 8 deletions

View File

@ -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.")

View File

@ -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

View File

@ -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

View File

@ -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)