Rename the modules subpkg to targets, to better reflect what it contains.
[catalyst.git] / catalyst / targets / netboot_target.py
1 """
2 netboot target, version 1
3 """
4 # NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
5
6 import os,string,types
7 from catalyst.support import *
8 from generic_stage_target import *
9
10 class netboot_target(generic_stage_target):
11         """
12         Builder class for a netboot build.
13         """
14         def __init__(self,spec,addlargs):
15                 self.valid_values = [
16                         "netboot/kernel/sources",
17                         "netboot/kernel/config",
18                         "netboot/kernel/prebuilt",
19
20                         "netboot/busybox_config",
21
22                         "netboot/extra_files",
23                         "netboot/packages"
24                 ]
25                 self.required_values=[]
26
27                 try:
28                         if "netboot/packages" in addlargs:
29                                 if type(addlargs["netboot/packages"]) == types.StringType:
30                                         loopy=[addlargs["netboot/packages"]]
31                                 else:
32                                         loopy=addlargs["netboot/packages"]
33
34                 #       for x in loopy:
35                 #               self.required_values.append("netboot/packages/"+x+"/files")
36                 except:
37                         raise CatalystError,"configuration error in netboot/packages."
38
39                 generic_stage_target.__init__(self,spec,addlargs)
40                 self.set_build_kernel_vars(addlargs)
41                 if "netboot/busybox_config" in addlargs:
42                         file_locate(self.settings, ["netboot/busybox_config"])
43
44                 # Custom Kernel Tarball --- use that instead ...
45
46                 # unless the user wants specific CFLAGS/CXXFLAGS, let's use -Os
47
48                 for envvar in "CFLAGS", "CXXFLAGS":
49                         if envvar not in os.environ and envvar not in addlargs:
50                                 self.settings[envvar] = "-Os -pipe"
51
52         def set_root_path(self):
53                 # ROOT= variable for emerges
54                 self.settings["root_path"]=normpath("/tmp/image")
55                 print "netboot root path is "+self.settings["root_path"]
56
57 #       def build_packages(self):
58 #               # build packages
59 #               if "netboot/packages" in self.settings:
60 #                       mypack=list_bashify(self.settings["netboot/packages"])
61 #               try:
62 #                       cmd("/bin/bash "+self.settings["controller_file"]+" packages "+mypack,env=self.env)
63 #               except CatalystError:
64 #                       self.unbind()
65 #                       raise CatalystError,"netboot build aborting due to error."
66
67         def build_busybox(self):
68                 # build busybox
69                 if "netboot/busybox_config" in self.settings:
70                         mycmd = self.settings["netboot/busybox_config"]
71                 else:
72                         mycmd = ""
73                 try:
74                         cmd("/bin/bash "+self.settings["controller_file"]+" busybox "+ mycmd,env=self.env)
75                 except CatalystError:
76                         self.unbind()
77                         raise CatalystError,"netboot build aborting due to error."
78
79         def copy_files_to_image(self):
80                 # create image
81                 myfiles=[]
82                 if "netboot/packages" in self.settings:
83                         if type(self.settings["netboot/packages"]) == types.StringType:
84                                 loopy=[self.settings["netboot/packages"]]
85                         else:
86                                 loopy=self.settings["netboot/packages"]
87
88                 for x in loopy:
89                         if "netboot/packages/"+x+"/files" in self.settings:
90                             if type(self.settings["netboot/packages/"+x+"/files"]) == types.ListType:
91                                     myfiles.extend(self.settings["netboot/packages/"+x+"/files"])
92                             else:
93                                     myfiles.append(self.settings["netboot/packages/"+x+"/files"])
94
95                 if "netboot/extra_files" in self.settings:
96                         if type(self.settings["netboot/extra_files"]) == types.ListType:
97                                 myfiles.extend(self.settings["netboot/extra_files"])
98                         else:
99                                 myfiles.append(self.settings["netboot/extra_files"])
100
101                 try:
102                         cmd("/bin/bash "+self.settings["controller_file"]+\
103                                 " image " + list_bashify(myfiles),env=self.env)
104                 except CatalystError:
105                         self.unbind()
106                         raise CatalystError,"netboot build aborting due to error."
107
108         def create_netboot_files(self):
109                 # finish it all up
110                 try:
111                         cmd("/bin/bash "+self.settings["controller_file"]+" finish",env=self.env)
112                 except CatalystError:
113                         self.unbind()
114                         raise CatalystError,"netboot build aborting due to error."
115
116                 # end
117                 print "netboot: build finished !"
118
119         def set_action_sequence(self):
120             self.settings["action_sequence"]=["unpack","unpack_snapshot",
121                                         "config_profile_link","setup_confdir","bind","chroot_setup",\
122                                                 "setup_environment","build_packages","build_busybox",\
123                                                 "build_kernel","copy_files_to_image",\
124                                                 "clean","create_netboot_files","unbind","clear_autoresume"]
125
126 def register(foo):
127         foo.update({"netboot":netboot_target})
128         return foo