Comment 3 for bug 1196084

Revision history for this message
Mark McLoughlin (markmc) wrote :

Look at the way register_deprecated() works in the nicira plugin to get an idea of how to implement this somewhat sanely

Basically, the only reason you want to parse these files directly is to get the list of [NEXUS_SWITCH:<ip>] sections

Once you've got the list of IPs, you can do e.g.

  nexus_opts = [
     cfg.StrOpt('username'),
    ...
  ]

  def _read_nexus_switch_config(conf, ip, nexus_dict):
       group_name = 'nexus_switch:' + ip
       conf.register_opts(nexus_opts, group=group_name)
       for key, value in conf[group_name].items():
           nexus_dict[(ip, key)] = value

  def _read_nexus_config(conf):
      multi_parser = cfg.MultiConfigParser()
      read_ok = multi_parser.read(conf.config_file)
      if len(read_ok) != len(conf.config_file):
          raise cfg.Error("Some config files were not parsed properly")

     nexus_dict = {}

      for parsed_file in multi_parser.parsed:
          for section in parsed_file.keys():
              if not section.lower().startswith("nexus_switch:"):
                  continue

              ip = section.split(':', 1)[1]

              _read_nexus_switch_config(conf, ip, nexus_dict):