Skip to content

Commit d8baa93

Browse files
committed
Align with xe-reset-networking in xapi
Signed-off-by: Ming Lu <[email protected]>
1 parent 504dde4 commit d8baa93

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

plugins-base/XSFeatureNetworkReset.py

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
inventory_file = '/etc/xensource-inventory'
2323
management_conf = '/etc/firstboot.d/data/management.conf'
2424
network_reset = '/var/tmp/network-reset'
25-
# The existence of this directory determines if the device renaming happened or not.
26-
# The renaming will get devices named like eth0, eth1, etc.
27-
interface_rename_dir = '/etc/sysconfig/network-scripts/interface-rename-data'
25+
rename_script = '/etc/sysconfig/network-scripts/interface-rename.py'
26+
rename_script_exists = os.path.exists(rename_script)
2827

2928
def read_dict_file(fname):
3029
f = open(fname, 'r')
@@ -333,6 +332,15 @@ def HandleModeChoice(self, inChoice):
333332
self.mode = 'static'
334333
self.ChangeState('STATICIP')
335334

335+
def get_bridge_name(self):
336+
# Construct bridge name for management interface based on convention
337+
if self.vlan:
338+
return 'xentemp'
339+
if self.device[:3] == 'eth':
340+
return 'xenbr' + self.device[3:]
341+
else:
342+
return 'br' + self.device
343+
336344
def Commit(self):
337345
# Update master's IP, if needed and given
338346
if self.master_ip != None:
@@ -342,17 +350,6 @@ def Commit(self):
342350
finally:
343351
f.close()
344352

345-
renamed = os.path.exists(interface_rename_dir)
346-
347-
if renamed:
348-
# Construct bridge name for management interface based on convention
349-
if self.device[:3] == 'eth':
350-
bridge = 'xenbr' + self.device[3:]
351-
else:
352-
bridge = 'br' + self.device
353-
# Else, the device name will not be like eth<N>. And networkd will
354-
# determine the bridge name.
355-
356353
# Ensure xapi is not running
357354
os.system('service xapi stop >/dev/null 2>/dev/null')
358355

@@ -361,17 +358,10 @@ def Commit(self):
361358
try: os.remove('/var/xapi/networkd.db')
362359
except: pass
363360

361+
# Update interfaces in inventory file
364362
inventory = read_inventory()
365-
if renamed:
366-
# Update interfaces in inventory file
367-
if self.vlan:
368-
inventory['MANAGEMENT_INTERFACE'] = 'xentemp'
369-
else:
370-
inventory['MANAGEMENT_INTERFACE'] = bridge
371-
else:
372-
# networkd will determine the bridge name and update to inventory file.
373-
inventory['MANAGEMENT_INTERFACE'] = ''
374-
363+
bridge = self.get_bridge_name() if rename_script_exists else ''
364+
inventory['MANAGEMENT_INTERFACE'] = bridge
375365
inventory['CURRENT_INTERFACES'] = ''
376366
write_inventory(inventory)
377367

@@ -412,7 +402,7 @@ def Commit(self):
412402
# Reset the domain 0 network interface naming configuration
413403
# back to a fresh-install state for the currently-installed
414404
# hardware.
415-
if renamed:
405+
if rename_script_exists:
416406
os.system("/etc/sysconfig/network-scripts/interface-rename.py --reset-to-install")
417407
# Else, networkd will do the reset during starting up
418408

0 commit comments

Comments
 (0)