1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
"""
A cobbler distribution. A distribution is a kernel, and initrd, and potentially
some kernel options.
Copyright 2006, Red Hat, Inc
Michael DeHaan <mdehaan@redhat.com>
This software may be freely redistributed under the terms of the GNU
general public license.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
"""
import utils
import item
import weakref
import os
import cexceptions
class Distro(item.Item):
def __init__(self,config):
"""
Constructor. Requires a back reference to the Config management object.
"""
self.config = config
self.clear()
def clear(self):
"""
Reset this object.
"""
self.name = None
self.kernel = None
self.initrd = None
self.kernel_options = ""
self.ks_meta = ""
def from_datastruct(self,seed_data):
"""
Modify this object to take on values in seed_data
"""
self.name = seed_data['name']
self.kernel = seed_data['kernel']
self.initrd = seed_data['initrd']
self.kernel_options = seed_data['kernel_options']
self.ks_meta = seed_data['ks_meta']
return self
def set_kernel(self,kernel):
"""
Specifies a kernel. The kernel parameter is a full path, a filename
in the configured kernel directory (set in /etc/cobbler.conf) or a
directory path that would contain a selectable kernel. Kernel
naming conventions are checked, see docs in the utils module
for find_kernel.
"""
if utils.find_kernel(kernel):
self.kernel = kernel
return True
raise cexceptions.CobblerException("no_kernel")
def set_initrd(self,initrd):
"""
Specifies an initrd image. Path search works as in set_kernel.
File must be named appropriately.
"""
if utils.find_initrd(initrd):
self.initrd = initrd
return True
raise cexceptions.CobblerException("no_initrd")
def is_valid(self):
"""
A distro requires that the kernel and initrd be set. All
other variables are optional.
"""
for x in (self.name,self.kernel,self.initrd):
if x is None: return False
return True
def to_datastruct(self):
"""
Return a serializable datastructure representation of this object.
"""
return {
'name': self.name,
'kernel': self.kernel,
'initrd' : self.initrd,
'kernel_options' : self.kernel_options,
'ks_meta' : self.ks_meta
}
def printable(self, id):
"""
Human-readable representation.
"""
kstr = utils.find_kernel(self.kernel)
istr = utils.find_initrd(self.initrd)
if kstr is None:
kstr = "%s (NOT FOUND)" % self.kernel
elif os.path.isdir(self.kernel):
kstr = "%s (FOUND BY SEARCH)" % kstr
if istr is None:
istr = "%s (NOT FOUND)" % self.initrd
elif os.path.isdir(self.initrd):
istr = "%s (FOUND BY SEARCH)" % istr
buf = "distro %-4s : %s\n" % (id, self.name)
buf = buf + "kernel : %s\n" % kstr
buf = buf + "initrd : %s\n" % istr
buf = buf + "kernel options : %s\n" % self.kernel_options
buf = buf + "ks metadata : %s\n" % self.ks_meta
return buf
|