Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit 9640363

Browse files
NickCaogithub-actions[bot]
authored andcommitted
Factor out get_ip_address
(cherry picked from commit 2ca3660)
1 parent 48bb122 commit 9640363

4 files changed

Lines changed: 18 additions & 17 deletions

File tree

packages/jumpstarter-cli-admin/jumpstarter_cli_admin/install.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import asyncclick as click
44
from jumpstarter_cli_common.opt import opt_context, opt_kubeconfig
55
from jumpstarter_cli_common.version import get_client_version
6-
from jumpstarter_kubernetes import get_ip_address, helm_installed, install_helm_chart
6+
from jumpstarter_kubernetes import helm_installed, install_helm_chart
7+
8+
from jumpstarter.common.ipaddress import get_ip_address
79

810

911
def get_chart_version() -> str:

packages/jumpstarter-kubernetes/jumpstarter_kubernetes/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
V1Alpha1ExporterList,
77
V1Alpha1ExporterStatus,
88
)
9-
from .install import get_ip_address, helm_installed, install_helm_chart
9+
from .install import helm_installed, install_helm_chart
1010
from .leases import (
1111
LeasesV1Alpha1Api,
1212
V1Alpha1Lease,
@@ -34,7 +34,6 @@
3434
"V1Alpha1LeaseSelector",
3535
"V1Alpha1LeaseSpec",
3636
"V1Alpha1List",
37-
"get_ip_address",
3837
"helm_installed",
3938
"install_helm_chart",
4039
]

packages/jumpstarter-kubernetes/jumpstarter_kubernetes/install.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
11
import asyncio
22
import shutil
3-
import socket
43
from typing import Literal, Optional
54

65

7-
def get_ip_address() -> str:
8-
"""Get the IP address of the host machine"""
9-
# Try to get the IP address using the hostname
10-
hostname = socket.gethostname()
11-
address = socket.gethostbyname(hostname)
12-
# If it returns a bogus address, do it the hard way
13-
if not address or address.startswith("127."):
14-
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
15-
s.connect(("1.1.1.1", 0))
16-
address = s.getsockname()[0]
17-
return address
18-
19-
206
def helm_installed(name: str) -> bool:
217
return shutil.which(name) is not None
228

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import socket
2+
3+
4+
def get_ip_address() -> str:
5+
"""Get the IP address of the host machine"""
6+
# Try to get the IP address using the hostname
7+
hostname = socket.gethostname()
8+
address = socket.gethostbyname(hostname)
9+
# If it returns a bogus address, do it the hard way
10+
if not address or address.startswith("127."):
11+
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
12+
s.connect(("1.1.1.1", 0))
13+
address = s.getsockname()[0]
14+
return address

0 commit comments

Comments
 (0)