Added two patches from Joshua Kinard from bug #138255 to fix livecd/fsops and also...
[catalyst.git] / modules / netboot2_target.py
1 # Copyright 1999-2005 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo/src/catalyst/modules/netboot2_target.py,v 1.3 2006/06/21 22:11:54 wolf31o2 Exp $
4
5 """
6 Builder class for a netboot build, version 2
7 """
8
9 import os,string,types
10 from catalyst_support import *
11 from generic_stage_target import *
12
13 class netboot2_target(generic_stage_target):
14         def __init__(self,spec,addlargs):
15                 self.required_values=[
16                         "boot/kernel",
17                         "netboot2/builddate",
18                         "netboot2/packages",                    
19                         "netboot2/use"                  
20                 ]
21                 self.valid_values=self.required_values[:]
22                 self.valid_values.extend(self.required_values)
23                 self.valid_values.extend(["netboot2/extra_files"])
24                         
25                 try:
26                         if addlargs.has_key("netboot2/packages"):
27                                 if type(addlargs["netboot2/packages"]) == types.StringType:
28                                         loopy=[addlargs["netboot2/packages"]]
29                                 else:
30                                         loopy=addlargs["netboot2/packages"]
31
32                                 for x in loopy:
33                                         self.valid_values.append("netboot2/packages/"+x+"/files")
34                 except:
35                         raise CatalystError,"configuration error in netboot2/packages."
36                 
37                 
38
39                 generic_stage_target.__init__(self,spec,addlargs)
40                 self.set_build_kernel_vars()
41
42                 # Merge packages into the buildroot, and pick out certain files to place in
43                 # /tmp/image
44                 self.settings["merge_path"]=normpath("/tmp/image")
45
46         def set_dest_path(self):
47                 if self.settings.has_key("merge_path"):
48                         self.settings["destpath"]=normpath(self.settings["chroot_path"]+self.settings["merge_path"])
49                 else:
50                         self.settings["destpath"]=normpath(self.settings["chroot_path"])
51
52         def set_target_path(self):
53                 self.settings["target_path"]=normpath(self.settings["storedir"]+"/builds/"+\
54                         self.settings["target_subpath"]+"/")
55                 if self.settings.has_key("AUTORESUME") \
56                         and os.path.exists(self.settings["autoresume_path"]+"setup_target_path"):
57                                 print "Resume point detected, skipping target path setup operation..."
58                 else:
59                         # first clean up any existing target stuff
60                         if os.path.isfile(self.settings["target_path"]):
61                                 cmd("rm -f "+self.settings["target_path"], \
62                                         "Could not remove existing file: "+self.settings["target_path"],env=self.env)
63                                 touch(self.settings["autoresume_path"]+"setup_target_path")
64
65                 if not os.path.exists(self.settings["storedir"]+"/builds/"):
66                         os.makedirs(self.settings["storedir"]+"/builds/")
67
68         def copy_files_to_image(self):
69                 # copies specific files from the buildroot to merge_path
70                 myfiles=[]
71
72                 # check for autoresume point
73                 if self.settings.has_key("AUTORESUME") \
74                         and os.path.exists(self.settings["autoresume_path"]+"copy_files_to_image"):
75                                 print "Resume point detected, skipping target path setup operation..."
76                 else:
77                         if self.settings.has_key("netboot2/packages"):
78                                 if type(self.settings["netboot2/packages"]) == types.StringType:
79                                         loopy=[self.settings["netboot2/packages"]]
80                                 else:
81                                         loopy=self.settings["netboot2/packages"]
82                 
83                         for x in loopy:
84                                 if self.settings.has_key("netboot2/packages/"+x+"/files"):
85                                     if type(self.settings["netboot2/packages/"+x+"/files"]) == types.ListType:
86                                             myfiles.extend(self.settings["netboot2/packages/"+x+"/files"])
87                                     else:
88                                             myfiles.append(self.settings["netboot2/packages/"+x+"/files"])
89
90                         if self.settings.has_key("netboot2/extra_files"):
91                                 if type(self.settings["netboot2/extra_files"]) == types.ListType:
92                                         myfiles.extend(self.settings["netboot2/extra_files"])
93                                 else:
94                                         myfiles.append(self.settings["netboot2/extra_files"])
95
96                         try:
97                                 cmd("/bin/bash "+self.settings["controller_file"]+\
98                                         " image " + list_bashify(myfiles),env=self.env)
99                         except CatalystError:
100                                 self.unbind()
101                                 raise CatalystError,"Failed to copy files to image!"
102
103                         touch(self.settings["autoresume_path"]+"copy_files_to_image")
104
105
106         def move_kernels(self):
107                 # we're done, move the kernels to builds/*
108                 # no auto resume here as we always want the
109                 # freshest images moved
110                 try:
111                         cmd("/bin/bash "+self.settings["controller_file"]+\
112                                 " final",env=self.env)
113                         print ">>> Netboot Build Finished!"
114                 except CatalystError:
115                         self.unbind()
116                         raise CatalystError,"Failed to move kernel images!"
117
118
119         def set_action_sequence(self):
120             self.settings["action_sequence"]=["unpack","unpack_snapshot","config_profile_link",
121                                         "setup_confdir","bind","chroot_setup",\
122                                         "setup_environment","build_packages","root_overlay",\
123                                         "copy_files_to_image","build_kernel","move_kernels",\
124                                         "unbind","clean","clear_autoresume"]
125
126 def register(foo):
127         foo.update({"netboot2":netboot2_target})
128         return foo