Skip to content
Browse files

Add setting to enable/disable dynamic settings changes

Adding cobblersettings.aug to distributed files, since we need a copy that doesn't insert tabs
Added a "cobbler check" that checks if dynamic settings is enabled and prints a sed command to cleanup the settings file spacing/indents
  • Loading branch information...
1 parent 0b99662 commit 6a8e9938a616078d943b0d7f9e5610ca49a491e9 @jimi-c jimi-c committed
Showing with 105 additions and 1 deletion.
  1. +16 −0 cobbler/action_check.py
  2. +6 −1 cobbler/cli.py
  3. +1 −0 cobbler/settings.py
  4. +6 −0 config/settings
  5. +72 −0 misc/augeas/cobblersettings.aug
  6. +4 −0 setup.py
View
16 cobbler/action_check.py
@@ -94,6 +94,7 @@ def run(self):
self.check_for_unreferenced_repos(status)
self.check_for_unsynced_repos(status)
self.check_for_cman(status)
+ self.check_dynamic_settings(status)
return status
@@ -435,3 +436,18 @@ def check_dhcpd_conf(self,status):
else:
status.append(_("missing file: %(file)s") % { "file" : self.settings.dhcpd_conf })
+ def check_dynamic_settings(self,status):
+ """
+ Checks to see if the settings file is spaced cleanly
+ so that the augeas lens will rewrite it without corrupting
+ the YAML format. Only applies if the setting
+ allow_dynamic_settings = 1
+ """
+ try:
+ if self.settings.allow_dynamic_settings != 1:
+ return
+ else:
+ status.append(_("Dynamic settings changes are enabled, be sure you run \"sed -i 's/^[[:space:]]\+/ /' /etc/cobbler/settings\" to ensure the settings file is properly indented"))
+ except:
+ pass
+ return
View
7 cobbler/cli.py
@@ -321,7 +321,12 @@ def object_command(self, object_type, object_action):
if object_action in [ "add", "edit", "copy", "rename", "remove" ]:
try:
if object_type == "setting":
- if self.remote.modify_setting(options.name,options.value,self.token):
+ settings = self.remote.get_settings()
+ if not settings.get('allow_dynamic_settings',False):
+ raise RuntimeError("Dynamic settings changes are not enabled. Change the allow_dynamic_settings to 1 and restart cobblerd to enable dynamic settings changes")
+ elif options.name == 'allow_dynamic_settings':
+ raise RuntimeError("Cannot modify that setting live")
+ elif self.remote.modify_setting(options.name,options.value,self.token):
raise RuntimeError("Changing the setting failed")
else:
self.remote.xapi_object_edit(object_type, options.name, object_action, utils.strip_none(vars(options), omit_none=True), self.token)
View
1 cobbler/settings.py
@@ -38,6 +38,7 @@
"allow_duplicate_hostnames" : [0,"bool"],
"allow_duplicate_macs" : [0,"bool"],
"allow_duplicate_ips" : [0,"bool"],
+ "allow_dynamic_settings" : [0,"bool"],
"bind_chroot_path" : ["","str"],
"bind_master" : ["127.0.0.1","str"],
"build_reporting_enabled" : [0,"bool"],
View
6 config/settings
@@ -19,6 +19,12 @@ allow_duplicate_ips: 0
# this is undesirable.
allow_duplicate_macs: 0
+# if 1, cobbler will allow settings to be changed dynamically without
+# a restart of the cobblerd daemon. You can only change this variable
+# by manually editing the settings file, and you MUST restart cobblerd
+# after changing it.
+allow_dynamic_settings: 0
+
# by default, installs are *not* set to send installation logs to the cobbler
# # # server. With 'anamon_enabled', kickstart templates may use the pre_anamon
# # # snippet to allow remote live monitoring of their installations from the
View
72 misc/augeas/cobblersettings.aug
@@ -0,0 +1,72 @@
+(*
+ Parse the /etc/cobbler/settings file which is in
+ YAML 1.0 format.
+
+ The lens can handle the following contructs
+ * key: value
+ * key: "value"
+ * key: 'value'
+ * key: [value1, value2]
+ * key:
+ - value1
+ - value2
+ * key:
+ key2: value1
+ key3: value2
+
+ Author: Bryan Kearney
+
+ About: License
+ This file is licensed under the LGPLv2+, like the rest of Augeas.
+*)
+module CobblerSettings =
+ autoload xfm
+
+ let kw = /[a-zA-Z0-9_]+/
+ (* TODO Would be better if this stripped off the "" and '' chracters *)
+ let kv = /([^]['", \n#:@-]+|"[^"\n]*"|'[^'\n]*')/
+
+ let lbr = del /\[/ "["
+ let rbr = del /\]/ "]"
+ let colon = del /[ \t]*:[ \t]*/ ": "
+ let dash = del /-[ \t]*/ "- "
+ (* let comma = del /,[ \t]*(\n[ \t]+)?/ ", " *)
+ let comma = del /[ \t]*,[ \t]*/ ", "
+
+ let eol_only = del /\n/ "\n"
+
+ (* TODO Would be better to make items a child of a document *)
+ let docmarker = /-{3}/
+
+ let eol = Util.eol
+ let comment = Util.comment
+ let empty = Util.empty
+ let indent = del /^[ \t]+/ " "
+ let ws = del /[ \t]*/ " "
+
+ let value_list = Build.opt_list [label "item" . store kv] comma
+ let setting = [key kw . colon . store kv] . eol
+ let simple_setting_suffix = store kv . eol
+ let setting_list_suffix = [label "sequence" . lbr . ws . (value_list . ws)? . rbr ] . eol
+ let indendented_setting_list_suffix = eol_only . (indent . setting)+
+ let indented_list_suffix = [label "list" . eol_only . ([ label "value" . indent . dash . store kv] . eol)+]
+
+ (* Break out setting because of a current bug in augeas *)
+ let nested_setting = [key kw . colon . (
+ (* simple_setting_suffix | *)
+ setting_list_suffix |
+ indendented_setting_list_suffix |
+ indented_list_suffix
+ )
+ ]
+
+ let document = [label "---" . store docmarker] . eol
+
+ let lns = (document | comment | empty | setting | nested_setting )*
+
+ let xfm = transform lns (incl "/etc/cobbler/settings")
+
+
+(* Local Variables: *)
+(* mode: caml *)
+(* End: *)
View
4 setup.py
@@ -166,6 +166,7 @@ def run(self):
initpath = "/etc/init.d/"
libpath = "/var/lib/cobbler/"
logpath = "/var/log/"
+ augeaspath = "/usr/share/augeas/lenses/"
if os.path.exists("/etc/SuSE-release"):
webconfig = "/etc/apache2/conf.d"
@@ -238,6 +239,9 @@ def run(self):
("%spower" % etcpath, ["templates/power/*"]),
("%sldap" % etcpath, ["templates/ldap/*"]),
+ #Miscellaneous Files
+ ("%s" % augeaspath, ["misc/augeas/*"]),
+
#Build empty directories to hold triggers
("%striggers/add/distro/pre" % libpath, []),
("%striggers/add/distro/post" % libpath, []),

0 comments on commit 6a8e993

Please sign in to comment.
Something went wrong with that request. Please try again.