Skip to content

Commit 13cc294

Browse files
committed
CP-54442: Update for network devices not being renamed
A new proposed change in networkd will replace the interface-rename functionality to order the network devices. The result of the ordering performed by interface-rename is to rename the devices like eth0, eth1, etc. The new change in networkd will not rename the devices any more. Consequently, the use of hard-coded eth<N> in network reset in xsconsole should be eliminated to cope with the new change. Additionally, the new networkd replacing the interface rename functionality will perform the network reset with xapi together. The interface rename functionality will be deprecated in the future. Signed-off-by: Ming Lu <ming.lu@cloud.com>
1 parent 7b7a3bd commit 13cc294

1 file changed

Lines changed: 32 additions & 15 deletions

File tree

plugins-base/XSFeatureNetworkReset.py

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
inventory_file = '/etc/xensource-inventory'
2424
management_conf = '/etc/firstboot.d/data/management.conf'
2525
network_reset = '/var/tmp/network-reset'
26+
# The existence of this directory determines if the device renaming happened or not.
27+
# The renaming will get devices named like eth0, eth1, etc.
28+
interface_rename_dir = '/etc/sysconfig/network-scripts/interface-rename-data'
2629

2730
def read_dict_file(fname):
2831
f = open(fname, 'r')
@@ -74,7 +77,12 @@ def __init__(self):
7477
conf = read_management_conf()
7578
self.device = conf['LABEL']
7679
except:
77-
self.device = "eth0"
80+
if os.path.exists(interface_rename_dir):
81+
self.device = "eth0"
82+
else:
83+
# Something is wrong as no mgmt device in management_conf file.
84+
# Leave it empty to ensure that the user must specify one.
85+
self.device = ""
7886

7987
try:
8088
conf = read_management_conf()
@@ -335,11 +343,16 @@ def Commit(self):
335343
finally:
336344
f.close()
337345

338-
# Construct bridge name for management interface based on convention
339-
if self.device[:3] == 'eth':
340-
bridge = 'xenbr' + self.device[3:]
341-
else:
342-
bridge = 'br' + self.device
346+
renamed = os.path.exists(interface_rename_dir)
347+
348+
if renamed:
349+
# Construct bridge name for management interface based on convention
350+
if self.device[:3] == 'eth':
351+
bridge = 'xenbr' + self.device[3:]
352+
else:
353+
bridge = 'br' + self.device
354+
# Else, the device name will not be like eth<N>. And networkd will
355+
# determine the bridge name.
343356

344357
# Ensure xapi is not running
345358
os.system('service xapi stop >/dev/null 2>/dev/null')
@@ -357,14 +370,16 @@ def Commit(self):
357370
try: os.remove('/var/xapi/networkd.db')
358371
except: pass
359372

360-
# Update interfaces in inventory file
361-
inventory = read_inventory()
362-
if self.vlan:
363-
inventory['MANAGEMENT_INTERFACE'] = 'xentemp'
364-
else:
365-
inventory['MANAGEMENT_INTERFACE'] = bridge
366-
inventory['CURRENT_INTERFACES'] = ''
367-
write_inventory(inventory)
373+
if renamed:
374+
# Update interfaces in inventory file
375+
inventory = read_inventory()
376+
if self.vlan:
377+
inventory['MANAGEMENT_INTERFACE'] = 'xentemp'
378+
else:
379+
inventory['MANAGEMENT_INTERFACE'] = bridge
380+
inventory['CURRENT_INTERFACES'] = ''
381+
write_inventory(inventory)
382+
# Else, networkd will update the inventory file.
368383

369384
# Rewrite firstboot management.conf file, which will be picked it by xcp-networkd on restart (if used)
370385
f = open(management_conf, 'w')
@@ -403,7 +418,9 @@ def Commit(self):
403418
# Reset the domain 0 network interface naming configuration
404419
# back to a fresh-install state for the currently-installed
405420
# hardware.
406-
os.system("/etc/sysconfig/network-scripts/interface-rename.py --reset-to-install")
421+
if renamed:
422+
os.system("/etc/sysconfig/network-scripts/interface-rename.py --reset-to-install")
423+
# Else, networkd will do the reset during starting up
407424

408425
class XSFeatureNetworkReset:
409426
@classmethod

0 commit comments

Comments
 (0)