diff --git a/plugins-base/XSFeatureNetworkReset.py b/plugins-base/XSFeatureNetworkReset.py index c934851..45699d2 100644 --- a/plugins-base/XSFeatureNetworkReset.py +++ b/plugins-base/XSFeatureNetworkReset.py @@ -19,13 +19,11 @@ from XSConsoleStandard import * pool_conf = '%s/pool.conf' % (Config.Inst().XCPConfigDir()) -interface_reconfigure = '%s/interface-reconfigure' % (Config.Inst().LibexecPath()) inventory_file = '/etc/xensource-inventory' management_conf = '/etc/firstboot.d/data/management.conf' network_reset = '/var/tmp/network-reset' -# The existence of this directory determines if the device renaming happened or not. -# The renaming will get devices named like eth0, eth1, etc. -interface_rename_dir = '/etc/sysconfig/network-scripts/interface-rename-data' +rename_script = '/etc/sysconfig/network-scripts/interface-rename.py' +rename_script_exists = os.path.exists(rename_script) def read_dict_file(fname): f = open(fname, 'r') @@ -334,6 +332,15 @@ def HandleModeChoice(self, inChoice): self.mode = 'static' self.ChangeState('STATICIP') + def get_bridge_name(self): + # Construct bridge name for management interface based on convention + if self.vlan: + return 'xentemp' + if self.device[:3] == 'eth': + return 'xenbr' + self.device[3:] + else: + return 'br' + self.device + def Commit(self): # Update master's IP, if needed and given if self.master_ip != None: @@ -343,43 +350,20 @@ def Commit(self): finally: f.close() - renamed = os.path.exists(interface_rename_dir) - - if renamed: - # Construct bridge name for management interface based on convention - if self.device[:3] == 'eth': - bridge = 'xenbr' + self.device[3:] - else: - bridge = 'br' + self.device - # Else, the device name will not be like eth. And networkd will - # determine the bridge name. - # Ensure xapi is not running os.system('service xapi stop >/dev/null 2>/dev/null') # Reconfigure new management interface - if os.access('/tmp/do-not-use-networkd', os.F_OK): - if_args = ' --force ' + bridge + ' rewrite --mac=x --device=' + self.device + ' --mode=' + self.mode - if self.mode == 'static': - if_args += ' --ip=' + self.IP + ' --netmask=' + self.netmask - if self.gateway != '': - if_args += ' --gateway=' + self.gateway - os.system(interface_reconfigure + if_args + ' >/dev/null 2>/dev/null') - else: - os.system('service xcp-networkd stop >/dev/null 2>/dev/null') - try: os.remove('/var/xapi/networkd.db') - except: pass - - if renamed: - # Update interfaces in inventory file - inventory = read_inventory() - if self.vlan: - inventory['MANAGEMENT_INTERFACE'] = 'xentemp' - else: - inventory['MANAGEMENT_INTERFACE'] = bridge - inventory['CURRENT_INTERFACES'] = '' - write_inventory(inventory) - # Else, networkd will update the inventory file. + os.system('service xcp-networkd stop >/dev/null 2>/dev/null') + try: os.remove('/var/xapi/networkd.db') + except: pass + + # Update interfaces in inventory file + inventory = read_inventory() + bridge = self.get_bridge_name() if rename_script_exists else '' + inventory['MANAGEMENT_INTERFACE'] = bridge + inventory['CURRENT_INTERFACES'] = '' + write_inventory(inventory) # Rewrite firstboot management.conf file, which will be picked it by xcp-networkd on restart (if used) f = open(management_conf, 'w') @@ -418,7 +402,7 @@ def Commit(self): # Reset the domain 0 network interface naming configuration # back to a fresh-install state for the currently-installed # hardware. - if renamed: + if rename_script_exists: os.system("/etc/sysconfig/network-scripts/interface-rename.py --reset-to-install") # Else, networkd will do the reset during starting up