Skip to content

Commit 4c1d034

Browse files
authored
CP-54441 Adapt interface ordering in xe-reset-networking (#6544)
If interface-rename script doesn't exist, networkd will - handle the interfaces sorting - write inventory when first boot So, when interface-rename doesn't exist, xe-reset-networking should: - NOT call interface-rename script - Delete MANAGEMENT_INTERFACE value in inventory. BTW, the current bridge name conversion method rely on hardcode 'eth' which is correct only when interface-rename script exists.
2 parents 0a75417 + cb365f2 commit 4c1d034

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

python3/bin/xe-reset-networking

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ pool_conf = '@ETCXENDIR@/pool.conf'
2424
inventory_file = '@INVENTORY@'
2525
management_conf = '/etc/firstboot.d/data/management.conf'
2626
network_reset = '/var/tmp/network-reset'
27-
27+
RENAME_SCRIPT = '/etc/sysconfig/network-scripts/interface-rename.py'
28+
rename_script_exists = os.path.exists(RENAME_SCRIPT)
2829

2930
@contextmanager
3031
def fsync_write(filename):
@@ -66,6 +67,15 @@ def valid_vlan(vlan):
6667
return False
6768
return True
6869

70+
def get_bridge_name(device, vlan):
71+
# Construct bridge name for management interface based on convention
72+
# NOTE: Only correct when interface-rename script exists
73+
if vlan != None:
74+
return 'xentemp'
75+
if device[:3] == 'eth':
76+
return 'xenbr' + device[3:]
77+
return 'br' + device
78+
6979
if __name__ == "__main__":
7080
parser = OptionParser()
7181
parser.add_option("-m", "--master", help="Master's address", dest="address", default=None)
@@ -208,15 +218,9 @@ Type 'no' to cancel.
208218
with fsync_write(pool_conf) as f:
209219
f.write('slave:' + address)
210220

211-
# Construct bridge name for management interface based on convention
212-
if device[:3] == 'eth':
213-
bridge = 'xenbr' + device[3:]
214-
else:
215-
bridge = 'br' + device
216-
217221
# Ensure xapi is not running
218222
print("Stopping xapi...")
219-
os.system('service xapi stop >/dev/null 2>/dev/null')
223+
os.system('systemctl stop xapi >/dev/null 2>/dev/null')
220224

221225
# Reconfigure new management interface
222226
print("Reconfiguring " + device + "...")
@@ -229,10 +233,10 @@ Type 'no' to cancel.
229233
# Update interfaces in inventory file
230234
print('Updating inventory file...')
231235
inventory = read_inventory()
232-
if vlan != None:
233-
inventory['MANAGEMENT_INTERFACE'] = 'xentemp'
234-
else:
235-
inventory['MANAGEMENT_INTERFACE'] = bridge
236+
# If rename script does not exist, needn't to set MANAGEMENT_INTERFACE in inventory file
237+
# Networkd will handle it while replacing the rename script to sort interfaces
238+
bridge = '' if not rename_script_exists else get_bridge_name(device, vlan)
239+
inventory['MANAGEMENT_INTERFACE'] = bridge
236240
inventory['CURRENT_INTERFACES'] = ''
237241
write_inventory(inventory)
238242

@@ -280,11 +284,11 @@ Type 'no' to cancel.
280284
f.write('GATEWAY_V6=' + options.gateway_v6 + '\n')
281285
if is_static and options.dns != '':
282286
f.write('DNS=' + options.dns + '\n')
283-
284-
# Reset the domain 0 network interface naming configuration
285-
# back to a fresh-install state for the currently-installed
286-
# hardware.
287-
os.system("/etc/sysconfig/network-scripts/interface-rename.py --reset-to-install")
287+
if rename_script_exists:
288+
# Reset the domain 0 network interface naming configuration
289+
# back to a fresh-install state for the currently-installed
290+
# hardware.
291+
os.system(f"{RENAME_SCRIPT} --reset-to-install")
288292

289293
# Reboot
290294
os.system("mount -o remount,rw / && reboot -f")

0 commit comments

Comments
 (0)