This repository was archived by the owner on Jan 23, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
jumpstarter-cli-admin/jumpstarter_cli_admin
jumpstarter-driver-http/jumpstarter_driver_http
jumpstarter-driver-tftp/jumpstarter_driver_tftp
jumpstarter-kubernetes/jumpstarter_kubernetes
jumpstarter/jumpstarter/common Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33import asyncclick as click
44from jumpstarter_cli_common .opt import opt_context , opt_kubeconfig
55from 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 .ipaddr import get_ip_address
79
810
911def get_chart_version () -> str :
Original file line number Diff line number Diff line change 66from aiohttp import web
77from jumpstarter_driver_opendal .driver import Opendal
88
9+ from jumpstarter .common .ipaddr import get_ip_address
910from jumpstarter .driver import Driver , export
1011
1112
@@ -41,18 +42,7 @@ def __post_init__(self):
4142 ]
4243 )
4344 if self .host is None :
44- self .host = self .get_default_ip ()
45-
46- def get_default_ip (self ):
47- try :
48- import socket
49-
50- with socket .socket (socket .AF_INET , socket .SOCK_DGRAM ) as s :
51- s .connect (("8.8.8.8" , 80 ))
52- return s .getsockname ()[0 ]
53- except Exception :
54- self .logger .warning ("Could not determine default IP address, falling back to 0.0.0.0" )
55- return "0.0.0.0"
45+ self .host = get_ip_address (logger = self .logger )
5646
5747 @classmethod
5848 def client (cls ) -> str :
Original file line number Diff line number Diff line change 11import asyncio
22import os
3- import socket
43import threading
54from dataclasses import dataclass , field
65from typing import Optional
98
109from jumpstarter_driver_tftp .server import TftpServer
1110
11+ from jumpstarter .common .ipaddr import get_ip_address
1212from jumpstarter .driver import Driver , export
1313
1414
@@ -55,17 +55,7 @@ def __post_init__(self):
5555 self .storage = self .children ["storage" ]
5656
5757 if self .host == "" :
58- self .host = self .get_default_ip ()
59-
60- def get_default_ip (self ):
61- """Get the IP address of the default route interface"""
62- try :
63- with socket .socket (socket .AF_INET , socket .SOCK_DGRAM ) as s :
64- s .connect (("8.8.8.8" , 80 ))
65- return s .getsockname ()[0 ]
66- except Exception :
67- self .logger .warning ("Could not determine default IP address, falling back to 0.0.0.0" )
68- return "0.0.0.0"
58+ self .host = get_ip_address (logger = self .logger )
6959
7060 @classmethod
7161 def client (cls ) -> str :
Original file line number Diff line number Diff line change 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
1010from .leases import (
1111 LeasesV1Alpha1Api ,
1212 V1Alpha1Lease ,
3434 "V1Alpha1LeaseSelector" ,
3535 "V1Alpha1LeaseSpec" ,
3636 "V1Alpha1List" ,
37- "get_ip_address" ,
3837 "helm_installed" ,
3938 "install_helm_chart" ,
4039]
Original file line number Diff line number Diff line change 11import asyncio
22import shutil
3- import socket
43from 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-
206def helm_installed (name : str ) -> bool :
217 return shutil .which (name ) is not None
228
Original file line number Diff line number Diff line change 1+ import logging
2+ import socket
3+ from ipaddress import ip_address
4+
5+
6+ def get_ip_address (logger : logging .Logger | None = None ) -> str :
7+ """Get the IP address of the host machine"""
8+ # Try to get the IP address using the hostname
9+ hostname = socket .gethostname ()
10+ address = socket .gethostbyname (hostname )
11+ # If it returns nothing or a loopbadck address, do it the hard way
12+ if not address or ip_address (address ).is_loopback :
13+ try :
14+ with socket .socket (socket .AF_INET , socket .SOCK_DGRAM ) as s :
15+ s .connect (("192.175.48.1" , 53 )) # AS112
16+ return s .getsockname ()[0 ]
17+ except Exception :
18+ if logger :
19+ logger .warning ("Could not determine default IP address, falling back to 0.0.0.0" )
20+ return "0.0.0.0"
21+
22+ return address
You can’t perform that action at this time.
0 commit comments