3 # Copyright (c) 2003 Intel Corporation
6 # Copyright (c) 2004-2006 The Trustees of Princeton University
8 # expected /proc/partitions format
12 from Exceptions import *
21 Writes out the following configuration files for the node:
23 /etc/resolv.conf (if applicable)
25 /etc/ssh/ssh_host_rsa_key
26 /etc/ssh/ssh_host_dsa_key
28 Expect the following variables from the store:
29 VERSION the version of the install
30 SYSIMG_PATH the path where the system image will be mounted
31 (always starts with TEMP_PATH)
32 PARTITIONS dictionary of generic part. types (root/swap)
33 and their associated devices.
34 PLCONF_DIR The directory to store the configuration file in
35 NETWORK_SETTINGS A dictionary of the values from the network
37 BOOT_CD_VERSION A tuple of the current bootcd version
39 Sets the following variables:
44 log.write( "\n\nStep: Install: Writing configuration files.\n" )
46 # make sure we have the variables we need
48 VERSION= vars["VERSION"]
50 raise ValueError, "VERSION"
52 SYSIMG_PATH= vars["SYSIMG_PATH"]
54 raise ValueError, "SYSIMG_PATH"
56 PARTITIONS= vars["PARTITIONS"]
57 if PARTITIONS == None:
58 raise ValueError, "PARTITIONS"
60 PLCONF_DIR= vars["PLCONF_DIR"]
62 raise ValueError, "PLCONF_DIR"
64 NETWORK_SETTINGS= vars["NETWORK_SETTINGS"]
65 if NETWORK_SETTINGS == "":
66 raise ValueError, "NETWORK_SETTINGS"
68 BOOT_CD_VERSION= vars["BOOT_CD_VERSION"]
69 if BOOT_CD_VERSION == "":
70 raise ValueError, "BOOT_CD_VERSION"
73 raise BootManagerException, "Missing variable in vars: %s\n" % var
74 except ValueError, var:
75 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
77 log.write( "Setting local time to UTC\n" )
78 utils.sysexec( "chroot %s ln -sf /usr/share/zoneinfo/UTC /etc/localtime" % \
81 log.write( "Enabling ntp at boot\n" )
82 utils.sysexec( "chroot %s chkconfig ntpd on" % SYSIMG_PATH, log )
84 log.write( "Creating system directory %s\n" % PLCONF_DIR )
85 if not utils.makedirs( "%s/%s" % (SYSIMG_PATH,PLCONF_DIR) ):
86 log.write( "Unable to create directory\n" )
89 utils.breakpoint("Before fstab");
90 log.write( "Writing system /etc/fstab\n" )
91 fstab= file( "%s/etc/fstab" % SYSIMG_PATH, "w" )
92 fstab.write( "%s none swap sw 0 0\n" % \
93 PARTITIONS["mapper-swap"] )
94 fstab.write( "%s / ext3 defaults 0 0\n" % \
95 PARTITIONS["mapper-root"] )
96 fstab.write( "%s /vservers ext3 tagxid,defaults 0 0\n" % \
97 PARTITIONS["mapper-vservers"] )
98 fstab.write( "none /proc proc defaults 0 0\n" )
99 fstab.write( "none /dev/shm tmpfs defaults 0 0\n" )
100 fstab.write( "none /dev/pts devpts defaults 0 0\n" )
102 # fstab.write( "none /rcfs rcfs defaults 0 0\n" )
105 utils.breakpoint("after fstab");
107 log.write( "Writing system /etc/issue\n" )
108 issue= file( "%s/etc/issue" % SYSIMG_PATH, "w" )
109 issue.write( "PlanetLab Node: \\n\n" )
110 issue.write( "Kernel \\r on an \\m\n" )
111 issue.write( "http://www.planet-lab.org\n\n" )
114 log.write( "Setting up authentication (non-ssh)\n" )
115 utils.sysexec( "chroot %s authconfig --nostart --kickstart --enablemd5 " \
116 "--enableshadow" % SYSIMG_PATH, log )
117 utils.sysexec( "sed -e 's/^root\:\:/root\:*\:/g' " \
118 "%s/etc/shadow > %s/etc/shadow.new" % \
119 (SYSIMG_PATH,SYSIMG_PATH), log )
120 utils.sysexec( "chroot %s mv " \
121 "/etc/shadow.new /etc/shadow" % SYSIMG_PATH, log )
122 utils.sysexec( "chroot %s chmod 400 /etc/shadow" % SYSIMG_PATH, log )
124 # if we are setup with dhcp, copy the current /etc/resolv.conf into
125 # the system image so we can run programs inside that need network access
128 method= vars['NETWORK_SETTINGS']['method']
133 utils.sysexec( "cp /etc/resolv.conf %s/etc/" % SYSIMG_PATH, log )
135 log.write( "Writing node install version\n" )
136 utils.makedirs( "%s/etc/planetlab" % SYSIMG_PATH )
137 ver= file( "%s/etc/planetlab/install_version" % SYSIMG_PATH, "w" )
138 ver.write( "%s\n" % VERSION )
141 log.write( "Creating ssh host keys\n" )
142 key_gen_prog= "/usr/bin/ssh-keygen"
144 log.write( "Generating SSH1 RSA host key:\n" )
145 key_file= "/etc/ssh/ssh_host_key"
146 utils.sysexec( "chroot %s %s -q -t rsa1 -f %s -C '' -N ''" %
147 (SYSIMG_PATH,key_gen_prog,key_file), log )
148 utils.sysexec( "chmod 600 %s/%s" % (SYSIMG_PATH,key_file), log )
149 utils.sysexec( "chmod 644 %s/%s.pub" % (SYSIMG_PATH,key_file), log )
151 log.write( "Generating SSH2 RSA host key:\n" )
152 key_file= "/etc/ssh/ssh_host_rsa_key"
153 utils.sysexec( "chroot %s %s -q -t rsa -f %s -C '' -N ''" %
154 (SYSIMG_PATH,key_gen_prog,key_file), log )
155 utils.sysexec( "chmod 600 %s/%s" % (SYSIMG_PATH,key_file), log )
156 utils.sysexec( "chmod 644 %s/%s.pub" % (SYSIMG_PATH,key_file), log )
158 log.write( "Generating SSH2 DSA host key:\n" )
159 key_file= "/etc/ssh/ssh_host_dsa_key"
160 utils.sysexec( "chroot %s %s -q -t dsa -f %s -C '' -N ''" %
161 (SYSIMG_PATH,key_gen_prog,key_file), log )
162 utils.sysexec( "chmod 600 %s/%s" % (SYSIMG_PATH,key_file), log )
163 utils.sysexec( "chmod 644 %s/%s.pub" % (SYSIMG_PATH,key_file), log )