Parsing OpenStack config files with susti

In this post I introduce my “susti” python script for easily parsing options in the “.ini” config files of OpenStack in an easy and elegant way.

Since I started working with OpenStack about one year ago, I found that the configuration files of all components have that terrible Windows-like syntax called “ini”, which I personally strongly dislike.

“ini” files contain “sections” which contain keywords, but those keywords may be repeated in several sections, providing completely independent functions. For example, if you grep the keyword “admin_password” in a nova.conf file you will get at least 3 matches, in the sections “keystone_authtoken”, “neutron” and “ironic”.

If you want to use something like sed, you will have a very hard time figuring out how to match only, and just only that “admin_password” string using complex regular expressions together with quick and dirty tricks.

The question is: Why do developers keep this syntax instead of setting options as strings with unique value within each configuration file?

IT and specially administrative tasks are supposed to have a clear logic, in order to be able to easily automate them. But well… let’s be “solution oriented” people and move on with the  susti script.

So, here is how it works. By executing:

susti /etc/keystone/keystone.conf DEFAULT "verbose = True"

  1. Set a section string with the square brackets around the parsed value
  2. Set the keyword to parse as the part before the “=” symbol in the last provided (quoted) argument.
  3. Set a search pattern to the keyword parsed, only in case the line contains a “=” symbol right after it.
  4. Start trying to parse the section:
      4.1) If the section is present in the config file and the keyword also exists and it is uncommented => substitute the line with:  keyword = “new value” and set the “match” variable to 1 (which will bypass the rest of the script). Also, if there are more (uncommented) matches for the same keyword prepend “###” at the beginning of the line, to comment them out. There are three “#” signs just to keep record of what the script commented out.
      4.2) If the section is present but the keyword is commented out => substitute
      4.3) If the section is present but the keyword is not set or commented => substitute
      4.4) If the section is not present in the config file, create it in the bottom and add the line
  5. Write the content of the modified “config_file” variable back to the original config file.

And that’s all 🙂
Once again, the version 0.1 of the susti script is in my git repository, following this link.

Leave a Reply

Your email address will not be published. Required fields are marked *