mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 01:57:35 -03:30
Allow setting ip_address for execution nodes
This commit is contained in:
parent
7169c75b1a
commit
3bd25c682e
@ -5391,7 +5391,7 @@ class InstanceSerializer(BaseSerializer):
|
||||
|
||||
class Meta:
|
||||
model = Instance
|
||||
read_only_fields = ('ip_address', 'uuid', 'version')
|
||||
read_only_fields = ('uuid', 'version')
|
||||
fields = (
|
||||
'id',
|
||||
'hostname',
|
||||
@ -5487,6 +5487,10 @@ class InstanceSerializer(BaseSerializer):
|
||||
node_type = get_field_from_model_or_attrs("node_type")
|
||||
peers_from_control_nodes = get_field_from_model_or_attrs("peers_from_control_nodes")
|
||||
listener_port = get_field_from_model_or_attrs("listener_port")
|
||||
ip_address = get_field_from_model_or_attrs("ip_address")
|
||||
hostname = get_field_from_model_or_attrs("hostname")
|
||||
if not ip_address:
|
||||
attrs["ip_address"] = hostname
|
||||
|
||||
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."))
|
||||
@ -5549,7 +5553,19 @@ class InstanceSerializer(BaseSerializer):
|
||||
class InstanceHealthCheckSerializer(BaseSerializer):
|
||||
class Meta:
|
||||
model = Instance
|
||||
read_only_fields = ('uuid', 'hostname', 'version', 'last_health_check', 'errors', 'cpu', 'memory', 'cpu_capacity', 'mem_capacity', 'capacity')
|
||||
read_only_fields = (
|
||||
'uuid',
|
||||
'hostname',
|
||||
'ip_address',
|
||||
'version',
|
||||
'last_health_check',
|
||||
'errors',
|
||||
'cpu',
|
||||
'memory',
|
||||
'cpu_capacity',
|
||||
'mem_capacity',
|
||||
'capacity',
|
||||
)
|
||||
fields = read_only_fields
|
||||
|
||||
|
||||
|
||||
@ -344,6 +344,7 @@ class InstanceDetail(RetrieveUpdateAPIView):
|
||||
data.pop('listener_port', None)
|
||||
data.pop('node_type', None)
|
||||
data.pop('hostname', None)
|
||||
data.pop('ip_address', None)
|
||||
return super(InstanceDetail, self).update_raw_data(data)
|
||||
|
||||
def update(self, request, *args, **kwargs):
|
||||
|
||||
@ -121,7 +121,8 @@ def generate_inventory_yml(instance_obj):
|
||||
def generate_group_vars_all_yml(instance_obj):
|
||||
peers = []
|
||||
for instance in instance_obj.peers.all():
|
||||
peers.append(dict(host=instance.hostname, port=instance.listener_port))
|
||||
host_or_ip = instance.ip_address or instance.hostname
|
||||
peers.append(dict(host=host_or_ip, port=instance.listener_port))
|
||||
return render_to_string("instance_install_bundle/group_vars/all.yml", context=dict(instance=instance_obj, peers=peers))
|
||||
|
||||
|
||||
|
||||
@ -704,7 +704,8 @@ def generate_config_data():
|
||||
|
||||
receptor_config = list(RECEPTOR_CONFIG_STARTER)
|
||||
for instance in instances:
|
||||
peer = {'tcp-peer': {'address': f'{instance.hostname}:{instance.listener_port}', 'tls': 'tlsclient'}}
|
||||
host_or_ip = instance.ip_address or instance.hostname
|
||||
peer = {'tcp-peer': {'address': f'{host_or_ip}:{instance.listener_port}', 'tls': 'tlsclient'}}
|
||||
receptor_config.append(peer)
|
||||
should_update = should_update_config(instances)
|
||||
return receptor_config, should_update
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user