Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 22 additions & 38 deletions plugins-base/XSFeatureNetworkReset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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:
Expand All @@ -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<N>. 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')
Expand Down Expand Up @@ -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

Expand Down