Commit feebb113 authored by Marco Mariani's avatar Marco Mariani

split mammoth run() function

parent 77b561ed
......@@ -935,15 +935,13 @@ class Parser(OptionParser):
return options, args[0]
def run(config):
# Define the computer
if config.input_definition_file:
filepath = os.path.abspath(config.input_definition_file)
config.logger.info('Using definition file %r' % filepath)
def parse_computer_definition(config, definition_path):
config.logger.info('Using definition file %r' % definition_path)
computer_definition = ConfigParser.RawConfigParser({
'software_user': 'slapsoft',
})
computer_definition.read(filepath)
computer_definition.read(definition_path)
interface = None
address = None
netmask = None
......@@ -980,18 +978,21 @@ def run(config):
tap=tap,
))
computer.partition_list = partition_list
else:
# 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, ))
computer = Computer.load(config.computer_xml,
reference=config.computer_id, ipv6_interface=config.ipv6_interface)
return computer
def parse_computer_xml(config, xml_path):
if os.path.exists(xml_path):
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
computer.interface = Interface(config.interface_name, config.ipv4_local_network,
config.ipv6_interface)
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.computer_id, ))
computer = Computer(
......@@ -1030,6 +1031,16 @@ def run(config):
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.software_root = config.software_root
config.logger.info('Updating computer')
......@@ -1056,9 +1067,9 @@ def run(config):
computer_definition.set(section, 'network_interface', partition.tap.name)
computer_definition.set(section, 'pathname', partition.reference)
partition_number += 1
filepath = os.path.abspath(config.output_definition_file)
computer_definition.write(open(filepath, 'w'))
config.logger.info('Stored computer definition in %r' % filepath)
computer_definition.write(open(config.output_definition_file, 'w'))
config.logger.info('Stored computer definition in %r' % config.output_definition_file)
computer.construct(alter_user=config.alter_user,
alter_network=config.alter_network, create_tap=config.create_tap)
......@@ -1181,6 +1192,7 @@ class Config(object):
self.checkRequiredBinary([['tunctl', '-d']])
if self.alter_network:
self.checkRequiredBinary(['ip'])
# Required, even for dry run
if self.alter_network and self.create_tap:
self.checkRequiredBinary(['brctl'])
......@@ -1237,6 +1249,12 @@ class Config(object):
# Calculate path once
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):
......
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