Commit 2ed1c39e authored by Marco Mariani's avatar Marco Mariani

ask if bridge is needed, disable create_tap if bridge is not needed

parent c19d4b77
...@@ -20,7 +20,10 @@ setup(name=name, ...@@ -20,7 +20,10 @@ setup(name=name,
author='VIFIB', author='VIFIB',
packages=['slapprepare'], packages=['slapprepare'],
include_package_data=True, include_package_data=True,
install_requires=['slapos.libnetworkcache',], install_requires=[
'slapos.libnetworkcache',
'iniparse',
],
zip_safe=False, zip_safe=False,
entry_points={ entry_points={
'console_scripts': [ 'console_scripts': [
......
...@@ -29,13 +29,14 @@ ...@@ -29,13 +29,14 @@
from optparse import OptionParser, Option from optparse import OptionParser, Option
import ConfigParser, os import ConfigParser, os
import pkg_resources import pkg_resources
import re
import socket import socket
from subprocess import call as subprocessCall from subprocess import call as subprocessCall
import sys import sys
import urllib2 import urllib2
from pwd import getpwnam from pwd import getpwnam
import iniparse
SLAPOS_MARK='# Added by SlapOS\n' SLAPOS_MARK='# Added by SlapOS\n'
...@@ -162,16 +163,16 @@ def get_computer_name(slapos_configuration): ...@@ -162,16 +163,16 @@ def get_computer_name(slapos_configuration):
return socket.gethostname() return socket.gethostname()
def enable_bridge(slapos_configuration): def setup_bridge(slapos_configuration, create_tap):
# we don't use ConfigParser here, as it would remove comments
slapos_cfg_path = os.path.join(slapos_configuration, 'slapos.cfg') slapos_cfg_path = os.path.join(slapos_configuration, 'slapos.cfg')
lines = []
for line in open(slapos_cfg_path): # using iniparse instead of ConfigParser, will retain the comments
if re.match('^create_tap *=', line): slapos_cfg = iniparse.RawConfigParser()
line = 'create_tap = true\n' slapos_cfg.read(slapos_cfg_path)
lines.append(line)
slapos_cfg.set('slapformat', 'create_tap', 'true' if create_tap else 'false')
with open(slapos_cfg_path, 'w') as fout: with open(slapos_cfg_path, 'w') as fout:
fout.writelines(lines) slapos_cfg.write(fout)
# Function to get ssh key # Function to get ssh key
...@@ -448,11 +449,15 @@ class Config: ...@@ -448,11 +449,15 @@ class Config:
self.partition_amount = raw_input("""Number of SlapOS partitions for this computer? Default is 20 :""") self.partition_amount = raw_input("""Number of SlapOS partitions for this computer? Default is 20 :""")
if self.partition_amount == '': if self.partition_amount == '':
self.partition_amount = '20' self.partition_amount = '20'
self.virtual = get_yes_no("Is this a virtual Machine?",False) self.virtual = get_yes_no("Is this a virtual Machine?",False)
if not self.virtual: if not self.virtual:
self.one_disk = not get_yes_no ("Do you want to use SlapOS with a second disk?",True) self.one_disk = not get_yes_no ("Do you want to use SlapOS with a second disk?",True)
else: else:
self.one_disk=True self.one_disk=True
self.need_bridge = get_yes_no("Do you to setup the network to allow virtual machines inside this node?",False)
self.force_vpn = get_yes_no ("Do you want to use vpn to provide ipv6?",True) self.force_vpn = get_yes_no ("Do you want to use vpn to provide ipv6?",True)
self.force_slapcontainer = get_yes_no ("Do you want to force the use lxc on this computer?",False) self.force_slapcontainer = get_yes_no ("Do you want to force the use lxc on this computer?",False)
if self.force_vpn : if self.force_vpn :
...@@ -504,8 +509,11 @@ def prepare_from_scratch(config): ...@@ -504,8 +509,11 @@ def prepare_from_scratch(config):
,'--interface-name', 'br0' ,'--interface-name', 'br0'
,'--ipv6-interface', config.ipv6_interface ,'--ipv6-interface', config.ipv6_interface
,'--partition-number', config.partition_amount]) ,'--partition-number', config.partition_amount])
# Prepare for bridge
enable_bridge(slapos_configuration) if config.need_bridge:
setup_bridge(slapos_configuration, True)
else:
setup_bridge(slapos_configuration, False)
computer_id = get_computer_name( computer_id = get_computer_name(
os.path.join('/', slapos_configuration, 'slapos.cfg')) os.path.join('/', slapos_configuration, 'slapos.cfg'))
......
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