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
49 changes: 25 additions & 24 deletions plugins-base/XSFeatureNetworkReset.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +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'
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 @@ -74,7 +75,12 @@ def __init__(self):
conf = read_management_conf()
self.device = conf['LABEL']
except:
self.device = "eth0"
if os.path.exists(interface_rename_dir):
self.device = "eth0"
else:
# Something is wrong as no mgmt device in management_conf file.
# Leave it empty to ensure that the user must specify one.
self.device = ""

try:
conf = read_management_conf()
Expand Down Expand Up @@ -326,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 @@ -335,34 +350,18 @@ def Commit(self):
finally:
f.close()

# Construct bridge name for management interface based on convention
if self.device[:3] == 'eth':
bridge = 'xenbr' + self.device[3:]
else:
bridge = 'br' + self.device

# 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
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()
if self.vlan:
inventory['MANAGEMENT_INTERFACE'] = 'xentemp'
else:
inventory['MANAGEMENT_INTERFACE'] = bridge
bridge = self.get_bridge_name() if rename_script_exists else ''
inventory['MANAGEMENT_INTERFACE'] = bridge
inventory['CURRENT_INTERFACES'] = ''
write_inventory(inventory)

Expand Down Expand Up @@ -403,7 +402,9 @@ def Commit(self):
# Reset the domain 0 network interface naming configuration
# back to a fresh-install state for the currently-installed
# hardware.
os.system("/etc/sysconfig/network-scripts/interface-rename.py --reset-to-install")
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

class XSFeatureNetworkReset:
@classmethod
Expand Down