6 # Copyright (c) 2003 Intel Corporation
9 # Copyright (c) 2004-2006 The Trustees of Princeton University
10 # All rights reserved.
11 # expected /proc/partitions format
15 from Exceptions import *
24 Writes out the following configuration files for the node:
26 /etc/resolv.conf (if applicable)
28 /etc/ssh/ssh_host_rsa_key
29 /etc/ssh/ssh_host_dsa_key
31 Expect the following variables from the store:
32 VERSION the version of the install
33 SYSIMG_PATH the path where the system image will be mounted
34 (always starts with TEMP_PATH)
35 PARTITIONS dictionary of generic part. types (root/swap)
36 and their associated devices.
37 PLCONF_DIR The directory to store the configuration file in
38 INTERFACE_SETTINGS A dictionary of the values from the network
40 Sets the following variables:
45 log.write( "\n\nStep: Install: Writing configuration files.\n" )
47 # make sure we have the variables we need
49 VERSION= vars["VERSION"]
51 raise ValueError, "VERSION"
53 SYSIMG_PATH= vars["SYSIMG_PATH"]
55 raise ValueError, "SYSIMG_PATH"
57 PARTITIONS= vars["PARTITIONS"]
58 if PARTITIONS == None:
59 raise ValueError, "PARTITIONS"
61 PLCONF_DIR= vars["PLCONF_DIR"]
63 raise ValueError, "PLCONF_DIR"
65 INTERFACE_SETTINGS= vars["INTERFACE_SETTINGS"]
66 if INTERFACE_SETTINGS == "":
67 raise ValueError, "INTERFACE_SETTINGS"
70 raise BootManagerException, "Missing variable in vars: %s\n" % var
71 except ValueError, var:
72 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
74 log.write( "Setting local time to UTC\n" )
75 utils.sysexec_chroot( SYSIMG_PATH,
76 "ln -sf /usr/share/zoneinfo/UTC /etc/localtime", log )
78 log.write( "Enabling ntp at boot\n" )
79 utils.sysexec_chroot( SYSIMG_PATH, "chkconfig ntpd on", log )
81 log.write( "Creating system directory %s\n" % PLCONF_DIR )
82 if not utils.makedirs( "%s/%s" % (SYSIMG_PATH,PLCONF_DIR) ):
83 log.write( "Unable to create directory\n" )
86 log.write( "Writing system /etc/fstab\n" )
87 fstab= file( "%s/etc/fstab" % SYSIMG_PATH, "w" )
88 fstab.write( "%s none swap sw 0 0\n" % \
89 PARTITIONS["mapper-swap"] )
90 fstab.write( "%s / ext3 defaults 1 1\n" % \
91 PARTITIONS["mapper-root"] )
92 fstab.write( "%s /vservers ext3 tagxid,defaults 1 2\n" % \
93 PARTITIONS["mapper-vservers"] )
94 fstab.write( "none /proc proc defaults 0 0\n" )
95 fstab.write( "none /dev/shm tmpfs defaults 0 0\n" )
96 fstab.write( "none /dev/pts devpts defaults 0 0\n" )
99 log.write( "Writing system /etc/issue\n" )
100 issue= file( "%s/etc/issue" % SYSIMG_PATH, "w" )
101 issue.write( "PlanetLab Node: \\n\n" )
102 issue.write( "Kernel \\r on an \\m\n" )
103 issue.write( "http://www.planet-lab.org\n\n" )
106 log.write( "Setting up authentication (non-ssh)\n" )
107 utils.sysexec_chroot( SYSIMG_PATH, "authconfig --nostart --kickstart --enablemd5 " \
108 "--enableshadow", log )
109 utils.sysexec( "sed -e 's/^root\:\:/root\:*\:/g' " \
110 "%s/etc/shadow > %s/etc/shadow.new" % \
111 (SYSIMG_PATH,SYSIMG_PATH), log )
112 utils.sysexec_chroot( SYSIMG_PATH, "mv " \
113 "/etc/shadow.new /etc/shadow", log )
114 utils.sysexec_chroot( SYSIMG_PATH, "chmod 400 /etc/shadow", log )
116 # if we are setup with dhcp, copy the current /etc/resolv.conf into
117 # the system image so we can run programs inside that need network access
120 method= vars['INTERFACE_SETTINGS']['method']
125 utils.sysexec( "cp /etc/resolv.conf %s/etc/" % SYSIMG_PATH, log )
127 log.write( "Writing node install version\n" )
128 utils.makedirs( "%s/etc/planetlab" % SYSIMG_PATH )
129 ver= file( "%s/etc/planetlab/install_version" % SYSIMG_PATH, "w" )
130 ver.write( "%s\n" % VERSION )
133 log.write( "Creating ssh host keys\n" )
134 key_gen_prog= "/usr/bin/ssh-keygen"
136 log.write( "Generating SSH1 RSA host key:\n" )
137 key_file= "/etc/ssh/ssh_host_key"
138 utils.sysexec_chroot( SYSIMG_PATH, "%s -q -t rsa1 -f %s -C '' -N ''" %
139 (key_gen_prog,key_file), log )
140 utils.sysexec( "chmod 600 %s/%s" % (SYSIMG_PATH,key_file), log )
141 utils.sysexec( "chmod 644 %s/%s.pub" % (SYSIMG_PATH,key_file), log )
143 log.write( "Generating SSH2 RSA host key:\n" )
144 key_file= "/etc/ssh/ssh_host_rsa_key"
145 utils.sysexec_chroot( SYSIMG_PATH, "%s -q -t rsa -f %s -C '' -N ''" %
146 (key_gen_prog,key_file), log )
147 utils.sysexec( "chmod 600 %s/%s" % (SYSIMG_PATH,key_file), log )
148 utils.sysexec( "chmod 644 %s/%s.pub" % (SYSIMG_PATH,key_file), log )
150 log.write( "Generating SSH2 DSA host key:\n" )
151 key_file= "/etc/ssh/ssh_host_dsa_key"
152 utils.sysexec_chroot( SYSIMG_PATH, "%s -q -t dsa -f %s -C '' -N ''" %
153 (key_gen_prog,key_file), log )
154 utils.sysexec( "chmod 600 %s/%s" % (SYSIMG_PATH,key_file), log )
155 utils.sysexec( "chmod 644 %s/%s.pub" % (SYSIMG_PATH,key_file), log )