James Cammarata wrote:
This patch is to add a new option to 'cobbler profile'
(--enable-menu=[yes|no]) that will
allow the user to specify whether or not the profile should be added to the default
PXE boot menu. The reasoning behind this is, that with the addition of memtest and
rescue PXE images, there is a real chance that a user could select the wrong menu
option and destroy a system. Also, with large numbers of profiles listed in the menu,
it
would be nice to be able to selectively trim some down.
This has also been added to /etc/cobbler/settings, to allow for a global default.
mdehaan mentioned this would need to be added to images as well, however I thought
I would do that as a separate patch (I do need to read up on images first...)
---
diff --git a/cobbler/item_profile.py b/cobbler/item_profile.py
index 238e2cb..3b8525f 100644
--- a/cobbler/item_profile.py
+++ b/cobbler/item_profile.py
@@ -44,6 +44,7 @@ class Profile(item.Item):
self.name = None
self.owners = self.settings.default_ownership
self.distro = (None,
'<<inherit>>')[is_subobject]
+ self.enable_menu = (self.settings.enable_menu,
'<<inherit>>')[is_subobject]
self.kickstart = (self.settings.default_kickstart ,
'<<inherit>>')[is_subobject]
self.kernel_options = ({},
'<<inherit>>')[is_subobject]
self.kernel_options_post = ({},
'<<inherit>>')[is_subobject]
@@ -70,6 +71,7 @@ class Profile(item.Item):
self.name = self.load_item(seed_data,'name')
self.owners =
self.load_item(seed_data,'owners',self.settings.default_ownership)
self.distro = self.load_item(seed_data,'distro')
+ self.enable_menu = self.load_item(seed_data,'enable_menu')
self.kickstart = self.load_item(seed_data,'kickstart')
self.kernel_options = self.load_item(seed_data,'kernel_options')
self.kernel_options_post =
self.load_item(seed_data,'kernel_options_post')
@@ -148,6 +150,19 @@ class Profile(item.Item):
return True
raise CX(_("distribution not found"))
+ def set_enable_menu(self,enable_menu):
+ """
+ Sets whether or not the profile will be listed in the default
+ PXE boot menu. This is pretty forgiving for YAML's sake.
+ """
+ if type(enable_menu) == bool:
+ self.enable_menu = enable_menu
+ elif str(enable_menu).lower() in
["yes","y","on","1","true"]:
+ self.enable_menu = True
+ else:
+ self.enable_menu = False
+ return True
+
def set_dhcp_tag(self,dhcp_tag):
self.dhcp_tag = dhcp_tag
return True
@@ -232,6 +247,7 @@ class Profile(item.Item):
'name' : self.name,
'owners' : self.owners,
'distro' : self.distro,
+ 'enable_menu' : self.enable_menu,
'kickstart' : self.kickstart,
'kernel_options' : self.kernel_options,
'kernel_options_post' : self.kernel_options_post,
@@ -259,6 +275,7 @@ class Profile(item.Item):
buf = buf + _("parent : %s\n") % self.parent
else:
buf = buf + _("distro : %s\n") % self.distro
+ buf = buf + _("enable_menu : %s\n") % self.enable_menu
buf = buf + _("dhcp tag : %s\n") % self.dhcp_tag
buf = buf + _("kernel options : %s\n") % self.kernel_options
buf = buf + _("post kernel options : %s\n") %
self.kernel_options_post
@@ -283,6 +300,7 @@ class Profile(item.Item):
'parent' : self.set_parent,
'profile' : self.set_name,
'distro' : self.set_distro,
+ 'enable_menu' : self.set_enable_menu,
'kickstart' : self.set_kickstart,
'kopts' : self.set_kernel_options,
'kopts-post' : self.set_kernel_options_post,
diff --git a/cobbler/modules/cli_profile.py b/cobbler/modules/cli_profile.py
index 8831b6e..acdff40 100644
--- a/cobbler/modules/cli_profile.py
+++ b/cobbler/modules/cli_profile.py
@@ -56,6 +56,7 @@ class ProfileFunction(commands.CobblerFunction):
p.add_option("--inherit", dest="inherit",
help="inherit from this profile name, defaults to no")
if not self.matches_args(args,["find"]):
p.add_option("--in-place",action="store_true",
dest="inplace", default=False, help="edit items in kopts, kopts_post or
ksmeta without clearing the other items")
+ p.add_option("--enable-menu", dest="enable_menu",
help="yes/no. When yes, adds profile to default PXE menu")
p.add_option("--kickstart", dest="kickstart",
help="absolute path to kickstart template (RECOMMENDED)")
p.add_option("--ksmeta", dest="ksmeta",
help="ex: 'blippy=7'")
p.add_option("--kopts", dest="kopts",
help="ex: 'noipv6'")
@@ -108,6 +109,7 @@ class ProfileFunction(commands.CobblerFunction):
if not self.matches_args(self.args,["dumpvars","getks"]):
if self.options.inherit: obj.set_parent(self.options.inherit)
if self.options.distro: obj.set_distro(self.options.distro)
+ if self.options.enable_menu:
obj.set_enable_menu(self.options.enable_menu)
if self.options.kickstart: obj.set_kickstart(self.options.kickstart)
if self.options.kopts:
obj.set_kernel_options(self.options.kopts,self.options.inplace)
if self.options.kopts_post:
obj.set_kernel_options_post(self.options.kopts_post,self.options.inplace)
diff --git a/cobbler/pxegen.py b/cobbler/pxegen.py
index 7d12d95..da33aaf 100644
--- a/cobbler/pxegen.py
+++ b/cobbler/pxegen.py
@@ -261,6 +261,9 @@ class PXEGen:
# build out the menu entries
pxe_menu_items = ""
for profile in profile_list:
+ if type(profile.enable_menu) == bool and not profile.enable_menu:
+ # This profile has been excluded from the menu
+ continue
distro = profile.get_conceptual_parent()
# xen distros can be ruled out as they won't boot
if distro.name.find("-xen") != -1:
diff --git a/cobbler/settings.py b/cobbler/settings.py
index b9356f6..b6e490e 100644
--- a/cobbler/settings.py
+++ b/cobbler/settings.py
@@ -44,6 +44,7 @@ DEFAULTS = {
"dhcpd_bin" : "/usr/sbin/dhcpd",
"dnsmasq_bin" : "/usr/sbin/dnsmasq",
"dnsmasq_conf" : "/etc/dnsmasq.conf",
+ "enable_menu" : 1,
"httpd_bin" : "/usr/sbin/httpd",
"http_port" : "80",
"isc_set_host_name" : 0,
diff --git a/config/settings b/config/settings
index 533f121..887f585 100644
--- a/config/settings
+++ b/config/settings
@@ -43,6 +43,11 @@ default_virt_ram: 512
# owner and/or group. Can be a comma seperated list.
default_ownership: "admin"
+# if 1, cobbler will add the profile entry to the default
+# PXE boot menu. This can be over-ridden on a per-profile
+# basis when adding/editing profiles
+enable_menu: 1
+
# location for some important binaries and config files
# that can vary based on the distribution.
dhcpd_bin: /usr/sbin/dhcpd
Both are applied, works very well, thanks!
I also added the new setting to the Web app. Thinking about it, I don't
think we need to add this to images as the point of this is to be able
to remove menu items from the PXE menu to keep users from inadvertently
reinstalling and so forth. Though if people have too many images
(unlikely?) eventually someone may want to add that. It should be easy
to follow this pattern in this case if we want to add it.
Nice feature!
--Michael