Commit feebb113 authored by Marco Mariani's avatar Marco Mariani

split mammoth run() function

parent 77b561ed
...@@ -935,15 +935,13 @@ class Parser(OptionParser): ...@@ -935,15 +935,13 @@ class Parser(OptionParser):
return options, args[0] return options, args[0]
def run(config):
# Define the computer def parse_computer_definition(config, definition_path):
if config.input_definition_file: config.logger.info('Using definition file %r' % definition_path)
filepath = os.path.abspath(config.input_definition_file)
config.logger.info('Using definition file %r' % filepath)
computer_definition = ConfigParser.RawConfigParser({ computer_definition = ConfigParser.RawConfigParser({
'software_user': 'slapsoft', 'software_user': 'slapsoft',
}) })
computer_definition.read(filepath) computer_definition.read(definition_path)
interface = None interface = None
address = None address = None
netmask = None netmask = None
...@@ -980,18 +978,21 @@ def run(config): ...@@ -980,18 +978,21 @@ def run(config):
tap=tap, tap=tap,
)) ))
computer.partition_list = partition_list computer.partition_list = partition_list
else: return computer
# no definition file, figure out computer
if os.path.exists(config.computer_xml):
config.logger.info('Loading previous computer data from %r' % (
config.computer_xml, )) def parse_computer_xml(config, xml_path):
computer = Computer.load(config.computer_xml, if os.path.exists(xml_path):
reference=config.computer_id, ipv6_interface=config.ipv6_interface) config.logger.info('Loading previous computer data from %r' % xml_path)
computer = Computer.load(xml_path,
reference=config.computer_id,
ipv6_interface=config.ipv6_interface)
# Connect to the interface defined by the configuration # Connect to the interface defined by the configuration
computer.interface = Interface(config.interface_name, config.ipv4_local_network, computer.interface = Interface(config.interface_name, config.ipv4_local_network,
config.ipv6_interface) config.ipv6_interface)
else: else:
# If no pre-existent configuration found, creating a new computer object # If no pre-existent configuration found, create a new computer object
config.logger.warning('Creating new data computer with id %r' % ( config.logger.warning('Creating new data computer with id %r' % (
config.computer_id, )) config.computer_id, ))
computer = Computer( computer = Computer(
...@@ -1030,6 +1031,16 @@ def run(config): ...@@ -1030,6 +1031,16 @@ def run(config):
tap=tap, tap=tap,
)) ))
return computer
def run(config):
if config.input_definition_file:
computer = parse_computer_definition(config, config.input_definition_file)
else:
# no definition file, figure out computer
computer = parse_computer_xml(config, config.computer_xml)
computer.instance_root = config.instance_root computer.instance_root = config.instance_root
computer.software_root = config.software_root computer.software_root = config.software_root
config.logger.info('Updating computer') config.logger.info('Updating computer')
...@@ -1056,9 +1067,9 @@ def run(config): ...@@ -1056,9 +1067,9 @@ def run(config):
computer_definition.set(section, 'network_interface', partition.tap.name) computer_definition.set(section, 'network_interface', partition.tap.name)
computer_definition.set(section, 'pathname', partition.reference) computer_definition.set(section, 'pathname', partition.reference)
partition_number += 1 partition_number += 1
filepath = os.path.abspath(config.output_definition_file) computer_definition.write(open(config.output_definition_file, 'w'))
computer_definition.write(open(filepath, 'w')) config.logger.info('Stored computer definition in %r' % config.output_definition_file)
config.logger.info('Stored computer definition in %r' % filepath)
computer.construct(alter_user=config.alter_user, computer.construct(alter_user=config.alter_user,
alter_network=config.alter_network, create_tap=config.create_tap) alter_network=config.alter_network, create_tap=config.create_tap)
...@@ -1181,6 +1192,7 @@ class Config(object): ...@@ -1181,6 +1192,7 @@ class Config(object):
self.checkRequiredBinary([['tunctl', '-d']]) self.checkRequiredBinary([['tunctl', '-d']])
if self.alter_network: if self.alter_network:
self.checkRequiredBinary(['ip']) self.checkRequiredBinary(['ip'])
# Required, even for dry run # Required, even for dry run
if self.alter_network and self.create_tap: if self.alter_network and self.create_tap:
self.checkRequiredBinary(['brctl']) self.checkRequiredBinary(['brctl'])
...@@ -1237,6 +1249,12 @@ class Config(object): ...@@ -1237,6 +1249,12 @@ class Config(object):
# Calculate path once # Calculate path once
self.computer_xml = os.path.abspath(self.computer_xml) self.computer_xml = os.path.abspath(self.computer_xml)
if self.input_definition_file:
self.input_definition_file = os.path.abspath(self.input_definition_file)
if self.output_definition_file:
self.output_definition_file = os.path.abspath(self.output_definition_file)
def tracing_monkeypatch(config): def tracing_monkeypatch(config):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment