slapformat: no_bridge becomes 'not create_tap'.

create_tap is true by default.
rationale: better understanding of what does the option, and simpler use of
slapgrid.
parent 85c7fe0c
......@@ -179,7 +179,7 @@ class Computer(object):
def __getinitargs__(self):
return (self.reference, self.interface)
def getAddress(self, no_bridge=False):
def getAddress(self, allow_tap=False):
"""
Return a list of the interface address not attributed to any partition, (which
are therefore free for the computer itself).
......@@ -201,7 +201,7 @@ class Computer(object):
if address_dict['addr'] not in computer_partition_address_list:
return address_dict
if not no_bridge:
if allow_tap:
# all addresses on interface are for partition, so lets add new one
computer_tap = Tap('compdummy')
computer_tap.createWithOwner(User('root'), attach_to_tap=True)
......@@ -854,10 +854,6 @@ class Parser(OptionParser):
help="Don't actually do anything.",
default=False,
action="store_true"),
Option("-b", "--no_bridge",
help="Don't use bridge but use real interface like eth0.",
default=False,
action="store_true"),
Option("-v", "--verbose",
default=False,
action="store_true",
......@@ -982,7 +978,7 @@ def run(config):
computer.instance_root = config.instance_root
computer.software_root = config.software_root
config.logger.info('Updating computer')
address = computer.getAddress(config.no_bridge)
address = computer.getAddress(config.create_tap)
computer.address = address['addr']
computer.netmask = address['netmask']
......@@ -1009,7 +1005,7 @@ def run(config):
computer_definition.write(open(filepath, 'w'))
config.logger.info('Stored computer definition in %r' % filepath)
computer.construct(alter_user=config.alter_user,
alter_network=config.alter_network, create_tap=not config.no_bridge)
alter_network=config.alter_network, create_tap=config.create_tap)
# Dumping and sending to the erp5 the current configuration
if not config.dry_run:
......@@ -1023,6 +1019,7 @@ class Config(object):
cert_file = None
alter_network = None
alter_user = None
create_tap = None
computer_xml = None
logger = None
log_file = None
......@@ -1070,7 +1067,7 @@ class Config(object):
'tap_base_name', 'ipv4_local_network', 'ipv6_interface']:
if getattr(self, parameter, None) is None:
setattr(self, parameter, None)
# Backward compatibility
if not getattr(self, "interface_name", None) \
and getattr(self, "bridge_name", None):
......@@ -1083,6 +1080,8 @@ class Config(object):
self.alter_user = 'True'
if self.software_user is None:
self.software_user = 'slapsoft'
if self.create_tap is None:
self.create_tap = True
# set up logging
self.logger = logging.getLogger("slapformat")
......@@ -1091,7 +1090,7 @@ class Config(object):
self.logger.addHandler(logging.StreamHandler())
# Convert strings to booleans
for o in ['alter_network', 'alter_user', 'no_bridge']:
for o in ['alter_network', 'alter_user', 'create_tap']:
attr = getattr(self, o)
if isinstance(attr, str):
if attr.lower() == 'true':
......@@ -1108,12 +1107,12 @@ class Config(object):
if not self.dry_run:
if self.alter_user:
self.checkRequiredBinary(['groupadd', 'useradd', 'usermod'])
if not self.no_bridge:
if self.create_tap:
self.checkRequiredBinary(['tunctl'])
if self.alter_network:
self.checkRequiredBinary(['ip'])
# Required, even for dry run
if self.alter_network and not self.no_bridge:
if self.alter_network and self.create_tap:
self.checkRequiredBinary(['brctl'])
# Check if root is needed
......@@ -1152,8 +1151,8 @@ class Config(object):
self.logger.debug("Verbose mode enabled.")
if self.dry_run:
self.logger.info("Dry-run mode enabled.")
if self.no_bridge:
self.logger.info("No-bridge mode enabled.")
if self.create_tap:
self.logger.info("Tap mode enabled.")
# Calculate path once
self.computer_xml = os.path.abspath(self.computer_xml)
......
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