Use CLUSTER_HOST_ID as default hostname argument value

Incorporates feedback from https://github.com/ansible/awx/pull/13445/files#r1106012308

Signed-off-by: Stanislav Zaprudskiy <s.zaprudskiy@sap.com>
This commit is contained in:
Stanislav Zaprudskiy 2023-02-17 17:33:45 +01:00
parent f2ab8d637c
commit 35fbb94aa6

View File

@ -1,4 +1,3 @@
import socket
import time
from urllib.parse import urljoin
@ -18,7 +17,7 @@ class AWXInstance:
self.get_instance()
def get_instance(self):
filter = self.filter if self.filter is not None else dict(hostname=socket.gethostname())
filter = self.filter if self.filter is not None else dict(hostname=settings.CLUSTER_HOST_ID)
qs = Instance.objects.filter(**filter)
if not qs.exists():
raise ValueError(f"No AWX instance found with {filter} parameters")
@ -88,7 +87,7 @@ class Command(BaseCommand):
filter_group.add_argument(
"--hostname",
type=str,
default=socket.gethostname(),
default=settings.CLUSTER_HOST_ID,
help=f"{Instance.hostname.field.help_text} Defaults to the hostname of the machine where the Python interpreter is currently executing".strip(),
)
filter_group.add_argument("--id", type=self.ge_1, help=Instance.id.field.help_text)