Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 0 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -271,19 +271,6 @@ inputs = [
# Python 3
"python3/",
"ocaml/xcp-rrdd",
# Python2: These will generate warnings that need to be fixed:
"scripts/static-vdis",
"scripts/generate-iscsi-iqn",
"scripts/hatests",
"scripts/host-display",
"scripts/mail-alarm",
"scripts/print-custom-templates",
"scripts/probe-device-for-file",
"scripts/xe-reset-networking",
"scripts/xe-scsi-dev-map",
"scripts/examples/python",
"scripts/yum-plugins",
"scripts/*.py",

# To be added later,
# when converted to Python3-compatible syntax:
Expand Down
1 change: 1 addition & 0 deletions python3/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ install:
$(IPROG) libexec/restore-sr-metadata.py $(DESTDIR)$(LIBEXECDIR)

$(IPROG) bin/hfx_filename $(DESTDIR)$(OPTDIR)/bin
$(IPROG) bin/xe-reset-networking $(DESTDIR)$(OPTDIR)/bin
$(IPROG) bin/perfmon $(DESTDIR)$(OPTDIR)/bin
$(IPROG) bin/xe-scsi-dev-map $(DESTDIR)$(OPTDIR)/bin
$(IPROG) bin/static-vdis $(DESTDIR)$(OPTDIR)/bin
Expand Down
59 changes: 28 additions & 31 deletions scripts/xe-reset-networking → python3/bin/xe-reset-networking
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,30 @@ GNU Lesser General Public License for more details.
"""
from __future__ import print_function

import sys
import os
import time
import re
import sys
from contextlib import contextmanager
from optparse import OptionParser
#import XenAPI

pool_conf = '@ETCXENDIR@/pool.conf'
inventory_file = '@INVENTORY@'
management_conf = '/etc/firstboot.d/data/management.conf'
network_reset = '/tmp/network-reset'


@contextmanager
def fsync_write(filename):
"""Context manager that writes to a file and fsyncs it after writing."""

with open(filename, "w", encoding="utf-8") as file:
try: # Run the context, ignoring exceptions:
yield file
finally:
file.flush() # Flush the file buffer to the OS
os.fsync(file.fileno()) # Ask the OS to write the file to disk


def read_dict_file(fname):
f = open(fname, 'r')
d = {}
Expand All @@ -40,16 +52,15 @@ def read_inventory():
def read_management_conf():
return read_dict_file(management_conf)

def write_inventory(inventory):
f = open(inventory_file, 'w')
for k in inventory:
f.write(k + "='" + inventory[k] + "'\n")
f.flush()
os.fsync(f.fileno())
f.close()

def write_inventory(inventory_dict):
with fsync_write(inventory_file) as file:
for k in inventory_dict:
file.write(k + "='" + inventory_dict[k] + "'\n")


def valid_vlan(vlan):
if not re.match('^\d+$', vlan):
if not re.match(r"^\d+$", vlan):
return False
if int(vlan)<0 or int(vlan)>4094:
return False
Expand Down Expand Up @@ -88,8 +99,9 @@ if __name__ == "__main__":
address = options.address
finally:
f.close()
except:
pass
except Exception:
master = None
address = ""

# Get the management device from the firstboot data if not specified by the user
if options.device == None:
Expand Down Expand Up @@ -192,13 +204,8 @@ Type 'no' to cancel.
# Update master's IP, if needed and given
if master == False and options.address != None:
print("Setting master's ip (" + address + ")...")
try:
f = open(pool_conf, 'w')
with fsync_write(pool_conf) as f:
f.write('slave:' + address)
finally:
f.flush()
os.fsync(f.fileno())
f.close()

# Construct bridge name for management interface based on convention
if device[:3] == 'eth':
Expand Down Expand Up @@ -230,8 +237,7 @@ Type 'no' to cancel.

# Rewrite firstboot management.conf file, which will be picked it by xcp-networkd on restart (if used)
is_static = False
try:
f = open(management_conf, 'w')
with fsync_write(management_conf) as f:
f.write("LABEL='" + device + "'\n")
if options.mode != "none":
f.write("MODE='" + options.mode + "'\n")
Expand All @@ -252,14 +258,9 @@ Type 'no' to cancel.
f.write("IPv6_GATEWAY='" + options.gateway_v6 + "'\n")
if is_static and options.dns != '':
f.write("DNS='" + options.dns + "'\n")
finally:
f.flush()
os.fsync(f.fileno())
f.close()

# Write trigger file for XAPI to continue the network reset on startup
try:
f = open(network_reset, 'w')
with fsync_write(network_reset) as f:
f.write('DEVICE=' + device + '\n')
if options.mode != "none":
f.write('MODE=' + options.mode + '\n')
Expand All @@ -278,10 +279,6 @@ Type 'no' to cancel.
f.write('GATEWAY_V6=' + options.gateway_v6 + '\n')
if is_static and options.dns != '':
f.write('DNS=' + options.dns + '\n')
finally:
f.flush()
os.fsync(f.fileno())
f.close()

# Reset the domain 0 network interface naming configuration
# back to a fresh-install state for the currently-installed
Expand Down
1 change: 0 additions & 1 deletion scripts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ install:
mkdir -p $(DESTDIR)$(OPTDIR)/debug
$(IPROG) debug_ha_query_liveset $(DESTDIR)$(OPTDIR)/debug
$(IPROG) xe-mount-iso-sr $(DESTDIR)$(OPTDIR)/bin
$(IPROG) xe-reset-networking $(DESTDIR)$(OPTDIR)/bin
$(IPROG) xe-toolstack-restart $(DESTDIR)$(OPTDIR)/bin
$(IPROG) xe-xentrace $(DESTDIR)$(OPTDIR)/bin
$(IPROG) xe-edit-bootloader $(DESTDIR)$(OPTDIR)/bin
Expand Down