Skip to content

Commit 9d16209

Browse files
lizk886Release Workflow
andauthored
aws script to replace network interface for r7 instances (#2177)
* draft * clean up * [CI Pipeline] Released Snapshot version: 5.61.28-alpha-559-SNAPSHOT * [CI Pipeline] Released Snapshot version: 5.61.29-alpha-196-SNAPSHOT * vulnerability * simplify * [CI Pipeline] Released Snapshot version: 5.61.30-alpha-562-SNAPSHOT * add r7 instances * start fresh * [CI Pipeline] Released Snapshot version: 5.61.31-alpha-197-SNAPSHOT * [CI Pipeline] Released Snapshot version: 5.61.32-alpha-198-SNAPSHOT * allow more time for auxiliaries to stabilize * [CI Pipeline] Released Snapshot version: 5.61.33-alpha-564-SNAPSHOT * update network interface retriever function naming, instead of sleep 2 do retry * remove redundant logics * remove redundant logics * log existing/defualt network interface * [CI Pipeline] Released Snapshot version: 5.61.34-alpha-565-SNAPSHOT * Guarantees cleanup AFTER stopping * resolve pom conflict * [CI Pipeline] Released Snapshot version: 5.62.35-alpha-566-SNAPSHOT * update pom conflict --------- Co-authored-by: Release Workflow <[email protected]>
1 parent e475b5c commit 9d16209

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

scripts/aws/UID_CloudFormation.template.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Parameters:
3838
- m6i.4xlarge
3939
- r6i.2xlarge
4040
- r6i.4xlarge
41+
- r7i.2xlarge
42+
- r7i.4xlarge
4143
ConstraintDescription: must be a valid EC2 instance type.
4244
RootVolumeSize:
4345
Description: Instance root volume size

scripts/aws/ec2.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,47 @@ def __run_config_server(self) -> None:
167167

168168
self.run_service([command, command], "flask_config_server", separate_process=True)
169169

170+
def __configure_sockd_network_interface(self) -> None:
171+
"""
172+
Auto-detects the primary network interface and configures sockd.conf.
173+
This ensures compatibility with R7i instances which use 'enp39s0' instead of 'ens5'.
174+
"""
175+
logging.info("Auto-detecting network interface for SOCKS proxy configuration")
176+
177+
try:
178+
with open('/etc/sockd.conf', 'r') as f:
179+
config = f.read()
180+
181+
# Extract current interface from config
182+
current_match = re.search(r'external:\s+(\S+)', config)
183+
current_interface = current_match.group(1) if current_match else "unknown"
184+
185+
# Detect primary network interface
186+
result = subprocess.run(
187+
["ip", "-o", "route", "get", "1"],
188+
capture_output=True, text=True, check=True
189+
)
190+
match = re.search(r'dev\s+(\S+)', result.stdout)
191+
primary_interface = match.group(1) if match else "ens5"
192+
193+
logging.info(f"Detected primary network interface: {primary_interface} (default in config: {current_interface})")
194+
195+
new_config = re.sub(r'external:\s+\S+', f'external: {primary_interface}', config)
196+
197+
with open('/etc/sockd.conf', 'w') as f:
198+
f.write(new_config)
199+
200+
logging.info(f"/etc/sockd.conf configured with interface: {primary_interface}")
201+
202+
except Exception as e:
203+
logging.error(f"Failed to auto-detect network interface: {e}")
204+
logging.info("Continuing with existing /etc/sockd.conf configuration")
205+
170206
def __run_socks_proxy(self) -> None:
171207
logging.info("Starts the SOCKS proxy service")
208+
209+
self.__configure_sockd_network_interface()
210+
172211
command = ["sockd", "-D"]
173212

174213
# -d specifies debug level

0 commit comments

Comments
 (0)