Skip to content

Commit

Permalink
optional listener port UI (ansible#14300)
Browse files Browse the repository at this point in the history
  • Loading branch information
fosterseth authored and djyasin committed Sep 11, 2024
1 parent e15992a commit 4672af3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
11 changes: 9 additions & 2 deletions awx/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5501,8 +5501,12 @@ def get_field_from_model_or_attrs(fd):
_("Setting peers manually for control nodes is not allowed. Enable peers_from_control_nodes on the hop and execution nodes instead.")
)

if peers_from_control_nodes and listener_port is None:
if not listener_port and peers_from_control_nodes:
raise serializers.ValidationError(_("Field listener_port must be a valid integer when peers_from_control_nodes is enabled."))

if not listener_port and self.instance and self.instance.peers_from.exists():
raise serializers.ValidationError(_("Field listener_port must be a valid integer when other nodes peer to it."))

for peer in attrs.get('peers', []):
if peer.listener_port is None:
raise serializers.ValidationError(_("Field listener_port must be set on peer ") + peer.hostname + ".")
Expand Down Expand Up @@ -5544,7 +5548,10 @@ def validate_hostname(self, value):
return value

def validate_listener_port(self, value):
if self.instance and self.instance.listener_port != value:
"""
Cannot change listener port, unless going from none to integer, and vice versa
"""
if value and self.instance and self.instance.listener_port and self.instance.listener_port != value:
raise serializers.ValidationError(_("Cannot change listener port."))

return value
Expand Down
10 changes: 5 additions & 5 deletions awx/main/models/ha.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,14 +513,14 @@ def on_instance_saved(sender, instance, created=False, raw=False, **kwargs):
# node and kick off write_receptor_config
connection.on_commit(lambda: remove_deprovisioned_node.apply_async([instance.hostname]))
else:
control_instances = set(Instance.objects.filter(node_type__in=[Instance.Types.CONTROL, Instance.Types.HYBRID]))
if instance.peers_from_control_nodes:
control_instances = Instance.objects.filter(node_type__in=[Instance.Types.CONTROL, Instance.Types.HYBRID])
if set(instance.peers_from.all()) != control_instances:
instance.peers_from.set(control_instances)
if (control_instances & set(instance.peers_from.all())) != set(control_instances):
instance.peers_from.add(*control_instances)
schedule_write_receptor_config() # keep method separate to make pytest mocking easier
else:
if instance.peers_from.exists():
instance.peers_from.clear()
if set(control_instances) & set(instance.peers_from.all()):
instance.peers_from.remove(*control_instances)
schedule_write_receptor_config()

if created or instance.has_policy_changes():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ function InstanceDetail({ setBreadcrumb, isK8s }) {
<Detail label={t`Instance Port`} value={instance.listener_port} />
{(isExecutionNode || isHopNode) && (
<Detail
label={t`Connection to control nodes`}
label={t`Peers from control nodes`}
value={instance.peers_from_control_nodes ? t`On` : t`Off`}
/>
)}
Expand Down
14 changes: 6 additions & 8 deletions awx/ui/src/screens/Instances/Shared/InstanceForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ function InstanceFormFields({ isEdit }) {
label={t`Listener Port`}
name="listener_port"
type="number"
tooltip={t`Select the port that Receptor will listen on for incoming connections. Default is 27199.`}
isRequired
tooltip={t`Select the port that Receptor will listen on for incoming connections, e.g. 27199.`}
/>
<FormGroup
fieldId="instance-type"
Expand Down Expand Up @@ -122,8 +121,8 @@ function InstanceFormFields({ isEdit }) {
<CheckboxField
id="peers_from_control_nodes"
name="peers_from_control_nodes"
label={t`Connect to control nodes`}
tooltip={t`Connect this instance to control nodes. If disabled, instance will be connected only to peers selected.`}
label={t`Peers from control nodes`}
tooltip={t`If enabled, control nodes will peer to this instance automatically. If disabled, instance will be connected only to associated peers.`}
/>
</FormGroup>
</>
Expand All @@ -146,17 +145,16 @@ function InstanceForm({
description: instance.description || '',
node_type: instance.node_type || 'execution',
node_state: instance.node_state || 'installed',
listener_port: instance.listener_port || 27199,
listener_port: instance.listener_port,
enabled: instance.enabled || true,
managed_by_policy: instance.managed_by_policy || true,
peers_from_control_nodes: instance.peers_from_control_nodes
? true
: !isEdit,
peers_from_control_nodes: instance.peers_from_control_nodes || false,
peers: instance_peers,
}}
onSubmit={(values) => {
handleSubmit({
...values,
listener_port: values.listener_port === '' ? null : values.listener_port,
peers: values.peers.map((peer) => peer.hostname || peer),
});
}}
Expand Down

0 comments on commit 4672af3

Please sign in to comment.