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