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 *
20 Writes out the following configuration files for the node:
22 /etc/resolv.conf (if applicable)
24 /etc/ssh/ssh_host_rsa_key
25 /etc/ssh/ssh_host_dsa_key
27 Expect the following variables from the store:
28 VERSION the version of the install
29 SYSIMG_PATH the path where the system image will be mounted
30 (always starts with TEMP_PATH)
31 PARTITIONS dictionary of generic part. types (root/swap)
32 and their associated devices.
33 PLCONF_DIR The directory to store the configuration file in
34 INTERFACE_SETTINGS A dictionary of the values from the network
36 Sets the following variables:
41 log.write( "\n\nStep: Install: Writing configuration files.\n" )
43 # make sure we have the variables we need
45 VERSION= vars["VERSION"]
47 raise ValueError, "VERSION"
49 SYSIMG_PATH= vars["SYSIMG_PATH"]
51 raise ValueError, "SYSIMG_PATH"
53 PARTITIONS= vars["PARTITIONS"]
54 if PARTITIONS == None:
55 raise ValueError, "PARTITIONS"
57 PLCONF_DIR= vars["PLCONF_DIR"]
59 raise ValueError, "PLCONF_DIR"
61 INTERFACE_SETTINGS= vars["INTERFACE_SETTINGS"]
62 if INTERFACE_SETTINGS == "":
63 raise ValueError, "INTERFACE_SETTINGS"
66 raise BootManagerException, "Missing variable in vars: %s\n" % var
67 except ValueError, var:
68 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
70 log.write( "Setting local time to UTC\n" )
71 utils.sysexec_chroot( SYSIMG_PATH,
72 "ln -sf /usr/share/zoneinfo/UTC /etc/localtime", log )
74 # clearly this does not depend on vs / lxc but let's keep it simple
75 log.write( "Enabling ntp at boot\n" )
76 if vars['virt'] == 'vs':
77 utils.sysexec_chroot( SYSIMG_PATH, "chkconfig ntpd on", log )
79 utils.sysexec_chroot( SYSIMG_PATH, "systemctl enable ntpd.service", 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 if vars['virt'] == 'vs':
93 fstab.write( "%s /vservers ext3 tagxid,defaults 1 2\n" % \
94 PARTITIONS["mapper-vservers"] )
96 fstab.write( "%s /vservers btrfs defaults 1 2\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" )
103 log.write( "Writing system /etc/issue\n" )
104 issue= file( "%s/etc/issue" % SYSIMG_PATH, "w" )
105 issue.write( "PlanetLab Node: \\n\n" )
106 issue.write( "Kernel \\r on an \\m\n" )
107 issue.write( "http://www.planet-lab.org\n\n" )
110 log.write( "Setting up authentication (non-ssh)\n" )
111 utils.sysexec_chroot( SYSIMG_PATH, "authconfig --nostart --kickstart --enablemd5 " \
112 "--enableshadow", log )
113 utils.sysexec( "sed -e 's/^root\:\:/root\:*\:/g' " \
114 "%s/etc/shadow > %s/etc/shadow.new" % \
115 (SYSIMG_PATH,SYSIMG_PATH), log )
116 utils.sysexec_chroot( SYSIMG_PATH, "mv " \
117 "/etc/shadow.new /etc/shadow", log )
118 utils.sysexec_chroot( SYSIMG_PATH, "chmod 400 /etc/shadow", log )
120 # if we are setup with dhcp, copy the current /etc/resolv.conf into
121 # the system image so we can run programs inside that need network access
124 method= vars['INTERFACE_SETTINGS']['method']
129 utils.sysexec( "cp /etc/resolv.conf %s/etc/" % SYSIMG_PATH, log )
131 log.write( "Writing node install version\n" )
132 utils.makedirs( "%s/etc/planetlab" % SYSIMG_PATH )
133 ver= file( "%s/etc/planetlab/install_version" % SYSIMG_PATH, "w" )
134 ver.write( "%s\n" % VERSION )
137 log.write( "Creating ssh host keys\n" )
138 key_gen_prog= "/usr/bin/ssh-keygen"
140 log.write( "Generating SSH1 RSA host key:\n" )
141 key_file= "/etc/ssh/ssh_host_key"
142 utils.sysexec_chroot( SYSIMG_PATH, "%s -q -t rsa1 -f %s -C '' -N ''" %
143 (key_gen_prog,key_file), log )
144 utils.sysexec( "chmod 600 %s/%s" % (SYSIMG_PATH,key_file), log )
145 utils.sysexec( "chmod 644 %s/%s.pub" % (SYSIMG_PATH,key_file), log )
147 log.write( "Generating SSH2 RSA host key:\n" )
148 key_file= "/etc/ssh/ssh_host_rsa_key"
149 utils.sysexec_chroot( SYSIMG_PATH, "%s -q -t rsa -f %s -C '' -N ''" %
150 (key_gen_prog,key_file), log )
151 utils.sysexec( "chmod 600 %s/%s" % (SYSIMG_PATH,key_file), log )
152 utils.sysexec( "chmod 644 %s/%s.pub" % (SYSIMG_PATH,key_file), log )
154 log.write( "Generating SSH2 DSA host key:\n" )
155 key_file= "/etc/ssh/ssh_host_dsa_key"
156 utils.sysexec_chroot( SYSIMG_PATH, "%s -q -t dsa -f %s -C '' -N ''" %
157 (key_gen_prog,key_file), log )
158 utils.sysexec( "chmod 600 %s/%s" % (SYSIMG_PATH,key_file), log )
159 utils.sysexec( "chmod 644 %s/%s.pub" % (SYSIMG_PATH,key_file), log )