Skip to content

Commit

Permalink
Allow setting ip_address for execution nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
fosterseth committed Aug 24, 2023
1 parent 569a674 commit cb10ce2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
20 changes: 18 additions & 2 deletions awx/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -5487,6 +5487,10 @@ def get_field_from_model_or_attrs(fd):
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."))
Expand Down Expand Up @@ -5549,7 +5553,19 @@ def validate_listener_port(self, value):
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


Expand Down
1 change: 1 addition & 0 deletions awx/api/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ def update_raw_data(self, data):
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):
Expand Down
3 changes: 2 additions & 1 deletion awx/api/views/instance_install_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))


Expand Down
3 changes: 2 additions & 1 deletion awx/main/tasks/receptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cb10ce2

Please sign in to comment.