This repository has been archived by the owner on Dec 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pxelinux_boot_label.py
101 lines (87 loc) · 3.65 KB
/
pxelinux_boot_label.py
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
# boot_label.py
#
# Copyright (C) 2008, 2010 Fabian Knittel <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
import textwrap
class BootLabel(object):
SPACES = ' ' * 8
def __init__(self, name, desc = None, default = False, help = None,
disabled = False, password = None, indent = None):
self.name = name
self.desc = desc
self.default = default
self.help = help
self.disabled = disabled
self.password = password
self.indent = indent
def dump(self):
"""Template method for sub-classes. Dumps specific label data."""
return ''
def __str__(self):
str = "LABEL %s\n" % self.name
if self.desc is not None:
str += self.SPACES + "MENU LABEL %s\n" % self.desc
if self.indent is not None:
str += self.SPACES + "MENU INDENT %d\n" % self.indent
if self.password is not None:
str += self.SPACES + "MENU PASSWD %s\n" % self.password
if self.help is not None:
str += self.SPACES + "TEXT HELP\n"
str += textwrap.fill(self.help, initial_indent = self.SPACES,
subsequent_indent = self.SPACES) + "\n"
str += self.SPACES + "ENDTEXT\n"
str += self.dump()
if self.disabled:
str += self.SPACES + "MENU DISABLE\n"
elif self.default:
str += self.SPACES + "MENU DEFAULT\n"
str += "\n"
return str
class SeparatorBootLabel(BootLabel):
def __init__(self, name = '', disabled = True, **kwargs):
BootLabel.__init__(self, name, disabled = disabled, **kwargs)
def __str__(self):
str = "MENU SEPARATOR\n\n"
str += BootLabel.__str__(self)
return str
class LocalBootLabel(BootLabel):
def dump(self):
return self.SPACES + "localboot 0\n"
class KernelBootLabel(BootLabel):
def __init__(self, name, kernel, append=None, **kwargs):
BootLabel.__init__(self, name, **kwargs)
self.kernel = kernel
self.append = append
def dump(self):
str = self.SPACES + "KERNEL %s\n" % self.kernel
if self.append:
str += self.SPACES + "APPEND %s\n" % self.append
return str
class ChainBootLabel(KernelBootLabel):
def __init__(self, name, hd, part, **kwargs):
KernelBootLabel.__init__(self, name, kernel='chain.c32',
append='%s %d' % (hd, part), **kwargs)
class LinuxBootLabel(KernelBootLabel):
def __init__(self, name, kernel, initrd, append='', **kwargs):
KernelBootLabel.__init__(self, name, kernel=kernel,
append='initrd=%s %s' % (initrd, append), **kwargs)
class LinuxNfsRootBootLabel(LinuxBootLabel):
def __init__(self, name, kernel, initrd, append, nfsroot,
ramdisk_size = 14332, **kwargs):
append = "ramdisk_size=%d root=/dev/nfs nfsroot=%s ip=dhcp %s" % \
(ramdisk_size, nfsroot, append)
LinuxBootLabel.__init__(self, name, kernel, initrd, append, **kwargs)
# vim:set ft=python sw=4 et: