1 # Copyright (c) 2003 Intel Corporation
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above
12 # copyright notice, this list of conditions and the following
13 # disclaimer in the documentation and/or other materials provided
14 # with the distribution.
16 # * Neither the name of the Intel Corporation nor the names of its
17 # contributors may be used to endorse or promote products derived
18 # from this software without specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
24 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 # EXPORT LAWS: THIS LICENSE ADDS NO RESTRICTIONS TO THE EXPORT LAWS OF
33 # YOUR JURISDICTION. It is licensee's responsibility to comply with any
34 # export regulations applicable in licensee's jurisdiction. Under
35 # CURRENT (May 2000) U.S. export regulations this software is eligible
36 # for export from the U.S. and can be downloaded by or otherwise
37 # exported or reexported worldwide EXCEPT to U.S. embargoed destinations
38 # which include Cuba, Iraq, Libya, North Korea, Iran, Syria, Sudan,
39 # Afghanistan and any other country to which the U.S. has embargoed
46 from Exceptions import *
50 # if this file is present in the vservers /etc directory,
51 # the resolv.conf and hosts files will automatically be updated
53 UPDATE_FILE_FLAG= "AUTO_UPDATE_NET_FILES"
55 # the name of the vserver-reference directory
56 VSERVER_REFERENCE_DIR_NAME='vserver-reference'
61 Setup directories for building vserver reference image.
63 Except the following variables from the store:
64 SYSIMG_PATH the path where the system image will be mounted
65 (always starts with TEMP_PATH)
66 NETWORK_SETTINGS A dictionary of the values from the network
69 Sets the following variables:
74 log.write( "\n\nStep: Install: Setting up VServer image.\n" )
76 # make sure we have the variables we need
78 SYSIMG_PATH= vars["SYSIMG_PATH"]
80 raise ValueError, "SYSIMG_PATH"
82 NETWORK_SETTINGS= vars["NETWORK_SETTINGS"]
83 if NETWORK_SETTINGS == "":
84 raise ValueError, "NETWORK_SETTINGS"
87 raise BootManagerException, "Missing variable in vars: %s\n" % var
88 except ValueError, var:
89 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
91 vserver_ref_dir= "/vservers/vserver-reference"
92 full_vserver_ref_path= "%s/%s" % (SYSIMG_PATH,vserver_ref_dir)
94 utils.makedirs( full_vserver_ref_path )
95 utils.makedirs( "%s/etc" % full_vserver_ref_path )
97 log.write( "Setting permissions on directories\n" )
98 utils.sysexec( "chmod 0000 %s/vservers/" % SYSIMG_PATH, log )
104 def update_vserver_network_files( vserver_dir, vars, log ):
106 Update the /etc/resolv.conf and /etc/hosts files in the specified
107 vserver directory. If the files do not exist, write them out. If they
108 do exist, rewrite them with new values if the file UPDATE_FILE_FLAG
109 exists it /etc. if this is called with the vserver-reference directory,
110 always update the network config files and create the UPDATE_FILE_FLAG.
112 This is currently called when setting up the initial vserver reference,
113 and later when nodes boot to update existing vserver images.
115 Expect the following variables from the store:
116 SYSIMG_PATH the path where the system image will be mounted
117 (always starts with TEMP_PATH)
118 NETWORK_SETTINGS A dictionary of the values from the network
123 SYSIMG_PATH= vars["SYSIMG_PATH"]
124 if SYSIMG_PATH == "":
125 raise ValueError, "SYSIMG_PATH"
127 NETWORK_SETTINGS= vars["NETWORK_SETTINGS"]
128 if NETWORK_SETTINGS == "":
129 raise ValueError, "NETWORK_SETTINGS"
131 except KeyError, var:
132 raise BootManagerException, "Missing variable in vars: %s\n" % var
133 except ValueError, var:
134 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
137 ip= NETWORK_SETTINGS['ip']
138 method= NETWORK_SETTINGS['method']
139 hostname= NETWORK_SETTINGS['hostname']
140 domainname= NETWORK_SETTINGS['domainname']
141 except KeyError, var:
142 raise BootManagerException, \
143 "Missing network value %s in var NETWORK_SETTINGS\n" % var
146 os.listdir(vserver_dir)
148 log.write( "Directory %s does not exist to write network conf in.\n" %
152 file_path= "%s/etc/%s" % (vserver_dir,UPDATE_FILE_FLAG)
154 if os.access(file_path,os.F_OK):
158 if vserver_dir.find(VSERVER_REFERENCE_DIR_NAME) != -1:
159 log.write( "Forcing update on vserver-reference directory:\n%s\n" %
161 utils.sysexec_noerr( "echo '%s' > %s/etc/%s" %
162 (UPDATE_FILE_FLAG,vserver_dir,UPDATE_FILE_FLAG),
168 log.write( "Updating network files in %s.\n" % vserver_dir )
170 file_path= "%s/etc/hosts" % vserver_dir
171 hosts_file= file(file_path, "w" )
172 hosts_file.write( "127.0.0.1 localhost\n" )
173 if method == "static":
174 hosts_file.write( "%s %s.%s\n" % (ip, hostname, domainname) )
179 file_path= "%s/etc/resolv.conf" % vserver_dir
181 # copy the resolv.conf from the boot cd env.
182 utils.sysexec( "cp /etc/resolv.conf %s/etc" % vserver_dir, log )
184 # copy the generated resolv.conf from the system image, since
185 # we generated it via static settings
186 utils.sysexec( "cp %s/etc/resolv.conf %s/etc" % \
187 (SYSIMG_PATH,vserver_dir), log )