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 *
19 Write out the network configuration for this machine:
21 /etc/sysconfig/network-scripts/ifcfg-eth0
22 /etc/resolv.conf (if applicable)
23 /etc/sysconfig/network
25 It is assumed the caller mounted the root partition and the vserver partition
26 starting on SYSIMG_PATH - it is not checked here.
28 The values to be used for the network settings are to be set in vars
29 in the variable 'NETWORK_SETTINGS', which is a dictionary
32 Key Used by this function
33 -----------------------------------------------
48 Expect the following variables from the store:
49 SYSIMG_PATH the path where the system image will be mounted
50 (always starts with TEMP_PATH)
51 NETWORK_SETTINGS A dictionary of the values from the network
53 Sets the following variables:
57 log.write( "\n\nStep: Install: Writing Network Configuration files.\n" )
60 SYSIMG_PATH= vars["SYSIMG_PATH"]
62 raise ValueError, "SYSIMG_PATH"
65 raise BootManagerException, "Missing variable in vars: %s\n" % var
66 except ValueError, var:
67 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
71 network_settings= vars['NETWORK_SETTINGS']
73 raise BootManagerException, "No network settings found in vars."
76 hostname= network_settings['hostname']
77 domainname= network_settings['domainname']
78 method= network_settings['method']
79 ip= network_settings['ip']
80 gateway= network_settings['gateway']
81 network= network_settings['network']
82 netmask= network_settings['netmask']
83 dns1= network_settings['dns1']
84 mac= network_settings['mac']
86 raise BootManagerException, "Missing value %s in network settings." % str(e)
90 dns2= network_settings['dns2']
95 log.write( "Writing /etc/hosts\n" )
96 hosts_file= file("%s/etc/hosts" % SYSIMG_PATH, "w" )
97 hosts_file.write( "127.0.0.1 localhost\n" )
98 if method == "static":
99 hosts_file.write( "%s %s.%s\n" % (ip, hostname, domainname) )
104 log.write( "Writing /etc/sysconfig/network-scripts/ifcfg-eth0\n" )
105 eth0_file= file("%s/etc/sysconfig/network-scripts/ifcfg-eth0" %
107 eth0_file.write( "DEVICE=eth0\n" )
108 if method == "static":
109 eth0_file.write( "BOOTPROTO=static\n" )
110 eth0_file.write( "IPADDR=%s\n" % ip )
111 eth0_file.write( "NETMASK=%s\n" % netmask )
112 eth0_file.write( "GATEWAY=%s\n" % gateway )
114 eth0_file.write( "BOOTPROTO=dhcp\n" )
115 eth0_file.write( "DHCP_HOSTNAME=%s\n" % hostname )
117 eth0_file.write( "HWADDR=%s\n" % mac )
118 eth0_file.write( "ONBOOT=yes\n" )
119 eth0_file.write( "USERCTL=no\n" )
123 if method == "static":
124 log.write( "Writing /etc/resolv.conf\n" )
125 resolv_file= file("%s/etc/resolv.conf" % SYSIMG_PATH, "w" )
127 resolv_file.write( "nameserver %s\n" % dns1 )
129 resolv_file.write( "nameserver %s\n" % dns2 )
130 resolv_file.write( "search %s\n" % domainname )
134 log.write( "Writing /etc/sysconfig/network\n" )
135 network_file= file("%s/etc/sysconfig/network" % SYSIMG_PATH, "w" )
136 network_file.write( "NETWORKING=yes\n" )
137 network_file.write( "HOSTNAME=%s.%s\n" % (hostname, domainname) )
138 if method == "static":
139 network_file.write( "GATEWAY=%s\n" % gateway )