-#!/usr/bin/python
#
# Copyright (c) 2003 Intel Corporation
# All rights reserved.
# All rights reserved.
# expected /proc/partitions format
+# pylint: disable=c0111, c0103
+
import os
import os.path
from Exceptions import *
import utils
-import BootAPI
-import ModelOptions
+
def Run(vars, log):
/etc/ssh/ssh_host_key
/etc/ssh/ssh_host_rsa_key
/etc/ssh/ssh_host_dsa_key
-
+
Expect the following variables from the store:
VERSION the version of the install
SYSIMG_PATH the path where the system image will be mounted
configuration file
Sets the following variables:
None
-
+
"""
- log.write( "\n\nStep: Install: Writing configuration files.\n")
-
+ log.write("\n\nStep: Install: Writing configuration files.\n")
+
# make sure we have the variables we need
try:
VERSION = vars["VERSION"]
raise ValueError("SYSIMG_PATH")
PARTITIONS = vars["PARTITIONS"]
- if PARTITIONS == None:
+ if PARTITIONS is None:
raise ValueError("PARTITIONS")
PLCONF_DIR = vars["PLCONF_DIR"]
if INTERFACE_SETTINGS == "":
raise ValueError("INTERFACE_SETTINGS")
- except KeyError, var:
+ except KeyError as var:
raise BootManagerException("Missing variable in vars: {}\n".format(var))
- except ValueError, var:
+ except ValueError as var:
raise BootManagerException("Variable in vars, shouldn't be: {}\n".format(var))
log.write("Setting local time to UTC\n")
- utils.sysexec_chroot(SYSIMG_PATH,
+ utils.sysexec_chroot(
+ SYSIMG_PATH,
"ln -sf /usr/share/zoneinfo/UTC /etc/localtime", log)
log.write("Creating system directory {}\n".format(PLCONF_DIR))
return 0
log.write("Writing system /etc/fstab\n")
- fstab = file("{}/etc/fstab".format(SYSIMG_PATH), "w")
- fstab.write("{} none swap sw 0 0\n"\
- .format(PARTITIONS["swap"]))
- fstab.write("{} / ext3 defaults 1 1\n"\
- .format(PARTITIONS["root"]))
- if (vars['ONE_PARTITION'] != '1'):
- if vars['virt'] == 'vs':
- fstab.write("{} /vservers ext3 tagxid,defaults 1 2\n"\
- .format(PARTITIONS["vservers"]))
- else:
- fstab.write("{} /vservers btrfs defaults 1 2\n"\
- .format(PARTITIONS["vservers"]))
- fstab.write("none /proc proc defaults 0 0\n")
- fstab.write("none /dev/shm tmpfs defaults 0 0\n")
- fstab.write("none /dev/pts devpts defaults 0 0\n")
- fstab.close()
+ with open("{}/etc/fstab".format(SYSIMG_PATH), "w") as fstab:
+ fstab.write("{} none swap sw 0 0\n"\
+ .format(PARTITIONS["swap"]))
+ fstab.write("{} / ext3 defaults 1 1\n"\
+ .format(PARTITIONS["root"]))
+ if (vars['ONE_PARTITION'] != '1'):
+ if vars['virt'] == 'vs':
+ fstab.write("{} /vservers ext3 tagxid,defaults 1 2\n"\
+ .format(PARTITIONS["vservers"]))
+ else:
+ fstab.write("{} /vservers btrfs defaults 1 2\n"\
+ .format(PARTITIONS["vservers"]))
+ fstab.write("none /proc proc defaults 0 0\n")
+ fstab.write("none /dev/shm tmpfs defaults 0 0\n")
+ fstab.write("none /dev/pts devpts defaults 0 0\n")
log.write("Writing system /etc/issue\n")
- issue= file("{}/etc/issue".format(SYSIMG_PATH), "w")
- issue.write("PlanetLab Node: \\n\n")
- issue.write("Kernel \\r on an \\m\n")
- issue.write("http://www.planet-lab.org\n\n")
- issue.close()
+ with open("{}/etc/issue".format(SYSIMG_PATH), "w") as issue:
+ issue.write("PlanetLab Node: \\n\n")
+ issue.write("Kernel \\r on an \\m\n")
+ issue.write("http://www.planet-lab.org\n\n")
if (vars['ONE_PARTITION'] != '1'):
log.write("Setting up authentication (non-ssh)\n")
method = vars['INTERFACE_SETTINGS']['method']
except:
pass
-
+
if method == "dhcp":
utils.sysexec("cp /etc/resolv.conf {}/etc/".format(SYSIMG_PATH), log)
log.write("Writing node install_version\n")
utils.makedirs("{}/etc/planetlab".format(SYSIMG_PATH))
- ver = file("{}/etc/planetlab/install_version".format(SYSIMG_PATH), "w")
- ver.write("{}\n".format(VERSION))
- ver.close()
+ with open("{}/etc/planetlab/install_version".format(SYSIMG_PATH), "w") as ver:
+ ver.write("{}\n".format(VERSION))
- # for upgrades : do not overwrite already existing keys
+ # for upgrades : do not overwrite already existing keys
log.write("Creating ssh host keys\n")
key_gen_prog = "/usr/bin/ssh-keygen"
else:
run = utils.sysexec_noerr
run_chroot = utils.sysexec_chroot_noerr
- run_chroot(SYSIMG_PATH, "{} -q -t {} -f {} -C '' -N ''"\
- .format(key_gen_prog, key_type, key_file), log)
+ run_chroot(
+ SYSIMG_PATH,
+ "{} -q -t {} -f {} -C '' -N ''"
+ .format(key_gen_prog, key_type, key_file),
+ log)
run("chmod 600 {}/{}".format(SYSIMG_PATH, key_file), log)
run("chmod 644 {}/{}.pub".format(SYSIMG_PATH, key_file), log)
-
+
return 1
-#!/usr/bin/python
#
# Copyright (c) 2003 Intel Corporation
# All rights reserved.
# All rights reserved.
# expected /proc/partitions format
+# pylint: disable=c0111
+
from __future__ import print_function
-import os, sys, shutil
+import sys
+import os
+import shutil
import subprocess
import shlex
import socket
import fcntl
-import string
-import exceptions
+# handling breakpoints in the startup process
+import select
from Exceptions import *
####################
-# the simplest way to debug is to let the node take off,
+# the simplest way to debug is to let the node take off,
# ssh into it as root using the debug ssh key in /etc/planetlab
-# then go to /tmp/source
+# then go to /tmp/source
# edit this file locally to turn on breakpoints if needed, then run
# ./BootManager.py
####################
-### handling breakpoints in the startup process
-import select, sys, string
-
### global debugging settings
# enabling this will cause the node to ask for breakpoint-mode at startup
display = "[y]/n"
else:
display = "y/[n]"
- sys.stdout.write ("Want to run in breakpoint mode ? {} ".format(display))
+ sys.stdout.write("Want to run in breakpoint mode ? {} ".format(display))
sys.stdout.flush()
- r, w, e = select.select ([sys.stdin], [], [], PROMPT_TIMEOUT)
+ r, w, e = select.select([sys.stdin], [], [], PROMPT_TIMEOUT)
if r:
- answer = string.strip(sys.stdin.readline())
+ answer = sys.stdin.readline().strip()
else:
sys.stdout.write("\nTimed-out ({}s)".format(PROMPT_TIMEOUT))
if answer:
- BREAKPOINT_MODE = (answer == "y" or answer == "Y")
+ BREAKPOINT_MODE = (answer in 'yY')
else:
BREAKPOINT_MODE = default_answer
label = "Off"
label = "On"
sys.stdout.write("\nCurrent BREAKPOINT_MODE is {}\n".format(label))
-def breakpoint (message, cmd = None):
+def breakpoint (message, cmd=None):
if BREAKPOINT_MODE:
os.system(cmd)
else:
- print("Ignoring breakpoint (BREAKPOINT_MODE=False) : {}".format(message))
+ print("Ignoring breakpoint (BREAKPOINT_MODE=False) : {}".format(message))
########################################
os.listdir(path)
except OSError:
raise BootManagerException("Unable to create directory tree: {}".format(path))
-
+
return 1
try:
shutil.rmtree(path)
- except OSError as desc:
+ except OSError:
raise BootManagerException("Unable to remove directory tree: {}".format(path))
-
+
return 1
returncode = prog.wait()
if fsck:
- # The exit code returned by fsck is the sum of the following conditions:
- # 0 - No errors
- # 1 - File system errors corrected
- # 2 - System should be rebooted
- # 4 - File system errors left uncorrected
- # 8 - Operational error
- # 16 - Usage or syntax error
- # 32 - Fsck canceled by user request
- # 128 - Shared library error
- if returncode != 0 and returncode != 1:
+ # The exit code returned by fsck is the sum of the following conditions:
+ # 0 - No errors
+ # 1 - File system errors corrected
+ # 2 - System should be rebooted
+ # 4 - File system errors left uncorrected
+ # 8 - Operational error
+ # 16 - Usage or syntax error
+ # 32 - Fsck canceled by user request
+ # 128 - Shared library error
+ if returncode not in (0, 1):
raise BootManagerException("Running {} failed (rc={})".format(cmd, returncode))
else:
if returncode != 0:
"""
same as sysexec, but inside a chroot
"""
- preload = ""
- release = os.uname()[2]
- # 2.6.12 kernels need this
- if release[:5] == "2.6.1":
- library = "{}/lib/libc-opendir-hack.so".format(path)
- if not os.path.exists(library):
- shutil.copy("./libc-opendir-hack.so", library)
- preload = "/bin/env LD_PRELOAD=/lib/libc-opendir-hack.so"
- sysexec("chroot {} {} {}".format(path, preload, cmd), log, shell=shell)
+ return sysexec("chroot {} {}".format(path, cmd), log, shell=shell)
def sysexec_chroot_noerr(path, cmd, log=None, shell=False):
given a device name, like eth0, return its mac_address.
return None if the device doesn't exist.
"""
-
+
SIOCGIFHWADDR = 0x8927 # magic number
- s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
- ifname = string.strip(ifname)
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ ifname = ifname.strip()
ifr = ifname + '\0'*(32-len(ifname))
try:
ret = ':'.join(["{:02x}".format(ord(n)) for n in r[18:24]])
except IOError as e:
ret = None
-
+
return ret
def check_file_hash(filename, hash_filename):