Commit 4884a05a authored by Marco Mariani's avatar Marco Mariani

prepare: general, light cleanup

parent 74ef042c
......@@ -62,8 +62,7 @@ class Parser(OptionParser):
help="Simulate the execution steps",
default=False,
action="store_true"),
]
)
])
def check_args(self):
"""
......@@ -129,8 +128,7 @@ def getSlaposConfiguration(slapos_configuration_file_path=None):
for path in [
slapos_configuration_file_path,
'/etc/opt/slapos/slapos.cfg',
'/etc/slapos/slapos.cfg'
]:
'/etc/slapos/slapos.cfg']:
if path and os.path.isfile(path):
config = ConfigParser.RawConfigParser()
config.read(path)
......@@ -176,17 +174,16 @@ def get_ssh(temp_dir):
# Downloading ssh_key
count = 10
gotten = True
while count > 0:
while count:
try:
print "Enter the url of your public ssh key"
ssh_web = raw_input('--> ')
try:
ssh_key_all = urllib2.urlopen(''.join(ssh_web))
ssh_key_all = urllib2.urlopen(ssh_web)
gotten = True
except ValueError:
# add http:// if it is missing (needed by urllib2)
ssh_web = """http://""" + ssh_web
ssh_key_all = urllib2.urlopen(''.join(ssh_web))
ssh_key_all = urllib2.urlopen('http://%s' % ssh_web)
gotten = True
except urllib2.URLError:
print " URL ERROR"
......@@ -241,8 +238,9 @@ def slapserver(config):
if not dry_run:
open(host_path, 'w').write(
pkg_resources.resource_stream(__name__,
'template/hosts.in').read() % dict(
computer_id=config.computer_id))
'template/hosts.in').read() % {
'computer_id': config.computer_id
})
# Creating safe sshd_config
sshd_path = os.path.normpath('/'.join([mount_dir_path, 'etc', 'ssh',
......@@ -252,7 +250,7 @@ def slapserver(config):
open(sshd_path, 'w').write(
pkg_resources.resource_stream(__name__,
'template/sshd_config.in').read())
os.chmod(sshd_path, 0600)
os.chmod(sshd_path, 0o600)
# Creating default bridge config
br0_path = os.path.normpath('/'.join([mount_dir_path, 'etc',
......@@ -288,16 +286,16 @@ def slapserver(config):
if not dry_run:
print "Setting uid:gid of %r to %s:%s" % (ssh_key_directory, uid, gid)
os.chown(ssh_key_directory, uid, gid)
os.chmod(ssh_key_directory, 0700)
os.chmod(ssh_key_directory, 0o700)
print "Creating file: %s" % ssh_key_path
if not dry_run:
open(ssh_key_path, 'a').write(''.join(open(config.key_path, 'r').read()))
open(ssh_key_path, 'a').write(''.join(open(config.key_path).read()))
if not dry_run:
print "Setting uid:gid of %r to %s:%s" % (ssh_key_path, uid, gid)
os.chown(ssh_key_path, uid, gid)
os.chmod(ssh_key_path, 0600)
os.chmod(ssh_key_path, 0o600)
# Put file to force VPN if user asked
if config.force_slapcontainer:
......@@ -312,7 +310,7 @@ def slapserver(config):
if not dry_run:
open(path, 'w').write(pkg_resources.resource_stream(__name__,
'script/%s' % script).read())
os.chmod(path, 0755)
os.chmod(path, 0o755)
else:
for script in ['slapos_firstboot']:
path = os.path.join(mount_dir_path, 'etc', 'init.d', script)
......@@ -346,34 +344,34 @@ def prepare_scripts(config):
slapos_configuration = '/etc/opt/slapos/'
# Creating boot script
path = os.path.join('/', 'usr', 'sbin', 'slapos-boot-dedicated')
path = '/usr/sbin/slapos-boot-dedicated'
print "Creating %r" % path
if not dry_run:
open(path, 'w').write(
pkg_resources.resource_stream(__name__,
'script/%s' % 'slapos').read()
% {'slapos_configuration': slapos_configuration})
os.chmod(path, 0755)
'script/%s' % 'slapos').read() % {
'slapos_configuration': slapos_configuration
})
os.chmod(path, 0o755)
path = os.path.join('/', 'etc',
'systemd', 'system',
'slapos-boot-dedicated.service')
path = '/etc/systemd/system/slapos-boot-dedicated.service'
print "Creating %r" % path
if not dry_run:
open(path, 'w').write(
pkg_resources.resource_stream(__name__,
'script/%s' % 'slapos.service').read()
% dict(slapos_configuration=slapos_configuration))
os.chmod(path, 0755)
'script/%s' % 'slapos.service').read() % {
'slapos_configuration': slapos_configuration
})
os.chmod(path, 0o755)
# add clientipv4
path = os.path.join('/', 'etc', 'openvpn', 'clientipv4.conf')
path = '/etc/openvpn/clientipv4.conf'
print "Creating %r" % path
if not dry_run:
open(path, 'w').write(
pkg_resources.resource_stream(__name__,
'template/%s' % 'clientipv4.conf.in').read())
os.chmod(path, 0755)
os.chmod(path, 0o755)
# Remove old-timers scripts
remove_former_scripts(slapos_configuration)
......@@ -382,7 +380,7 @@ def prepare_scripts(config):
def configureNtp():
"""Configures NTP daemon"""
server = "server pool.ntp.org"
old_ntp = open('/etc/ntp.conf', 'r').readlines()
old_ntp = open('/etc/ntp.conf').readlines()
new_ntp = open('/etc/ntp.conf', 'w')
for line in old_ntp:
if line.startswith('server'):
......@@ -439,13 +437,13 @@ class Config:
if not get_yes_no("A SlapOS Node configuration has been found. Do you want to overwrite it?", False):
print "Okay, let's start from scratch."
return False
self.master_url = raw_input("""SlapOS Master URL? Empty answer will make it use slapos.org Master: """)
self.master_url = raw_input("SlapOS Master URL? Empty answer will make it use slapos.org Master: ")
if self.master_url:
self.master_url_web = raw_input("""SlapOS Master "web" URL?: """)
self.master_url_web = raw_input('SlapOS Master "web" URL?: ')
else:
self.master_url_web = ''
self.computer_name = raw_input("Define a unique name for this computer: ")
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 == '':
self.partition_amount = '20'
elif not already_configured:
......@@ -484,10 +482,10 @@ class Config:
def prepare_from_scratch(config):
try:
temp_directory = os.path.join('/tmp/slaptemp/')
temp_directory = '/tmp/slaptemp/'
if not os.path.exists(temp_directory):
print "Creating directory: %s" % temp_directory
os.mkdir(temp_directory, 0711)
os.mkdir(temp_directory, 0o711)
while True:
if config.userConfig():
......@@ -534,7 +532,7 @@ def prepare_from_scratch(config):
print 'Warning: impossible to set up bridge because slapos configuration doesn\'t exist.'
computer_id = get_computer_name(
os.path.join('/', slapos_configuration, 'slapos.cfg'))
os.path.join(slapos_configuration, 'slapos.cfg'))
print "Your Computer is : %s" % computer_id
......@@ -543,7 +541,7 @@ def prepare_from_scratch(config):
hostname_path='/etc/HOSTNAME',
host_path='/etc/hosts',
key_path=os.path.join(temp_directory, 'authorized_keys'),
master_url="""https://slap.vifib.com""",
master_url='https://slap.vifib.com',
temp_dir=temp_directory,
computer_id=computer_id)
......
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